root/i2c/trunk/Makefile @ 3386

Revision 3386, 6.1 KB (checked in by frodo, 14 years ago)

Now `make clean' also removes the .temp file in the mkpatch dir

  • 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# There are two build systems supported. The lm_sensors-like one builds
22# everything without needing write-access to the kernel tree. The original
23# i2c one adds versioning for module symbols; it needs to write in your
24# kernel tree for this (and seems to give minor troubles in some cases).
25# Make your choice.
26BUILD_SYSTEM=lm_sensors
27#BUILD_SYSTEM=i2c
28
29# If your /bin/sh is not bash, change the below definition so that make can
30# find bash. Or you can hope your sh-like shell understands all scripts.
31# I think so, but I have not tested it.
32# SHELL=/usr/bin/bash
33
34# The location of linux itself. This is used to find the kernel headers
35# and other things.
36LINUX=/usr/src/linux
37LINUX_HEADERS=$(LINUX)/include
38
39# Determine whether we need to compile the kernel modules, or only the
40# user-space utilities. By default, the kernel modules are compiled.
41#COMPILE_KERNEL := 0
42COMPILE_KERNEL := 1
43
44
45# Uncomment the third line on SMP systems if the magic invocation fails. It
46# is a bit complicated because SMP configuration changed around kernel 2.1.130
47SMP := $(shell if grep -q '^SMP[[:space:]]*=' $(LINUX)/Makefile || \
48                  grep -q '^[[:space:]]*\#define[[:space:]]*CONFIG_SMP[[:space:]]*1' $(LINUX_HEADERS)/linux/autoconf.h ; \
49               then echo 1; else echo 0; fi)
50#SMP := 0
51#SMP := 1
52
53# Uncomment the second or third line if the magic invocation fails.
54# We need to know whether CONFIG_MODVERSIONS is defined.
55MODVER := $(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)
56#MODVER := 0
57#MODVER := 1
58
59# This is the directory into which the modules will be installed.
60# The magic invocation will return something like this:
61#   /lib/modules/2.2.15-ac9/extra/misc
62MODDIR := /lib/modules/`sed -ne '1,4 { s/.*= *\(.*\)/\1/; 1,2 s/.*/&./; p; };' <$(LINUX)/Makefile | tr -d '\n'`
63ifeq ($(BUILD_SYSTEM),i2c)
64MODDIR := $(MODDIR)/extra/misc
65else
66MODDIR := $(MODDIR)/misc
67endif
68
69
70# This is the directory into which the header files will be installed.
71# If you want to make sure your current kernel tree is not overwritten,
72# the default should work. This is ignored for the i2c build system.
73LINUX_INCLUDE_DIR := /usr/local/include/linux
74#LINUX_INCLUDE_DIR := $(LINUX_HEADERS)
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
81##################################################
82# Below this, nothing should need to be changed. #
83##################################################
84
85.PHONY: all clean install patch
86
87ifeq ($(BUILD_SYSTEM),i2c)
88
89all:
90ifeq ($(COMPILE_KERNEL),1)
91        $(MAKE) -C kernel KERNEL_LOCATION=$(LINUX) MODULE_DIR=$(MODDIR) here
92endif
93
94install:
95ifeq ($(COMPILE_KERNEL),1)
96        $(MAKE) -C kernel KERNEL_LOCATION=$(LINUX) MODULE_DIR=$(MODDIR) \
97                I2CKERNELDIR=(LINUX_HEADERS) I2CMODDIR=$(MODDIR) install
98endif
99
100clean:
101ifeq ($(COMPILE_KERNEL),1)
102        $(MAKE) -C kernel KERNEL_LOCATION=$(LINUX) MODULE_DIR=$(MODDIR) clean
103endif
104
105else
106
107# Note that this is a monolithic Makefile; it calls no sub-Makefiles,
108# but instead, it compiles everything right from here. Yes, there are
109# some distinct advantages to this; see the following paper for more info:
110#   http://www.tip.net.au/~millerp/rmch/recu-make-cons-harm.html
111# Note that is still uses Makefile fragments in sub-directories; these
112# are called 'Module.mk'.
113
114# Within each Module.mk, rules and dependencies can be added to targets
115# all, install and clean. Use double colons instead of single ones
116# to do this.
117
118# The subdirectories we need to build things in
119SRCDIRS := mkpatch
120ifeq ($(COMPILE_KERNEL),1)
121SRCDIRS += kernel
122endif
123
124# Some often-used commands with default options
125MKDIR := mkdir -p
126RM := rm -f
127CC := gcc
128BISON := bison
129FLEX := flex
130AR := ar
131INSTALL := install
132LN := ln -sfn
133GREP := grep
134
135# Determine the default compiler flags
136# MODCFLAGS is to create in-kernel object files (modules)
137
138CFLAGS := -I$(LINUX_HEADERS) -O2 -DLM_SENSORS
139
140ifeq ($(WARN),1)
141CFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \
142          -Wcast-align -Wwrite-strings -Wnested-externs -Winline
143endif
144
145
146# The -DEXPORT_SYMTAB is to keep the symbol export mechanism quiet.
147MODCFLAGS := $(CFLAGS) -D__KERNEL__ -DMODULE -fomit-frame-pointer \
148             -DEXPORT_SYMTAB
149
150ifeq ($(SMP),1)
151MODCFLAGS += -D__SMP__
152endif
153
154ifeq ($(MODVER),1)
155MODCFLAGS += -DMODVERSIONS -include $(LINUX_HEADERS)/linux/modversions.h
156endif
157
158.PHONY: dep
159# Make all the default rule
160all::
161
162# Include all makefiles for sub-modules
163INCLUDEFILES :=
164ifneq ($(SRCDIRS),)
165include $(patsubst %,%/Module.mk,$(SRCDIRS))
166endif
167ifneq ($(MAKECMDGOALS),clean)
168ifneq ($(INCLUDEFILES),)
169include $(INCLUDEFILES)
170endif
171endif
172
173# Making the dependency files - done automatically!
174dep :
175
176all ::
177
178install :: all
179
180clean::
181        $(RM) lm_sensors-*
182
183# Here, we define all implicit rules we want to use.
184
185.SUFFIXES:
186
187# We need to create dependency files. Tricky. We sed rule puts dir/file.d and
188# dir/file.c # in front of the dependency file rule.
189
190# .o files are used for modules
191%.o: %.c
192        $(CC) $(MODCFLAGS) -c $< -o $@
193
194%.d: %.c
195        $(CC) -M -MG $(MODCFLAGS) $< | \
196        sed -e 's@^\(.*\)\.o:@$*.d $*.o: Makefile '`dirname $*.d`/Module.mk' @' > $@
197
198endif
Note: See TracBrowser for help on using the browser.