root/i2c/trunk/Makefile @ 3967

Revision 3967, 9.3 KB (checked in by khali, 8 years ago)

Kill duplicate sparc64 compilation flags, sorry for the noise.

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