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