root/i2c/trunk/Makefile @ 4101

Revision 4101, 9.5 KB (checked in by khali, 8 years ago)

Revert previous Makefile change (Silent errors on missing dependency files)
as it appears to break with GNU make 3.81.

  • 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, 2000  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# If your /bin/sh is not bash, change the below definition so that make can
22# find bash. Or you can hope your sh-like shell understands all scripts.
23# I think so, but I have not tested it.
24#SHELL := /usr/bin/bash
25
26# The currently running kernel version. This is used right below to
27# determine where the kernel sources can be found.
28KERNELVERSION := $(shell uname -r)
29
30# The location of linux itself. This is used to find the kernel headers
31# and other things.
32#LINUX := /usr/src/linux
33LINUX := $(shell if [ -L /lib/modules/$(KERNELVERSION)/build ] ; \
34        then echo "/lib/modules/$(KERNELVERSION)/build" ; \
35        else echo "/usr/src/linux" ; fi)
36LINUX_HEADERS := $(LINUX)/include
37
38# Determine whether we need to compile the kernel modules, or only the
39# user-space utilities. By default, the kernel modules are compiled.
40#COMPILE_KERNEL := 0
41COMPILE_KERNEL := 1
42
43
44# Uncomment the third line on SMP systems if the magic invocation fails. It
45# is a bit complicated because SMP configuration changed around kernel 2.1.130
46SMP := $(shell if grep -q '^SMP[[:space:]]*=' $(LINUX)/Makefile || \
47                  grep -q '^[[:space:]]*\#define[[:space:]]*CONFIG_SMP[[:space:]]*1' $(LINUX_HEADERS)/linux/autoconf.h ; \
48               then echo 1; else echo 0; fi)
49#SMP := 0
50#SMP := 1
51
52# Uncomment the second or third line if the magic invocation fails.
53# We need to know whether CONFIG_MODVERSIONS is defined.
54MODVER := $(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)
55#MODVER := 0
56#MODVER := 1
57
58# Your C compiler
59CC := gcc
60
61# This is the directory into which the modules will be installed.
62# The magic invocation will return something like this:
63#   /lib/modules/2.4.29
64KERNELVERSION := $(shell $(CC) -I$(LINUX_HEADERS) -E etc/config.c | grep uts_release | cut -f 2 -d'"')
65MODPREF := /lib/modules/$(KERNELVERSION)
66
67# Prevent 2.6+ users from using this package, as this won't work.
68ifeq (,$(findstring /2.4., $(MODPREF)))
69    ifeq (, $(MAKECMDGOALS))
70        $(error For 2.6 kernels and later, you do not need this package)
71    endif
72    ifeq (install, $(MAKECMDGOALS))
73        $(error For 2.6 kernels and later, you do not need this package)
74    endif
75endif
76
77# This is the directory into which the header files will be installed.
78# If you want to make sure your current kernel tree is not overwritten,
79# the default should work. This is ignored for the i2c build system.
80LINUX_INCLUDE_DIR := /usr/local/include/linux
81#LINUX_INCLUDE_DIR := $(LINUX_HEADERS)/linux
82
83# If you want to isntall everything at some other place then at which
84# you will run it, DESTDIR defines a prefix used at installation-time.
85DESTDIR :=
86
87# Uncomment the second line if you are a developer. This will enable many
88# additional warnings at compile-time
89WARN := 0
90#WARN := 1
91
92MACHINE := $(shell uname -m)
93
94##################################################
95# Below this, nothing should need to be changed. #
96##################################################
97
98.PHONY: all clean install patch
99
100# Note that this is a monolithic Makefile; it calls no sub-Makefiles,
101# but instead, it compiles everything right from here. Yes, there are
102# some distinct advantages to this; see the following paper for more info:
103#   http://www.tip.net.au/~millerp/rmch/recu-make-cons-harm.html
104# Note that is still uses Makefile fragments in sub-directories; these
105# are called 'Module.mk'.
106
107# Within each Module.mk, rules and dependencies can be added to targets
108# all, install and clean. Use double colons instead of single ones
109# to do this.
110
111# The subdirectories we need to build things in
112SRCDIRS := mkpatch
113ifeq ($(COMPILE_KERNEL),1)
114SRCDIRS += kernel
115endif
116
117# Some often-used commands with default options
118MKDIR := mkdir -p
119RMDIR := rmdir
120RM := rm -f
121BISON := bison
122FLEX := flex
123AR := ar
124INSTALL := install
125LN := ln -sfn
126GREP := grep
127
128# Determine the default compiler flags
129# MODCFLAGS is to create in-kernel object files (modules)
130
131CPPFLAGS := -I$(LINUX_HEADERS)
132CFLAGS := -Wall -O2
133
134ifeq ($(WARN),1)
135CFLAGS += -W -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \
136          -Wcast-align -Wwrite-strings -Wnested-externs -Winline
137endif
138
139
140# The -DEXPORT_SYMTAB is to keep the symbol export mechanism quiet.
141MODCFLAGS := $(CFLAGS) -D__KERNEL__ -DMODULE -fomit-frame-pointer \
142             -DEXPORT_SYMTAB -fno-strict-aliasing
143
144ifeq ($(MACHINE),alpha)
145MODCFLAGS += -ffixed-8 -mno-fp-regs -mcpu=ev56
146endif
147
148ifeq ($(MACHINE),x86_64)
149MODCFLAGS += -fno-common -fomit-frame-pointer -mno-red-zone \
150             -mcmodel=kernel -fno-reorder-blocks -finline-limit=2000 -fno-strength-reduce
151endif
152
153ifeq ($(MACHINE),mips)
154MODCFLAGS += -mabi=32 -mips3 -Wa,-32 -Wa,-mips3 -Wa,--trap
155endif
156
157ifeq ($(MACHINE),sparc32)
158MODCFLAGS += -m32 -pipe -mno-fpu -fcall-used-g5 -fcall-used-g7
159endif
160
161ifeq ($(MACHINE),sparc64)
162MODCFLAGS += -m64 -pipe -mno-fpu -mcpu=ultrasparc -mcmodel=medlow \
163             -ffixed-g4 -fcall-used-g5 -fcall-used-g7 -Wno-sign-compare \
164             -Wa,--undeclared-regs
165endif
166
167ifeq ($(SMP),1)
168MODCPPFLAGS += -D__SMP__
169endif
170
171ifeq ($(MODVER),1)
172MODCPPFLAGS += -DMODVERSIONS -include $(LINUX_HEADERS)/linux/modversions.h
173endif
174
175# This magic is from the kernel Makefile.
176# Extra cflags for kbuild 2.4.  The default is to forbid includes by kernel code
177# from user space headers.
178kbuild_2_4_nostdinc := -nostdinc $(shell LC_ALL=C $(CC) -print-search-dirs | sed -ne 's/install: \(.*\)/-I \1include/gp')
179MODCPPFLAGS += $(CPPFLAGS) $(kbuild_2_4_nostdinc)
180
181# Make all the default rule
182all::
183
184# Include all makefiles for sub-modules
185INCLUDEFILES :=
186ifneq ($(SRCDIRS),)
187include $(patsubst %,%/Module.mk,$(SRCDIRS))
188endif
189ifneq ($(MAKECMDGOALS),clean)
190include $(INCLUDEFILES)
191endif
192
193all ::
194ifeq ($(shell if grep -q '^CONFIG_I2C=y' $(LINUX)/.config; then echo 1; fi),1)
195        @echo "*************** WARNING *************************** WARNING ***************"
196        @echo "***                                                                     ***"
197        @echo "*** You have I2C support built into your kernel (CONFIG_I2C=y). Unless  ***"
198        @echo "*** you know what you are doing, installing our version of i2c will not ***"
199        @echo "*** work. Newly built i2c modules probably won't load. Other modules    ***"
200        @echo "*** that rely on the i2c layer, such as lm_sensors, will fail to        ***"
201        @echo "*** compile. Please consider compiling your kernel again with I2C       ***"
202        @echo "*** support enabled as modules or disabled.                             ***"
203        @echo "***                                                                     ***"
204        @echo "*************** WARNING *************************** WARNING ***************"
205endif
206
207install :: all
208ifeq ($(DESTDIR),)
209        -if [ -r $(MODPREF)/build/System.map -a -x /sbin/depmod ] ; then \
210          /sbin/depmod -a -F $(MODPREF)/build/System.map $(KERNELVERSION) ; \
211        fi
212else
213        @echo "*** This is a \`staged' install using \"$(DESTDIR)\" as prefix."
214        @echo "***"
215        @echo "*** Once the modules have been moved to their final destination"
216        @echo "*** you must run the command \"/sbin/depmod -a\"."
217        @echo "***"
218        @echo "*** Alternatively, if you build a package (e.g. rpm), include the"
219        @echo "*** command \"/sbin/depmod -a\" in the post-(un)install procedure."
220        @echo "***"
221        @echo "*** If the depmod command mentioned above generates errors, you should"
222        @echo "*** pay particular attention to the note #1 below."
223endif
224        @echo "*** Installation successful!"
225        @echo "*** Important notes:"
226        @echo "*** 1* Compatibility with the Linux 2.4 kernel has been restored."
227        @echo "*** 2* The i2c-elektor and i2c-pcf-epp modules were not built. If you"
228        @echo "***    need them, you have to use compilation option 3 as described in"
229        @echo "***    the INSTALL file."
230
231clean::
232
233$(LINUX)/.config:
234        @echo
235        @echo "Error - missing file $(LINUX)/.config !! "
236        @echo "  Verify kernel source is in $(LINUX) and then"
237        @echo "  cd to $(LINUX) and run 'make config' !!"
238        @echo
239        @echo "Exception: if you're using a stock RedHat/Fedora kernel..."
240        @echo "  (1) Install the appropriate kernel-source RPM."
241        @echo "  (2) Copy the appropriate config..."
242        @echo "      from $(LINUX)/configs/<...>"
243        @echo "      to $(LINUX)/.config"
244        @echo "  (3) Do *NOT* 'make dep' or 'make config'."
245        @echo
246        @exit 1
247
248# Here, we define all implicit rules we want to use.
249
250.SUFFIXES:
251
252# We need to create dependency files. Tricky. The sed rule puts dir/file.d and
253# dir/file.c in front of the dependency file rule.
254
255# .o files are used for modules
256# depend on the kernel config file!
257%.o: %.c $(LINUX)/.config
258        $(CC) $(MODCPPFLAGS) $(MODCFLAGS) -c $< -o $@
259
260%.d: %.c $(LINUX)/.config
261        $(CC) -M -MG $(MODCPPFLAGS) $(MODCFLAGS) $< | \
262        sed -e 's@^\(.*\)\.o:@$*.d $*.o: Makefile '`dirname $*.d`/Module.mk' @' > $@
263
Note: See TracBrowser for help on using the browser.