root/lm-sensors/tags/V2-10-5/Makefile

Revision 4738, 16.2 kB (checked in by khali, 1 year ago)

Fix kernel version detection (#2187).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 #  Makefile - Makefile for a Linux module for reading sensor data.
2 #  Copyright (c) 1998, 1999  Frodo Looijaard <frodol@dds.nl>
3 #
4 #  This program is free software; you can redistribute it and/or modify
5 #  it under the terms of the GNU General Public License as published by
6 #  the Free Software Foundation; either version 2 of the License, or
7 #  (at your option) any later version.
8 #
9 #  This program is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #  GNU General Public License for more details.
13 #
14 #  You should have received a copy of the GNU General Public License
15 #  along with this program; if not, write to the Free Software
16 #  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 # Everything you may want to change is in the top of this file. Usually, you
19 # can just use the defaults, fortunately.
20
21 # You need a full complement of GNU utilities to run this Makefile
22 # successfully; most notably, you need bash, GNU make, flex (>= 2.5.1)
23 # and bison.
24
25 # If your /bin/sh is not bash, change the below definition so that make can
26 # find bash. Or you can hope your sh-like shell understands all scripts.
27 # I think so, but I have not tested it.
28 #SHELL := /usr/bin/bash
29
30 # The currently running kernel version. This is used right below to
31 # determine where the kernel sources can be found.
32 KERNELVERSION := $(shell uname -r)
33
34 # The location of linux itself. This is used to find the kernel headers
35 # and other things.
36 #LINUX := /usr/src/linux
37 LINUX := $(shell if [ -L "/lib/modules/$(KERNELVERSION)/build" ] ; \
38         then echo "/lib/modules/$(KERNELVERSION)/build" ; \
39         else echo "/usr/src/linux" ; fi)
40 LINUX_HEADERS := $(LINUX)/include
41
42 # If you have installed the i2c header at some other place (like
43 # /usr/local/include/linux), set that directory here. Please check this out
44 # if you get strange compilation errors; the default Linux i2c headers
45 # may be used mistakenly. Note: This should point to the directory
46 # *above* the linux/ subdirectory, so to /usr/local/include in the
47 # above example.
48 I2C_HEADERS := /usr/local/include
49 #I2C_HEADERS := $(LINUX_HEADERS)
50
51 ifneq ($(MAKECMDGOALS),user)
52 ifneq ($(MAKECMDGOALS),user_install)
53 ifneq ($(MAKECMDGOALS),user_uninstall)
54 SMP := $(shell if grep -q '^[[:space:]]*\#define[[:space:]]*CONFIG_SMP[[:space:]]*1' $(LINUX_HEADERS)/linux/autoconf.h ; \
55                then echo 1; else echo 0; fi)
56 MODVER := $(shell if grep -q '^[[:space:]]*\#define[[:space:]]*CONFIG_MODVERSIONS[[:space:]]*1' $(LINUX_HEADERS)/linux/autoconf.h ; \
57                   then echo 1; else echo 0; fi)
58 endif
59 endif
60 endif
61
62 # Uncomment the second line if you are a developer. This will enable many
63 # additional warnings at compile-time
64 WARN := 0
65 #WARN := 1
66
67 # Uncomment the second line if you want to get (loads of) debug information
68 # at run-time.
69 # Not recommended, unless you are actually debugging the code
70 DEBUG := 0
71 #DEBUG := 1
72
73 # If you want to install at some other place then at from which you will run
74 # everything, set DESTDIR to the extra prefix.
75 DESTDIR :=
76
77 # This is the prefix that will be used for almost all directories below.
78 PREFIX := /usr/local
79
80 # Your C compiler
81 CC := gcc
82
83 # This is the main modules directory into which the modules will be installed.
84 # The magic invocation will return something like this:
85 #   /lib/modules/2.4.29
86 ifneq (,$(findstring /2.4., /$(KERNELVERSION)))
87         UTSRELEASE := $(shell $(CC) -I$(LINUX_HEADERS) -E etc/config.c | grep uts_release | cut -f 2 -d'"')
88         MODPREF := /lib/modules/$(UTSRELEASE)
89 endif
90
91 # When building userspace for use with 2.4.x series kernels, we turn off
92 # sysfs support by default.  You can override this (e.g. if you want
93 # to build binaries that work for both 2.4.x, and 2.6.x and above)
94 # by uncommenting the line after the next endif.  Keep in mind, if and only
95 # if you do this: you will need to install the libsysfs libraries on your
96 # kernel 2.4.x systems also.
97 ifeq (,$(findstring /2.4., /$(KERNELVERSION)))
98         SYSFS_SUPPORT := 1
99 else
100         SYSFS_SUPPORT :=
101 endif
102 #SYSFS_SUPPORT := 1
103
104 # Prevent 2.6+ users from using improper targets, as this won't work.
105 ifeq (,$(findstring /2.4., /$(KERNELVERSION)))
106     ifeq (, $(MAKECMDGOALS))
107         $(error For 2.6 kernels and later, use "make user")
108     endif
109     ifeq (install, $(MAKECMDGOALS))
110         $(error For 2.6 kernels and later, use "make user_install")
111     endif
112 endif
113
114 # This is the directory where sensors.conf will be installed, if no other
115 # configuration file is found
116 ETCDIR := /etc
117
118 # You should not need to change this. It is the directory into which the
119 # library files (both static and shared) will be installed.
120 LIBDIR := $(PREFIX)/lib
121
122 EXLDFLAGS := -Wl,-rpath,$(LIBDIR)
123
124 # You should not need to change this. It is the directory into which the
125 # executable program files will be installed. BINDIR for programs that are
126 # also useful for normal users, SBINDIR for programs that can only be run
127 # by the superuser.
128 # Note that not all programs in this package are really installed;
129 # some are just examples. You can always install them by hand, of
130 # course.
131 BINDIR := $(PREFIX)/bin
132 SBINDIR := $(PREFIX)/sbin
133
134 # You should not need to change this. It is the basic directory into which
135 # include files will be installed. The actual directory will be
136 # $(INCLUDEDIR)/linux for system include files, and $(INCLUDEDIR)/sensors
137 # for library include files. If PREFIX equals the default /usr/local,
138 # you will be able to use '#include <linux/sensors.h>' regardless of the
139 # current kernel selected.
140 INCLUDEDIR := $(PREFIX)/include
141 SYSINCLUDEDIR := $(INCLUDEDIR)/linux
142 LIBINCLUDEDIR := $(INCLUDEDIR)/sensors
143
144 # You should not need to change this. It is the base directory under which the
145 # manual pages will be installed.
146 MANDIR := $(PREFIX)/man
147
148 MACHINE := $(shell uname -m)
149
150 # Extra non-default programs to build; e.g., sensord
151 # PROG_EXTRA := sensord
152
153 # Set these to add preprocessor or compiler flags, or use
154 # environment variables
155 # CFLAGS :=
156 # CPPFLAGS :=
157
158 ##################################################
159 # Below this, nothing should need to be changed. #
160 ##################################################
161
162 # Note that this is a monolithic Makefile; it calls no sub-Makefiles,
163 # but instead, it compiles everything right from here. Yes, there are
164 # some distinct advantages to this; see the following paper for more info:
165 #   http://www.tip.net.au/~millerp/rmch/recu-make-cons-harm.html
166 # Note that is still uses Makefile fragments in sub-directories; these
167 # are called 'Module.mk'.
168
169 # Within each Module.mk, rules and dependencies can be added to targets
170 # all, install and clean. Use double colons instead of single ones
171 # to do this.
172
173 # The subdirectories we need to build things in
174 SRCDIRS :=
175 ifneq ($(MAKECMDGOALS),user)
176 ifneq ($(MAKECMDGOALS),user_install)
177 ifneq ($(MAKECMDGOALS),user_uninstall)
178 ifneq ($(MAKECMDGOALS),package)
179 ifneq ($(MAKECMDGOALS),userpackage)
180 ifneq ($(MAKECMDGOALS),manhtml)
181 SRCDIRS += mkpatch
182 SRCDIRS += kernel/busses kernel/chips
183 endif
184 endif
185 endif
186 endif
187 endif
188 endif
189 SRCDIRS += kernel/include
190 SRCDIRS += lib prog/detect prog/dump prog/eeprom prog/pwm \
191            prog/sensors prog/xeon ${PROG_EXTRA:%=prog/%} etc
192 SRCDIRS += lib/test
193
194 # Some often-used commands with default options
195 MKDIR := mkdir -p
196 RMDIR := rmdir
197 RM := rm -f
198 BISON := bison
199 FLEX := flex
200 AR := ar
201 INSTALL := install
202 LN := ln -sf
203 GREP := grep
204 AWK := awk
205 SED := sed
206
207 # Determine the default compiler flags
208 # Set CFLAGS or CPPFLAGS above to add your own flags to all.
209 # ALLCPPFLAGS/ALLCFLAGS are common flags, plus any user-specified overrides from the environment or make command line.
210 # MODCPPFLAGS/MODCFLAGS is to create in-kernel object files (modules).
211 # PROGCPPFLAGS/PROGCFLAGS is to create non-kernel object files (which are linked into executables).
212 # ARCPPFLAGS/ARCFLAGS are used to create archive object files (static libraries).
213 # LIBCPPFLAGS/LIBCFLAGS are for shared library objects.
214 ALL_CPPFLAGS := -I. -Ikernel/include -I$(I2C_HEADERS)
215 ALL_CFLAGS := -Wall
216
217 ifeq ($(DEBUG),1)
218 ALL_CPPFLAGS += -DDEBUG
219 ALL_CFLAGS += -O -g
220 else
221 ALL_CFLAGS += -O2
222 endif
223
224 ifeq ($(WARN),1)
225 ALL_CFLAGS += -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \
226             -Wcast-align -Wwrite-strings -Wnested-externs -Winline
227 endif
228
229 ALL_CPPFLAGS += $(CPPFLAGS)
230 ALL_CFLAGS += $(CFLAGS)
231
232 MODCPPFLAGS :=
233 MODCFLAGS := -fno-strict-aliasing
234
235 ifeq ($(MACHINE),alpha)
236 MODCFLAGS += -ffixed-8 -mno-fp-regs -mcpu=ev56
237 endif
238
239 ifeq ($(MACHINE),x86_64)
240 MODCFLAGS += -fno-common -fomit-frame-pointer -mno-red-zone \
241              -mcmodel=kernel -fno-reorder-blocks -finline-limit=2000 -fno-strength-reduce
242 endif
243
244 ifeq ($(MACHINE),mips)
245 MODCFLAGS += -mabi=32 -mips3 -Wa,-32 -Wa,-mips3 -Wa,--trap
246 endif
247
248 ifeq ($(MACHINE),sparc32)
249 MODCFLAGS += -m32 -pipe -mno-fpu -fcall-used-g5 -fcall-used-g7
250 endif
251
252 ifeq ($(MACHINE),sparc64)
253 MODCFLAGS += -m64 -pipe -mno-fpu -mcpu=ultrasparc -mcmodel=medlow \
254              -ffixed-g4 -fcall-used-g5 -fcall-used-g7 -Wno-sign-compare \
255              -Wa,--undeclared-regs
256 endif
257
258 ifeq ($(SMP),1)
259 MODCPPFLAGS += -D__SMP__
260 endif
261
262 ifeq ($(MODVER),1)
263 MODCPPFLAGS += -DMODVERSIONS -include $(LINUX_HEADERS)/linux/modversions.h
264 endif
265
266 # This magic is from the kernel Makefile.
267 # Extra cflags for kbuild 2.4.  The default is to forbid includes by kernel code
268 # from user space headers.
269 kbuild_2_4_nostdinc := -nostdinc $(shell LC_ALL=C $(CC) -print-search-dirs | sed -ne 's/install: \(.*\)/-I \1include/gp')
270
271 MODCPPFLAGS += -D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -fomit-frame-pointer $(ALL_CPPFLAGS) -I$(LINUX_HEADERS) $(kbuild_2_4_nostdinc)
272 MODCFLAGS += $(ALL_CFLAGS)
273 PROGCPPFLAGS := -DETCDIR="\"$(ETCDIR)\"" $(ALL_CPPFLAGS) -Wundef
274 PROGCFLAGS := $(ALL_CFLAGS)
275 ARCPPFLAGS := $(ALL_CPPFLAGS)
276 ifdef SYSFS_SUPPORT
277 ARCPPFLAGS := $(ARCPPFLAGS) -DSYSFS_SUPPORT
278 endif
279 ARCFLAGS := $(ALL_CFLAGS)
280 LIBCPPFLAGS := $(ALL_CPPFLAGS)
281 ifdef SYSFS_SUPPORT
282 LIBCPPFLAGS := $(LIBCPPFLAGS) -DSYSFS_SUPPORT
283 endif
284 LIBCFLAGS := -fpic -D_REENTRANT $(ALL_CFLAGS)
285
286 .PHONY: all user clean install user_install uninstall user_uninstall version package
287
288 # Make all the default rule
289 all::
290
291 # Include all makefiles for sub-modules
292 INCLUDEFILES :=
293 include $(patsubst %,%/Module.mk,$(SRCDIRS))
294 ifneq ($(MAKECMDGOALS),clean)
295 ifneq ($(MAKECMDGOALS),uninstall)
296 ifneq ($(MAKECMDGOALS),user_uninstall)
297 ifneq ($(MAKECMDGOALS),help)
298 ifneq ($(MAKECMDGOALS),package)
299 ifneq ($(MAKECMDGOALS),userpackage)
300 include $(INCLUDEFILES)
301 endif
302 endif
303 endif
304 endif
305 endif
306 endif
307
308 # Man pages
309 MANPAGES := $(LIBMAN3FILES) $(LIBMAN5FILES) $(PROGDETECTMAN8FILES) $(PROGDUMPMAN8FILES) \
310             $(PROGSENSORSMAN1FILES) $(PROGPWMMAN8FILES) prog/sensord/sensord.8
311
312 user ::
313 user_install::
314         @echo "*** Important note:"
315         @echo "***  * The libsensors configuration file ($(ETCDIR)/sensors.conf) is never"
316         @echo "***    overwritten by our installation process, so that you won't lose"
317         @echo "***    your personal settings in that file. You still can get our latest"
318         @echo "***    default config file in etc/sensors.conf.eg and manually copy it to"
319         @echo "***    $(ETCDIR)/sensors.conf if you want. You will then want to edit it"
320         @echo "***    to fit your needs again."
321 all :: user
322 install :: all user_install
323 ifeq ($(DESTDIR),)
324         -if [ -r $(MODPREF)/build/System.map -a -x /sbin/depmod ] ; then \
325           /sbin/depmod -a -F $(MODPREF)/build/System.map $(UTSRELEASE) ; \
326         fi
327 else
328         @echo "*** This is a \`staged' install using \"$(DESTDIR)\" as prefix."
329         @echo "***"
330         @echo "*** Once the modules have been moved to their final destination"
331         @echo "*** you must run the command \"/sbin/depmod -a\"."
332         @echo "***"
333         @echo "*** Alternatively, if you build a package (e.g. rpm), include the"
334         @echo "*** command \"/sbin/depmod -a\" in the post-(un)install procedure."
335         @echo "***"
336         @echo "*** The depmod command mentioned above may generate errors. We are"
337         @echo "*** aware of the problem and are working on a solution."
338 endif
339
340 clean::
341         $(RM) lm_sensors-* lex.backup
342
343 user_uninstall::
344
345 uninstall :: user_uninstall
346         @echo "*** Note:"
347         @echo "***  * Kernel modules were not uninstalled."
348
349 # This is tricky, but it works like a charm. It needs lots of utilities
350 # though: cut, find, gzip, ln, tail and tar.
351 package: version clean
352         lmversion=`tail -1 version.h|cut -f 2 -d \"`; \
353         lmpackage=lm_sensors-$$lmversion; \
354         ln -s . $$lmpackage;  \
355         find $$lmpackage/ -type f | grep -v ^$$lmpackage/$$lmpackage$$ | \
356                                     grep -v ^$$lmpackage/$$lmpackage.tar$$ | \
357                                     grep -v ^$$lmpackage/$$ | \
358                                     grep -v /CVS | \
359                                     grep -v /\\.# | \
360                                     tar rvf $$lmpackage.tar -T -; \
361         gzip -9 $$lmpackage.tar ;\
362         $(RM) $$lmpackage.tar $$lmpackage
363         cat doc/developers/checklist
364
365 # doesn't work well yet... needs Makefile changes too
366 userpackage: version clean $(KERNELINCLUDEDIR)/sensors.h
367         lmversion=`tail -1 version.h|cut -f 2 -d \"`; \
368         lmpackage=lm_sensors-user-$$lmversion; \
369         ln -s . $$lmpackage;  \
370         find $$lmpackage/ -type f | grep -v ^$$lmpackage/$$lmpackage$$ | \
371                                     grep -v ^$$lmpackage/$$lmpackage.tar$$ | \
372                                     grep -v ^$$lmpackage/doc/chips | \
373                                     grep -v ^$$lmpackage/doc/busses | \
374                                     grep -v ^$$lmpackage/kernel/chips | \
375                                     grep -v ^$$lmpackage/kernel/busses | \
376                                     grep -v ^$$lmpackage/$$ | \
377                                     grep -v /CVS | \
378                                     grep -v /\\.# | \
379                                     tar rvf $$lmpackage.tar -T -; \
380         gzip -9 $$lmpackage.tar ;\
381         $(RM) $$lmpackage.tar $$lmpackage
382         cat doc/developers/checklist
383
384 version:
385         $(RM) version.h
386         echo '#define LM_DATE "'`date +'%Y%m%d'`\" > version.h
387         echo -n 'Version: '; \
388         echo '#define LM_VERSION "'`read VER; echo $$VER`\" >> version.h
389
390 help:
391         @echo 'Make targets are:'
392         @echo '  all (default): build modules and userspace programs'
393         @echo '  install: install modules and userspace programs'
394         @echo '  user: build userspace programs'
395         @echo '  user_install: install userspace programs'
396         @echo '  user_uninstall: remove userspace programs'
397         @echo '  clean: cleanup'
398         @echo '  package: create a distribution package'
399
400 $(LINUX)/.config:
401         @echo
402         @echo "Error - missing file $(LINUX)/.config !! "
403         @echo "  Verify kernel source is in $(LINUX) and then"
404         @echo "  cd to $(LINUX) and run 'make config' !!"
405         @echo
406         @echo "Exception: if you're using a stock RedHat kernel..."
407         @echo "  (1) Install the appropriate kernel-source RPM."
408         @echo "  (2) Copy the appropriate config..."
409         @echo "      from $(LINUX)/configs/<...>"
410         @echo "      to $(LINUX)/.config"
411         @echo "  (3) Do *NOT* 'make dep' or 'make config'."
412         @echo
413         @exit 1
414
415 # Generate html man pages to be copied to the lm_sensors website.
416 # This uses the man2html from here
417 # http://ftp.math.utah.edu/pub/sgml/
418 # which works directly from the nroff source
419 manhtml:
420         $(MKDIR) html
421         cp $(MANPAGES) html
422         cd html ; \
423         export LOGNAME=sensors ; \
424         export HOSTNAME=www.lm-sensors.org ; \
425         man2html *.[1-8] ; \
426         $(RM) *.[1-8]
427
428 # Here, we define all implicit rules we want to use.
429
430 .SUFFIXES:
431
432 # We need to create dependency files. Tricky. The sed rule puts dir/file.d and
433 # dir/file.c in front of the dependency file rule.
434
435 # .o files are used for modules
436 # depend on the kernel config file!
437 %.o: %.c $(LINUX)/.config
438         $(CC) $(MODCPPFLAGS) $(MODCFLAGS) -c $< -o $@
439
440 %.d: %.c $(LINUX)/.config
441         $(CC) -M -MG $(MODCPPFLAGS) $(MODCFLAGS) $< | \
442         $(SED) -e 's@^\(.*\)\.o:@$*.d $*.o: Makefile '`dirname $*.d`/Module.mk' @' > $@
443
444
445
446 # .ro files are used for programs (as opposed to modules)
447 %.ro: %.c
448         $(CC) $(PROGCPPFLAGS) $(PROGCFLAGS) -c $< -o $@
449
450 %.rd: %.c
451         $(CC) -M -MG $(PROGCPPFLAGS) $(PROGCFLAGS) $< | \
452         $(SED) -e 's@^\(.*\)\.o:@$*.rd $*.ro: Makefile '`dirname $*.rd`/Module.mk' @' > $@
453
454
455 %: %.ro
456         $(CC) $(EXLDFLAGS) -o $@ $^
457
458
459 # .ao files are used for static archives
460 %.ao: %.c
461         $(CC) $(ARCPPFLAGS) $(ARCFLAGS) -c $< -o $@
462
463 %.ad: %.c
464         $(CC) -M -MG $(ARCPPFLAGS) $(ARCFLAGS) $< | \
465         $(SED) -e 's@^\(.*\)\.o:@$*.ad $*.ao: Makefile '`dirname $*.ad`/Module.mk' @' > $@
466
467
468 # .lo files are used for shared libraries
469 %.lo: %.c
470         $(CC) $(LIBCPPFLAGS) $(LIBCFLAGS) -c $< -o $@
471
472 %.ld: %.c
473         $(CC) -M -MG $(LIBCPPFLAGS) $(LIBCFLAGS) $< | \
474         $(SED) -e 's@^\(.*\)\.o:@$*.ld $*.lo: Makefile '`dirname $*.ld`/Module.mk' @' > $@
475
476
477 # Flex and Bison
478 %c: %y
479         $(BISON) -p sensors_yy -d $< -o $@
480
481 ifeq ($(DEBUG),1)
482 FLEX_FLAGS := -Psensors_yy -t -b -Cfe -8
483 else
484 FLEX_FLAGS := -Psensors_yy -t -Cfe -8
485 endif
486
487 %.c: %.l
488         $(FLEX) $(FLEX_FLAGS) $< > $@
Note: See TracBrowser for help on using the browser.