root/lm-sensors/trunk/Makefile @ 1746

Revision 1746, 11.2 KB (checked in by mds, 10 years ago)

replace -idirafter with -nostdinc and other magic from the kernel

makefile. This prevents ever picking up headers from /usr/include
for module builds. Headers must be located in
/lib/modules/uname -r/build

  • 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# Determine whether we need to compile the kernel modules, or only the
42# user-space utilities. By default, the kernel modules are compiled.
43#COMPILE_KERNEL := 0
44COMPILE_KERNEL := 1
45
46# If you have installed the i2c header at some other place (like
47# /usr/local/include/linux), set that directory here. Please check this out
48# if you get strange compilation errors; the default Linux i2c headers
49# may be used mistakenly. Note: This should point to the directory
50# *above* the linux/ subdirectory, so to /usr/local/include in the
51# above example.
52I2C_HEADERS := /usr/local/include
53#I2C_HEADERS := $(LINUX_HEADERS)
54
55# Uncomment the third line on SMP systems if the magic invocation fails. It
56# is a bit complicated because SMP configuration changed around kernel 2.1.130
57SMP := $(shell if grep -q '^SMP[[:space:]]*=' $(LINUX)/Makefile || \
58                  grep -q '^[[:space:]]*\#define[[:space:]]*CONFIG_SMP[[:space:]]*1' $(LINUX_HEADERS)/linux/autoconf.h ; \
59               then echo 1; else echo 0; fi)
60#SMP := 0
61#SMP := 1
62
63# Uncomment the second or third line if the magic invocation fails.
64# We need to know whether CONFIG_MODVERSIONS is defined.
65MODVER := $(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)
66#MODVER := 0
67#MODVER := 1
68
69# Uncomment the second line if you are a developer. This will enable many
70# additional warnings at compile-time
71WARN := 0
72#WARN := 1
73
74# Uncomment the second line if you want to get (loads of) debug information
75# at run-time.
76# Not recommended, unless you are actually debugging the code
77DEBUG := 0
78#DEBUG := 1
79
80# If you want to install at some other place then at from which you will run
81# everything, set DESTDIR to the extra prefix.
82DESTDIR :=
83
84# This is the prefix that will be used for almost all directories below.
85PREFIX := /usr/local
86
87# This is the main modules directory into which the modules will be installed.
88# The magic invocation will return something like this:
89#   /lib/modules/2.2.15-ac9
90#MODDIR := /lib/modules/`grep UTS_RELEASE $(LINUX_HEADERS)/linux/version.h|cut -f 2 -d'"'`/misc
91#MODPREF := /lib/modules/$(KERNELVERSION)
92#MODPREF := /lib/modules/`grep UTS_RELEASE $(LINUX_HEADERS)/linux/version.h|cut -f 2 -d'"'`
93MODPREF := /lib/modules/$(shell $(CC) -I$(LINUX_HEADERS) -E etc/config.c | grep uts_release |cut -f 2 -d'"')
94
95# This is the directory where sensors.conf will be installed, if no other
96# configuration file is found
97ETCDIR := /etc
98
99# You should not need to change this. It is the directory into which the
100# library files (both static and shared) will be installed.
101LIBDIR := $(PREFIX)/lib
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
127# You should not need to change this. It defines the manual owner and group
128# as which manual pages are installed.
129MANOWN := root
130MANGRP := root
131
132MACHINE := $(shell uname -m)
133
134# Extra non-default programs to build; e.g., sensord
135# PROG_EXTRA := sensord
136
137# Set these to add preprocessor or compiler flags, or use
138# environment variables
139# CFLAGS :=
140# CPPFLAGS :=
141
142##################################################
143# Below this, nothing should need to be changed. #
144##################################################
145
146# Note that this is a monolithic Makefile; it calls no sub-Makefiles,
147# but instead, it compiles everything right from here. Yes, there are
148# some distinct advantages to this; see the following paper for more info:
149#   http://www.tip.net.au/~millerp/rmch/recu-make-cons-harm.html
150# Note that is still uses Makefile fragments in sub-directories; these
151# are called 'Module.mk'.
152
153# Within each Module.mk, rules and dependencies can be added to targets
154# all, install and clean. Use double colons instead of single ones
155# to do this.
156
157# The subdirectories we need to build things in
158SRCDIRS := mkpatch
159ifeq ($(COMPILE_KERNEL),1)
160SRCDIRS += kernel kernel/busses kernel/chips kernel/include
161endif
162SRCDIRS += lib prog/sensors prog/dump prog/detect ${PROG_EXTRA:%=prog/%} etc
163
164# Some often-used commands with default options
165MKDIR := mkdir -p
166RM := rm -f
167CC := gcc
168BISON := bison
169FLEX := flex
170AR := ar
171INSTALL := install
172LN := ln -sfn
173GREP := grep
174
175# Determine the default compiler flags
176# Set CFLAGS or CPPFLAGS above to add your own flags to all.
177# ALLCPPFLAGS/ALLCFLAGS are common flags, plus any user-specified overrides from the environment or make command line.
178# MODCPPFLAGS/MODCFLAGS is to create in-kernel object files (modules).
179# PROGCPPFLAGS/PROGCFLAGS is to create non-kernel object files (which are linked into executables).
180# ARCPPFLAGS/ARCFLAGS are used to create archive object files (static libraries).
181# LIBCPPFLAGS/LIBCFLAGS are for shared library objects.
182ALL_CPPFLAGS := -I. -Ikernel/include -I$(I2C_HEADERS) -I$(LINUX_HEADERS)
183ALL_CFLAGS := -O2
184
185ifeq ($(DEBUG),1)
186ALL_CPPFLAGS += -DDEBUG
187endif
188
189ifeq ($(WARN),1)
190ALL_CFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \
191            -Wcast-align -Wwrite-strings -Wnested-externs -Winline
192endif
193
194ALL_CPPFLAGS += $(CPPFLAGS)
195ALL_CFLAGS += $(CFLAGS)
196
197MODCPPFLAGS :=
198MODCFLAGS :=
199
200ifeq ($(MACHINE),alpha)
201MODCFLAGS += -ffixed-8
202endif
203
204ifeq ($(MACHINE),x86_64)
205MODCFLAGS += -fno-strict-aliasing -fno-common -fomit-frame-pointer -mno-red-zone\
206             -mcmodel=kernel -fno-reorder-blocks -finline-limit=2000 -fno-strength-reduce
207endif
208
209ifeq ($(SMP),1)
210MODCPPFLAGS += -D__SMP__
211endif
212
213ifeq ($(MODVER),1)
214MODCPPFLAGS += -DMODVERSIONS -include $(LINUX_HEADERS)/linux/modversions.h
215endif
216
217# This magic is from the kernel Makefile.
218# Extra cflags for kbuild 2.4.  The default is to forbid includes by kernel code
219# from user space headers.
220kbuild_2_4_nostdinc := -nostdinc $(shell $(CC) -print-search-dirs | sed -ne 's/install: \(.*\)/-I \1include/gp')
221
222MODCPPFLAGS += -D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -fomit-frame-pointer $(ALL_CPPFLAGS) $(kbuild_2_4_nostdinc)
223MODCFLAGS += $(ALL_CFLAGS)
224PROGCPPFLAGS := $(ALL_CPPFLAGS)
225PROGCFLAGS := $(ALL_CFLAGS)
226ARCPPFLAGS := $(ALL_CPPFLAGS)
227ARCFLAGS := $(ALL_CFLAGS)
228LIBCPPFLAGS := $(ALL_CPPFLAGS)
229LIBCFLAGS := -fpic $(ALL_CFLAGS)
230
231.PHONY: all clean install version package dep
232
233# Make all the default rule
234all::
235
236# Include all makefiles for sub-modules
237INCLUDEFILES := 
238include $(patsubst %,%/Module.mk,$(SRCDIRS))
239ifneq ($(MAKECMDGOALS),clean)
240include $(INCLUDEFILES)
241endif
242
243# Making the dependency files - done automatically!
244dep :
245
246all ::
247
248install :: all
249
250clean::
251        $(RM) lm_sensors-*
252
253# This is tricky, but it works like a charm. It needs lots of utilities
254# though: cut, find, gzip, ln, tail and tar.
255package: version clean
256        lmversion=`tail -1 version.h|cut -f 2 -d \"`; \
257        lmpackage=lm_sensors-$$lmversion; \
258        ln -s . $$lmpackage;  \
259        find $$lmpackage/ -type f | grep -v ^$$lmpackage/$$lmpackage$$ | \
260                                    grep -v ^$$lmpackage/$$lmpackage.tar$$ | \
261                                    grep -v ^$$lmpackage/$$ | \
262                                    grep -v /CVS | \
263                                    grep -v /\\.# | \
264                                    tar rvf $$lmpackage.tar -T -; \
265        gzip -9 $$lmpackage.tar ;\
266        $(RM) $$lmpackage.tar $$lmpackage
267        cat doc/developers/checklist
268
269version:
270        $(RM) version.h
271        echo '#define LM_DATE "'`date +'%Y%m%d'`\" > version.h
272        echo -n 'Version: '; \
273        echo '#define LM_VERSION "'`read VER; echo $$VER`\" >> version.h
274
275
276# Here, we define all implicit rules we want to use.
277
278.SUFFIXES:
279
280# We need to create dependency files. Tricky. We sed rule puts dir/file.d and
281# dir/file.c in front of the dependency file rule.
282
283# .o files are used for modules
284%.o: %.c
285        $(CC) $(MODCPPFLAGS) $(MODCFLAGS) -c $< -o $@
286
287%.d: %.c
288        $(CC) -M -MG $(MODCPPFLAGS) $(MODCFLAGS) $< | \
289        sed -e 's@^\(.*\)\.o:@$*.d $*.o: Makefile '`dirname $*.d`/Module.mk' @' > $@
290
291
292
293# .ro files are used for programs (as opposed to modules)
294%.ro: %.c
295        $(CC) $(PROGCPPFLAGS) $(PROGCFLAGS) -c $< -o $@
296
297%.rd: %.c
298        $(CC) -M -MG $(PROGCPPFLAGS) $(PROGCFLAGS) $< | \
299        sed -e 's@^\(.*\)\.o:@$*.rd $*.ro: Makefile '`dirname $*.rd`/Module.mk' @' > $@
300
301
302%: %.ro
303        $(CC) $(EXLDFLAGS) -o $@ $^
304
305
306# .ao files are used for static archives
307%.ao: %.c
308        $(CC) $(ARCPPFLAGS) $(ARCFLAGS) -c $< -o $@
309
310%.ad: %.c
311        $(CC) -M -MG $(ARCPPFLAGS) $(ARCFLAGS) $< | \
312        sed -e 's@^\(.*\)\.o:@$*.ad $*.ao: Makefile '`dirname $*.ad`/Module.mk' @' > $@
313
314
315# .lo files are used for shared libraries
316%.lo: %.c
317        $(CC) $(LIBCPPFLAGS) $(LIBCFLAGS) -c $< -o $@
318
319%.ld: %.c
320        $(CC) -M -MG $(LIBCPPFLAGS) $(LIBCFLAGS) $< | \
321        sed -e 's@^\(.*\)\.o:@$*.ld $*.lo: Makefile '`dirname $*.ld`/Module.mk' @' > $@
322
323
324# Flex and Bison
325%c: %y
326        $(BISON) -p sensors_yy -d $< -o $@
327
328%.c: %.l
329        $(FLEX) -Psensors_yy -t $< > $@
Note: See TracBrowser for help on using the browser.