| 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 | # You need a full complement of GNU utilities to run this Makefile |
|---|
| 22 | # successfully; most notably, you need bash, GNU make, flex (>= 2.5.1) |
|---|
| 23 | # and bison. |
|---|
| 24 | |
|---|
| 25 | # If your /bin/sh is not bash, change the below definition so that make can |
|---|
| 26 | # find bash. Or you can hope your sh-like shell understands all scripts. |
|---|
| 27 | # I think so, but I have not tested it. |
|---|
| 28 | #SHELL := /usr/bin/bash |
|---|
| 29 | |
|---|
| 30 | # Uncomment the second line if you are a developer. This will enable many |
|---|
| 31 | # additional warnings at compile-time |
|---|
| 32 | WARN := 0 |
|---|
| 33 | #WARN := 1 |
|---|
| 34 | |
|---|
| 35 | # Uncomment the second line if you want to get (loads of) debug information |
|---|
| 36 | # at run-time. |
|---|
| 37 | # Not recommended, unless you are actually debugging the code |
|---|
| 38 | DEBUG := 0 |
|---|
| 39 | #DEBUG := 1 |
|---|
| 40 | |
|---|
| 41 | # If you want to install at some other place then at from which you will run |
|---|
| 42 | # everything, set DESTDIR to the extra prefix. |
|---|
| 43 | DESTDIR := |
|---|
| 44 | |
|---|
| 45 | # This is the prefix that will be used for almost all directories below. |
|---|
| 46 | PREFIX := /usr/local |
|---|
| 47 | |
|---|
| 48 | # Your C compiler |
|---|
| 49 | CC := gcc |
|---|
| 50 | |
|---|
| 51 | # This is the directory where sensors.conf will be installed, if no other |
|---|
| 52 | # configuration file is found |
|---|
| 53 | ETCDIR := /etc |
|---|
| 54 | |
|---|
| 55 | # You should not need to change this. It is the directory into which the |
|---|
| 56 | # library files (both static and shared) will be installed. |
|---|
| 57 | LIBDIR := $(PREFIX)/lib |
|---|
| 58 | |
|---|
| 59 | EXLDFLAGS := -Wl,-rpath,$(LIBDIR) |
|---|
| 60 | |
|---|
| 61 | # You should not need to change this. It is the directory into which the |
|---|
| 62 | # executable program files will be installed. BINDIR for programs that are |
|---|
| 63 | # also useful for normal users, SBINDIR for programs that can only be run |
|---|
| 64 | # by the superuser. |
|---|
| 65 | # Note that not all programs in this package are really installed; |
|---|
| 66 | # some are just examples. You can always install them by hand, of |
|---|
| 67 | # course. |
|---|
| 68 | BINDIR := $(PREFIX)/bin |
|---|
| 69 | SBINDIR := $(PREFIX)/sbin |
|---|
| 70 | |
|---|
| 71 | # You should not need to change this. It is the basic directory into which |
|---|
| 72 | # include files will be installed. The actual directory will be |
|---|
| 73 | # $(INCLUDEDIR)/sensors for library include files. |
|---|
| 74 | INCLUDEDIR := $(PREFIX)/include |
|---|
| 75 | LIBINCLUDEDIR := $(INCLUDEDIR)/sensors |
|---|
| 76 | |
|---|
| 77 | # You should not need to change this. It is the base directory under which the |
|---|
| 78 | # manual pages will be installed. |
|---|
| 79 | MANDIR := $(PREFIX)/man |
|---|
| 80 | |
|---|
| 81 | MACHINE := $(shell uname -m) |
|---|
| 82 | |
|---|
| 83 | # Extra non-default programs to build; e.g., sensord |
|---|
| 84 | # PROG_EXTRA := sensord |
|---|
| 85 | |
|---|
| 86 | # Set these to add preprocessor or compiler flags, or use |
|---|
| 87 | # environment variables |
|---|
| 88 | # CFLAGS := |
|---|
| 89 | # CPPFLAGS := |
|---|
| 90 | |
|---|
| 91 | ################################################## |
|---|
| 92 | # Below this, nothing should need to be changed. # |
|---|
| 93 | ################################################## |
|---|
| 94 | |
|---|
| 95 | # Note that this is a monolithic Makefile; it calls no sub-Makefiles, |
|---|
| 96 | # but instead, it compiles everything right from here. Yes, there are |
|---|
| 97 | # some distinct advantages to this; see the following paper for more info: |
|---|
| 98 | # http://www.tip.net.au/~millerp/rmch/recu-make-cons-harm.html |
|---|
| 99 | # Note that is still uses Makefile fragments in sub-directories; these |
|---|
| 100 | # are called 'Module.mk'. |
|---|
| 101 | |
|---|
| 102 | # Within each Module.mk, rules and dependencies can be added to targets |
|---|
| 103 | # all, install and clean. Use double colons instead of single ones |
|---|
| 104 | # to do this. |
|---|
| 105 | |
|---|
| 106 | # The subdirectories we need to build things in |
|---|
| 107 | SRCDIRS := |
|---|
| 108 | SRCDIRS += lib prog/detect prog/dump prog/pwm \ |
|---|
| 109 | prog/sensors ${PROG_EXTRA:%=prog/%} etc |
|---|
| 110 | SRCDIRS += lib/test |
|---|
| 111 | |
|---|
| 112 | # Some often-used commands with default options |
|---|
| 113 | MKDIR := mkdir -p |
|---|
| 114 | RMDIR := rmdir |
|---|
| 115 | RM := rm -f |
|---|
| 116 | BISON := bison |
|---|
| 117 | FLEX := flex |
|---|
| 118 | AR := ar |
|---|
| 119 | INSTALL := install |
|---|
| 120 | LN := ln -sf |
|---|
| 121 | GREP := grep |
|---|
| 122 | AWK := awk |
|---|
| 123 | SED := sed |
|---|
| 124 | |
|---|
| 125 | # Determine the default compiler flags |
|---|
| 126 | # Set CFLAGS or CPPFLAGS above to add your own flags to all. |
|---|
| 127 | # ALLCPPFLAGS/ALLCFLAGS are common flags, plus any user-specified overrides from the environment or make command line. |
|---|
| 128 | # PROGCPPFLAGS/PROGCFLAGS is to create regular object files (which are linked into executables). |
|---|
| 129 | # ARCPPFLAGS/ARCFLAGS are used to create archive object files (static libraries). |
|---|
| 130 | # LIBCPPFLAGS/LIBCFLAGS are for shared library objects. |
|---|
| 131 | ALL_CPPFLAGS := -I. |
|---|
| 132 | ALL_CFLAGS := -Wall |
|---|
| 133 | |
|---|
| 134 | ifeq ($(DEBUG),1) |
|---|
| 135 | ALL_CPPFLAGS += -DDEBUG |
|---|
| 136 | ALL_CFLAGS += -O -g |
|---|
| 137 | else |
|---|
| 138 | ALL_CFLAGS += -O2 |
|---|
| 139 | endif |
|---|
| 140 | |
|---|
| 141 | ifeq ($(WARN),1) |
|---|
| 142 | ALL_CFLAGS += -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual \ |
|---|
| 143 | -Wcast-align -Wwrite-strings -Wnested-externs -Winline -W \ |
|---|
| 144 | -Wmissing-prototypes -Wundef |
|---|
| 145 | endif |
|---|
| 146 | |
|---|
| 147 | ALL_CPPFLAGS += $(CPPFLAGS) |
|---|
| 148 | ALL_CFLAGS += $(CFLAGS) |
|---|
| 149 | |
|---|
| 150 | PROGCPPFLAGS := -DETCDIR="\"$(ETCDIR)\"" $(ALL_CPPFLAGS) -Wundef |
|---|
| 151 | PROGCFLAGS := $(ALL_CFLAGS) |
|---|
| 152 | ARCPPFLAGS := $(ALL_CPPFLAGS) |
|---|
| 153 | ARCFLAGS := $(ALL_CFLAGS) |
|---|
| 154 | LIBCPPFLAGS := $(ALL_CPPFLAGS) |
|---|
| 155 | LIBCFLAGS := -fpic -D_REENTRANT $(ALL_CFLAGS) |
|---|
| 156 | |
|---|
| 157 | .PHONY: all user clean install user_install uninstall user_uninstall package |
|---|
| 158 | |
|---|
| 159 | # Make all the default rule |
|---|
| 160 | all:: |
|---|
| 161 | |
|---|
| 162 | # Include all makefiles for sub-modules |
|---|
| 163 | INCLUDEFILES := |
|---|
| 164 | include $(patsubst %,%/Module.mk,$(SRCDIRS)) |
|---|
| 165 | ifneq ($(MAKECMDGOALS),clean) |
|---|
| 166 | ifneq ($(MAKECMDGOALS),uninstall) |
|---|
| 167 | ifneq ($(MAKECMDGOALS),user_uninstall) |
|---|
| 168 | ifneq ($(MAKECMDGOALS),help) |
|---|
| 169 | ifneq ($(MAKECMDGOALS),package) |
|---|
| 170 | ifneq ($(MAKECMDGOALS),userpackage) |
|---|
| 171 | include $(INCLUDEFILES) |
|---|
| 172 | endif |
|---|
| 173 | endif |
|---|
| 174 | endif |
|---|
| 175 | endif |
|---|
| 176 | endif |
|---|
| 177 | endif |
|---|
| 178 | |
|---|
| 179 | # Man pages |
|---|
| 180 | MANPAGES := $(LIBMAN3FILES) $(LIBMAN5FILES) $(PROGDETECTMAN8FILES) $(PROGDUMPMAN8FILES) \ |
|---|
| 181 | $(PROGSENSORSMAN1FILES) $(PROGPWMMAN8FILES) prog/sensord/sensord.8 |
|---|
| 182 | |
|---|
| 183 | user :: |
|---|
| 184 | user_install:: |
|---|
| 185 | @echo "*** Important note:" |
|---|
| 186 | @echo "*** * The libsensors configuration file ($(ETCDIR)/sensors.conf) is never" |
|---|
| 187 | @echo "*** overwritten by our installation process, so that you won't lose" |
|---|
| 188 | @echo "*** your personal settings in that file. You still can get our latest" |
|---|
| 189 | @echo "*** default config file in etc/sensors.conf.eg and manually copy it to" |
|---|
| 190 | @echo "*** $(ETCDIR)/sensors.conf if you want. You will then want to edit it" |
|---|
| 191 | @echo "*** to fit your needs again." |
|---|
| 192 | all :: user |
|---|
| 193 | install :: all user_install |
|---|
| 194 | |
|---|
| 195 | clean:: |
|---|
| 196 | $(RM) lm_sensors-* lex.backup |
|---|
| 197 | |
|---|
| 198 | user_uninstall:: |
|---|
| 199 | |
|---|
| 200 | uninstall :: user_uninstall |
|---|
| 201 | |
|---|
| 202 | # This is tricky, but it works like a charm. It needs lots of utilities |
|---|
| 203 | # though: cut, find, gzip, ln, tail and tar. |
|---|
| 204 | package: version.h clean |
|---|
| 205 | lmversion=`tail -1 version.h|cut -f 2 -d \"`; \ |
|---|
| 206 | lmpackage=lm_sensors-$$lmversion; \ |
|---|
| 207 | ln -s . $$lmpackage; \ |
|---|
| 208 | find $$lmpackage/ -type f | grep -v ^$$lmpackage/$$lmpackage$$ | \ |
|---|
| 209 | grep -v ^$$lmpackage/$$lmpackage.tar$$ | \ |
|---|
| 210 | grep -v ^$$lmpackage/$$ | \ |
|---|
| 211 | grep -v /CVS | \ |
|---|
| 212 | grep -v /\\.# | \ |
|---|
| 213 | tar rvf $$lmpackage.tar -T -; \ |
|---|
| 214 | gzip -9 $$lmpackage.tar ;\ |
|---|
| 215 | $(RM) $$lmpackage.tar $$lmpackage |
|---|
| 216 | cat doc/developers/checklist |
|---|
| 217 | |
|---|
| 218 | help: |
|---|
| 219 | @echo 'Make targets are:' |
|---|
| 220 | @echo ' all (default): build library and userspace programs' |
|---|
| 221 | @echo ' install: install library and userspace programs' |
|---|
| 222 | @echo ' uninstall: uninstall library and userspace programs' |
|---|
| 223 | @echo ' clean: cleanup' |
|---|
| 224 | @echo ' package: create a distribution package' |
|---|
| 225 | |
|---|
| 226 | # Generate html man pages to be copied to the lm_sensors website. |
|---|
| 227 | # This uses the man2html from here |
|---|
| 228 | # http://ftp.math.utah.edu/pub/sgml/ |
|---|
| 229 | # which works directly from the nroff source |
|---|
| 230 | manhtml: |
|---|
| 231 | $(MKDIR) html |
|---|
| 232 | cp $(MANPAGES) html |
|---|
| 233 | cd html ; \ |
|---|
| 234 | export LOGNAME=sensors ; \ |
|---|
| 235 | export HOSTNAME=www.lm-sensors.org ; \ |
|---|
| 236 | man2html *.[1-8] ; \ |
|---|
| 237 | $(RM) *.[1-8] |
|---|
| 238 | |
|---|
| 239 | # Here, we define all implicit rules we want to use. |
|---|
| 240 | |
|---|
| 241 | .SUFFIXES: |
|---|
| 242 | |
|---|
| 243 | # We need to create dependency files. Tricky. The sed rule puts dir/file.d and |
|---|
| 244 | # dir/file.c in front of the dependency file rule. |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | # .ro files are used for programs (as opposed to modules) |
|---|
| 248 | %.ro: %.c |
|---|
| 249 | $(CC) $(PROGCPPFLAGS) $(PROGCFLAGS) -c $< -o $@ |
|---|
| 250 | |
|---|
| 251 | %.rd: %.c |
|---|
| 252 | $(CC) -M -MG $(PROGCPPFLAGS) $(PROGCFLAGS) $< | \ |
|---|
| 253 | $(SED) -e 's@^\(.*\)\.o:@$*.rd $*.ro: Makefile '`dirname $*.rd`/Module.mk' @' > $@ |
|---|
| 254 | |
|---|
| 255 | |
|---|
| 256 | %: %.ro |
|---|
| 257 | $(CC) $(EXLDFLAGS) -o $@ $^ |
|---|
| 258 | |
|---|
| 259 | |
|---|
| 260 | # .ao files are used for static archives |
|---|
| 261 | %.ao: %.c |
|---|
| 262 | $(CC) $(ARCPPFLAGS) $(ARCFLAGS) -c $< -o $@ |
|---|
| 263 | |
|---|
| 264 | %.ad: %.c |
|---|
| 265 | $(CC) -M -MG $(ARCPPFLAGS) $(ARCFLAGS) $< | \ |
|---|
| 266 | $(SED) -e 's@^\(.*\)\.o:@$*.ad $*.ao: Makefile '`dirname $*.ad`/Module.mk' @' > $@ |
|---|
| 267 | |
|---|
| 268 | |
|---|
| 269 | # .lo files are used for shared libraries |
|---|
| 270 | %.lo: %.c |
|---|
| 271 | $(CC) $(LIBCPPFLAGS) $(LIBCFLAGS) -c $< -o $@ |
|---|
| 272 | |
|---|
| 273 | %.ld: %.c |
|---|
| 274 | $(CC) -M -MG $(LIBCPPFLAGS) $(LIBCFLAGS) $< | \ |
|---|
| 275 | $(SED) -e 's@^\(.*\)\.o:@$*.ld $*.lo: Makefile '`dirname $*.ld`/Module.mk' @' > $@ |
|---|
| 276 | |
|---|
| 277 | |
|---|
| 278 | # Flex and Bison |
|---|
| 279 | %c: %y |
|---|
| 280 | $(BISON) -p sensors_yy -d $< -o $@ |
|---|
| 281 | |
|---|
| 282 | ifeq ($(DEBUG),1) |
|---|
| 283 | FLEX_FLAGS := -Psensors_yy -t -b -Cfe -8 |
|---|
| 284 | else |
|---|
| 285 | FLEX_FLAGS := -Psensors_yy -t -Cfe -8 |
|---|
| 286 | endif |
|---|
| 287 | |
|---|
| 288 | %.c: %.l |
|---|
| 289 | $(FLEX) $(FLEX_FLAGS) $< > $@ |
|---|