root/lm-sensors/trunk/Makefile @ 2272

Revision 2272, 12.9 KB (checked in by khali, 11 years ago)

No, do not ignore errors.

  • 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)
156SRCDIRS += mkpatch
157SRCDIRS += kernel kernel/busses kernel/chips
158endif
159endif
160SRCDIRS += kernel/include
161SRCDIRS += lib prog/detect prog/dump prog/eeprom prog/pwm \
162           prog/sensors prog/xeon ${PROG_EXTRA:%=prog/%} etc
163
164# Some often-used commands with default options
165MKDIR := mkdir -p
166RMDIR := rmdir
167RM := rm -f
168BISON := bison
169FLEX := flex
170AR := ar
171INSTALL := install
172LN := ln -sf
173GREP := grep
174AWK := awk
175SED := sed
176
177# Determine the default compiler flags
178# Set CFLAGS or CPPFLAGS above to add your own flags to all.
179# ALLCPPFLAGS/ALLCFLAGS are common flags, plus any user-specified overrides from the environment or make command line.
180# MODCPPFLAGS/MODCFLAGS is to create in-kernel object files (modules).
181# PROGCPPFLAGS/PROGCFLAGS is to create non-kernel object files (which are linked into executables).
182# ARCPPFLAGS/ARCFLAGS are used to create archive object files (static libraries).
183# LIBCPPFLAGS/LIBCFLAGS are for shared library objects.
184ALL_CPPFLAGS := -I. -Ikernel/include -I$(I2C_HEADERS)
185ALL_CFLAGS := -Wall
186
187ifeq ($(DEBUG),1)
188ALL_CPPFLAGS += -DDEBUG
189ALL_CFLAGS += -O -g
190else
191ALL_CFLAGS += -O2
192endif
193
194ifeq ($(WARN),1)
195ALL_CFLAGS += -W -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \
196            -Wcast-align -Wwrite-strings -Wnested-externs -Winline
197endif
198
199ALL_CPPFLAGS += $(CPPFLAGS)
200ALL_CFLAGS += $(CFLAGS)
201
202MODCPPFLAGS :=
203MODCFLAGS :=
204
205ifeq ($(MACHINE),alpha)
206MODCFLAGS += -ffixed-8 -mno-fp-regs -mcpu=ev56
207endif
208
209ifeq ($(MACHINE),x86_64)
210MODCFLAGS += -fno-strict-aliasing -fno-common -fomit-frame-pointer -mno-red-zone \
211             -mcmodel=kernel -fno-reorder-blocks -finline-limit=2000 -fno-strength-reduce
212endif
213
214ifeq ($(SMP),1)
215MODCPPFLAGS += -D__SMP__
216endif
217
218ifeq ($(MODVER),1)
219MODCPPFLAGS += -DMODVERSIONS -include $(LINUX_HEADERS)/linux/modversions.h
220endif
221
222# This magic is from the kernel Makefile.
223# Extra cflags for kbuild 2.4.  The default is to forbid includes by kernel code
224# from user space headers.
225kbuild_2_4_nostdinc := -nostdinc $(shell LC_ALL=C $(CC) -print-search-dirs | sed -ne 's/install: \(.*\)/-I \1include/gp')
226
227MODCPPFLAGS += -D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -fomit-frame-pointer $(ALL_CPPFLAGS) -I$(LINUX_HEADERS) $(kbuild_2_4_nostdinc)
228MODCFLAGS += $(ALL_CFLAGS)
229PROGCPPFLAGS := $(ALL_CPPFLAGS)
230PROGCFLAGS := $(ALL_CFLAGS)
231ARCPPFLAGS := $(ALL_CPPFLAGS)
232ARCFLAGS := $(ALL_CFLAGS)
233LIBCPPFLAGS := $(ALL_CPPFLAGS)
234LIBCFLAGS := -fpic $(ALL_CFLAGS)
235
236.PHONY: all clean install version package dep
237
238# Make all the default rule
239all::
240
241# Include all makefiles for sub-modules
242INCLUDEFILES := 
243include $(patsubst %,%/Module.mk,$(SRCDIRS))
244ifneq ($(MAKECMDGOALS),clean)
245include $(INCLUDEFILES)
246endif
247
248# Making the dependency files - done automatically!
249dep :
250
251user ::
252user_install::
253all :: user
254install :: all user_install
255        @echo "*** The depmod command below may generate errors. We are aware of the"
256        @echo "*** problem and are working on a solution."
257ifeq ($(DESTDIR),)
258        -/sbin/depmod -a
259else
260        -/sbin/depmod -a -b $(DESTDIR)
261endif
262        @echo "*** Installation successful!"
263        @echo "*** Important note:"
264        @echo "***  * The libsensors configuration file ($(ETCDIR)/sensors.conf) is never"
265        @echo "***    overwritten by our installation process, so that you won't lose"
266        @echo "***    your personal settings in that file. You still can get our latest"
267        @echo "***    default config file in etc/sensors.conf.eg and manually copy it to"
268        @echo "***    $(ETCDIR)/sensors.conf if you want. You will then want to edit it"
269        @echo "***    to fit your needs again."
270
271clean::
272        $(RM) lm_sensors-*
273
274# This is tricky, but it works like a charm. It needs lots of utilities
275# though: cut, find, gzip, ln, tail and tar.
276package: version clean
277        lmversion=`tail -1 version.h|cut -f 2 -d \"`; \
278        lmpackage=lm_sensors-$$lmversion; \
279        ln -s . $$lmpackage;  \
280        find $$lmpackage/ -type f | grep -v ^$$lmpackage/$$lmpackage$$ | \
281                                    grep -v ^$$lmpackage/$$lmpackage.tar$$ | \
282                                    grep -v ^$$lmpackage/$$ | \
283                                    grep -v /CVS | \
284                                    grep -v /\\.# | \
285                                    tar rvf $$lmpackage.tar -T -; \
286        gzip -9 $$lmpackage.tar ;\
287        $(RM) $$lmpackage.tar $$lmpackage
288        cat doc/developers/checklist
289
290version:
291        $(RM) version.h
292        echo '#define LM_DATE "'`date +'%Y%m%d'`\" > version.h
293        echo -n 'Version: '; \
294        echo '#define LM_VERSION "'`read VER; echo $$VER`\" >> version.h
295
296help:
297        @echo 'Make targets are:'
298        @echo '  all (default): build modules and userspace programs'
299        @echo '  install: install modules and userspace programs'
300        @echo '  user: build userspace programs'
301        @echo '  user_install: install userspace programs'
302        @echo '  clean: cleanup'
303        @echo '  package: create a distribution package'
304        @echo 'Note: make dep is automatic'
305
306$(LINUX)/.config:
307        @echo
308        @echo "Error - missing file $(LINUX)/.config !! "
309        @echo "  Verify kernel source is in $(LINUX) and then"
310        @echo "  cd to $(LINUX) and run 'make config' !!"
311        @echo
312        @echo "Exception: if you're using a stock RedHat kernel..."
313        @echo "  (1) Install the appropriate kernel-source RPM."
314        @echo "  (2) Copy the appropriate config..."
315        @echo "      from $(LINUX)/configs/<...>"
316        @echo "      to $(LINUX)/.config"
317        @echo "  (3) Do *NOT* 'make dep' or 'make config'."
318        @echo
319        @exit 1
320
321# Here, we define all implicit rules we want to use.
322
323.SUFFIXES:
324
325# We need to create dependency files. Tricky. We sed rule puts dir/file.d and
326# dir/file.c in front of the dependency file rule.
327
328# .o files are used for modules
329# depend on the kernel config file!
330%.o: %.c $(LINUX)/.config
331        $(CC) $(MODCPPFLAGS) $(MODCFLAGS) -c $< -o $@
332
333%.d: %.c $(LINUX)/.config
334        $(CC) -M -MG $(MODCPPFLAGS) $(MODCFLAGS) $< | \
335        $(SED) -e 's@^\(.*\)\.o:@$*.d $*.o: Makefile '`dirname $*.d`/Module.mk' @' > $@
336
337
338
339# .ro files are used for programs (as opposed to modules)
340%.ro: %.c
341        $(CC) $(PROGCPPFLAGS) $(PROGCFLAGS) -c $< -o $@
342
343%.rd: %.c
344        $(CC) -M -MG $(PROGCPPFLAGS) $(PROGCFLAGS) $< | \
345        $(SED) -e 's@^\(.*\)\.o:@$*.rd $*.ro: Makefile '`dirname $*.rd`/Module.mk' @' > $@
346
347
348%: %.ro
349        $(CC) $(EXLDFLAGS) -o $@ $^
350
351
352# .ao files are used for static archives
353%.ao: %.c
354        $(CC) $(ARCPPFLAGS) $(ARCFLAGS) -c $< -o $@
355
356%.ad: %.c
357        $(CC) -M -MG $(ARCPPFLAGS) $(ARCFLAGS) $< | \
358        $(SED) -e 's@^\(.*\)\.o:@$*.ad $*.ao: Makefile '`dirname $*.ad`/Module.mk' @' > $@
359
360
361# .lo files are used for shared libraries
362%.lo: %.c
363        $(CC) $(LIBCPPFLAGS) $(LIBCFLAGS) -c $< -o $@
364
365%.ld: %.c
366        $(CC) -M -MG $(LIBCPPFLAGS) $(LIBCFLAGS) $< | \
367        $(SED) -e 's@^\(.*\)\.o:@$*.ld $*.lo: Makefile '`dirname $*.ld`/Module.mk' @' > $@
368
369
370# Flex and Bison
371%c: %y
372        $(BISON) -p sensors_yy -d $< -o $@
373
374%.c: %.l
375        $(FLEX) -Psensors_yy -t $< > $@
Note: See TracBrowser for help on using the browser.