| 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. |
|---|
| 20 | SMP := $(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. |
|---|
| 26 | MODVER := $(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! |
|---|
| 35 | I2C := 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 |
|---|
| 40 | WARN := 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 |
|---|
| 45 | DEBUG := 0 |
|---|
| 46 | #DEBUG := 1 |
|---|
| 47 | |
|---|
| 48 | # This is the directory into which the modules will be installed, if you |
|---|
| 49 | # call 'make install' |
|---|
| 50 | MODDIR := /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. |
|---|
| 56 | INCLUDEDIR := /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 |
|---|
| 73 | MODULES := src |
|---|
| 74 | ifeq ($(I2C),1) |
|---|
| 75 | MODULES += i2c i2c/detect i2c/drivers i2c/eeprom |
|---|
| 76 | endif |
|---|
| 77 | |
|---|
| 78 | # Some often-used commands with default options |
|---|
| 79 | MKDIR := mkdir -p |
|---|
| 80 | RM := rm -f |
|---|
| 81 | CC := 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). |
|---|
| 86 | CFLAGS := -D__KERNEL__ -DMODULE -I. -Ii2c -O2 -fomit-frame-pointer -DLM_SENSORS |
|---|
| 87 | EXCFLAGS := -I. -Ii2c -O2 -D LM_SENSORS |
|---|
| 88 | |
|---|
| 89 | ifeq ($(DEBUG),1) |
|---|
| 90 | CFLAGS += -DDEBUG |
|---|
| 91 | EXCFLAGS += -DDEBUG |
|---|
| 92 | endif |
|---|
| 93 | |
|---|
| 94 | ifeq ($(SMP),1) |
|---|
| 95 | CFLAGS += -D__SMP__ |
|---|
| 96 | endif |
|---|
| 97 | |
|---|
| 98 | ifeq ($(WARN),1) |
|---|
| 99 | CFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \ |
|---|
| 100 | -Wcast-align -Wwrite-strings -Wnested-externs -Winline |
|---|
| 101 | EXCFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \ |
|---|
| 102 | -Wcast-align -Wwrite-strings -Wnested-externs -Winline |
|---|
| 103 | endif |
|---|
| 104 | |
|---|
| 105 | ifeq ($(MODVER),1) |
|---|
| 106 | CFLAGS += -DMODVERSIONS -include /usr/include/linux/modversions.h |
|---|
| 107 | endif |
|---|
| 108 | |
|---|
| 109 | ifeq ($(I2C),1) |
|---|
| 110 | CFLAGS += -DI2C |
|---|
| 111 | endif |
|---|
| 112 | |
|---|
| 113 | .PHONY: all clean install version package dep |
|---|
| 114 | |
|---|
| 115 | # Make all the default rule |
|---|
| 116 | all:: |
|---|
| 117 | |
|---|
| 118 | # Include all makefiles for sub-modules |
|---|
| 119 | INCLUDEFILES := |
|---|
| 120 | include $(patsubst %,%/Module.mk,$(MODULES)) |
|---|
| 121 | ifneq ($(MAKECMDGOALS),clean) |
|---|
| 122 | include $(INCLUDEFILES) |
|---|
| 123 | endif |
|---|
| 124 | |
|---|
| 125 | # Making the dependency files - done automatically! |
|---|
| 126 | dep : |
|---|
| 127 | |
|---|
| 128 | all :: |
|---|
| 129 | |
|---|
| 130 | install :: all |
|---|
| 131 | |
|---|
| 132 | clean:: |
|---|
| 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. |
|---|
| 144 | package: 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 | |
|---|
| 157 | version: |
|---|
| 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 | |
|---|