1 # Makefile for cpupowerutils
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 # --- CONFIGURATION BEGIN ---
25 # Set the following to `true' to make a unstripped, unoptimized
26 # binary. Leave this set to `false' for production use.
29 # make the build silent. Set this to something else to make it noisy again.
32 # Internationalization support (output in different languages).
36 # Set the following to 'true' to build/install the
37 # cpufreq-bench benchmarking tool
40 # Prefix to the directories we're installing to
43 # --- CONFIGURATION END ---
47 # Package-related definitions. Distributions can modify the version
48 # and _should_ modify the PACKAGE_BUGREPORT definition
54 PACKAGE = cpupowerutils
55 PACKAGE_BUGREPORT = cpufreq@vger.kernel.org
56 LANGUAGES = de fr it cs pt
59 # Directory definitions. These are default and most probably
60 # do not need to be changed. Please note that DESTDIR is
61 # added in front of any of them
66 includedir ?= /usr/include
68 localedir ?= /usr/share/locale
69 docdir ?= /usr/share/doc/packages/cpupowerutils
72 # Toolchain: what tools do we use, and what options do they need:
75 INSTALL = /usr/bin/install -c
76 INSTALL_PROGRAM = ${INSTALL}
77 INSTALL_DATA = ${INSTALL} -m 644
78 INSTALL_SCRIPT = ${INSTALL_PROGRAM}
80 # If you are running a cross compiler, you may want to set this
81 # to something more interesting, like "arm-linux-". If you want
82 # to compile vs uClibc, that can be done here as well.
83 CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
88 RANLIB = $(CROSS)ranlib
92 # Now we set up the build system
95 # set up PWD so that older versions of make will work with our build.
98 export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS
100 # check if compiler option is supported
101 cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;}
103 # use '-Os' optimization if available, else use -O2
104 OPTIMIZATION := $(call cc-supports,-Os,-O2)
106 WARNINGS := -Wall -Wchar-subscripts -Wpointer-arith -Wsign-compare
107 WARNINGS += $(call cc-supports,-Wno-pointer-sign)
108 WARNINGS += $(call cc-supports,-Wdeclaration-after-statement)
111 CPPFLAGS += -DVERSION=\"$(VERSION)\" -DPACKAGE=\"$(PACKAGE)\" \
112 -DPACKAGE_BUGREPORT=\"$(PACKAGE_BUGREPORT)\" -D_GNU_SOURCE
114 UTIL_OBJS = utils/helpers/amd.o utils/helpers/topology.o utils/helpers/msr.o \
115 utils/helpers/sysfs.o utils/helpers/misc.o utils/helpers/cpuid.o \
116 utils/helpers/pci.o utils/helpers/bitmask.o \
117 utils/idle_monitor/nhm_idle.o utils/idle_monitor/snb_idle.o \
118 utils/idle_monitor/amd_fam14h_idle.o utils/idle_monitor/cpuidle_sysfs.o \
119 utils/idle_monitor/mperf_monitor.o utils/idle_monitor/cpupower-monitor.o \
120 utils/cpupower.o utils/cpufreq-info.o utils/cpufreq-set.o \
121 utils/cpupower-set.o utils/cpupower-info.o utils/cpuidle-info.o
123 UTIL_HEADERS = utils/helpers/helpers.h utils/idle_monitor/cpupower-monitor.h \
124 utils/helpers/bitmask.h \
125 utils/idle_monitor/idle_monitors.h utils/idle_monitor/idle_monitors.def
127 UTIL_SRC := $(UTIL_OBJS:.o=.c)
129 LIB_HEADERS = lib/cpufreq.h lib/sysfs.h
130 LIB_SRC = lib/cpufreq.c lib/sysfs.c
131 LIB_OBJS = lib/cpufreq.o lib/sysfs.o
135 ifeq ($(strip $(NLS)),true)
136 INSTALL_NLS += install-gmo
137 COMPILE_NLS += update-gmo
140 ifeq ($(strip $(CPUFRQ_BENCH)),true)
141 INSTALL_BENCH += install-bench
142 COMPILE_BENCH += compile-bench
145 CFLAGS += $(WARNINGS)
147 ifeq ($(strip $(V)),false)
148 QUIET=@$(PWD)/build/ccdv
149 HOST_PROGS=build/ccdv
155 # if DEBUG is enabled, then we do not strip or optimize
156 ifeq ($(strip $(DEBUG)),true)
159 STRIPCMD = /bin/true -Since_we_are_debugging
161 CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer
162 STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
166 # the actual make rules
168 all: ccdv libcpufreq cpupower $(COMPILE_NLS) $(COMPILE_BENCH)
171 build/ccdv: build/ccdv.c
172 @echo "Building ccdv"
173 @$(HOSTCC) -O1 $< -o $@
175 lib/%.o: $(LIB_SRC) $(LIB_HEADERS) build/ccdv
176 $(QUIET) $(CC) $(CPPFLAGS) $(CFLAGS) -fPIC -o $@ -c lib/$*.c
178 libcpufreq.so.$(LIB_MAJ): $(LIB_OBJS)
179 $(QUIET) $(CC) -shared $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
180 -Wl,-soname,libcpufreq.so.$(LIB_MIN) $(LIB_OBJS)
181 @ln -sf $@ libcpufreq.so
182 @ln -sf $@ libcpufreq.so.$(LIB_MIN)
184 libcpufreq: libcpufreq.so.$(LIB_MAJ)
186 # Let all .o files depend on its .c file and all headers
187 # Might be worth to put this into utils/Makefile at some point of time
188 $(UTIL_OBJS): $(UTIL_HEADERS)
191 $(QUIET) $(CC) $(CFLAGS) $(CPPFLAGS) -I./lib -I ./utils -o $@ -c $*.c
193 cpupower: $(UTIL_OBJS) libcpufreq
194 $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) -lcpufreq -lrt -lpci -L. -o $@ $(UTIL_OBJS)
197 po/$(PACKAGE).pot: $(UTIL_SRC)
198 @xgettext --default-domain=$(PACKAGE) --add-comments \
199 --keyword=_ --keyword=N_ $(UTIL_SRC) && \
200 test -f $(PACKAGE).po && \
201 mv -f $(PACKAGE).po po/$(PACKAGE).pot
203 update-gmo: po/$(PACKAGE).pot
204 @for HLANG in $(LANGUAGES); do \
205 echo -n "Translating $$HLANG "; \
206 if msgmerge po/$$HLANG.po po/$(PACKAGE).pot -o \
207 po/$$HLANG.new.po; then \
208 mv -f po/$$HLANG.new.po po/$$HLANG.po; \
210 echo "msgmerge for $$HLANG failed!"; \
211 rm -f po/$$HLANG.new.po; \
213 msgfmt --statistics -o po/$$HLANG.gmo po/$$HLANG.po; \
216 compile-bench: libcpufreq.so.$(LIB_MAJ)
217 @V=$(V) confdir=$(confdir) $(MAKE) -C bench
220 -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
225 -rm -f libcpufreq.so*
227 -rm -rf po/*.gmo po/*.pot
228 $(MAKE) -C bench clean
232 $(INSTALL) -d $(DESTDIR)${libdir}
233 $(CP) libcpufreq.so* $(DESTDIR)${libdir}/
234 $(INSTALL) -d $(DESTDIR)${includedir}
235 $(INSTALL_DATA) lib/cpufreq.h $(DESTDIR)${includedir}/cpufreq.h
238 $(INSTALL) -d $(DESTDIR)${bindir}
239 $(INSTALL_PROGRAM) cpupower $(DESTDIR)${bindir}
242 $(INSTALL_DATA) -D man/cpupower.1 $(DESTDIR)${mandir}/man1/cpupower.1
243 $(INSTALL_DATA) -D man/cpupower-frequency-set.1 $(DESTDIR)${mandir}/man1/cpupower-frequency-set.1
244 $(INSTALL_DATA) -D man/cpupower-frequency-info.1 $(DESTDIR)${mandir}/man1/cpupower-frequency-info.1
245 $(INSTALL_DATA) -D man/cpupower-set.1 $(DESTDIR)${mandir}/man1/cpupower-set.1
246 $(INSTALL_DATA) -D man/cpupower-info.1 $(DESTDIR)${mandir}/man1/cpupower-info.1
247 $(INSTALL_DATA) -D man/cpupower-monitor.1 $(DESTDIR)${mandir}/man1/cpupower-monitor.1
250 $(INSTALL) -d $(DESTDIR)${localedir}
251 for HLANG in $(LANGUAGES); do \
252 echo '$(INSTALL_DATA) -D po/$$HLANG.gmo $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupowerutils.mo'; \
253 $(INSTALL_DATA) -D po/$$HLANG.gmo $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupowerutils.mo; \
257 @#DESTDIR must be set from outside to survive
258 @sbindir=$(sbindir) bindir=$(bindir) docdir=$(docdir) confdir=$(confdir) $(MAKE) -C bench install
260 install: all install-lib install-tools install-man $(INSTALL_NLS) $(INSTALL_BENCH)
263 - rm -f $(DESTDIR)${libdir}/libcpufreq.*
264 - rm -f $(DESTDIR)${includedir}/cpufreq.h
265 - rm -f $(DESTDIR)${bindir}/utils/cpupower
266 - rm -f $(DESTDIR)${mandir}/man1/cpufreq-set.1
267 - rm -f $(DESTDIR)${mandir}/man1/cpufreq-info.1
268 - for HLANG in $(LANGUAGES); do \
269 rm -f $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupowerutils.mo; \
272 .PHONY: all utils libcpufreq ccdv update-po update-gmo install-lib install-tools install-man install-gmo install uninstall \