| 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. |
|---|
| 26 | BUILD_SYSTEM=lm_sensors |
|---|
| 27 | #BUILD_SYSTEM=i2c |
|---|
| 28 | |
|---|
| 29 | # The location of your kernel headers (which should be the linux and asm |
|---|
| 30 | # subdirectories). For most people, the below works perfectly. If you use |
|---|
| 31 | # Debian, you may want to change this to something like /usr/src/linux/include. |
|---|
| 32 | LINUX_HEADERS=/usr/include |
|---|
| 33 | |
|---|
| 34 | # The location of linux itself. This is only used to determine whether you |
|---|
| 35 | # use a SMP kernel in the magic invocation just below. |
|---|
| 36 | LINUX=/usr/src/linux |
|---|
| 37 | # Uncomment the third line on SMP systems if the magic invocation fails. It |
|---|
| 38 | # is a bit complicated because SMP configuration changed around kernel 2.1.130 |
|---|
| 39 | SMP := $(shell if grep -q '^SMP[[:space:]]*=' $(LINUX)/Makefile || \ |
|---|
| 40 | grep -q '^[[:space:]]*\#define[[:space:]]*CONFIG_SMP[[:space:]]*1' $(LINUX_HEADERS)/linux/autoconf.h ; \ |
|---|
| 41 | then echo 1; else echo 0; fi) |
|---|
| 42 | #SMP := 0 |
|---|
| 43 | #SMP := 1 |
|---|
| 44 | |
|---|
| 45 | # Uncomment the second or third line if the magic invocation fails. |
|---|
| 46 | # We need to know whether CONFIG_MODVERSIONS is defined. |
|---|
| 47 | 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) |
|---|
| 48 | #MODVER := 0 |
|---|
| 49 | #MODVER := 1 |
|---|
| 50 | |
|---|
| 51 | # This is the directory into which the modules will be installed. |
|---|
| 52 | MODDIR := /lib/modules/current/extra/misc |
|---|
| 53 | |
|---|
| 54 | # Uncomment the second line if you are a developer. This will enable many |
|---|
| 55 | # additional warnings at compile-time |
|---|
| 56 | #WARN := 0 |
|---|
| 57 | WARN := 1 |
|---|
| 58 | |
|---|
| 59 | ################################################## |
|---|
| 60 | # Below this, nothing should need to be changed. # |
|---|
| 61 | ################################################## |
|---|
| 62 | |
|---|
| 63 | ifeq ($(BUILD_SYSTEM),i2c) |
|---|
| 64 | |
|---|
| 65 | all: |
|---|
| 66 | $(MAKE) -C kernel KERNEL_LOCATION=$(LINUX) MODULE_DIR=$(MODDIR) here |
|---|
| 67 | |
|---|
| 68 | install: |
|---|
| 69 | $(MAKE) -C kernel KERNEL_LOCATION=$(LINUX) MODULE_DIR=$(MODDIR) install |
|---|
| 70 | |
|---|
| 71 | clean: |
|---|
| 72 | $(MAKE) -C kernel KERNEL_LOCATION=$(LINUX) MODULE_DIR=$(MODDIR) clean |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | else |
|---|
| 76 | |
|---|
| 77 | # Note that this is a monolithic Makefile; it calls no sub-Makefiles, |
|---|
| 78 | # but instead, it compiles everything right from here. Yes, there are |
|---|
| 79 | # some distinct advantages to this; see the following paper for more info: |
|---|
| 80 | # http://www.tip.net.au/~millerp/rmch/recu-make-cons-harm.html |
|---|
| 81 | # Note that is still uses Makefile fragments in sub-directories; these |
|---|
| 82 | # are called 'Module.mk'. |
|---|
| 83 | |
|---|
| 84 | # Within each Module.mk, rules and dependencies can be added to targets |
|---|
| 85 | # all, install and clean. Use double colons instead of single ones |
|---|
| 86 | # to do this. |
|---|
| 87 | |
|---|
| 88 | # The subdirectories we need to build things in |
|---|
| 89 | SRCDIRS := kernel |
|---|
| 90 | |
|---|
| 91 | # Some often-used commands with default options |
|---|
| 92 | MKDIR := mkdir -p |
|---|
| 93 | RM := rm -f |
|---|
| 94 | CC := gcc |
|---|
| 95 | BISON := bison |
|---|
| 96 | FLEX := flex |
|---|
| 97 | AR := ar |
|---|
| 98 | INSTALL := install |
|---|
| 99 | LN := ln -sfn |
|---|
| 100 | GREP := grep |
|---|
| 101 | |
|---|
| 102 | # Determine the default compiler flags |
|---|
| 103 | # MODCFLAGS is to create in-kernel object files (modules) |
|---|
| 104 | |
|---|
| 105 | CFLAGS := -I$(LINUX_HEADERS) -O2 -DLM_SENSORS |
|---|
| 106 | |
|---|
| 107 | ifeq ($(WARN),1) |
|---|
| 108 | CFLAGS += -Wall -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \ |
|---|
| 109 | -Wcast-align -Wwrite-strings -Wnested-externs -Winline |
|---|
| 110 | endif |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | # The -DEXPORT_SYMTAB is to keep the symbol export mechanism quiet. |
|---|
| 114 | MODCFLAGS := $(CFLAGS) -D__KERNEL__ -DMODULE -fomit-frame-pointer \ |
|---|
| 115 | -DEXPORT_SYMTAB |
|---|
| 116 | |
|---|
| 117 | ifeq ($(SMP),1) |
|---|
| 118 | MODCFLAGS += -D__SMP__ |
|---|
| 119 | endif |
|---|
| 120 | |
|---|
| 121 | ifeq ($(MODVER),1) |
|---|
| 122 | MODCFLAGS += -DMODVERSIONS -include /usr/include/linux/modversions.h |
|---|
| 123 | endif |
|---|
| 124 | |
|---|
| 125 | .PHONY: all clean install version package dep |
|---|
| 126 | # Make all the default rule |
|---|
| 127 | all:: |
|---|
| 128 | |
|---|
| 129 | # Include all makefiles for sub-modules |
|---|
| 130 | INCLUDEFILES := |
|---|
| 131 | include $(patsubst %,%/Module.mk,$(SRCDIRS)) |
|---|
| 132 | ifneq ($(MAKECMDGOALS),clean) |
|---|
| 133 | include $(INCLUDEFILES) |
|---|
| 134 | endif |
|---|
| 135 | |
|---|
| 136 | # Making the dependency files - done automatically! |
|---|
| 137 | dep : |
|---|
| 138 | |
|---|
| 139 | all :: |
|---|
| 140 | |
|---|
| 141 | install :: all |
|---|
| 142 | |
|---|
| 143 | clean:: |
|---|
| 144 | $(RM) lm_sensors-* |
|---|
| 145 | |
|---|
| 146 | # Here, we define all implicit rules we want to use. |
|---|
| 147 | |
|---|
| 148 | .SUFFIXES: |
|---|
| 149 | |
|---|
| 150 | # We need to create dependency files. Tricky. We sed rule puts dir/file.d and |
|---|
| 151 | # dir/file.c # in front of the dependency file rule. |
|---|
| 152 | |
|---|
| 153 | # .o files are used for modules |
|---|
| 154 | %.o: %.c |
|---|
| 155 | $(CC) $(MODCFLAGS) -c $< -o $@ |
|---|
| 156 | |
|---|
| 157 | %.d: %.c |
|---|
| 158 | $(CC) -M -MG $(MODCFLAGS) $< | \ |
|---|
| 159 | sed -e 's@^\(.*\)\.o:@$*.d $*.o: Makefile '`dirname $*.d`/Module.mk' @' > $@ |
|---|
| 160 | |
|---|
| 161 | endif |
|---|