root/lm-sensors/trunk/Makefile @ 52

Revision 52, 5.7 KB (checked in by frodo, 15 years ago)

Another Makefile simplification

Object files for executables (as opposed to modules) will now use the .ro
extension; their dependency file is a .rd file. Currently, this affects only
the i2c/eeprom/eeprom program. but in the future, there will be more
executables generated.

  • 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
19# Uncomment the third line on SMP systems if the magic invocation fails.
20SMP := $(shell if grep -q '^SMP[[:space:]]*=' /usr/src/linux/Makefile; then echo 1; else echo 0; fi)
21#SMP := 0
22#SMP := 1
23
24# Uncomment the second or third line if the magic invocation fails.
25# We need to know whether CONFIG_MODVERSIONS is defined.
26MODVER := $(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)
27#MODVER := 0
28#MODVER := 1
29
30# Uncomment the second line if you do not want to compile the included
31# i2c modules. WARNING! If the i2c module version does not match the
32# smbus/sensor module versions, you will get into severe problems.
33# If you want to use a self-compiled version of the i2c modules, make
34# sure <linux/i2c.h> contains the *correct* i2c header file!
35I2C := 1
36#I2C := 0
37
38# Uncomment the second line if you are a developer. This will enable many
39# additional warnings at compile-time
40WARN := 0
41#WARN := 1
42
43# Uncomment the second line if you want to get (loads of) debug information.
44# Not recommended, unless you are actually debugging the code
45DEBUG := 0
46#DEBUG := 1
47
48# This is the directory into which the modules will be installed, if you
49# call 'make install'
50MODDIR := /lib/modules/extra/misc
51
52# This is the directory into which the include files will be installed,
53# if you call 'make install'. If you install it in the directory below,
54# #include <linux/smbus.h>, for example, should work, regardless of the
55# current linux kernel.
56INCLUDEDIR := /usr/local/include/linux
57
58
59# Below this, nothing should need to be changed.
60
61# Note that this is a monolithic Makefile; it calls no sub-Makefiles,
62# but instead, it compiles everything right from here. Yes, there are
63# some distinct advantages to this; see the following paper for more info:
64#   http://www.tip.net.au/~millerp/rmch/recu-make-cons-harm.html
65# Note that is still uses Makefile fragments in sub-directories; these
66# are called 'Module.mk'.
67
68# Within each Module.mk, rules and dependencies can be added to targets
69# all, install and clean. Use double colons instead of single ones
70# to do this.
71
72# The subdirectories we need to build things in
73MODULES := src
74ifeq ($(I2C),1)
75MODULES += i2c i2c/detect i2c/drivers i2c/eeprom
76endif
77
78# Some often-used commands with default options
79MKDIR := mkdir -p
80RM := rm -f
81CC := gcc
82
83# Determine the default compiler flags
84# CFLAGS is to create in-kernel object files (modules); EXCFLAGS is to create
85# non-kernel object files (which are linked into executables).
86CFLAGS := -D__KERNEL__ -DMODULE -I. -Ii2c -O2 -fomit-frame-pointer -DLM_SENSORS
87EXCFLAGS := -I. -Ii2c -O2 -D LM_SENSORS
88
89ifeq ($(DEBUG),1)
90CFLAGS += -DDEBUG
91EXCFLAGS += -DDEBUG
92endif
93
94ifeq ($(SMP),1)
95CFLAGS += -D__SMP__
96endif
97
98ifeq ($(WARN),1)
99CFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \
100          -Wcast-align -Wwrite-strings -Wnested-externs -Winline
101EXCFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \
102            -Wcast-align -Wwrite-strings -Wnested-externs -Winline
103endif
104
105ifeq ($(MODVER),1)
106CFLAGS += -DMODVERSIONS -include /usr/include/linux/modversions.h
107endif
108
109ifeq ($(I2C),1)
110CFLAGS += -DI2C
111endif
112
113.PHONY: all clean install version package dep
114
115# Make all the default rule
116all::
117
118# Include all makefiles for sub-modules
119INCLUDEFILES := 
120include $(patsubst %,%/Module.mk,$(MODULES))
121ifneq ($(MAKECMDGOALS),clean)
122include $(INCLUDEFILES)
123endif
124
125# Making the dependency files - done automatically!
126dep :
127
128all ::
129
130install :: all
131
132clean::
133        $(RM) lm_sensors-*
134
135# Create a dependency file. Tricky. We sed rule puts dir/file.d and dir/file.c
136# in front of the dependency file rule.
137%.d: %.c
138        $(CC) -M -MG $(CFLAGS) $< | \
139        sed -e 's@^\(.*\)\.o:@$*.d $*.o Makefile '`dirname $*.d`/Module.mk':@' > $@
140
141
142# This is tricky, but it works like a charm. It needs lots of utilities
143# though: cut, find, gzip, ln, tail and tar.
144package: version clean
145        lmversion=`tail -1 version.h|cut -f 2 -d \"`; \
146        lmpackage=lm_sensors-$$lmversion; \
147        ln -s . $$lmpackage;  \
148        find $$lmpackage/ -type f | grep -v ^$$lmpackage/$$lmpackage$$ | \
149                                    grep -v ^$$lmpackage/$$lmpackage.tar$$ | \
150                                    grep -v ^$$lmpackage/$$ | \
151                                    grep -v CVS | \
152                                    grep -v ^$$lmpackage/.# | \
153                                    tar rvf $$lmpackage.tar -T -; \
154        gzip -9 $$lmpackage.tar ;\
155        $(RM) $$lmpackage.tar $$lmpackage
156
157version:
158        $(RM) version.h
159        echo '#define LM_DATE "'`date +'%Y%m%d'`\" > version.h
160        echo -n 'Version: '; \
161        echo '#define LM_VERSION "'`read VER; echo $$VER`\" >> version.h
162
163# .ro files are used for programs (as opposed to modules)
164%.ro: %.c
165        $(CC) $(EXCFLAGS) -c $< -o $@
166
167%: %.ro
168        $(CC) $(EXLDFLAGS) -o $@ $^
169
170%.rd: %.c
171        $(CC) -M -MG $(CFLAGS) $< | \
172        sed -e 's@^\(.*\)\.o:@$*.rd $*.ro Makefile '`dirname $*.rd`/Module.mk':@' > $@
173
Note: See TracBrowser for help on using the browser.