| 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 | # If your /bin/sh is not bash, change the below definition so that make can |
|---|
| 22 | # find bash. Or you can hope your sh-like shell understands all scripts. |
|---|
| 23 | # I think so, but I have not tested it. |
|---|
| 24 | #SHELL := /usr/bin/bash |
|---|
| 25 | |
|---|
| 26 | # The currently running kernel version. This is used right below to |
|---|
| 27 | # determine where the kernel sources can be found. |
|---|
| 28 | KERNELVERSION := $(shell uname -r) |
|---|
| 29 | |
|---|
| 30 | # The location of linux itself. This is used to find the kernel headers |
|---|
| 31 | # and other things. |
|---|
| 32 | #LINUX := /usr/src/linux |
|---|
| 33 | LINUX := $(shell if [ -L /lib/modules/$(KERNELVERSION)/build ] ; \ |
|---|
| 34 | then echo "/lib/modules/$(KERNELVERSION)/build" ; \ |
|---|
| 35 | else echo "/usr/src/linux" ; fi) |
|---|
| 36 | LINUX_HEADERS := $(LINUX)/include |
|---|
| 37 | |
|---|
| 38 | # Determine whether we need to compile the kernel modules, or only the |
|---|
| 39 | # user-space utilities. By default, the kernel modules are compiled. |
|---|
| 40 | #COMPILE_KERNEL := 0 |
|---|
| 41 | COMPILE_KERNEL := 1 |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | # Uncomment the third line on SMP systems if the magic invocation fails. It |
|---|
| 45 | # is a bit complicated because SMP configuration changed around kernel 2.1.130 |
|---|
| 46 | SMP := $(shell if grep -q '^SMP[[:space:]]*=' $(LINUX)/Makefile || \ |
|---|
| 47 | grep -q '^[[:space:]]*\#define[[:space:]]*CONFIG_SMP[[:space:]]*1' $(LINUX_HEADERS)/linux/autoconf.h ; \ |
|---|
| 48 | then echo 1; else echo 0; fi) |
|---|
| 49 | #SMP := 0 |
|---|
| 50 | #SMP := 1 |
|---|
| 51 | |
|---|
| 52 | # Uncomment the second or third line if the magic invocation fails. |
|---|
| 53 | # We need to know whether CONFIG_MODVERSIONS is defined. |
|---|
| 54 | MODVER := $(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) |
|---|
| 55 | #MODVER := 0 |
|---|
| 56 | #MODVER := 1 |
|---|
| 57 | |
|---|
| 58 | # This is the directory into which the modules will be installed. |
|---|
| 59 | # The magic invocation will return something like this: |
|---|
| 60 | # /lib/modules/2.2.15-ac9/misc |
|---|
| 61 | #MODDIR := /lib/modules/`grep UTS_RELEASE $(LINUX_HEADERS)/linux/version.h|cut -f 2 -d'"'`/misc |
|---|
| 62 | #MODPREF := /lib/modules/`grep UTS_RELEASE $(LINUX_HEADERS)/linux/version.h|cut -f 2 -d'"'` |
|---|
| 63 | #MODPREF := /lib/modules/$(KERNELVERSION) |
|---|
| 64 | MODPREF := /lib/modules/$(shell $(CC) -I$(LINUX_HEADERS) -E etc/config.c | grep uts_release |cut -f 2 -d'"') |
|---|
| 65 | |
|---|
| 66 | # This is the directory into which the header files will be installed. |
|---|
| 67 | # If you want to make sure your current kernel tree is not overwritten, |
|---|
| 68 | # the default should work. This is ignored for the i2c build system. |
|---|
| 69 | LINUX_INCLUDE_DIR := /usr/local/include/linux |
|---|
| 70 | #LINUX_INCLUDE_DIR := $(LINUX_HEADERS)/linux |
|---|
| 71 | |
|---|
| 72 | # If you want to isntall everything at some other place then at which |
|---|
| 73 | # you will run it, DESTDIR defines a prefix used at installation-time. |
|---|
| 74 | DESTDIR := |
|---|
| 75 | |
|---|
| 76 | # Uncomment the second line if you are a developer. This will enable many |
|---|
| 77 | # additional warnings at compile-time |
|---|
| 78 | WARN := 0 |
|---|
| 79 | #WARN := 1 |
|---|
| 80 | |
|---|
| 81 | MACHINE := $(shell uname -m) |
|---|
| 82 | |
|---|
| 83 | ################################################## |
|---|
| 84 | # Below this, nothing should need to be changed. # |
|---|
| 85 | ################################################## |
|---|
| 86 | |
|---|
| 87 | .PHONY: all clean install patch |
|---|
| 88 | |
|---|
| 89 | # Note that this is a monolithic Makefile; it calls no sub-Makefiles, |
|---|
| 90 | # but instead, it compiles everything right from here. Yes, there are |
|---|
| 91 | # some distinct advantages to this; see the following paper for more info: |
|---|
| 92 | # http://www.tip.net.au/~millerp/rmch/recu-make-cons-harm.html |
|---|
| 93 | # Note that is still uses Makefile fragments in sub-directories; these |
|---|
| 94 | # are called 'Module.mk'. |
|---|
| 95 | |
|---|
| 96 | # Within each Module.mk, rules and dependencies can be added to targets |
|---|
| 97 | # all, install and clean. Use double colons instead of single ones |
|---|
| 98 | # to do this. |
|---|
| 99 | |
|---|
| 100 | # The subdirectories we need to build things in |
|---|
| 101 | SRCDIRS := mkpatch |
|---|
| 102 | ifeq ($(COMPILE_KERNEL),1) |
|---|
| 103 | SRCDIRS += kernel |
|---|
| 104 | endif |
|---|
| 105 | |
|---|
| 106 | # Some often-used commands with default options |
|---|
| 107 | MKDIR := mkdir -p |
|---|
| 108 | RMDIR := rmdir |
|---|
| 109 | RM := rm -f |
|---|
| 110 | CC := gcc |
|---|
| 111 | BISON := bison |
|---|
| 112 | FLEX := flex |
|---|
| 113 | AR := ar |
|---|
| 114 | INSTALL := install |
|---|
| 115 | LN := ln -sfn |
|---|
| 116 | GREP := grep |
|---|
| 117 | |
|---|
| 118 | # Determine the default compiler flags |
|---|
| 119 | # MODCFLAGS is to create in-kernel object files (modules) |
|---|
| 120 | |
|---|
| 121 | CPPFLAGS := -I$(LINUX_HEADERS) |
|---|
| 122 | CFLAGS := -O2 -DLM_SENSORS |
|---|
| 123 | |
|---|
| 124 | ifeq ($(WARN),1) |
|---|
| 125 | CFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \ |
|---|
| 126 | -Wcast-align -Wwrite-strings -Wnested-externs -Winline |
|---|
| 127 | endif |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | # The -DEXPORT_SYMTAB is to keep the symbol export mechanism quiet. |
|---|
| 131 | MODCFLAGS := $(CFLAGS) -D__KERNEL__ -DMODULE -fomit-frame-pointer \ |
|---|
| 132 | -DEXPORT_SYMTAB |
|---|
| 133 | |
|---|
| 134 | ifeq ($(MACHINE),alpha) |
|---|
| 135 | MODCFLAGS += -ffixed-8 |
|---|
| 136 | endif |
|---|
| 137 | |
|---|
| 138 | ifeq ($(MACHINE),x86_64) |
|---|
| 139 | MODCFLAGS += -fno-strict-aliasing -fno-common -fomit-frame-pointer -mno-red-zone\ |
|---|
| 140 | -mcmodel=kernel -fno-reorder-blocks -finline-limit=2000 -fno-strength-reduce |
|---|
| 141 | endif |
|---|
| 142 | |
|---|
| 143 | ifeq ($(SMP),1) |
|---|
| 144 | MODCPPFLAGS += -D__SMP__ |
|---|
| 145 | endif |
|---|
| 146 | |
|---|
| 147 | ifeq ($(MODVER),1) |
|---|
| 148 | MODCPPFLAGS += -DMODVERSIONS -include $(LINUX_HEADERS)/linux/modversions.h |
|---|
| 149 | endif |
|---|
| 150 | |
|---|
| 151 | # This magic is from the kernel Makefile. |
|---|
| 152 | # Extra cflags for kbuild 2.4. The default is to forbid includes by kernel code |
|---|
| 153 | # from user space headers. |
|---|
| 154 | kbuild_2_4_nostdinc := -nostdinc $(shell $(CC) -print-search-dirs | sed -ne 's/install: \(.*\)/-I \1include/gp') |
|---|
| 155 | MODCPPFLAGS += $(CPPFLAGS) $(kbuild_2_4_nostdinc) |
|---|
| 156 | |
|---|
| 157 | .PHONY: dep |
|---|
| 158 | # Make all the default rule |
|---|
| 159 | all:: |
|---|
| 160 | |
|---|
| 161 | # Include all makefiles for sub-modules |
|---|
| 162 | INCLUDEFILES := |
|---|
| 163 | ifneq ($(SRCDIRS),) |
|---|
| 164 | include $(patsubst %,%/Module.mk,$(SRCDIRS)) |
|---|
| 165 | endif |
|---|
| 166 | ifneq ($(MAKECMDGOALS),clean) |
|---|
| 167 | ifneq ($(INCLUDEFILES),) |
|---|
| 168 | include $(INCLUDEFILES) |
|---|
| 169 | endif |
|---|
| 170 | endif |
|---|
| 171 | |
|---|
| 172 | # Making the dependency files - done automatically! |
|---|
| 173 | dep : |
|---|
| 174 | |
|---|
| 175 | all :: |
|---|
| 176 | |
|---|
| 177 | install :: all |
|---|
| 178 | |
|---|
| 179 | clean:: |
|---|
| 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) $(MODCPPFLAGS) $(MODCFLAGS) -c $< -o $@ |
|---|
| 192 | |
|---|
| 193 | %.d: %.c |
|---|
| 194 | $(CC) -M -MG $(MODCPPFLAGS) $(MODCFLAGS) $< | \ |
|---|
| 195 | sed -e 's@^\(.*\)\.o:@$*.d $*.o: Makefile '`dirname $*.d`/Module.mk' @' > $@ |
|---|
| 196 | |
|---|