root/lm-sensors/trunk/Makefile @ 1835

Revision 1835, 11.9 KB (checked in by mmh, 11 years ago)

use tab instead of spaces before depmod command

  • 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  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 (>= 2.5.1) and bison.
23
24# If your /bin/sh is not bash, change the below definition so that make can
25# find bash. Or you can hope your sh-like shell understands all scripts.
26# I think so, but I have not tested it.
27#SHELL := /usr/bin/bash
28
29# The currently running kernel version. This is used right below to
30# determine where the kernel sources can be found.
31KERNELVERSION := $(shell uname -r)
32
33# The location of linux itself. This is used to find the kernel headers
34# and other things.
35#LINUX := /usr/src/linux
36LINUX := $(shell if [ -L /lib/modules/$(KERNELVERSION)/build ] ; \
37        then echo "/lib/modules/$(KERNELVERSION)/build" ; \
38        else echo "/usr/src/linux" ; fi)
39LINUX_HEADERS := $(LINUX)/include
40
41# Determine whether we need to compile the kernel modules, or only the
42# user-space utilities. By default, the kernel modules are compiled.
43# Leave this set to 1. If you want to compile and install only
44# the library and the userspace programs,
45#  use 'make user' and 'make user_install'
46#COMPILE_KERNEL := 0
47COMPILE_KERNEL := 1
48
49# If you have installed the i2c header at some other place (like
50# /usr/local/include/linux), set that directory here. Please check this out
51# if you get strange compilation errors; the default Linux i2c headers
52# may be used mistakenly. Note: This should point to the directory
53# *above* the linux/ subdirectory, so to /usr/local/include in the
54# above example.
55I2C_HEADERS := /usr/local/include
56#I2C_HEADERS := $(LINUX_HEADERS)
57
58# Uncomment the third line on SMP systems if the magic invocation fails. It
59# is a bit complicated because SMP configuration changed around kernel 2.1.130
60SMP := $(shell if grep -q '^SMP[[:space:]]*=' $(LINUX)/Makefile || \
61                  grep -q '^[[:space:]]*\#define[[:space:]]*CONFIG_SMP[[:space:]]*1' $(LINUX_HEADERS)/linux/autoconf.h ; \
62               then echo 1; else echo 0; fi)
63#SMP := 0
64#SMP := 1
65
66# Uncomment the second or third line if the magic invocation fails.
67# We need to know whether CONFIG_MODVERSIONS is defined.
68MODVER := $(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)
69#MODVER := 0
70#MODVER := 1
71
72# Uncomment the second line if you are a developer. This will enable many
73# additional warnings at compile-time
74WARN := 0
75#WARN := 1
76
77# Uncomment the second line if you want to get (loads of) debug information
78# at run-time.
79# Not recommended, unless you are actually debugging the code
80DEBUG := 0
81#DEBUG := 1
82
83# If you want to install at some other place then at from which you will run
84# everything, set DESTDIR to the extra prefix.
85DESTDIR :=
86
87# This is the prefix that will be used for almost all directories below.
88PREFIX := /usr/local
89
90# This is the main modules directory into which the modules will be installed.
91# The magic invocation will return something like this:
92#   /lib/modules/2.2.15-ac9
93#MODDIR := /lib/modules/`grep UTS_RELEASE $(LINUX_HEADERS)/linux/version.h|cut -f 2 -d'"'`/misc
94#MODPREF := /lib/modules/$(KERNELVERSION)
95#MODPREF := /lib/modules/`grep UTS_RELEASE $(LINUX_HEADERS)/linux/version.h|cut -f 2 -d'"'`
96MODPREF := /lib/modules/$(shell $(CC) -I$(LINUX_HEADERS) -E etc/config.c | grep uts_release |cut -f 2 -d'"')
97
98# This is the directory where sensors.conf will be installed, if no other
99# configuration file is found
100ETCDIR := /etc
101
102# You should not need to change this. It is the directory into which the
103# library files (both static and shared) will be installed.
104LIBDIR := $(PREFIX)/lib
105
106# You should not need to change this. It is the directory into which the
107# executable program files will be installed. BINDIR for programs that are
108# also useful for normal users, SBINDIR for programs that can only be run
109# by the superuser.
110# Note that not all programs in this package are really installed;
111# some are just examples. You can always install them by hand, of
112# course.
113BINDIR := $(PREFIX)/bin
114SBINDIR := $(PREFIX)/sbin
115
116# You should not need to change this. It is the basic directory into which
117# include files will be installed. The actual directory will be
118# $(INCLUDEDIR)/linux for system include files, and $(INCLUDEDIR)/sensors
119# for library include files. If PREFIX equals the default /usr/local/bin,
120# you will be able to use '#include <linux/sensors.h>' regardless of the
121# current kernel selected.
122INCLUDEDIR := $(PREFIX)/include
123SYSINCLUDEDIR := $(INCLUDEDIR)/linux
124LIBINCLUDEDIR := $(INCLUDEDIR)/sensors
125
126# You should not need to change this. It is the base directory under which the
127# manual pages will be installed.
128MANDIR := $(PREFIX)/man
129
130# You should not need to change this. It defines the manual owner and group
131# as which manual pages are installed.
132MANOWN := root
133MANGRP := root
134
135MACHINE := $(shell uname -m)
136
137# Extra non-default programs to build; e.g., sensord
138# PROG_EXTRA := sensord
139
140# Set these to add preprocessor or compiler flags, or use
141# environment variables
142# CFLAGS :=
143# CPPFLAGS :=
144
145##################################################
146# Below this, nothing should need to be changed. #
147##################################################
148
149# Note that this is a monolithic Makefile; it calls no sub-Makefiles,
150# but instead, it compiles everything right from here. Yes, there are
151# some distinct advantages to this; see the following paper for more info:
152#   http://www.tip.net.au/~millerp/rmch/recu-make-cons-harm.html
153# Note that is still uses Makefile fragments in sub-directories; these
154# are called 'Module.mk'.
155
156# Within each Module.mk, rules and dependencies can be added to targets
157# all, install and clean. Use double colons instead of single ones
158# to do this.
159
160# The subdirectories we need to build things in
161SRCDIRS := mkpatch
162ifeq ($(COMPILE_KERNEL),1)
163SRCDIRS += kernel kernel/busses kernel/chips kernel/include
164endif
165SRCDIRS += lib prog/sensors prog/dump prog/detect ${PROG_EXTRA:%=prog/%} etc
166
167# Some often-used commands with default options
168MKDIR := mkdir -p
169RMDIR := rmdir
170RM := rm -f
171CC := gcc
172BISON := bison
173FLEX := flex
174AR := ar
175INSTALL := install
176LN := ln -sfn
177GREP := grep
178AWK := awk
179SED := sed
180
181# Determine the default compiler flags
182# Set CFLAGS or CPPFLAGS above to add your own flags to all.
183# ALLCPPFLAGS/ALLCFLAGS are common flags, plus any user-specified overrides from the environment or make command line.
184# MODCPPFLAGS/MODCFLAGS is to create in-kernel object files (modules).
185# PROGCPPFLAGS/PROGCFLAGS is to create non-kernel object files (which are linked into executables).
186# ARCPPFLAGS/ARCFLAGS are used to create archive object files (static libraries).
187# LIBCPPFLAGS/LIBCFLAGS are for shared library objects.
188ALL_CPPFLAGS := -I. -Ikernel/include -I$(I2C_HEADERS) -I$(LINUX_HEADERS)
189ALL_CFLAGS := -Wall -O2
190
191ifeq ($(DEBUG),1)
192ALL_CPPFLAGS += -DDEBUG
193endif
194
195ifeq ($(WARN),1)
196ALL_CFLAGS += -W -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \
197            -Wcast-align -Wwrite-strings -Wnested-externs -Winline
198endif
199
200ALL_CPPFLAGS += $(CPPFLAGS)
201ALL_CFLAGS += $(CFLAGS)
202
203MODCPPFLAGS :=
204MODCFLAGS :=
205
206ifeq ($(MACHINE),alpha)
207MODCFLAGS += -ffixed-8
208endif
209
210ifeq ($(MACHINE),x86_64)
211MODCFLAGS += -fno-strict-aliasing -fno-common -fomit-frame-pointer -mno-red-zone\
212             -mcmodel=kernel -fno-reorder-blocks -finline-limit=2000 -fno-strength-reduce
213endif
214
215ifeq ($(SMP),1)
216MODCPPFLAGS += -D__SMP__
217endif
218
219ifeq ($(MODVER),1)
220MODCPPFLAGS += -DMODVERSIONS -include $(LINUX_HEADERS)/linux/modversions.h
221endif
222
223# This magic is from the kernel Makefile.
224# Extra cflags for kbuild 2.4.  The default is to forbid includes by kernel code
225# from user space headers.
226kbuild_2_4_nostdinc := -nostdinc $(shell LC_ALL=C $(CC) -print-search-dirs | sed -ne 's/install: \(.*\)/-I \1include/gp')
227
228MODCPPFLAGS += -D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -fomit-frame-pointer $(ALL_CPPFLAGS) $(kbuild_2_4_nostdinc)
229MODCFLAGS += $(ALL_CFLAGS)
230PROGCPPFLAGS := $(ALL_CPPFLAGS)
231PROGCFLAGS := $(ALL_CFLAGS)
232ARCPPFLAGS := $(ALL_CPPFLAGS)
233ARCFLAGS := $(ALL_CFLAGS)
234LIBCPPFLAGS := $(ALL_CPPFLAGS)
235LIBCFLAGS := -fpic $(ALL_CFLAGS)
236
237.PHONY: all clean install version package dep
238
239# Make all the default rule
240all::
241
242# Include all makefiles for sub-modules
243INCLUDEFILES := 
244include $(patsubst %,%/Module.mk,$(SRCDIRS))
245ifneq ($(MAKECMDGOALS),clean)
246include $(INCLUDEFILES)
247endif
248
249# Making the dependency files - done automatically!
250dep :
251
252user ::
253user_install::
254all :: user
255install :: all user_install
256ifeq ($(DESTDIR),)
257        -/sbin/depmod -a
258else
259        -/sbin/depmod -a -b $(DESTDIR)
260endif
261
262clean::
263        $(RM) lm_sensors-*
264
265# This is tricky, but it works like a charm. It needs lots of utilities
266# though: cut, find, gzip, ln, tail and tar.
267package: version clean
268        lmversion=`tail -1 version.h|cut -f 2 -d \"`; \
269        lmpackage=lm_sensors-$$lmversion; \
270        ln -s . $$lmpackage;  \
271        find $$lmpackage/ -type f | grep -v ^$$lmpackage/$$lmpackage$$ | \
272                                    grep -v ^$$lmpackage/$$lmpackage.tar$$ | \
273                                    grep -v ^$$lmpackage/$$ | \
274                                    grep -v /CVS | \
275                                    grep -v /\\.# | \
276                                    tar rvf $$lmpackage.tar -T -; \
277        gzip -9 $$lmpackage.tar ;\
278        $(RM) $$lmpackage.tar $$lmpackage
279        cat doc/developers/checklist
280
281version:
282        $(RM) version.h
283        echo '#define LM_DATE "'`date +'%Y%m%d'`\" > version.h
284        echo -n 'Version: '; \
285        echo '#define LM_VERSION "'`read VER; echo $$VER`\" >> version.h
286
287help:
288        @echo 'Make targets are:'
289        @echo '  all (default): build modules and userspace programs'
290        @echo '  install: install modules and userspace programs'
291        @echo '  user: build userspace programs'
292        @echo '  user_install: install userspace programs'
293        @echo '  clean: cleanup'
294        @echo '  package: create a distribution package'
295        @echo 'Note: make dep is automatic'
296
297# Here, we define all implicit rules we want to use.
298
299.SUFFIXES:
300
301# We need to create dependency files. Tricky. We sed rule puts dir/file.d and
302# dir/file.c in front of the dependency file rule.
303
304# .o files are used for modules
305%.o: %.c
306        $(CC) $(MODCPPFLAGS) $(MODCFLAGS) -c $< -o $@
307
308%.d: %.c
309        $(CC) -M -MG $(MODCPPFLAGS) $(MODCFLAGS) $< | \
310        $(SED) -e 's@^\(.*\)\.o:@$*.d $*.o: Makefile '`dirname $*.d`/Module.mk' @' > $@
311
312
313
314# .ro files are used for programs (as opposed to modules)
315%.ro: %.c
316        $(CC) $(PROGCPPFLAGS) $(PROGCFLAGS) -c $< -o $@
317
318%.rd: %.c
319        $(CC) -M -MG $(PROGCPPFLAGS) $(PROGCFLAGS) $< | \
320        $(SED) -e 's@^\(.*\)\.o:@$*.rd $*.ro: Makefile '`dirname $*.rd`/Module.mk' @' > $@
321
322
323%: %.ro
324        $(CC) $(EXLDFLAGS) -o $@ $^
325
326
327# .ao files are used for static archives
328%.ao: %.c
329        $(CC) $(ARCPPFLAGS) $(ARCFLAGS) -c $< -o $@
330
331%.ad: %.c
332        $(CC) -M -MG $(ARCPPFLAGS) $(ARCFLAGS) $< | \
333        $(SED) -e 's@^\(.*\)\.o:@$*.ad $*.ao: Makefile '`dirname $*.ad`/Module.mk' @' > $@
334
335
336# .lo files are used for shared libraries
337%.lo: %.c
338        $(CC) $(LIBCPPFLAGS) $(LIBCFLAGS) -c $< -o $@
339
340%.ld: %.c
341        $(CC) -M -MG $(LIBCPPFLAGS) $(LIBCFLAGS) $< | \
342        $(SED) -e 's@^\(.*\)\.o:@$*.ld $*.lo: Makefile '`dirname $*.ld`/Module.mk' @' > $@
343
344
345# Flex and Bison
346%c: %y
347        $(BISON) -p sensors_yy -d $< -o $@
348
349%.c: %.l
350        $(FLEX) -Psensors_yy -t $< > $@
Note: See TracBrowser for help on using the browser.