root/lm-sensors/trunk/Makefile @ 2766

Revision 2766, 14.2 KB (checked in by khali, 10 years ago)

Make ETCDIR available to compiled programs.

  • 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 succesfully;
22# most notably, you need bash, GNU make, flex (>= 2.5.1) and bison.
23
24# If your /bin/sh is not bash, change the below definition so that make can
25# find bash. Or you can hope your sh-like shell understands all scripts.
26# I think so, but I have not tested it.
27#SHELL := /usr/bin/bash
28
29# The currently running kernel version. This is used right below to
30# determine where the kernel sources can be found.
31KERNELVERSION := $(shell uname -r)
32
33# The location of linux itself. This is used to find the kernel headers
34# and other things.
35#LINUX := /usr/src/linux
36LINUX := $(shell if [ -L /lib/modules/$(KERNELVERSION)/build ] ; \
37        then echo "/lib/modules/$(KERNELVERSION)/build" ; \
38        else echo "/usr/src/linux" ; fi)
39LINUX_HEADERS := $(LINUX)/include
40
41# If you have installed the i2c header at some other place (like
42# /usr/local/include/linux), set that directory here. Please check this out
43# if you get strange compilation errors; the default Linux i2c headers
44# may be used mistakenly. Note: This should point to the directory
45# *above* the linux/ subdirectory, so to /usr/local/include in the
46# above example.
47I2C_HEADERS := /usr/local/include
48#I2C_HEADERS := $(LINUX_HEADERS)
49
50# Uncomment the third line on SMP systems if the magic invocation fails. It
51# is a bit complicated because SMP configuration changed around kernel 2.1.130
52SMP := $(shell if grep -q '^SMP[[:space:]]*=' $(LINUX)/Makefile || \
53                  grep -q '^[[:space:]]*\#define[[:space:]]*CONFIG_SMP[[:space:]]*1' $(LINUX_HEADERS)/linux/autoconf.h ; \
54               then echo 1; else echo 0; fi)
55#SMP := 0
56#SMP := 1
57
58# Uncomment the second or third line if the magic invocation fails.
59# We need to know whether CONFIG_MODVERSIONS is defined.
60MODVER := $(shell if cat $(LINUX_HEADERS)/linux/config.h $(LINUX_HEADERS)/linux/autoconf.h 2>/dev/null | grep -q '^[[:space:]]*\#define[[:space:]]*CONFIG_MODVERSIONS[[:space:]]*1'; then echo 1; else echo 0; fi)
61#MODVER := 0
62#MODVER := 1
63
64# Uncomment the second line if you are a developer. This will enable many
65# additional warnings at compile-time
66WARN := 0
67#WARN := 1
68
69# Uncomment the second line if you want to get (loads of) debug information
70# at run-time.
71# Not recommended, unless you are actually debugging the code
72DEBUG := 0
73#DEBUG := 1
74
75# If you want to install at some other place then at from which you will run
76# everything, set DESTDIR to the extra prefix.
77DESTDIR :=
78
79# This is the prefix that will be used for almost all directories below.
80PREFIX := /usr/local
81
82# Your C compiler
83CC := gcc
84
85# This is the main modules directory into which the modules will be installed.
86# The magic invocation will return something like this:
87#   /lib/modules/2.2.15-ac9
88#MODDIR := /lib/modules/`grep UTS_RELEASE $(LINUX_HEADERS)/linux/version.h|cut -f 2 -d'"'`/misc
89#MODPREF := /lib/modules/$(KERNELVERSION)
90#MODPREF := /lib/modules/`grep UTS_RELEASE $(LINUX_HEADERS)/linux/version.h|cut -f 2 -d'"'`
91MODPREF := /lib/modules/$(shell $(CC) -I$(LINUX_HEADERS) -E etc/config.c | grep uts_release |cut -f 2 -d'"')
92
93# This is the directory where sensors.conf will be installed, if no other
94# configuration file is found
95ETCDIR := /etc
96
97# You should not need to change this. It is the directory into which the
98# library files (both static and shared) will be installed.
99LIBDIR := $(PREFIX)/lib
100
101EXLDFLAGS := -Wl,-rpath,$(LIBDIR)
102
103# You should not need to change this. It is the directory into which the
104# executable program files will be installed. BINDIR for programs that are
105# also useful for normal users, SBINDIR for programs that can only be run
106# by the superuser.
107# Note that not all programs in this package are really installed;
108# some are just examples. You can always install them by hand, of
109# course.
110BINDIR := $(PREFIX)/bin
111SBINDIR := $(PREFIX)/sbin
112
113# You should not need to change this. It is the basic directory into which
114# include files will be installed. The actual directory will be
115# $(INCLUDEDIR)/linux for system include files, and $(INCLUDEDIR)/sensors
116# for library include files. If PREFIX equals the default /usr/local/bin,
117# you will be able to use '#include <linux/sensors.h>' regardless of the
118# current kernel selected.
119INCLUDEDIR := $(PREFIX)/include
120SYSINCLUDEDIR := $(INCLUDEDIR)/linux
121LIBINCLUDEDIR := $(INCLUDEDIR)/sensors
122
123# You should not need to change this. It is the base directory under which the
124# manual pages will be installed.
125MANDIR := $(PREFIX)/man
126
127MACHINE := $(shell uname -m)
128
129# Extra non-default programs to build; e.g., sensord
130# PROG_EXTRA := sensord
131
132# Set these to add preprocessor or compiler flags, or use
133# environment variables
134# CFLAGS :=
135# CPPFLAGS :=
136
137##################################################
138# Below this, nothing should need to be changed. #
139##################################################
140
141# Note that this is a monolithic Makefile; it calls no sub-Makefiles,
142# but instead, it compiles everything right from here. Yes, there are
143# some distinct advantages to this; see the following paper for more info:
144#   http://www.tip.net.au/~millerp/rmch/recu-make-cons-harm.html
145# Note that is still uses Makefile fragments in sub-directories; these
146# are called 'Module.mk'.
147
148# Within each Module.mk, rules and dependencies can be added to targets
149# all, install and clean. Use double colons instead of single ones
150# to do this.
151
152# The subdirectories we need to build things in
153SRCDIRS :=
154ifneq ($(MAKECMDGOALS),user)
155ifneq ($(MAKECMDGOALS),user_install)
156ifneq ($(MAKECMDGOALS),user_uninstall)
157SRCDIRS += mkpatch
158SRCDIRS += kernel kernel/busses kernel/chips
159endif
160endif
161endif
162SRCDIRS += kernel/include
163SRCDIRS += lib prog/detect prog/dump prog/eeprom prog/pwm \
164           prog/sensors prog/xeon ${PROG_EXTRA:%=prog/%} etc
165
166# Some often-used commands with default options
167MKDIR := mkdir -p
168RMDIR := rmdir
169RM := rm -f
170BISON := bison
171FLEX := flex
172AR := ar
173INSTALL := install
174LN := ln -sf
175GREP := grep
176AWK := awk
177SED := sed
178
179# Determine the default compiler flags
180# Set CFLAGS or CPPFLAGS above to add your own flags to all.
181# ALLCPPFLAGS/ALLCFLAGS are common flags, plus any user-specified overrides from the environment or make command line.
182# MODCPPFLAGS/MODCFLAGS is to create in-kernel object files (modules).
183# PROGCPPFLAGS/PROGCFLAGS is to create non-kernel object files (which are linked into executables).
184# ARCPPFLAGS/ARCFLAGS are used to create archive object files (static libraries).
185# LIBCPPFLAGS/LIBCFLAGS are for shared library objects.
186ALL_CPPFLAGS := -I. -Ikernel/include -I$(I2C_HEADERS)
187ALL_CFLAGS := -Wall
188
189ifeq ($(DEBUG),1)
190ALL_CPPFLAGS += -DDEBUG
191ALL_CFLAGS += -O -g
192else
193ALL_CFLAGS += -O2
194endif
195
196ifeq ($(WARN),1)
197ALL_CFLAGS += -W -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \
198            -Wcast-align -Wwrite-strings -Wnested-externs -Winline
199endif
200
201ALL_CPPFLAGS += $(CPPFLAGS)
202ALL_CFLAGS += $(CFLAGS)
203
204MODCPPFLAGS :=
205MODCFLAGS :=
206
207ifeq ($(MACHINE),alpha)
208MODCFLAGS += -ffixed-8 -mno-fp-regs -mcpu=ev56
209endif
210
211ifeq ($(MACHINE),x86_64)
212MODCFLAGS += -fno-strict-aliasing -fno-common -fomit-frame-pointer -mno-red-zone \
213             -mcmodel=kernel -fno-reorder-blocks -finline-limit=2000 -fno-strength-reduce
214endif
215
216ifeq ($(SMP),1)
217MODCPPFLAGS += -D__SMP__
218endif
219
220ifeq ($(MODVER),1)
221MODCPPFLAGS += -DMODVERSIONS -include $(LINUX_HEADERS)/linux/modversions.h
222endif
223
224# This magic is from the kernel Makefile.
225# Extra cflags for kbuild 2.4.  The default is to forbid includes by kernel code
226# from user space headers.
227kbuild_2_4_nostdinc := -nostdinc $(shell LC_ALL=C $(CC) -print-search-dirs | sed -ne 's/install: \(.*\)/-I \1include/gp')
228
229MODCPPFLAGS += -D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -fomit-frame-pointer $(ALL_CPPFLAGS) -I$(LINUX_HEADERS) $(kbuild_2_4_nostdinc)
230MODCFLAGS += $(ALL_CFLAGS)
231PROGCPPFLAGS := -DETCDIR="\"$(ETCDIR)\"" $(ALL_CPPFLAGS)
232PROGCFLAGS := $(ALL_CFLAGS)
233ARCPPFLAGS := $(ALL_CPPFLAGS)
234ARCFLAGS := $(ALL_CFLAGS)
235LIBCPPFLAGS := $(ALL_CPPFLAGS)
236LIBCFLAGS := -fpic $(ALL_CFLAGS)
237
238.PHONY: all clean install version package dep
239
240# Make all the default rule
241all::
242
243# Include all makefiles for sub-modules
244INCLUDEFILES := 
245include $(patsubst %,%/Module.mk,$(SRCDIRS))
246ifneq ($(MAKECMDGOALS),clean)
247ifneq ($(MAKECMDGOALS),uninstall)
248ifneq ($(MAKECMDGOALS),user_uninstall)
249ifneq ($(MAKECMDGOALS),help)
250include $(INCLUDEFILES)
251endif
252endif
253endif
254endif
255
256# Man pages
257MANPAGES := $(LIBMAN3FILES) $(LIBMAN5FILES) $(PROGDETECTMAN8FILES) $(PROGDUMPMAN8FILES) \
258            $(PROGSENSORSMAN1FILES) prog/sensord/sensord.8
259
260# Making the dependency files - done automatically!
261dep :
262
263user ::
264user_install::
265        @echo "*** Important note:"
266        @echo "***  * The libsensors configuration file ($(ETCDIR)/sensors.conf) is never"
267        @echo "***    overwritten by our installation process, so that you won't lose"
268        @echo "***    your personal settings in that file. You still can get our latest"
269        @echo "***    default config file in etc/sensors.conf.eg and manually copy it to"
270        @echo "***    $(ETCDIR)/sensors.conf if you want. You will then want to edit it"
271        @echo "***    to fit your needs again."
272all :: user
273install :: all user_install
274ifeq ($(DESTDIR),)
275        @echo "*** The depmod command below may generate errors. We are aware of the"
276        @echo "*** problem and are working on a solution."
277        -/sbin/depmod -a
278else
279        @echo "*** This is a \`staged' install using \"$(DESTDIR)\" as prefix."
280        @echo "***"
281        @echo "*** Once the modules have been moved to their final destination"
282        @echo "*** you must run the command \"/sbin/depmod -a\"."
283        @echo "***"
284        @echo "*** Alternatively, if you build a package (e.g. rpm), include the"
285        @echo "*** command \"/sbin/depmod -a\" in the post-(un)install procedure."
286        @echo "***"
287        @echo "*** The depmod command mentioned above may generate errors. We are"
288        @echo "*** aware of the problem and are working on a solution."
289endif
290
291clean::
292        $(RM) lm_sensors-*
293
294user_uninstall::
295       
296uninstall :: user_uninstall
297        @echo "*** Note:"
298        @echo "***  * Kernel modules were not uninstalled."
299
300# This is tricky, but it works like a charm. It needs lots of utilities
301# though: cut, find, gzip, ln, tail and tar.
302package: version clean
303        lmversion=`tail -1 version.h|cut -f 2 -d \"`; \
304        lmpackage=lm_sensors-$$lmversion; \
305        ln -s . $$lmpackage;  \
306        find $$lmpackage/ -type f | grep -v ^$$lmpackage/$$lmpackage$$ | \
307                                    grep -v ^$$lmpackage/$$lmpackage.tar$$ | \
308                                    grep -v ^$$lmpackage/$$ | \
309                                    grep -v /CVS | \
310                                    grep -v /\\.# | \
311                                    tar rvf $$lmpackage.tar -T -; \
312        gzip -9 $$lmpackage.tar ;\
313        $(RM) $$lmpackage.tar $$lmpackage
314        cat doc/developers/checklist
315
316version:
317        $(RM) version.h
318        echo '#define LM_DATE "'`date +'%Y%m%d'`\" > version.h
319        echo -n 'Version: '; \
320        echo '#define LM_VERSION "'`read VER; echo $$VER`\" >> version.h
321
322help:
323        @echo 'Make targets are:'
324        @echo '  all (default): build modules and userspace programs'
325        @echo '  install: install modules and userspace programs'
326        @echo '  user: build userspace programs'
327        @echo '  user_install: install userspace programs'
328        @echo '  user_uninstall: remove userspace programs'
329        @echo '  clean: cleanup'
330        @echo '  package: create a distribution package'
331        @echo 'Note: make dep is automatic'
332
333$(LINUX)/.config:
334        @echo
335        @echo "Error - missing file $(LINUX)/.config !! "
336        @echo "  Verify kernel source is in $(LINUX) and then"
337        @echo "  cd to $(LINUX) and run 'make config' !!"
338        @echo
339        @echo "Exception: if you're using a stock RedHat kernel..."
340        @echo "  (1) Install the appropriate kernel-source RPM."
341        @echo "  (2) Copy the appropriate config..."
342        @echo "      from $(LINUX)/configs/<...>"
343        @echo "      to $(LINUX)/.config"
344        @echo "  (3) Do *NOT* 'make dep' or 'make config'."
345        @echo
346        @exit 1
347
348# Generate html man pages to be copied to the lm_sensors website.
349# This uses the man2html from here
350# http://ftp.math.utah.edu/pub/sgml/
351# which works directly from the nroff source
352manhtml:
353        $(MKDIR) html
354        cp $(MANPAGES) html
355        cd html ; \
356        export LOGNAME=sensors ; \
357        export HOSTNAME=stimpy.netroedge.com ; \
358        man2html *.[1-8] ; \
359        $(RM) *.[1-8]
360
361# Here, we define all implicit rules we want to use.
362
363.SUFFIXES:
364
365# We need to create dependency files. Tricky. We sed rule puts dir/file.d and
366# dir/file.c in front of the dependency file rule.
367
368# .o files are used for modules
369# depend on the kernel config file!
370%.o: %.c $(LINUX)/.config
371        $(CC) $(MODCPPFLAGS) $(MODCFLAGS) -c $< -o $@
372
373%.d: %.c $(LINUX)/.config
374        $(CC) -M -MG $(MODCPPFLAGS) $(MODCFLAGS) $< | \
375        $(SED) -e 's@^\(.*\)\.o:@$*.d $*.o: Makefile '`dirname $*.d`/Module.mk' @' > $@
376
377
378
379# .ro files are used for programs (as opposed to modules)
380%.ro: %.c
381        $(CC) $(PROGCPPFLAGS) $(PROGCFLAGS) -c $< -o $@
382
383%.rd: %.c
384        $(CC) -M -MG $(PROGCPPFLAGS) $(PROGCFLAGS) $< | \
385        $(SED) -e 's@^\(.*\)\.o:@$*.rd $*.ro: Makefile '`dirname $*.rd`/Module.mk' @' > $@
386
387
388%: %.ro
389        $(CC) $(EXLDFLAGS) -o $@ $^
390
391
392# .ao files are used for static archives
393%.ao: %.c
394        $(CC) $(ARCPPFLAGS) $(ARCFLAGS) -c $< -o $@
395
396%.ad: %.c
397        $(CC) -M -MG $(ARCPPFLAGS) $(ARCFLAGS) $< | \
398        $(SED) -e 's@^\(.*\)\.o:@$*.ad $*.ao: Makefile '`dirname $*.ad`/Module.mk' @' > $@
399
400
401# .lo files are used for shared libraries
402%.lo: %.c
403        $(CC) $(LIBCPPFLAGS) $(LIBCFLAGS) -c $< -o $@
404
405%.ld: %.c
406        $(CC) -M -MG $(LIBCPPFLAGS) $(LIBCFLAGS) $< | \
407        $(SED) -e 's@^\(.*\)\.o:@$*.ld $*.lo: Makefile '`dirname $*.ld`/Module.mk' @' > $@
408
409
410# Flex and Bison
411%c: %y
412        $(BISON) -p sensors_yy -d $< -o $@
413
414%.c: %.l
415        $(FLEX) -Psensors_yy -t $< > $@
Note: See TracBrowser for help on using the browser.