root/i2c/trunk/Makefile @ 3493

Revision 3493, 6.2 KB (checked in by frodo, 13 years ago)

Fixed i2c build system: kernel headers were put in the wrong place.

  • 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# 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/misc
62MODDIR := /lib/modules/`grep UTS_RELEASE $(LINUX_HEADERS)/linux/version.h|cut -f 2 -d'"'`/misc
63
64# This is the directory into which the header files will be installed.
65# If you want to make sure your current kernel tree is not overwritten,
66# the default should work. This is ignored for the i2c build system.
67LINUX_INCLUDE_DIR := /usr/local/include/linux
68#LINUX_INCLUDE_DIR := $(LINUX_HEADERS)/linux
69
70# If you want to isntall everything at some other place then at which
71# you will run it, DESTDIR defines a prefix used at installation-time.
72# This is ignored for the i2c build system.
73DESTDIR :=
74
75# Uncomment the second line if you are a developer. This will enable many
76# additional warnings at compile-time
77WARN := 0
78#WARN := 1
79
80##################################################
81# Below this, nothing should need to be changed. #
82##################################################
83
84.PHONY: all clean install patch
85
86ifeq ($(BUILD_SYSTEM),i2c)
87
88all:
89ifeq ($(COMPILE_KERNEL),1)
90        $(MAKE) -C kernel KERNEL_LOCATION=$(LINUX) MODULE_DIR=$(MODDIR) here
91endif
92
93install:
94ifeq ($(COMPILE_KERNEL),1)
95        $(MAKE) -C kernel KERNEL_LOCATION=$(LINUX) MODULE_DIR=$(MODDIR) \
96                I2CKERNELDIR=$(LINUX_HEADERS)/linux I2CMODDIR=$(MODDIR) install
97endif
98
99clean:
100ifeq ($(COMPILE_KERNEL),1)
101        $(MAKE) -C kernel KERNEL_LOCATION=$(LINUX) MODULE_DIR=$(MODDIR) clean
102endif
103
104else
105
106# Note that this is a monolithic Makefile; it calls no sub-Makefiles,
107# but instead, it compiles everything right from here. Yes, there are
108# some distinct advantages to this; see the following paper for more info:
109#   http://www.tip.net.au/~millerp/rmch/recu-make-cons-harm.html
110# Note that is still uses Makefile fragments in sub-directories; these
111# are called 'Module.mk'.
112
113# Within each Module.mk, rules and dependencies can be added to targets
114# all, install and clean. Use double colons instead of single ones
115# to do this.
116
117# The subdirectories we need to build things in
118SRCDIRS := mkpatch
119ifeq ($(COMPILE_KERNEL),1)
120SRCDIRS += kernel
121endif
122
123# Some often-used commands with default options
124MKDIR := mkdir -p
125RM := rm -f
126CC := gcc
127BISON := bison
128FLEX := flex
129AR := ar
130INSTALL := install
131LN := ln -sfn
132GREP := grep
133
134# Determine the default compiler flags
135# MODCFLAGS is to create in-kernel object files (modules)
136
137CFLAGS := -I$(LINUX_HEADERS) -O2 -DLM_SENSORS
138
139ifeq ($(WARN),1)
140CFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \
141          -Wcast-align -Wwrite-strings -Wnested-externs -Winline
142endif
143
144
145# The -DEXPORT_SYMTAB is to keep the symbol export mechanism quiet.
146MODCFLAGS := $(CFLAGS) -D__KERNEL__ -DMODULE -fomit-frame-pointer \
147             -DEXPORT_SYMTAB
148
149ifeq ($(SMP),1)
150MODCFLAGS += -D__SMP__
151endif
152
153ifeq ($(MODVER),1)
154MODCFLAGS += -DMODVERSIONS -include $(LINUX_HEADERS)/linux/modversions.h
155endif
156
157.PHONY: dep
158# Make all the default rule
159all::
160
161# Include all makefiles for sub-modules
162INCLUDEFILES :=
163ifneq ($(SRCDIRS),)
164include $(patsubst %,%/Module.mk,$(SRCDIRS))
165endif
166ifneq ($(MAKECMDGOALS),clean)
167ifneq ($(INCLUDEFILES),)
168include $(INCLUDEFILES)
169endif
170endif
171
172# Making the dependency files - done automatically!
173dep :
174
175all ::
176
177install :: all
178
179clean::
180        $(RM) lm_sensors-*
181
182# Here, we define all implicit rules we want to use.
183
184.SUFFIXES:
185
186# We need to create dependency files. Tricky. We sed rule puts dir/file.d and
187# dir/file.c in front of the dependency file rule.
188
189# .o files are used for modules
190%.o: %.c
191        $(CC) $(MODCFLAGS) -c $< -o $@
192
193%.d: %.c
194        $(CC) -M -MG $(MODCFLAGS) $< | \
195        sed -e 's@^\(.*\)\.o:@$*.d $*.o: Makefile '`dirname $*.d`/Module.mk' @' > $@
196
197endif
Note: See TracBrowser for help on using the browser.