root/lm-sensors/branches/lm-sensors-2.10/Makefile

Revision 5762, 16.3 KB (checked in by khali, 3 years ago)

Recent versions of module-init-tools only want *.conf files under
/etc/modprobe.d. So rename our configuration file to lm_sensors.conf
there. Also let "make install" rename the file if it already exists.

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