root/lm-sensors/trunk/Makefile @ 179

Revision 179, 8.1 KB (checked in by frodo, 16 years ago)

Makefile tweaks for the new kernel directory structure

  • 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  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 and bison.
23
24# Uncomment the third line on SMP systems if the magic invocation fails. It
25# is a bit complicated because SMP configuration changed around kernel 2.1.130
26SMP := $(shell if grep -q '^SMP[[:space:]]*=' /usr/src/linux/Makefile || \
27                  grep -q '^[[:space:]]*\#define[[:space:]]*CONFIG_SMP[[:space:]]*1' /usr/include/linux/autoconf.h ; \
28               then echo 1; else echo 0; fi)
29#SMP := 0
30#SMP := 1
31
32# Uncomment the second or third line if the magic invocation fails.
33# We need to know whether CONFIG_MODVERSIONS is defined.
34MODVER := $(shell if cat /usr/include/linux/config.h /usr/include/linux/autoconf.h 2>/dev/null | grep -q '^[[:space:]]*\#define[[:space:]]*CONFIG_MODVERSIONS[[:space:]]*1'; then echo 1; else echo 0; fi)
35#MODVER := 0
36#MODVER := 1
37
38# Uncomment the second line if you do not want to compile the included
39# i2c modules. WARNING! If the i2c module version does not match the
40# smbus/sensor module versions, you will get into severe problems.
41# If you want to use a self-compiled version of the i2c modules, make
42# sure <linux/i2c.h> contains the *correct* i2c header file! The stock
43# Linux 2.1.xxx and 2.2.x modules are *not* good enough; you really need
44# Simon Vogl's version!
45I2C := 1
46#I2C := 0
47
48# Uncomment the second line if you are a developer. This will enable many
49# additional warnings at compile-time
50WARN := 0
51#WARN := 1
52
53# Uncomment the second line if you want to get (loads of) debug information.
54# Not recommended, unless you are actually debugging the code
55DEBUG := 0
56#DEBUG := 1
57
58# This is the prefix that will be used for almost all directories below.
59PREFIX := /usr/local
60
61# This is the directory into which the modules will be installed.
62MODDIR := /lib/modules/extra/misc
63
64# This is the directory where sensors.conf will be installed, if no other
65# configuration file is found
66ETCDIR := /etc
67
68# You should not need to change this. It is the directory into which the
69# library files (both static and shared) will be installed.
70LIBDIR := $(PREFIX)/lib
71
72# You should not need to change this. It is the directory into which the
73# executable program files will be installed.
74# Note that not all programs in this package are really installed;
75# some are just examples. You can always install them by hand, of
76# course.
77BINDIR := $(PREFIX)/bin
78
79# You should not need to change this. It is the basic directory into which
80# include files will be installed. The actual directory will be
81# $(INCLUDEDIR)/linux for system include files, and $(INCLUDEDIR)/sensors
82# for library include files. If PREFIX equals the default /usr/local/bin,
83# you will be able to use '#include <linux/sensors.h>' regardless of the
84# current kernel selected.
85INCLUDEDIR := $(PREFIX)/include
86SYSINCLUDEDIR := $(INCLUDEDIR)/linux
87LIBINCLUDEDIR := $(INCLUDEDIR)/sensors
88
89# If your /bin/sh is not bash, change the below definition so that make can
90# find bash.
91# SHELL=/usr/bin/bash
92
93# Below this, nothing should need to be changed.
94
95# Note that this is a monolithic Makefile; it calls no sub-Makefiles,
96# but instead, it compiles everything right from here. Yes, there are
97# some distinct advantages to this; see the following paper for more info:
98#   http://www.tip.net.au/~millerp/rmch/recu-make-cons-harm.html
99# Note that is still uses Makefile fragments in sub-directories; these
100# are called 'Module.mk'.
101
102# Within each Module.mk, rules and dependencies can be added to targets
103# all, install and clean. Use double colons instead of single ones
104# to do this.
105
106# The subdirectories we need to build things in
107SRCDIRS := kernel kernel/busses kernel/chips kernel/include lib prog/sensors \
108           prog/dump etc
109ifeq ($(I2C),1)
110SRCDIRS += i2c i2c/detect i2c/drivers i2c/eeprom
111endif
112
113# Some often-used commands with default options
114MKDIR := mkdir -p
115RM := rm -f
116CC := gcc
117BISON := bison
118FLEX := flex
119AR := ar
120INSTALL := install
121LN := ln -sfn
122
123# Determine the default compiler flags
124# MODCFLAGS is to create in-kernel object files (modules); PROGFLAGS is to
125# create non-kernel object files (which are linked into executables).
126# ARCFLAGS are used to create archive object files (static libraries), and
127# LIBCFLAGS are for shared library objects.
128CFLAGS := -I. -Ii2c -Ikernel -Ikernel/include -O2 -DLM_SENSORS
129
130ifeq ($(DEBUG),1)
131CFLAGS += -DDEBUG
132endif
133
134ifeq ($(WARN),1)
135CFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \
136          -Wcast-align -Wwrite-strings -Wnested-externs -Winline
137endif
138
139ifeq ($(I2C),1)
140CFLAGS += -DI2C
141endif
142
143MODCFLAGS := $(CFLAGS) -D__KERNEL__ -DMODULE -fomit-frame-pointer
144PROGCFLAGS := $(CFLAGS)
145ARCFLAGS := $(CFLAGS)
146LIBCFLAGS := $(CFLAGS) -fpic
147
148ifeq ($(SMP),1)
149MODCFLAGS += -D__SMP__
150endif
151
152ifeq ($(MODVER),1)
153MODCFLAGS += -DMODVERSIONS -include /usr/include/linux/modversions.h
154endif
155
156.PHONY: all clean install version package dep
157
158# Make all the default rule
159all::
160
161# Include all makefiles for sub-modules
162INCLUDEFILES := 
163include $(patsubst %,%/Module.mk,$(SRCDIRS))
164ifneq ($(MAKECMDGOALS),clean)
165include $(INCLUDEFILES)
166endif
167
168# Making the dependency files - done automatically!
169dep :
170
171all ::
172
173install :: all
174
175clean::
176        $(RM) lm_sensors-*
177
178# This is tricky, but it works like a charm. It needs lots of utilities
179# though: cut, find, gzip, ln, tail and tar.
180package: version clean
181        lmversion=`tail -1 version.h|cut -f 2 -d \"`; \
182        lmpackage=lm_sensors-$$lmversion; \
183        ln -s . $$lmpackage;  \
184        find $$lmpackage/ -type f | grep -v ^$$lmpackage/$$lmpackage$$ | \
185                                    grep -v ^$$lmpackage/$$lmpackage.tar$$ | \
186                                    grep -v ^$$lmpackage/$$ | \
187                                    grep -v CVS | \
188                                    grep -v ^$$lmpackage/.# | \
189                                    tar rvf $$lmpackage.tar -T -; \
190        gzip -9 $$lmpackage.tar ;\
191        $(RM) $$lmpackage.tar $$lmpackage
192
193version:
194        $(RM) version.h
195        echo '#define LM_DATE "'`date +'%Y%m%d'`\" > version.h
196        echo -n 'Version: '; \
197        echo '#define LM_VERSION "'`read VER; echo $$VER`\" >> version.h
198
199
200# Here, we define all implicit rules we want to use.
201
202.SUFFIXES:
203
204# We need to create dependency files. Tricky. We sed rule puts dir/file.d and
205# dir/file.c # in front of the dependency file rule.
206
207# .o files are used for modules
208%.o: %.c
209        $(CC) $(MODCFLAGS) -c $< -o $@
210
211%.d: %.c
212        $(CC) -M -MG $(MODCFLAGS) $< | \
213        sed -e 's@^\(.*\)\.o:@$*.d $*.o: Makefile '`dirname $*.d`/Module.mk' @' > $@
214
215
216
217# .ro files are used for programs (as opposed to modules)
218%.ro: %.c
219        $(CC) $(PROGCFLAGS) -c $< -o $@
220
221%.rd: %.c
222        $(CC) -M -MG $(PROGCFLAGS) $< | \
223        sed -e 's@^\(.*\)\.o:@$*.rd $*.ro: Makefile '`dirname $*.rd`/Module.mk' @' > $@
224
225
226%: %.ro
227        $(CC) $(EXLDFLAGS) -o $@ $^
228
229
230# .ao files are used for static archives
231%.ao: %.c
232        $(CC) $(ARCFLAGS) -c $< -o $@
233
234%.ad: %.c
235        $(CC) -M -MG $(ARCFLAGS) $< | \
236        sed -e 's@^\(.*\)\.o:@$*.ad $*.ao: Makefile '`dirname $*.ad`/Module.mk' @' > $@
237
238
239# .lo files are used for shared libraries
240%.lo: %.c
241        $(CC) $(LIBCFLAGS) -c $< -o $@
242
243%.ld: %.c
244        $(CC) -M -MG $(LIBCFLAGS) $< | \
245        sed -e 's@^\(.*\)\.o:@$*.ld $*.lo: Makefile '`dirname $*.ld`/Module.mk' @' > $@
246
247
248# Flex and Bison
249%c: %y
250        $(BISON) -p sensors_yy -d $< -o $@
251
252%.c: %.l
253        $(FLEX) -Psensors_yy -t $< > $@
Note: See TracBrowser for help on using the browser.