1 # SPDX-License-Identifier: GPL-2.0-only
2 # Makefile for cpupower
4 # Copyright (C) 2005,2006 Dominik Brodowski <linux@dominikbrodowski.net>
6 # Based largely on the Makefile for udev by:
8 # Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
11 ifeq ("$(origin O)", "command line")
16 # check that the output directory actually exists
17 OUTDIR := $(shell cd $(OUTPUT) && pwd)
18 $(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
22 # --- CONFIGURATION BEGIN ---
24 # Set the following to `true' to make a unstripped, unoptimized
25 # binary. Leave this set to `false' for production use.
28 # make the build silent. Set this to something else to make it noisy again.
31 # Internationalization support (output in different languages).
35 # Set the following to 'true' to build/install the
36 # cpufreq-bench benchmarking tool
39 # Do not build libraries, but build the code in statically
40 # Libraries are still built, otherwise the Makefile code would
42 export STATIC ?= false
44 # Prefix to the directories we're installing to
47 # --- CONFIGURATION END ---
51 # Package-related definitions. Distributions can modify the version
52 # and _should_ modify the PACKAGE_BUGREPORT definition
54 VERSION:= $(shell ./utils/version-gen.sh)
59 PACKAGE_BUGREPORT = linux-pm@vger.kernel.org
60 LANGUAGES = de fr it cs pt ka
63 # Directory definitions. These are default and most probably
64 # do not need to be changed. Please note that DESTDIR is
65 # added in front of any of them
70 includedir ?= /usr/include
71 localedir ?= /usr/share/locale
72 docdir ?= /usr/share/doc/packages/cpupower
74 bash_completion_dir ?= /usr/share/bash-completion/completions
76 # Toolchain: what tools do we use, and what options do they need:
79 INSTALL = /usr/bin/install -c
80 INSTALL_PROGRAM = ${INSTALL}
81 INSTALL_DATA = ${INSTALL} -m 644
82 #bash completion scripts get sourced and so they should be rw only.
83 INSTALL_SCRIPT = ${INSTALL} -m 644
85 # If you are running a cross compiler, you may want to set this
86 # to something more interesting, like "arm-linux-". If you want
87 # to compile vs uClibc, that can be done here as well.
88 CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
93 RANLIB = $(CROSS)ranlib
97 # 64bit library detection
98 include ../../scripts/Makefile.arch
100 ifeq ($(IS_64_BIT), 1)
106 # Now we set up the build system
109 GMO_FILES = ${shell for HLANG in ${LANGUAGES}; do echo $(OUTPUT)po/$$HLANG.gmo; done;}
111 export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS
113 # check if compiler option is supported
114 cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -x c /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;}
116 # use '-Os' optimization if available, else use -O2
117 OPTIMIZATION := $(call cc-supports,-Os,-O2)
119 WARNINGS := -Wall -Wchar-subscripts -Wpointer-arith -Wsign-compare
120 WARNINGS += $(call cc-supports,-Wno-pointer-sign)
121 WARNINGS += $(call cc-supports,-Wdeclaration-after-statement)
124 override CFLAGS += -DVERSION=\"$(VERSION)\" -DPACKAGE=\"$(PACKAGE)\" \
125 -DPACKAGE_BUGREPORT=\"$(PACKAGE_BUGREPORT)\" -D_GNU_SOURCE
127 UTIL_OBJS = utils/helpers/amd.o utils/helpers/msr.o \
128 utils/helpers/sysfs.o utils/helpers/misc.o utils/helpers/cpuid.o \
129 utils/helpers/pci.o utils/helpers/bitmask.o \
130 utils/idle_monitor/nhm_idle.o utils/idle_monitor/snb_idle.o \
131 utils/idle_monitor/hsw_ext_idle.o \
132 utils/idle_monitor/amd_fam14h_idle.o utils/idle_monitor/cpuidle_sysfs.o \
133 utils/idle_monitor/mperf_monitor.o utils/idle_monitor/cpupower-monitor.o \
134 utils/idle_monitor/rapl_monitor.o \
135 utils/cpupower.o utils/cpufreq-info.o utils/cpufreq-set.o \
136 utils/cpupower-set.o utils/cpupower-info.o utils/cpuidle-info.o \
137 utils/cpuidle-set.o utils/powercap-info.o
139 UTIL_SRC := $(UTIL_OBJS:.o=.c)
141 UTIL_OBJS := $(addprefix $(OUTPUT),$(UTIL_OBJS))
143 UTIL_HEADERS = utils/helpers/helpers.h utils/idle_monitor/cpupower-monitor.h \
144 utils/helpers/bitmask.h \
145 utils/idle_monitor/idle_monitors.h utils/idle_monitor/idle_monitors.def
147 LIB_HEADERS = lib/cpufreq.h lib/cpupower.h lib/cpuidle.h lib/acpi_cppc.h \
149 LIB_SRC = lib/cpufreq.c lib/cpupower.c lib/cpuidle.c lib/acpi_cppc.c \
151 LIB_OBJS = lib/cpufreq.o lib/cpupower.o lib/cpuidle.o lib/acpi_cppc.o \
153 LIB_OBJS := $(addprefix $(OUTPUT),$(LIB_OBJS))
155 override CFLAGS += -pipe
157 ifeq ($(strip $(NLS)),true)
158 INSTALL_NLS += install-gmo
159 COMPILE_NLS += create-gmo
160 override CFLAGS += -DNLS
163 ifeq ($(strip $(CPUFREQ_BENCH)),true)
164 INSTALL_BENCH += install-bench
165 COMPILE_BENCH += compile-bench
168 ifeq ($(strip $(STATIC)),true)
169 UTIL_OBJS += $(LIB_OBJS)
170 UTIL_HEADERS += $(LIB_HEADERS)
171 UTIL_SRC += $(LIB_SRC)
174 override CFLAGS += $(WARNINGS)
176 ifeq ($(strip $(V)),false)
185 # if DEBUG is enabled, then we do not strip or optimize
186 ifeq ($(strip $(DEBUG)),true)
187 override CFLAGS += -O1 -g -DDEBUG
188 STRIPCMD = /bin/true -Since_we_are_debugging
190 override CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer
191 STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
195 # the actual make rules
197 all: libcpupower $(OUTPUT)cpupower $(COMPILE_NLS) $(COMPILE_BENCH)
199 $(OUTPUT)lib/%.o: $(LIB_SRC) $(LIB_HEADERS)
201 $(QUIET) $(CC) $(CFLAGS) -fPIC -o $@ -c lib/$*.c
203 $(OUTPUT)libcpupower.so.$(LIB_MAJ): $(LIB_OBJS)
205 $(QUIET) $(CC) -shared $(CFLAGS) $(LDFLAGS) -o $@ \
206 -Wl,-soname,libcpupower.so.$(LIB_MIN) $(LIB_OBJS)
207 @ln -sf $(@F) $(OUTPUT)libcpupower.so
208 @ln -sf $(@F) $(OUTPUT)libcpupower.so.$(LIB_MIN)
210 libcpupower: $(OUTPUT)libcpupower.so.$(LIB_MAJ)
212 # Let all .o files depend on its .c file and all headers
213 # Might be worth to put this into utils/Makefile at some point of time
214 $(UTIL_OBJS): $(UTIL_HEADERS)
218 $(QUIET) $(CC) $(CFLAGS) -I./lib -I ./utils -o $@ -c $*.c
220 $(OUTPUT)cpupower: $(UTIL_OBJS) $(OUTPUT)libcpupower.so.$(LIB_MAJ)
222 ifeq ($(strip $(STATIC)),true)
223 $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) $(UTIL_OBJS) -lrt -lpci -L$(OUTPUT) -o $@
225 $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) $(UTIL_OBJS) -lcpupower -lrt -lpci -L$(OUTPUT) -o $@
227 $(QUIET) $(STRIPCMD) $@
229 $(OUTPUT)po/$(PACKAGE).pot: $(UTIL_SRC)
230 $(ECHO) " GETTEXT " $@
231 $(QUIET) xgettext --default-domain=$(PACKAGE) --add-comments \
232 --keyword=_ --keyword=N_ $(UTIL_SRC) -p $(@D) -o $(@F)
234 $(OUTPUT)po/%.gmo: po/%.po
235 $(ECHO) " MSGFMT " $@
236 $(QUIET) msgfmt -o $@ po/$*.po
238 create-gmo: ${GMO_FILES}
240 update-po: $(OUTPUT)po/$(PACKAGE).pot
241 $(ECHO) " MSGMRG " $@
242 $(QUIET) @for HLANG in $(LANGUAGES); do \
243 echo -n "Updating $$HLANG "; \
244 if msgmerge po/$$HLANG.po $< -o \
245 $(OUTPUT)po/$$HLANG.new.po; then \
246 mv -f $(OUTPUT)po/$$HLANG.new.po $(OUTPUT)po/$$HLANG.po; \
248 echo "msgmerge for $$HLANG failed!"; \
249 rm -f $(OUTPUT)po/$$HLANG.new.po; \
253 compile-bench: $(OUTPUT)libcpupower.so.$(LIB_MAJ)
254 @V=$(V) confdir=$(confdir) $(MAKE) -C bench O=$(OUTPUT)
256 # we compile into subdirectories. if the target directory is not the
257 # source directory, they might not exists. So we depend the various
258 # files onto their directories.
259 DIRECTORY_DEPS = $(LIB_OBJS) $(UTIL_OBJS) $(GMO_FILES)
260 $(DIRECTORY_DEPS): | $(sort $(dir $(DIRECTORY_DEPS)))
262 # In the second step, we make a rule to actually create these directories
263 $(sort $(dir $(DIRECTORY_DEPS))):
265 $(QUIET) $(MKDIR) -p $@ 2>/dev/null
268 -find $(OUTPUT) \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
270 -rm -f $(OUTPUT)cpupower
271 -rm -f $(OUTPUT)libcpupower.so*
272 -rm -rf $(OUTPUT)po/*.gmo
273 -rm -rf $(OUTPUT)po/*.pot
274 $(MAKE) -C bench O=$(OUTPUT) clean
277 install-lib: libcpupower
278 $(INSTALL) -d $(DESTDIR)${libdir}
279 $(CP) $(OUTPUT)libcpupower.so* $(DESTDIR)${libdir}/
280 $(INSTALL) -d $(DESTDIR)${includedir}
281 $(INSTALL_DATA) lib/cpufreq.h $(DESTDIR)${includedir}/cpufreq.h
282 $(INSTALL_DATA) lib/cpuidle.h $(DESTDIR)${includedir}/cpuidle.h
283 $(INSTALL_DATA) lib/powercap.h $(DESTDIR)${includedir}/powercap.h
285 install-tools: $(OUTPUT)cpupower
286 $(INSTALL) -d $(DESTDIR)${bindir}
287 $(INSTALL_PROGRAM) $(OUTPUT)cpupower $(DESTDIR)${bindir}
288 $(INSTALL) -d $(DESTDIR)${bash_completion_dir}
289 $(INSTALL_SCRIPT) cpupower-completion.sh '$(DESTDIR)${bash_completion_dir}/cpupower'
292 $(INSTALL_DATA) -D man/cpupower.1 $(DESTDIR)${mandir}/man1/cpupower.1
293 $(INSTALL_DATA) -D man/cpupower-frequency-set.1 $(DESTDIR)${mandir}/man1/cpupower-frequency-set.1
294 $(INSTALL_DATA) -D man/cpupower-frequency-info.1 $(DESTDIR)${mandir}/man1/cpupower-frequency-info.1
295 $(INSTALL_DATA) -D man/cpupower-idle-set.1 $(DESTDIR)${mandir}/man1/cpupower-idle-set.1
296 $(INSTALL_DATA) -D man/cpupower-idle-info.1 $(DESTDIR)${mandir}/man1/cpupower-idle-info.1
297 $(INSTALL_DATA) -D man/cpupower-set.1 $(DESTDIR)${mandir}/man1/cpupower-set.1
298 $(INSTALL_DATA) -D man/cpupower-info.1 $(DESTDIR)${mandir}/man1/cpupower-info.1
299 $(INSTALL_DATA) -D man/cpupower-monitor.1 $(DESTDIR)${mandir}/man1/cpupower-monitor.1
300 $(INSTALL_DATA) -D man/cpupower-powercap-info.1 $(DESTDIR)${mandir}/man1/cpupower-powercap-info.1
302 install-gmo: create-gmo
303 $(INSTALL) -d $(DESTDIR)${localedir}
304 for HLANG in $(LANGUAGES); do \
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; \
309 install-bench: compile-bench
310 @#DESTDIR must be set from outside to survive
311 @sbindir=$(sbindir) bindir=$(bindir) docdir=$(docdir) confdir=$(confdir) $(MAKE) -C bench O=$(OUTPUT) install
313 ifeq ($(strip $(STATIC)),true)
314 install: all install-tools install-man $(INSTALL_NLS) $(INSTALL_BENCH)
316 install: all install-lib install-tools install-man $(INSTALL_NLS) $(INSTALL_BENCH)
320 - rm -f $(DESTDIR)${libdir}/libcpupower.*
321 - rm -f $(DESTDIR)${includedir}/cpufreq.h
322 - rm -f $(DESTDIR)${includedir}/cpuidle.h
323 - rm -f $(DESTDIR)${bindir}/utils/cpupower
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
330 - rm -f $(DESTDIR)${mandir}/man1/cpupower-powercap-info.1
331 - for HLANG in $(LANGUAGES); do \
332 rm -f $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo; \
335 .PHONY: all utils libcpupower update-po create-gmo install-lib install-tools install-man install-gmo install uninstall clean