1 # Makefile for cpupower
3 # Copyright (C) 2005,2006 Dominik Brodowski <linux@dominikbrodowski.net>
5 # Based largely on the Makefile for udev by:
7 # Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
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.
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.
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
23 ifeq ("$(origin O)", "command line")
28 # check that the output directory actually exists
29 OUTDIR := $(shell cd $(OUTPUT) && pwd)
30 $(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
33 include ../../scripts/Makefile.arch
35 # --- CONFIGURATION BEGIN ---
37 # Set the following to `true' to make a unstripped, unoptimized
38 # binary. Leave this set to `false' for production use.
41 # make the build silent. Set this to something else to make it noisy again.
44 # Internationalization support (output in different languages).
48 # Set the following to 'true' to build/install the
49 # cpufreq-bench benchmarking tool
52 # Do not build libraries, but build the code in statically
53 # Libraries are still built, otherwise the Makefile code would
55 export STATIC ?= false
57 # Prefix to the directories we're installing to
60 # --- CONFIGURATION END ---
64 # Package-related definitions. Distributions can modify the version
65 # and _should_ modify the PACKAGE_BUGREPORT definition
67 VERSION= $(shell ./utils/version-gen.sh)
72 PACKAGE_BUGREPORT = linux-pm@vger.kernel.org
73 LANGUAGES = de fr it cs pt
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
83 includedir ?= /usr/include
84 ifeq ($(IS_64_BIT), 1)
89 localedir ?= /usr/share/locale
90 docdir ?= /usr/share/doc/packages/cpupower
92 bash_completion_dir ?= /usr/share/bash-completion/completions
94 # Toolchain: what tools do we use, and what options do they need:
97 INSTALL = /usr/bin/install -c
98 INSTALL_PROGRAM = ${INSTALL}
99 INSTALL_DATA = ${INSTALL} -m 644
100 #bash completion scripts get sourced and so they should be rw only.
101 INSTALL_SCRIPT = ${INSTALL} -m 644
103 # If you are running a cross compiler, you may want to set this
104 # to something more interesting, like "arm-linux-". If you want
105 # to compile vs uClibc, that can be done here as well.
106 CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
110 STRIP = $(CROSS)strip
111 RANLIB = $(CROSS)ranlib
116 # Now we set up the build system
119 GMO_FILES = ${shell for HLANG in ${LANGUAGES}; do echo $(OUTPUT)po/$$HLANG.gmo; done;}
121 export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS
123 # check if compiler option is supported
124 cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -x c /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;}
126 # use '-Os' optimization if available, else use -O2
127 OPTIMIZATION := $(call cc-supports,-Os,-O2)
129 WARNINGS := -Wall -Wchar-subscripts -Wpointer-arith -Wsign-compare
130 WARNINGS += $(call cc-supports,-Wno-pointer-sign)
131 WARNINGS += $(call cc-supports,-Wdeclaration-after-statement)
134 override CFLAGS += -DVERSION=\"$(VERSION)\" -DPACKAGE=\"$(PACKAGE)\" \
135 -DPACKAGE_BUGREPORT=\"$(PACKAGE_BUGREPORT)\" -D_GNU_SOURCE
137 UTIL_OBJS = utils/helpers/amd.o utils/helpers/msr.o \
138 utils/helpers/sysfs.o utils/helpers/misc.o utils/helpers/cpuid.o \
139 utils/helpers/pci.o utils/helpers/bitmask.o \
140 utils/idle_monitor/nhm_idle.o utils/idle_monitor/snb_idle.o \
141 utils/idle_monitor/hsw_ext_idle.o \
142 utils/idle_monitor/amd_fam14h_idle.o utils/idle_monitor/cpuidle_sysfs.o \
143 utils/idle_monitor/mperf_monitor.o utils/idle_monitor/cpupower-monitor.o \
144 utils/cpupower.o utils/cpufreq-info.o utils/cpufreq-set.o \
145 utils/cpupower-set.o utils/cpupower-info.o utils/cpuidle-info.o \
148 UTIL_SRC := $(UTIL_OBJS:.o=.c)
150 UTIL_OBJS := $(addprefix $(OUTPUT),$(UTIL_OBJS))
152 UTIL_HEADERS = utils/helpers/helpers.h utils/idle_monitor/cpupower-monitor.h \
153 utils/helpers/bitmask.h \
154 utils/idle_monitor/idle_monitors.h utils/idle_monitor/idle_monitors.def
156 LIB_HEADERS = lib/cpufreq.h lib/cpupower.h lib/cpuidle.h
157 LIB_SRC = lib/cpufreq.c lib/cpupower.c lib/cpuidle.c
158 LIB_OBJS = lib/cpufreq.o lib/cpupower.o lib/cpuidle.o
159 LIB_OBJS := $(addprefix $(OUTPUT),$(LIB_OBJS))
161 override CFLAGS += -pipe
163 ifeq ($(strip $(NLS)),true)
164 INSTALL_NLS += install-gmo
165 COMPILE_NLS += create-gmo
166 override CFLAGS += -DNLS
169 ifeq ($(strip $(CPUFREQ_BENCH)),true)
170 INSTALL_BENCH += install-bench
171 COMPILE_BENCH += compile-bench
174 ifeq ($(strip $(STATIC)),true)
175 UTIL_OBJS += $(LIB_OBJS)
176 UTIL_HEADERS += $(LIB_HEADERS)
177 UTIL_SRC += $(LIB_SRC)
180 override CFLAGS += $(WARNINGS)
182 ifeq ($(strip $(V)),false)
191 # if DEBUG is enabled, then we do not strip or optimize
192 ifeq ($(strip $(DEBUG)),true)
193 override CFLAGS += -O1 -g -DDEBUG
194 STRIPCMD = /bin/true -Since_we_are_debugging
196 override CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer
197 STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
201 # the actual make rules
203 all: libcpupower $(OUTPUT)cpupower $(COMPILE_NLS) $(COMPILE_BENCH)
205 $(OUTPUT)lib/%.o: $(LIB_SRC) $(LIB_HEADERS)
207 $(QUIET) $(CC) $(CFLAGS) -fPIC -o $@ -c lib/$*.c
209 $(OUTPUT)libcpupower.so.$(LIB_MAJ): $(LIB_OBJS)
211 $(QUIET) $(CC) -shared $(CFLAGS) $(LDFLAGS) -o $@ \
212 -Wl,-soname,libcpupower.so.$(LIB_MIN) $(LIB_OBJS)
213 @ln -sf $(@F) $(OUTPUT)libcpupower.so
214 @ln -sf $(@F) $(OUTPUT)libcpupower.so.$(LIB_MIN)
216 libcpupower: $(OUTPUT)libcpupower.so.$(LIB_MAJ)
218 # Let all .o files depend on its .c file and all headers
219 # Might be worth to put this into utils/Makefile at some point of time
220 $(UTIL_OBJS): $(UTIL_HEADERS)
224 $(QUIET) $(CC) $(CFLAGS) -I./lib -I ./utils -o $@ -c $*.c
226 $(OUTPUT)cpupower: $(UTIL_OBJS) $(OUTPUT)libcpupower.so.$(LIB_MAJ)
228 ifeq ($(strip $(STATIC)),true)
229 $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) $(UTIL_OBJS) -lrt -lpci -L$(OUTPUT) -o $@
231 $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) $(UTIL_OBJS) -lcpupower -lrt -lpci -L$(OUTPUT) -o $@
233 $(QUIET) $(STRIPCMD) $@
235 $(OUTPUT)po/$(PACKAGE).pot: $(UTIL_SRC)
236 $(ECHO) " GETTEXT " $@
237 $(QUIET) xgettext --default-domain=$(PACKAGE) --add-comments \
238 --keyword=_ --keyword=N_ $(UTIL_SRC) -p $(@D) -o $(@F)
240 $(OUTPUT)po/%.gmo: po/%.po
241 $(ECHO) " MSGFMT " $@
242 $(QUIET) msgfmt -o $@ po/$*.po
244 create-gmo: ${GMO_FILES}
246 update-po: $(OUTPUT)po/$(PACKAGE).pot
247 $(ECHO) " MSGMRG " $@
248 $(QUIET) @for HLANG in $(LANGUAGES); do \
249 echo -n "Updating $$HLANG "; \
250 if msgmerge po/$$HLANG.po $< -o \
251 $(OUTPUT)po/$$HLANG.new.po; then \
252 mv -f $(OUTPUT)po/$$HLANG.new.po $(OUTPUT)po/$$HLANG.po; \
254 echo "msgmerge for $$HLANG failed!"; \
255 rm -f $(OUTPUT)po/$$HLANG.new.po; \
259 compile-bench: $(OUTPUT)libcpupower.so.$(LIB_MAJ)
260 @V=$(V) confdir=$(confdir) $(MAKE) -C bench O=$(OUTPUT)
262 # we compile into subdirectories. if the target directory is not the
263 # source directory, they might not exists. So we depend the various
264 # files onto their directories.
265 DIRECTORY_DEPS = $(LIB_OBJS) $(UTIL_OBJS) $(GMO_FILES)
266 $(DIRECTORY_DEPS): | $(sort $(dir $(DIRECTORY_DEPS)))
268 # In the second step, we make a rule to actually create these directories
269 $(sort $(dir $(DIRECTORY_DEPS))):
271 $(QUIET) $(MKDIR) -p $@ 2>/dev/null
274 -find $(OUTPUT) \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
276 -rm -f $(OUTPUT)cpupower
277 -rm -f $(OUTPUT)libcpupower.so*
278 -rm -rf $(OUTPUT)po/*.gmo
279 -rm -rf $(OUTPUT)po/*.pot
280 $(MAKE) -C bench O=$(OUTPUT) clean
284 $(INSTALL) -d $(DESTDIR)${libdir}
285 $(CP) $(OUTPUT)libcpupower.so* $(DESTDIR)${libdir}/
286 $(INSTALL) -d $(DESTDIR)${includedir}
287 $(INSTALL_DATA) lib/cpufreq.h $(DESTDIR)${includedir}/cpufreq.h
288 $(INSTALL_DATA) lib/cpuidle.h $(DESTDIR)${includedir}/cpuidle.h
291 $(INSTALL) -d $(DESTDIR)${bindir}
292 $(INSTALL_PROGRAM) $(OUTPUT)cpupower $(DESTDIR)${bindir}
293 $(INSTALL) -d $(DESTDIR)${bash_completion_dir}
294 $(INSTALL_SCRIPT) cpupower-completion.sh '$(DESTDIR)${bash_completion_dir}/cpupower'
297 $(INSTALL_DATA) -D man/cpupower.1 $(DESTDIR)${mandir}/man1/cpupower.1
298 $(INSTALL_DATA) -D man/cpupower-frequency-set.1 $(DESTDIR)${mandir}/man1/cpupower-frequency-set.1
299 $(INSTALL_DATA) -D man/cpupower-frequency-info.1 $(DESTDIR)${mandir}/man1/cpupower-frequency-info.1
300 $(INSTALL_DATA) -D man/cpupower-idle-set.1 $(DESTDIR)${mandir}/man1/cpupower-idle-set.1
301 $(INSTALL_DATA) -D man/cpupower-idle-info.1 $(DESTDIR)${mandir}/man1/cpupower-idle-info.1
302 $(INSTALL_DATA) -D man/cpupower-set.1 $(DESTDIR)${mandir}/man1/cpupower-set.1
303 $(INSTALL_DATA) -D man/cpupower-info.1 $(DESTDIR)${mandir}/man1/cpupower-info.1
304 $(INSTALL_DATA) -D man/cpupower-monitor.1 $(DESTDIR)${mandir}/man1/cpupower-monitor.1
307 $(INSTALL) -d $(DESTDIR)${localedir}
308 for HLANG in $(LANGUAGES); do \
309 echo '$(INSTALL_DATA) -D $(OUTPUT)po/$$HLANG.gmo $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo'; \
310 $(INSTALL_DATA) -D $(OUTPUT)po/$$HLANG.gmo $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo; \
314 @#DESTDIR must be set from outside to survive
315 @sbindir=$(sbindir) bindir=$(bindir) docdir=$(docdir) confdir=$(confdir) $(MAKE) -C bench O=$(OUTPUT) install
317 ifeq ($(strip $(STATIC)),true)
318 install: all install-tools install-man $(INSTALL_NLS) $(INSTALL_BENCH)
320 install: all install-lib install-tools install-man $(INSTALL_NLS) $(INSTALL_BENCH)
324 - rm -f $(DESTDIR)${libdir}/libcpupower.*
325 - rm -f $(DESTDIR)${includedir}/cpufreq.h
326 - rm -f $(DESTDIR)${includedir}/cpuidle.h
327 - rm -f $(DESTDIR)${bindir}/utils/cpupower
328 - rm -f $(DESTDIR)${mandir}/man1/cpupower.1
329 - rm -f $(DESTDIR)${mandir}/man1/cpupower-frequency-set.1
330 - rm -f $(DESTDIR)${mandir}/man1/cpupower-frequency-info.1
331 - rm -f $(DESTDIR)${mandir}/man1/cpupower-set.1
332 - rm -f $(DESTDIR)${mandir}/man1/cpupower-info.1
333 - rm -f $(DESTDIR)${mandir}/man1/cpupower-monitor.1
334 - for HLANG in $(LANGUAGES); do \
335 rm -f $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo; \
338 .PHONY: all utils libcpupower update-po create-gmo install-lib install-tools install-man install-gmo install uninstall clean