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