root/i2c/trunk/Makefile

Revision 5295, 9.6 kB (checked in by khali, 5 months ago)

Fallback to simple depmod if System.map can't be found.

  • 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.
28 KERNELVERSION := $(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
33 LINUX := $(shell if [ -L /lib/modules/$(KERNELVERSION)/build ] ; \
34         then echo "/lib/modules/$(KERNELVERSION)/build" ; \
35         else echo "/usr/src/linux" ; fi)
36 LINUX_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
41 COMPILE_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
46 SMP := $(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.
54 MODVER := $(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
59 CC := 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
64 KERNELVERSION := $(shell $(CC) -I$(LINUX_HEADERS) -E etc/config.c | grep uts_release | cut -f 2 -d'"')
65 MODPREF := /lib/modules/$(KERNELVERSION)
66
67 # Prevent 2.6+ users from using this package, as this won't work.
68 ifeq (,$(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
75 endif
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.
80 LINUX_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.
85 DESTDIR :=
86
87 # Uncomment the second line if you are a developer. This will enable many
88 # additional warnings at compile-time
89 WARN := 0
90 #WARN := 1
91
92 MACHINE := $(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
112 SRCDIRS := mkpatch
113 ifeq ($(COMPILE_KERNEL),1)
114 SRCDIRS += kernel
115 endif
116
117 # Some often-used commands with default options
118 MKDIR := mkdir -p
119 RMDIR := rmdir
120 RM := rm -f
121 BISON := bison
122 FLEX := flex
123 AR := ar
124 INSTALL := install
125 LN := ln -sfn
126 GREP := grep
127
128 # Determine the default compiler flags
129 # MODCFLAGS is to create in-kernel object files (modules)
130
131 CPPFLAGS := -I$(LINUX_HEADERS)
132 CFLAGS := -Wall -O2
133
134 ifeq ($(WARN),1)
135 CFLAGS += -W -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \
136           -Wcast-align -Wwrite-strings -Wnested-externs -Winline
137 endif
138
139
140 # The -DEXPORT_SYMTAB is to keep the symbol export mechanism quiet.
141 MODCFLAGS := $(CFLAGS) -D__KERNEL__ -DMODULE -fomit-frame-pointer \
142              -DEXPORT_SYMTAB -fno-strict-aliasing
143
144 ifeq ($(MACHINE),alpha)
145 MODCFLAGS += -ffixed-8 -mno-fp-regs -mcpu=ev56
146 endif
147
148 ifeq ($(MACHINE),x86_64)
149 MODCFLAGS += -fno-common -fomit-frame-pointer -mno-red-zone \
150              -mcmodel=kernel -fno-reorder-blocks -finline-limit=2000 -fno-strength-reduce
151 endif
152
153 ifeq ($(MACHINE),mips)
154 MODCFLAGS += -mabi=32 -mips3 -Wa,-32 -Wa,-mips3 -Wa,--trap
155 endif
156
157 ifeq ($(MACHINE),sparc32)
158 MODCFLAGS += -m32 -pipe -mno-fpu -fcall-used-g5 -fcall-used-g7
159 endif
160
161 ifeq ($(MACHINE),sparc64)
162 MODCFLAGS += -m64 -pipe -mno-fpu -mcpu=ultrasparc -mcmodel=medlow \
163              -ffixed-g4 -fcall-used-g5 -fcall-used-g7 -Wno-sign-compare \
164              -Wa,--undeclared-regs
165 endif
166
167 ifeq ($(SMP),1)
168 MODCPPFLAGS += -D__SMP__
169 endif
170
171 ifeq ($(MODVER),1)
172 MODCPPFLAGS += -DMODVERSIONS -include $(LINUX_HEADERS)/linux/modversions.h
173 endif
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.
178 kbuild_2_4_nostdinc := -nostdinc $(shell LC_ALL=C $(CC) -print-search-dirs | sed -ne 's/install: \(.*\)/-I \1include/gp')
179 MODCPPFLAGS += $(CPPFLAGS) $(kbuild_2_4_nostdinc)
180
181 # Make all the default rule
182 all::
183
184 # Include all makefiles for sub-modules
185 INCLUDEFILES :=
186 ifneq ($(SRCDIRS),)
187 include $(patsubst %,%/Module.mk,$(SRCDIRS))
188 endif
189 ifneq ($(MAKECMDGOALS),clean)
190 include $(INCLUDEFILES)
191 endif
192
193 all ::
194 ifeq ($(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 ***************"
205 endif
206
207 install :: all
208 ifeq ($(DESTDIR),)
209         -if [ -x /sbin/depmod ] ; then \
210           if [ -r $(MODPREF)/build/System.map ] ; then \
211             /sbin/depmod -a -F $(MODPREF)/build/System.map $(KERNELVERSION) ; \
212           elif [ "$(KERNELVERSION)" = "`uname -r`"  ] ; then \
213             /sbin/depmod -a ; \
214           fi \
215         fi
216 else
217         @echo "*** This is a \`staged' install using \"$(DESTDIR)\" as prefix."
218         @echo "***"
219         @echo "*** Once the modules have been moved to their final destination"
220         @echo "*** you must run the command \"/sbin/depmod -a\"."
221         @echo "***"
222         @echo "*** Alternatively, if you build a package (e.g. rpm), include the"
223         @echo "*** command \"/sbin/depmod -a\" in the post-(un)install procedure."
224         @echo "***"
225         @echo "*** If the depmod command mentioned above generates errors, you should"
226         @echo "*** pay particular attention to the note #1 below."
227 endif
228         @echo "*** Installation successful!"
229         @echo "*** Important notes:"
230         @echo "*** 1* Compatibility with the Linux 2.4 kernel has been restored."
231         @echo "*** 2* The i2c-elektor and i2c-pcf-epp modules were not built. If you"
232         @echo "***    need them, you have to use compilation option 3 as described in"
233         @echo "***    the INSTALL file."
234
235 clean::
236
237 $(LINUX)/.config:
238         @echo
239         @echo "Error - missing file $(LINUX)/.config !! "
240         @echo "  Verify kernel source is in $(LINUX) and then"
241         @echo "  cd to $(LINUX) and run 'make config' !!"
242         @echo
243         @echo "Exception: if you're using a stock RedHat/Fedora kernel..."
244         @echo "  (1) Install the appropriate kernel-source RPM."
245         @echo "  (2) Copy the appropriate config..."
246         @echo "      from $(LINUX)/configs/<...>"
247         @echo "      to $(LINUX)/.config"
248         @echo "  (3) Do *NOT* 'make dep' or 'make config'."
249         @echo
250         @exit 1
251
252 # Here, we define all implicit rules we want to use.
253
254 .SUFFIXES:
255
256 # We need to create dependency files. Tricky. The sed rule puts dir/file.d and
257 # dir/file.c in front of the dependency file rule.
258
259 # .o files are used for modules
260 # depend on the kernel config file!
261 %.o: %.c $(LINUX)/.config
262         $(CC) $(MODCPPFLAGS) $(MODCFLAGS) -c $< -o $@
263
264 %.d: %.c $(LINUX)/.config
265         $(CC) -M -MG $(MODCPPFLAGS) $(MODCFLAGS) $< | \
266         sed -e 's@^\(.*\)\.o:@$*.d $*.o: Makefile '`dirname $*.d`/Module.mk' @' > $@
267
Note: See TracBrowser for help on using the browser.