kbuild: use $(abspath ...) instead of $(shell cd ... && /bin/pwd)
[linux-2.6-block.git] / tools / power / cpupower / Makefile
CommitLineData
ee3db6fc 1# Makefile for cpupower
7fe2f639
DB
2#
3# Copyright (C) 2005,2006 Dominik Brodowski <linux@dominikbrodowski.net>
4#
5# Based largely on the Makefile for udev by:
6#
7# Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; version 2 of the License.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16# General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21#
68bb2c3a
FBH
22OUTPUT=./
23ifeq ("$(origin O)", "command line")
24 OUTPUT := $(O)/
25endif
26
27ifneq ($(OUTPUT),)
28# check that the output directory actually exists
8e9b4667 29OUTDIR := $(realpath $(OUTPUT))
68bb2c3a
FBH
30$(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
31endif
7fe2f639
DB
32
33# --- CONFIGURATION BEGIN ---
34
35# Set the following to `true' to make a unstripped, unoptimized
36# binary. Leave this set to `false' for production use.
2dfc818b 37DEBUG ?= true
7fe2f639
DB
38
39# make the build silent. Set this to something else to make it noisy again.
40V ?= false
41
42# Internationalization support (output in different languages).
43# Requires gettext.
44NLS ?= true
45
46# Set the following to 'true' to build/install the
47# cpufreq-bench benchmarking tool
63b37de1 48CPUFREQ_BENCH ?= true
7fe2f639 49
e51207f0
TR
50# Do not build libraries, but build the code in statically
51# Libraries are still built, otherwise the Makefile code would
52# be rather ugly.
53export STATIC ?= false
54
7fe2f639 55# Prefix to the directories we're installing to
02af3cb5 56DESTDIR ?=
7fe2f639
DB
57
58# --- CONFIGURATION END ---
59
60
61
62# Package-related definitions. Distributions can modify the version
63# and _should_ modify the PACKAGE_BUGREPORT definition
64
af594f0c 65VERSION= $(shell ./utils/version-gen.sh)
ac5a181d 66LIB_MAJ= 0.0.1
7fe2f639
DB
67LIB_MIN= 0
68
ee3db6fc 69PACKAGE = cpupower
dec102aa 70PACKAGE_BUGREPORT = linux-pm@vger.kernel.org
7fe2f639
DB
71LANGUAGES = de fr it cs pt
72
73
74# Directory definitions. These are default and most probably
75# do not need to be changed. Please note that DESTDIR is
76# added in front of any of them
77
78bindir ?= /usr/bin
79sbindir ?= /usr/sbin
80mandir ?= /usr/man
81includedir ?= /usr/include
82libdir ?= /usr/lib
83localedir ?= /usr/share/locale
ee3db6fc 84docdir ?= /usr/share/doc/packages/cpupower
7fe2f639
DB
85confdir ?= /etc/
86
87# Toolchain: what tools do we use, and what options do they need:
88
89CP = cp -fpR
90INSTALL = /usr/bin/install -c
91INSTALL_PROGRAM = ${INSTALL}
92INSTALL_DATA = ${INSTALL} -m 644
93INSTALL_SCRIPT = ${INSTALL_PROGRAM}
94
95# If you are running a cross compiler, you may want to set this
96# to something more interesting, like "arm-linux-". If you want
97# to compile vs uClibc, that can be done here as well.
98CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
99CC = $(CROSS)gcc
100LD = $(CROSS)gcc
101AR = $(CROSS)ar
102STRIP = $(CROSS)strip
103RANLIB = $(CROSS)ranlib
104HOSTCC = gcc
68bb2c3a 105MKDIR = mkdir
7fe2f639
DB
106
107
108# Now we set up the build system
109#
110
68bb2c3a 111GMO_FILES = ${shell for HLANG in ${LANGUAGES}; do echo $(OUTPUT)po/$$HLANG.gmo; done;}
f5ac0641 112
7fe2f639
DB
113export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS
114
115# check if compiler option is supported
b1e0d8b7 116cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -x c /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;}
7fe2f639
DB
117
118# use '-Os' optimization if available, else use -O2
119OPTIMIZATION := $(call cc-supports,-Os,-O2)
120
121WARNINGS := -Wall -Wchar-subscripts -Wpointer-arith -Wsign-compare
122WARNINGS += $(call cc-supports,-Wno-pointer-sign)
123WARNINGS += $(call cc-supports,-Wdeclaration-after-statement)
124WARNINGS += -Wshadow
125
af594f0c 126CFLAGS += -DVERSION=\"$(VERSION)\" -DPACKAGE=\"$(PACKAGE)\" \
7fe2f639
DB
127 -DPACKAGE_BUGREPORT=\"$(PACKAGE_BUGREPORT)\" -D_GNU_SOURCE
128
ac5a181d 129UTIL_OBJS = utils/helpers/amd.o utils/helpers/msr.o \
7fe2f639
DB
130 utils/helpers/sysfs.o utils/helpers/misc.o utils/helpers/cpuid.o \
131 utils/helpers/pci.o utils/helpers/bitmask.o \
132 utils/idle_monitor/nhm_idle.o utils/idle_monitor/snb_idle.o \
7ee767b6 133 utils/idle_monitor/hsw_ext_idle.o \
7fe2f639
DB
134 utils/idle_monitor/amd_fam14h_idle.o utils/idle_monitor/cpuidle_sysfs.o \
135 utils/idle_monitor/mperf_monitor.o utils/idle_monitor/cpupower-monitor.o \
136 utils/cpupower.o utils/cpufreq-info.o utils/cpufreq-set.o \
c4f3610e
TR
137 utils/cpupower-set.o utils/cpupower-info.o utils/cpuidle-info.o \
138 utils/cpuidle-set.o
7fe2f639 139
68bb2c3a
FBH
140UTIL_SRC := $(UTIL_OBJS:.o=.c)
141
142UTIL_OBJS := $(addprefix $(OUTPUT),$(UTIL_OBJS))
143
7fe2f639
DB
144UTIL_HEADERS = utils/helpers/helpers.h utils/idle_monitor/cpupower-monitor.h \
145 utils/helpers/bitmask.h \
146 utils/idle_monitor/idle_monitors.h utils/idle_monitor/idle_monitors.def
147
ac5a181d
TR
148LIB_HEADERS = lib/cpufreq.h lib/cpupower.h lib/cpuidle.h
149LIB_SRC = lib/cpufreq.c lib/cpupower.c lib/cpuidle.c
150LIB_OBJS = lib/cpufreq.o lib/cpupower.o lib/cpuidle.o
68bb2c3a 151LIB_OBJS := $(addprefix $(OUTPUT),$(LIB_OBJS))
7fe2f639
DB
152
153CFLAGS += -pipe
154
155ifeq ($(strip $(NLS)),true)
156 INSTALL_NLS += install-gmo
f5ac0641 157 COMPILE_NLS += create-gmo
47c33630 158 CFLAGS += -DNLS
7fe2f639
DB
159endif
160
63b37de1 161ifeq ($(strip $(CPUFREQ_BENCH)),true)
7fe2f639
DB
162 INSTALL_BENCH += install-bench
163 COMPILE_BENCH += compile-bench
164endif
165
e51207f0
TR
166ifeq ($(strip $(STATIC)),true)
167 UTIL_OBJS += $(LIB_OBJS)
168 UTIL_HEADERS += $(LIB_HEADERS)
169 UTIL_SRC += $(LIB_SRC)
170endif
171
7fe2f639
DB
172CFLAGS += $(WARNINGS)
173
174ifeq ($(strip $(V)),false)
7443af9c
DB
175 QUIET=@
176 ECHO=@echo
7fe2f639
DB
177else
178 QUIET=
7443af9c 179 ECHO=@\#
7fe2f639 180endif
7443af9c 181export QUIET ECHO
7fe2f639
DB
182
183# if DEBUG is enabled, then we do not strip or optimize
184ifeq ($(strip $(DEBUG)),true)
af594f0c 185 CFLAGS += -O1 -g -DDEBUG
7fe2f639
DB
186 STRIPCMD = /bin/true -Since_we_are_debugging
187else
188 CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer
189 STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
190endif
191
192
193# the actual make rules
194
68bb2c3a 195all: libcpupower $(OUTPUT)cpupower $(COMPILE_NLS) $(COMPILE_BENCH)
7fe2f639 196
68bb2c3a 197$(OUTPUT)lib/%.o: $(LIB_SRC) $(LIB_HEADERS)
7443af9c 198 $(ECHO) " CC " $@
af594f0c 199 $(QUIET) $(CC) $(CFLAGS) -fPIC -o $@ -c lib/$*.c
7fe2f639 200
68bb2c3a 201$(OUTPUT)libcpupower.so.$(LIB_MAJ): $(LIB_OBJS)
7443af9c 202 $(ECHO) " LD " $@
af594f0c 203 $(QUIET) $(CC) -shared $(CFLAGS) $(LDFLAGS) -o $@ \
4c22337f 204 -Wl,-soname,libcpupower.so.$(LIB_MIN) $(LIB_OBJS)
68bb2c3a
FBH
205 @ln -sf $(@F) $(OUTPUT)libcpupower.so
206 @ln -sf $(@F) $(OUTPUT)libcpupower.so.$(LIB_MIN)
7fe2f639 207
68bb2c3a 208libcpupower: $(OUTPUT)libcpupower.so.$(LIB_MAJ)
7fe2f639
DB
209
210# Let all .o files depend on its .c file and all headers
211# Might be worth to put this into utils/Makefile at some point of time
212$(UTIL_OBJS): $(UTIL_HEADERS)
213
68bb2c3a 214$(OUTPUT)%.o: %.c
7443af9c 215 $(ECHO) " CC " $@
af594f0c 216 $(QUIET) $(CC) $(CFLAGS) -I./lib -I ./utils -o $@ -c $*.c
7fe2f639 217
68bb2c3a 218$(OUTPUT)cpupower: $(UTIL_OBJS) $(OUTPUT)libcpupower.so.$(LIB_MAJ)
7443af9c 219 $(ECHO) " CC " $@
e51207f0
TR
220ifeq ($(strip $(STATIC)),true)
221 $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) $(UTIL_OBJS) -lrt -lpci -L$(OUTPUT) -o $@
222else
b8ea351b 223 $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) $(UTIL_OBJS) -lcpupower -lrt -lpci -L$(OUTPUT) -o $@
e51207f0 224endif
7443af9c 225 $(QUIET) $(STRIPCMD) $@
7fe2f639 226
68bb2c3a 227$(OUTPUT)po/$(PACKAGE).pot: $(UTIL_SRC)
f5ac0641
DB
228 $(ECHO) " GETTEXT " $@
229 $(QUIET) xgettext --default-domain=$(PACKAGE) --add-comments \
38271504 230 --keyword=_ --keyword=N_ $(UTIL_SRC) -p $(@D) -o $(@F)
7fe2f639 231
68bb2c3a 232$(OUTPUT)po/%.gmo: po/%.po
f5ac0641
DB
233 $(ECHO) " MSGFMT " $@
234 $(QUIET) msgfmt -o $@ po/$*.po
235
236create-gmo: ${GMO_FILES}
237
68bb2c3a 238update-po: $(OUTPUT)po/$(PACKAGE).pot
f5ac0641
DB
239 $(ECHO) " MSGMRG " $@
240 $(QUIET) @for HLANG in $(LANGUAGES); do \
241 echo -n "Updating $$HLANG "; \
68bb2c3a
FBH
242 if msgmerge po/$$HLANG.po $< -o \
243 $(OUTPUT)po/$$HLANG.new.po; then \
244 mv -f $(OUTPUT)po/$$HLANG.new.po $(OUTPUT)po/$$HLANG.po; \
7fe2f639
DB
245 else \
246 echo "msgmerge for $$HLANG failed!"; \
68bb2c3a 247 rm -f $(OUTPUT)po/$$HLANG.new.po; \
7fe2f639 248 fi; \
7fe2f639
DB
249 done;
250
68bb2c3a
FBH
251compile-bench: $(OUTPUT)libcpupower.so.$(LIB_MAJ)
252 @V=$(V) confdir=$(confdir) $(MAKE) -C bench O=$(OUTPUT)
253
254# we compile into subdirectories. if the target directory is not the
255# source directory, they might not exists. So we depend the various
256# files onto their directories.
257DIRECTORY_DEPS = $(LIB_OBJS) $(UTIL_OBJS) $(GMO_FILES)
258$(DIRECTORY_DEPS): | $(sort $(dir $(DIRECTORY_DEPS)))
259
260# In the second step, we make a rule to actually create these directories
261$(sort $(dir $(DIRECTORY_DEPS))):
262 $(ECHO) " MKDIR " $@
263 $(QUIET) $(MKDIR) -p $@ 2>/dev/null
7fe2f639
DB
264
265clean:
68bb2c3a 266 -find $(OUTPUT) \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
7fe2f639 267 | xargs rm -f
68bb2c3a
FBH
268 -rm -f $(OUTPUT)cpupower
269 -rm -f $(OUTPUT)libcpupower.so*
8c00bdfb
PC
270 -rm -rf $(OUTPUT)po/*.gmo
271 -rm -rf $(OUTPUT)po/*.pot
68bb2c3a 272 $(MAKE) -C bench O=$(OUTPUT) clean
7fe2f639
DB
273
274
275install-lib:
276 $(INSTALL) -d $(DESTDIR)${libdir}
68bb2c3a 277 $(CP) $(OUTPUT)libcpupower.so* $(DESTDIR)${libdir}/
7fe2f639
DB
278 $(INSTALL) -d $(DESTDIR)${includedir}
279 $(INSTALL_DATA) lib/cpufreq.h $(DESTDIR)${includedir}/cpufreq.h
ac5a181d 280 $(INSTALL_DATA) lib/cpuidle.h $(DESTDIR)${includedir}/cpuidle.h
7fe2f639
DB
281
282install-tools:
283 $(INSTALL) -d $(DESTDIR)${bindir}
68bb2c3a 284 $(INSTALL_PROGRAM) $(OUTPUT)cpupower $(DESTDIR)${bindir}
7fe2f639
DB
285
286install-man:
287 $(INSTALL_DATA) -D man/cpupower.1 $(DESTDIR)${mandir}/man1/cpupower.1
288 $(INSTALL_DATA) -D man/cpupower-frequency-set.1 $(DESTDIR)${mandir}/man1/cpupower-frequency-set.1
289 $(INSTALL_DATA) -D man/cpupower-frequency-info.1 $(DESTDIR)${mandir}/man1/cpupower-frequency-info.1
84baab91
TR
290 $(INSTALL_DATA) -D man/cpupower-idle-set.1 $(DESTDIR)${mandir}/man1/cpupower-idle-set.1
291 $(INSTALL_DATA) -D man/cpupower-idle-info.1 $(DESTDIR)${mandir}/man1/cpupower-idle-info.1
7fe2f639
DB
292 $(INSTALL_DATA) -D man/cpupower-set.1 $(DESTDIR)${mandir}/man1/cpupower-set.1
293 $(INSTALL_DATA) -D man/cpupower-info.1 $(DESTDIR)${mandir}/man1/cpupower-info.1
294 $(INSTALL_DATA) -D man/cpupower-monitor.1 $(DESTDIR)${mandir}/man1/cpupower-monitor.1
295
296install-gmo:
297 $(INSTALL) -d $(DESTDIR)${localedir}
298 for HLANG in $(LANGUAGES); do \
68bb2c3a
FBH
299 echo '$(INSTALL_DATA) -D $(OUTPUT)po/$$HLANG.gmo $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo'; \
300 $(INSTALL_DATA) -D $(OUTPUT)po/$$HLANG.gmo $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo; \
7fe2f639
DB
301 done;
302
303install-bench:
304 @#DESTDIR must be set from outside to survive
68bb2c3a 305 @sbindir=$(sbindir) bindir=$(bindir) docdir=$(docdir) confdir=$(confdir) $(MAKE) -C bench O=$(OUTPUT) install
7443af9c 306
e51207f0
TR
307ifeq ($(strip $(STATIC)),true)
308install: all install-tools install-man $(INSTALL_NLS) $(INSTALL_BENCH)
309else
7fe2f639 310install: all install-lib install-tools install-man $(INSTALL_NLS) $(INSTALL_BENCH)
e51207f0 311endif
7fe2f639
DB
312
313uninstall:
4c22337f 314 - rm -f $(DESTDIR)${libdir}/libcpupower.*
7fe2f639 315 - rm -f $(DESTDIR)${includedir}/cpufreq.h
ac5a181d 316 - rm -f $(DESTDIR)${includedir}/cpuidle.h
7fe2f639 317 - rm -f $(DESTDIR)${bindir}/utils/cpupower
706f4c11
RR
318 - rm -f $(DESTDIR)${mandir}/man1/cpupower.1
319 - rm -f $(DESTDIR)${mandir}/man1/cpupower-frequency-set.1
320 - rm -f $(DESTDIR)${mandir}/man1/cpupower-frequency-info.1
321 - rm -f $(DESTDIR)${mandir}/man1/cpupower-set.1
322 - rm -f $(DESTDIR)${mandir}/man1/cpupower-info.1
323 - rm -f $(DESTDIR)${mandir}/man1/cpupower-monitor.1
7fe2f639 324 - for HLANG in $(LANGUAGES); do \
ee3db6fc 325 rm -f $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo; \
7fe2f639
DB
326 done;
327
4c22337f 328.PHONY: all utils libcpupower update-po create-gmo install-lib install-tools install-man install-gmo install uninstall clean