root/i2c/trunk/Makefile @ 3853

Revision 3853, 9.3 KB (checked in by mmh, 10 years ago)

copy recent lm_sensors2/Makefile changes here:
[add dependency on the kernel .config file; quit without it]

  • 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# This is the directory into which the modules will be installed.
59# The magic invocation will return something like this:
60#   /lib/modules/2.2.15-ac9/misc
61#MODDIR := /lib/modules/`grep UTS_RELEASE $(LINUX_HEADERS)/linux/version.h|cut -f 2 -d'"'`/misc
62#MODPREF := /lib/modules/`grep UTS_RELEASE $(LINUX_HEADERS)/linux/version.h|cut -f 2 -d'"'`
63#MODPREF := /lib/modules/$(KERNELVERSION)
64MODPREF := /lib/modules/$(shell $(CC) -I$(LINUX_HEADERS) -E etc/config.c | grep uts_release |cut -f 2 -d'"')
65
66# This is the directory into which the header files will be installed.
67# If you want to make sure your current kernel tree is not overwritten,
68# the default should work. This is ignored for the i2c build system.
69LINUX_INCLUDE_DIR := /usr/local/include/linux
70#LINUX_INCLUDE_DIR := $(LINUX_HEADERS)/linux
71
72# If you want to isntall everything at some other place then at which
73# you will run it, DESTDIR defines a prefix used at installation-time.
74DESTDIR :=
75
76# Uncomment the second line if you are a developer. This will enable many
77# additional warnings at compile-time
78WARN := 0
79#WARN := 1
80
81MACHINE := $(shell uname -m)
82
83##################################################
84# Below this, nothing should need to be changed. #
85##################################################
86
87.PHONY: all clean install patch
88
89# Note that this is a monolithic Makefile; it calls no sub-Makefiles,
90# but instead, it compiles everything right from here. Yes, there are
91# some distinct advantages to this; see the following paper for more info:
92#   http://www.tip.net.au/~millerp/rmch/recu-make-cons-harm.html
93# Note that is still uses Makefile fragments in sub-directories; these
94# are called 'Module.mk'.
95
96# Within each Module.mk, rules and dependencies can be added to targets
97# all, install and clean. Use double colons instead of single ones
98# to do this.
99
100# The subdirectories we need to build things in
101SRCDIRS := mkpatch
102ifeq ($(COMPILE_KERNEL),1)
103SRCDIRS += kernel
104endif
105
106# Some often-used commands with default options
107MKDIR := mkdir -p
108RMDIR := rmdir
109RM := rm -f
110CC := gcc
111BISON := bison
112FLEX := flex
113AR := ar
114INSTALL := install
115LN := ln -sfn
116GREP := grep
117
118# Determine the default compiler flags
119# MODCFLAGS is to create in-kernel object files (modules)
120
121CPPFLAGS := -I$(LINUX_HEADERS)
122CFLAGS := -Wall -O2 -DLM_SENSORS
123
124ifeq ($(WARN),1)
125CFLAGS += -W -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \
126          -Wcast-align -Wwrite-strings -Wnested-externs -Winline
127endif
128
129
130# The -DEXPORT_SYMTAB is to keep the symbol export mechanism quiet.
131MODCFLAGS := $(CFLAGS) -D__KERNEL__ -DMODULE -fomit-frame-pointer \
132             -DEXPORT_SYMTAB
133
134ifeq ($(MACHINE),alpha)
135MODCFLAGS += -ffixed-8
136endif
137
138ifeq ($(MACHINE),x86_64)
139MODCFLAGS += -fno-strict-aliasing -fno-common -fomit-frame-pointer -mno-red-zone\
140             -mcmodel=kernel -fno-reorder-blocks -finline-limit=2000 -fno-strength-reduce
141endif
142
143ifeq ($(SMP),1)
144MODCPPFLAGS += -D__SMP__
145endif
146
147ifeq ($(MODVER),1)
148MODCPPFLAGS += -DMODVERSIONS -include $(LINUX_HEADERS)/linux/modversions.h
149endif
150
151# This magic is from the kernel Makefile.
152# Extra cflags for kbuild 2.4.  The default is to forbid includes by kernel code
153# from user space headers.
154kbuild_2_4_nostdinc := -nostdinc $(shell LC_ALL=C $(CC) -print-search-dirs | sed -ne 's/install: \(.*\)/-I \1include/gp')
155MODCPPFLAGS += $(CPPFLAGS) $(kbuild_2_4_nostdinc)
156
157.PHONY: dep
158# Make all the default rule
159all::
160
161# Include all makefiles for sub-modules
162INCLUDEFILES :=
163ifneq ($(SRCDIRS),)
164include $(patsubst %,%/Module.mk,$(SRCDIRS))
165endif
166ifneq ($(MAKECMDGOALS),clean)
167ifneq ($(INCLUDEFILES),)
168include $(INCLUDEFILES)
169endif
170endif
171
172# Making the dependency files - done automatically!
173dep :
174
175all ::
176ifeq ($(shell if grep -q '^CONFIG_I2C=y' $(LINUX)/.config; then echo 1; fi),1)
177        @echo "*************** WARNING *************************** WARNING ***************"
178        @echo "***                                                                     ***"
179        @echo "*** You have I2C support built into your kernel (CONFIG_I2C=y). Unless  ***"
180        @echo "*** you know what you are doing, installing our version of i2c will not ***"
181        @echo "*** work. Newly built i2c modules probably won't load. Other modules    ***"
182        @echo "*** that rely on the i2c layer, such as lm_sensors, will fail to        ***"
183        @echo "*** compile. Please consider compiling your kernel again with I2C       ***"
184        @echo "*** support enabled as modules or disabled.                             ***"
185        @echo "***                                                                     ***"
186        @echo "*************** WARNING *************************** WARNING ***************"
187endif
188
189install :: all
190        @echo "*** The depmod command below may generate errors. We are aware of the"
191        @echo "*** problem and are working on a solution. You should ignore them for now."
192ifeq ($(DESTDIR),)
193        -/sbin/depmod -a
194else
195        -/sbin/depmod -a -b $(DESTDIR)
196endif
197        @echo "*** Installation successful!"
198        @echo "*** Important notes:"
199        @echo "*** 1* Due to a change in our i2c structures, i2c-related drivers from"
200        @echo "***    the Linux kernel and from external sources won't work with this"
201        @echo "***    version of i2c. Such drivers include commonly used video drivers"
202        @echo "***    such as bttv and zoran, and less commonly used ones such as"
203        @echo "***    i2c-matroxfb. If you really need these, then you shouldn't use our"
204        @echo "***    i2c package. If you can leave without them, you should make sure"
205        @echo "***    such drivers do not exist on your system anymore. Loading them"
206        @echo "***    now would result in a severe system crash. We are working on the"
207        @echo "***    problem and will soon submit a complete i2c patch for inclusion in"
208        @echo "***    the Linux 2.4 kernel."
209        @echo "*** 2* The i2c-elektor and i2c-pcf-epp modules were not built. If you"
210        @echo "***    need them, you have to use compilation option 3 as described in"
211        @echo "***    the INSTALL file."
212
213clean::
214        $(RM) lm_sensors-*
215
216$(LINUX)/.config:
217        @echo
218        @echo "Error - missing file $(LINUX)/.config !! "
219        @echo "  Verify kernel source is in $(LINUX) and then"
220        @echo "  cd to $(LINUX) and run 'make config' !!"
221        @echo
222        @echo "Exception: if you're using a stock RedHat/Fedora kernel..."
223        @echo "  (1) Install the appropriate kernel-source RPM."
224        @echo "  (2) Copy the appropriate config..."
225        @echo "      from $(LINUX)/configs/<...>"
226        @echo "      to $(LINUX)/.config"
227        @echo "  (3) Do *NOT* 'make dep' or 'make config'."
228        @echo
229        @exit 1
230
231# Here, we define all implicit rules we want to use.
232
233.SUFFIXES:
234
235# We need to create dependency files. Tricky. We sed rule puts dir/file.d and
236# dir/file.c in front of the dependency file rule.
237
238# .o files are used for modules
239# depend on the kernel config file!
240%.o: %.c $(LINUX)/.config
241        $(CC) $(MODCPPFLAGS) $(MODCFLAGS) -c $< -o $@
242
243%.d: %.c $(LINUX)/.config
244        $(CC) -M -MG $(MODCPPFLAGS) $(MODCFLAGS) $< | \
245        sed -e 's@^\(.*\)\.o:@$*.d $*.o: Makefile '`dirname $*.d`/Module.mk' @' > $@
246
Note: See TracBrowser for help on using the browser.