root/lm-sensors/branches/lm-sensors-3.0.0/Makefile @ 4357

Revision 4357, 16.2 KB (checked in by mmh, 6 years ago)

Merge from trunk (4303:4355) out to 3.0.0 branch.

  • 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/bin,
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 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
196BISON := bison
197FLEX := flex
198AR := ar
199INSTALL := install
200LN := ln -sf
201GREP := grep
202AWK := awk
203SED := sed
204
205# Determine the default compiler flags
206# Set CFLAGS or CPPFLAGS above to add your own flags to all.
207# ALLCPPFLAGS/ALLCFLAGS are common flags, plus any user-specified overrides from the environment or make command line.
208# MODCPPFLAGS/MODCFLAGS is to create in-kernel object files (modules).
209# PROGCPPFLAGS/PROGCFLAGS is to create non-kernel object files (which are linked into executables).
210# ARCPPFLAGS/ARCFLAGS are used to create archive object files (static libraries).
211# LIBCPPFLAGS/LIBCFLAGS are for shared library objects.
212ALL_CPPFLAGS := -I. -Ikernel/include -I$(I2C_HEADERS)
213ALL_CFLAGS := -Wall
214
215ifeq ($(DEBUG),1)
216ALL_CPPFLAGS += -DDEBUG
217ALL_CFLAGS += -O -g
218else
219ALL_CFLAGS += -O2
220endif
221
222ifeq ($(WARN),1)
223ALL_CFLAGS += -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \
224            -Wcast-align -Wwrite-strings -Wnested-externs -Winline
225endif
226
227ALL_CPPFLAGS += $(CPPFLAGS)
228ALL_CFLAGS += $(CFLAGS)
229
230MODCPPFLAGS :=
231MODCFLAGS := -fno-strict-aliasing
232
233ifeq ($(MACHINE),alpha)
234MODCFLAGS += -ffixed-8 -mno-fp-regs -mcpu=ev56
235endif
236
237ifeq ($(MACHINE),x86_64)
238MODCFLAGS += -fno-common -fomit-frame-pointer -mno-red-zone \
239             -mcmodel=kernel -fno-reorder-blocks -finline-limit=2000 -fno-strength-reduce
240endif
241
242ifeq ($(MACHINE),mips)
243MODCFLAGS += -mabi=32 -mips3 -Wa,-32 -Wa,-mips3 -Wa,--trap
244endif
245
246ifeq ($(MACHINE),sparc32)
247MODCFLAGS += -m32 -pipe -mno-fpu -fcall-used-g5 -fcall-used-g7
248endif
249
250ifeq ($(MACHINE),sparc64)
251MODCFLAGS += -m64 -pipe -mno-fpu -mcpu=ultrasparc -mcmodel=medlow \
252             -ffixed-g4 -fcall-used-g5 -fcall-used-g7 -Wno-sign-compare \
253             -Wa,--undeclared-regs
254endif
255
256ifeq ($(SMP),1)
257MODCPPFLAGS += -D__SMP__
258endif
259
260ifeq ($(MODVER),1)
261MODCPPFLAGS += -DMODVERSIONS -include $(LINUX_HEADERS)/linux/modversions.h
262endif
263
264# This magic is from the kernel Makefile.
265# Extra cflags for kbuild 2.4.  The default is to forbid includes by kernel code
266# from user space headers.
267kbuild_2_4_nostdinc := -nostdinc $(shell LC_ALL=C $(CC) -print-search-dirs | sed -ne 's/install: \(.*\)/-I \1include/gp')
268
269MODCPPFLAGS += -D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -fomit-frame-pointer $(ALL_CPPFLAGS) -I$(LINUX_HEADERS) $(kbuild_2_4_nostdinc)
270MODCFLAGS += $(ALL_CFLAGS)
271PROGCPPFLAGS := -DETCDIR="\"$(ETCDIR)\"" $(ALL_CPPFLAGS) -Wundef
272PROGCFLAGS := $(ALL_CFLAGS)
273ARCPPFLAGS := $(ALL_CPPFLAGS)
274ifdef SYSFS_SUPPORT
275ARCPPFLAGS := $(ARCPPFLAGS) -DSYSFS_SUPPORT
276endif
277ARCFLAGS := $(ALL_CFLAGS)
278LIBCPPFLAGS := $(ALL_CPPFLAGS)
279ifdef SYSFS_SUPPORT
280LIBCPPFLAGS := $(LIBCPPFLAGS) -DSYSFS_SUPPORT
281endif
282LIBCFLAGS := -fpic -D_REENTRANT $(ALL_CFLAGS)
283
284.PHONY: all user clean install user_install uninstall user_uninstall version package
285
286# Make all the default rule
287all::
288
289# Include all makefiles for sub-modules
290INCLUDEFILES := 
291include $(patsubst %,%/Module.mk,$(SRCDIRS))
292ifneq ($(MAKECMDGOALS),clean)
293ifneq ($(MAKECMDGOALS),uninstall)
294ifneq ($(MAKECMDGOALS),user_uninstall)
295ifneq ($(MAKECMDGOALS),help)
296ifneq ($(MAKECMDGOALS),package)
297ifneq ($(MAKECMDGOALS),userpackage)
298include $(INCLUDEFILES)
299endif
300endif
301endif
302endif
303endif
304endif
305
306# Man pages
307MANPAGES := $(LIBMAN3FILES) $(LIBMAN5FILES) $(PROGDETECTMAN8FILES) $(PROGDUMPMAN8FILES) \
308            $(PROGSENSORSMAN1FILES) $(PROGPWMMAN8FILES) prog/sensord/sensord.8
309
310user ::
311user_install::
312        @echo "*** Important note:"
313        @echo "***  * The libsensors configuration file ($(ETCDIR)/sensors.conf) is never"
314        @echo "***    overwritten by our installation process, so that you won't lose"
315        @echo "***    your personal settings in that file. You still can get our latest"
316        @echo "***    default config file in etc/sensors.conf.eg and manually copy it to"
317        @echo "***    $(ETCDIR)/sensors.conf if you want. You will then want to edit it"
318        @echo "***    to fit your needs again."
319all :: user
320install :: all user_install
321ifeq ($(DESTDIR),)
322        -if [ -r $(MODPREF)/build/System.map -a -x /sbin/depmod ] ; then \
323          /sbin/depmod -a -F $(MODPREF)/build/System.map $(KERNELVERSION) ; \
324        fi
325else
326        @echo "*** This is a \`staged' install using \"$(DESTDIR)\" as prefix."
327        @echo "***"
328        @echo "*** Once the modules have been moved to their final destination"
329        @echo "*** you must run the command \"/sbin/depmod -a\"."
330        @echo "***"
331        @echo "*** Alternatively, if you build a package (e.g. rpm), include the"
332        @echo "*** command \"/sbin/depmod -a\" in the post-(un)install procedure."
333        @echo "***"
334        @echo "*** The depmod command mentioned above may generate errors. We are"
335        @echo "*** aware of the problem and are working on a solution."
336endif
337
338clean::
339        $(RM) lm_sensors-* lex.backup
340
341user_uninstall::
342
343uninstall :: user_uninstall
344        @echo "*** Note:"
345        @echo "***  * Kernel modules were not uninstalled."
346
347# This is tricky, but it works like a charm. It needs lots of utilities
348# though: cut, find, gzip, ln, tail and tar.
349package: version clean
350        lmversion=`tail -1 version.h|cut -f 2 -d \"`; \
351        lmpackage=lm_sensors-$$lmversion; \
352        ln -s . $$lmpackage;  \
353        find $$lmpackage/ -type f | grep -v ^$$lmpackage/$$lmpackage$$ | \
354                                    grep -v ^$$lmpackage/$$lmpackage.tar$$ | \
355                                    grep -v ^$$lmpackage/$$ | \
356                                    grep -v /CVS | \
357                                    grep -v /\\.# | \
358                                    tar rvf $$lmpackage.tar -T -; \
359        gzip -9 $$lmpackage.tar ;\
360        $(RM) $$lmpackage.tar $$lmpackage
361        cat doc/developers/checklist
362
363# doesn't work well yet... needs Makefile changes too
364userpackage: version clean $(KERNELINCLUDEDIR)/sensors.h
365        lmversion=`tail -1 version.h|cut -f 2 -d \"`; \
366        lmpackage=lm_sensors-user-$$lmversion; \
367        ln -s . $$lmpackage;  \
368        find $$lmpackage/ -type f | grep -v ^$$lmpackage/$$lmpackage$$ | \
369                                    grep -v ^$$lmpackage/$$lmpackage.tar$$ | \
370                                    grep -v ^$$lmpackage/doc/chips | \
371                                    grep -v ^$$lmpackage/doc/busses | \
372                                    grep -v ^$$lmpackage/kernel/chips | \
373                                    grep -v ^$$lmpackage/kernel/busses | \
374                                    grep -v ^$$lmpackage/$$ | \
375                                    grep -v /CVS | \
376                                    grep -v /\\.# | \
377                                    tar rvf $$lmpackage.tar -T -; \
378        gzip -9 $$lmpackage.tar ;\
379        $(RM) $$lmpackage.tar $$lmpackage
380        cat doc/developers/checklist
381
382version:
383        $(RM) version.h
384        echo '#define LM_DATE "'`date +'%Y%m%d'`\" > version.h
385        echo -n 'Version: '; \
386        echo '#define LM_VERSION "'`read VER; echo $$VER`\" >> version.h
387
388help:
389        @echo 'Make targets are:'
390        @echo '  all (default): build modules and userspace programs'
391        @echo '  install: install modules and userspace programs'
392        @echo '  user: build userspace programs'
393        @echo '  user_install: install userspace programs'
394        @echo '  user_uninstall: remove userspace programs'
395        @echo '  clean: cleanup'
396        @echo '  package: create a distribution package'
397
398$(LINUX)/.config:
399        @echo
400        @echo "Error - missing file $(LINUX)/.config !! "
401        @echo "  Verify kernel source is in $(LINUX) and then"
402        @echo "  cd to $(LINUX) and run 'make config' !!"
403        @echo
404        @echo "Exception: if you're using a stock RedHat kernel..."
405        @echo "  (1) Install the appropriate kernel-source RPM."
406        @echo "  (2) Copy the appropriate config..."
407        @echo "      from $(LINUX)/configs/<...>"
408        @echo "      to $(LINUX)/.config"
409        @echo "  (3) Do *NOT* 'make dep' or 'make config'."
410        @echo
411        @exit 1
412
413# Generate html man pages to be copied to the lm_sensors website.
414# This uses the man2html from here
415# http://ftp.math.utah.edu/pub/sgml/
416# which works directly from the nroff source
417manhtml:
418        $(MKDIR) html
419        cp $(MANPAGES) html
420        cd html ; \
421        export LOGNAME=sensors ; \
422        export HOSTNAME=www.lm-sensors.org ; \
423        man2html *.[1-8] ; \
424        $(RM) *.[1-8]
425
426# Here, we define all implicit rules we want to use.
427
428.SUFFIXES:
429
430# We need to create dependency files. Tricky. The sed rule puts dir/file.d and
431# dir/file.c in front of the dependency file rule.
432
433# .o files are used for modules
434# depend on the kernel config file!
435%.o: %.c $(LINUX)/.config
436        $(CC) $(MODCPPFLAGS) $(MODCFLAGS) -c $< -o $@
437
438%.d: %.c $(LINUX)/.config
439        $(CC) -M -MG $(MODCPPFLAGS) $(MODCFLAGS) $< | \
440        $(SED) -e 's@^\(.*\)\.o:@$*.d $*.o: Makefile '`dirname $*.d`/Module.mk' @' > $@
441
442
443
444# .ro files are used for programs (as opposed to modules)
445%.ro: %.c
446        $(CC) $(PROGCPPFLAGS) $(PROGCFLAGS) -c $< -o $@
447
448%.rd: %.c
449        $(CC) -M -MG $(PROGCPPFLAGS) $(PROGCFLAGS) $< | \
450        $(SED) -e 's@^\(.*\)\.o:@$*.rd $*.ro: Makefile '`dirname $*.rd`/Module.mk' @' > $@
451
452
453%: %.ro
454        $(CC) $(EXLDFLAGS) -o $@ $^
455
456
457# .ao files are used for static archives
458%.ao: %.c
459        $(CC) $(ARCPPFLAGS) $(ARCFLAGS) -c $< -o $@
460
461%.ad: %.c
462        $(CC) -M -MG $(ARCPPFLAGS) $(ARCFLAGS) $< | \
463        $(SED) -e 's@^\(.*\)\.o:@$*.ad $*.ao: Makefile '`dirname $*.ad`/Module.mk' @' > $@
464
465
466# .lo files are used for shared libraries
467%.lo: %.c
468        $(CC) $(LIBCPPFLAGS) $(LIBCFLAGS) -c $< -o $@
469
470%.ld: %.c
471        $(CC) -M -MG $(LIBCPPFLAGS) $(LIBCFLAGS) $< | \
472        $(SED) -e 's@^\(.*\)\.o:@$*.ld $*.lo: Makefile '`dirname $*.ld`/Module.mk' @' > $@
473
474
475# Flex and Bison
476%c: %y
477        $(BISON) -p sensors_yy -d $< -o $@
478
479ifeq ($(DEBUG),1)
480FLEX_FLAGS := -Psensors_yy -t -b -Cfe -8
481else
482FLEX_FLAGS := -Psensors_yy -t -Cfe -8
483endif
484
485%.c: %.l
486        $(FLEX) $(FLEX_FLAGS) $< > $@
Note: See TracBrowser for help on using the browser.