Debian Codegraph @

tools/power/cpupower/Makefile

raw symbols SCIP
1 # SPDX-License-Identifier: GPL-2.0-only
2 # Makefile for cpupower
3 #
4 # Copyright (C) 2005,2006 Dominik Brodowski <[email protected]>
5 # Copyright (C) 2025 Francesco Poli <[email protected]>
6 #
7 # Based largely on the Makefile for udev by:
8 #
9 # Copyright (C) 2003,2004 Greg Kroah-Hartman <[email protected]>
10 #
11 OUTPUT=./
12 ifeq ("$(origin O)", "command line")
13 OUTPUT := $(O)/
14 endif
15
16 ifneq ($(OUTPUT),)
17 # check that the output directory actually exists
18 OUTDIR := $(shell cd $(OUTPUT) && pwd)
19 $(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
20 endif
21
22
23 # --- CONFIGURATION BEGIN ---
24
25 # Set the following to `true' to make a unstripped, unoptimized
26 # binary. Leave this set to `false' for production use.
27 DEBUG ?= true
28
29 # make the build silent. Set this to something else to make it noisy again.
30 V ?= false
31
32 # Internationalization support (output in different languages).
33 # Requires gettext.
34 NLS ?= true
35
36 # Set the following to 'true' to build/install the
37 # cpufreq-bench benchmarking tool
38 CPUFREQ_BENCH ?= true
39
40 # Build the code, including libraries, statically.
41 export STATIC ?= false
42
43 # Prefix to the directories we're installing to
44 DESTDIR ?=
45
46 # --- CONFIGURATION END ---
47
48
49
50 # Package-related definitions. Distributions can modify the version
51 # and _should_ modify the PACKAGE_BUGREPORT definition
52
53 VERSION:= $(shell ./utils/version-gen.sh)
54 LIB_FIX= 1
55 LIB_MIN= 0
56 LIB_MAJ= 1
57 LIB_VER= $(LIB_MAJ).$(LIB_MIN).$(LIB_FIX)
58
59
60 PACKAGE = cpupower
61 PACKAGE_BUGREPORT = [email protected]
62 LANGUAGES = de fr it cs pt ka zh_CN
63
64
65 # Directory definitions. These are default and most probably
66 # do not need to be changed. Please note that DESTDIR is
67 # added in front of any of them
68
69 bindir ?= /usr/bin
70 sbindir ?= /usr/sbin
71 mandir ?= /usr/man
72 libdir ?= /usr/lib
73 libexecdir ?= /usr/libexec
74 unitdir ?= /usr/lib/systemd/system
75 includedir ?= /usr/include
76 localedir ?= /usr/share/locale
77 docdir ?= /usr/share/doc/packages/cpupower
78 confdir ?= /etc/
79 bash_completion_dir ?= /usr/share/bash-completion/completions
80
81 # Toolchain: what tools do we use, and what options do they need:
82
83 CP = cp -fpR
84 INSTALL = /usr/bin/install -c
85 INSTALL_PROGRAM = ${INSTALL}
86 INSTALL_DATA = ${INSTALL} -m 644
87 SETPERM_DATA = chmod 644
88 #bash completion scripts get sourced and so they should be rw only.
89 INSTALL_SCRIPT = ${INSTALL} -m 644
90
91 # If you are running a cross compiler, you may want to set this
92 # to something more interesting, like "arm-linux-". If you want
93 # to compile vs uClibc, that can be done here as well.
94 CROSS ?= #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
95 ifneq ($(CROSS), )
96 CC = $(CROSS)gcc
97 LD = $(CROSS)gcc
98 AR = $(CROSS)ar
99 STRIP = $(CROSS)strip
100 RANLIB = $(CROSS)ranlib
101 else
102 CC ?= $(CROSS)gcc
103 LD ?= $(CROSS)gcc
104 AR ?= $(CROSS)ar
105 STRIP ?= $(CROSS)strip
106 RANLIB ?= $(CROSS)ranlib
107 endif
108 HOSTCC = gcc
109 MKDIR = mkdir
110
111 # Now we set up the build system
112 #
113
114 GMO_FILES = ${shell for HLANG in ${LANGUAGES}; do echo $(OUTPUT)po/$$HLANG.gmo; done;}
115
116 export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS
117
118 # check if compiler option is supported
119 cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -x c /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;}
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
129 override CFLAGS += -DVERSION=\"$(VERSION)\" -DPACKAGE=\"$(PACKAGE)\" \
130 -DPACKAGE_BUGREPORT=\"$(PACKAGE_BUGREPORT)\" -D_GNU_SOURCE
131
132 UTIL_OBJS = utils/helpers/amd.o utils/helpers/msr.o \
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 \
136 utils/idle_monitor/hsw_ext_idle.o \
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/idle_monitor/rapl_monitor.o \
140 utils/cpupower.o utils/cpufreq-info.o utils/cpufreq-set.o \
141 utils/cpupower-set.o utils/cpupower-info.o utils/cpuidle-info.o \
142 utils/cpuidle-set.o utils/powercap-info.o
143
144 UTIL_SRC := $(UTIL_OBJS:.o=.c)
145
146 UTIL_OBJS := $(addprefix $(OUTPUT),$(UTIL_OBJS))
147
148 UTIL_HEADERS = utils/helpers/helpers.h utils/idle_monitor/cpupower-monitor.h \
149 utils/helpers/bitmask.h \
150 utils/idle_monitor/idle_monitors.h utils/idle_monitor/idle_monitors.def
151
152 LIB_HEADERS = lib/cpufreq.h lib/cpupower.h lib/cpuidle.h lib/acpi_cppc.h \
153 lib/powercap.h
154 LIB_SRC = lib/cpufreq.c lib/cpupower.c lib/cpuidle.c lib/acpi_cppc.c \
155 lib/powercap.c
156 LIB_OBJS = lib/cpufreq.o lib/cpupower.o lib/cpuidle.o lib/acpi_cppc.o \
157 lib/powercap.o
158 LIB_OBJS := $(addprefix $(OUTPUT),$(LIB_OBJS))
159
160 override CFLAGS += -pipe
161
162 ifeq ($(strip $(NLS)),true)
163 INSTALL_NLS += install-gmo
164 COMPILE_NLS += create-gmo
165 override CFLAGS += -DNLS
166 endif
167
168 ifeq ($(strip $(CPUFREQ_BENCH)),true)
169 INSTALL_BENCH += install-bench
170 COMPILE_BENCH += compile-bench
171 endif
172
173 ifeq ($(strip $(STATIC)),true)
174 UTIL_OBJS += $(LIB_OBJS)
175 UTIL_HEADERS += $(LIB_HEADERS)
176 UTIL_SRC += $(LIB_SRC)
177 endif
178
179 override CFLAGS += $(WARNINGS)
180
181 ifeq ($(strip $(V)),false)
182 QUIET=@
183 ECHO=@echo
184 else
185 QUIET=
186 ECHO=@\#
187 endif
188 export QUIET ECHO
189
190 # if DEBUG is enabled, then we do not strip or optimize
191 ifeq ($(strip $(DEBUG)),true)
192 override CFLAGS += -O1 -g -DDEBUG
193 STRIPCMD = /bin/true -Since_we_are_debugging
194 else
195 override CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer
196 STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
197 endif
198
199
200 # the actual make rules
201
202 all: libcpupower $(OUTPUT)cpupower $(COMPILE_NLS) $(COMPILE_BENCH)
203
204 $(OUTPUT)lib/%.o: $(LIB_SRC) $(LIB_HEADERS)
205 $(ECHO) " CC " $@
206 $(QUIET) $(CC) $(CFLAGS) -fPIC -o $@ -c lib/$*.c
207
208 ifeq ($(strip $(STATIC)),true)
209 LIBCPUPOWER := libcpupower.a
210 else
211 LIBCPUPOWER := libcpupower.so.$(LIB_VER)
212 endif
213
214 $(OUTPUT)$(LIBCPUPOWER): $(LIB_OBJS)
215 ifeq ($(strip $(STATIC)),true)
216 $(ECHO) " AR " $@
217 $(QUIET) $(AR) rcs $@ $(LIB_OBJS)
218 else
219 $(ECHO) " LD " $@
220 $(QUIET) $(CC) -shared $(CFLAGS) $(LDFLAGS) -o $@ \
221 -Wl,-soname,libcpupower.so.$(LIB_MAJ) $(LIB_OBJS)
222 @ln -sf $(@F) $(OUTPUT)libcpupower.so
223 @ln -sf $(@F) $(OUTPUT)libcpupower.so.$(LIB_MAJ)
224 endif
225
226 libcpupower: $(OUTPUT)$(LIBCPUPOWER)
227
228 # Let all .o files depend on its .c file and all headers
229 # Might be worth to put this into utils/Makefile at some point of time
230 $(UTIL_OBJS): $(UTIL_HEADERS)
231
232 $(OUTPUT)%.o: %.c
233 $(ECHO) " CC " $@
234 $(QUIET) $(CC) $(CFLAGS) -I./lib -I ./utils -o $@ -c $*.c
235
236 $(OUTPUT)cpupower: $(UTIL_OBJS) $(OUTPUT)$(LIBCPUPOWER)
237 $(ECHO) " CC " $@
238 ifeq ($(strip $(STATIC)),true)
239 $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) $(UTIL_OBJS) -lrt -lpci -L$(OUTPUT) -o $@
240 else
241 $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) $(UTIL_OBJS) -lcpupower -lrt -lpci -L$(OUTPUT) -o $@
242 endif
243 $(QUIET) $(STRIPCMD) $@
244
245 ifeq (, $(shell which xgettext))
246 $(warning "Install xgettext to extract translatable strings.")
247 else
248 $(OUTPUT)po/$(PACKAGE).pot: $(UTIL_SRC)
249 $(ECHO) " GETTEXT " $@
250 $(QUIET) xgettext --default-domain=$(PACKAGE) --add-comments \
251 --keyword=_ --keyword=N_ $(UTIL_SRC) -p $(@D) -o $(@F)
252 endif
253
254 ifeq (, $(shell which msgfmt))
255 $(warning "Install msgfmt to generate binary message catalogs.")
256 else
257 $(OUTPUT)po/%.gmo: po/%.po
258 $(ECHO) " MSGFMT " $@
259 $(QUIET) msgfmt -o $@ po/$*.po
260 endif
261
262 create-gmo: ${GMO_FILES}
263
264 ifeq (, $(shell which msgmerge))
265 $(warning "Install msgmerge to merge translations.")
266 else
267 update-po: $(OUTPUT)po/$(PACKAGE).pot
268 $(ECHO) " MSGMRG " $@
269 $(QUIET) @for HLANG in $(LANGUAGES); do \
270 echo -n "Updating $$HLANG "; \
271 if msgmerge po/$$HLANG.po $< -o \
272 $(OUTPUT)po/$$HLANG.new.po; then \
273 mv -f $(OUTPUT)po/$$HLANG.new.po $(OUTPUT)po/$$HLANG.po; \
274 else \
275 echo "msgmerge for $$HLANG failed!"; \
276 rm -f $(OUTPUT)po/$$HLANG.new.po; \
277 fi; \
278 done;
279 endif
280
281 compile-bench: $(OUTPUT)$(LIBCPUPOWER)
282 @V=$(V) confdir=$(confdir) $(MAKE) -C bench O=$(OUTPUT)
283
284 # we compile into subdirectories. if the target directory is not the
285 # source directory, they might not exists. So we depend the various
286 # files onto their directories.
287 DIRECTORY_DEPS = $(LIB_OBJS) $(UTIL_OBJS) $(GMO_FILES)
288 $(DIRECTORY_DEPS): | $(sort $(dir $(DIRECTORY_DEPS)))
289
290 # In the second step, we make a rule to actually create these directories
291 $(sort $(dir $(DIRECTORY_DEPS))):
292 $(ECHO) " MKDIR " $@
293 $(QUIET) $(MKDIR) -p $@ 2>/dev/null
294
295 clean:
296 -find $(OUTPUT) \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
297 | xargs rm -f
298 -rm -f $(OUTPUT)cpupower
299 -rm -f $(OUTPUT)libcpupower.a
300 -rm -f $(OUTPUT)libcpupower.so*
301 -rm -rf $(OUTPUT)po/*.gmo
302 -rm -rf $(OUTPUT)po/*.pot
303 $(MAKE) -C bench O=$(OUTPUT) clean
304
305
306 install-lib: libcpupower
307 $(INSTALL) -d $(DESTDIR)${libdir}
308 ifeq ($(strip $(STATIC)),true)
309 $(CP) $(OUTPUT)libcpupower.a $(DESTDIR)${libdir}/
310 else
311 $(CP) $(OUTPUT)libcpupower.so* $(DESTDIR)${libdir}/
312 endif
313 $(INSTALL) -d $(DESTDIR)${includedir}
314 $(INSTALL_DATA) lib/cpufreq.h $(DESTDIR)${includedir}/cpufreq.h
315 $(INSTALL_DATA) lib/cpuidle.h $(DESTDIR)${includedir}/cpuidle.h
316 $(INSTALL_DATA) lib/powercap.h $(DESTDIR)${includedir}/powercap.h
317
318 # SYSTEMD=false disables installation of the systemd unit file
319 SYSTEMD ?= true
320
321 install-systemd:
322 $(INSTALL) -d $(DESTDIR)${unitdir}
323 sed 's|___CDIR___|${confdir}|; s|___LDIR___|${libexecdir}|' cpupower.service.in > '$(DESTDIR)${unitdir}/cpupower.service'
324 $(SETPERM_DATA) '$(DESTDIR)${unitdir}/cpupower.service'
325
326 INSTALL_SYSTEMD := $(if $(filter true,$(strip $(SYSTEMD))),install-systemd)
327
328 install-tools: $(OUTPUT)cpupower $(INSTALL_SYSTEMD)
329 $(INSTALL) -d $(DESTDIR)${bindir}
330 $(INSTALL_PROGRAM) $(OUTPUT)cpupower $(DESTDIR)${bindir}
331 $(INSTALL) -d $(DESTDIR)${bash_completion_dir}
332 $(INSTALL_SCRIPT) cpupower-completion.sh '$(DESTDIR)${bash_completion_dir}/cpupower'
333 $(INSTALL) -d $(DESTDIR)${confdir}
334 $(INSTALL_DATA) cpupower-service.conf '$(DESTDIR)${confdir}'
335 $(INSTALL) -d $(DESTDIR)${libexecdir}
336 $(INSTALL_PROGRAM) cpupower.sh '$(DESTDIR)${libexecdir}/cpupower'
337
338 install-man:
339 $(INSTALL_DATA) -D man/cpupower.1 $(DESTDIR)${mandir}/man1/cpupower.1
340 $(INSTALL_DATA) -D man/cpupower-frequency-set.1 $(DESTDIR)${mandir}/man1/cpupower-frequency-set.1
341 $(INSTALL_DATA) -D man/cpupower-frequency-info.1 $(DESTDIR)${mandir}/man1/cpupower-frequency-info.1
342 $(INSTALL_DATA) -D man/cpupower-idle-set.1 $(DESTDIR)${mandir}/man1/cpupower-idle-set.1
343 $(INSTALL_DATA) -D man/cpupower-idle-info.1 $(DESTDIR)${mandir}/man1/cpupower-idle-info.1
344 $(INSTALL_DATA) -D man/cpupower-set.1 $(DESTDIR)${mandir}/man1/cpupower-set.1
345 $(INSTALL_DATA) -D man/cpupower-info.1 $(DESTDIR)${mandir}/man1/cpupower-info.1
346 $(INSTALL_DATA) -D man/cpupower-monitor.1 $(DESTDIR)${mandir}/man1/cpupower-monitor.1
347 $(INSTALL_DATA) -D man/cpupower-powercap-info.1 $(DESTDIR)${mandir}/man1/cpupower-powercap-info.1
348
349 install-gmo: create-gmo
350 $(INSTALL) -d $(DESTDIR)${localedir}
351 for HLANG in $(LANGUAGES); do \
352 echo '$(INSTALL_DATA) -D $(OUTPUT)po/$$HLANG.gmo $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo'; \
353 $(INSTALL_DATA) -D $(OUTPUT)po/$$HLANG.gmo $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo; \
354 done;
355
356 install-bench: compile-bench
357 @#DESTDIR must be set from outside to survive
358 @sbindir=$(sbindir) bindir=$(bindir) docdir=$(docdir) confdir=$(confdir) $(MAKE) -C bench O=$(OUTPUT) install
359
360 install: all install-lib install-tools install-man $(INSTALL_NLS) $(INSTALL_BENCH)
361
362 uninstall:
363 - rm -f $(DESTDIR)${libdir}/libcpupower.*
364 - rm -f $(DESTDIR)${includedir}/cpufreq.h
365 - rm -f $(DESTDIR)${includedir}/cpuidle.h
366 - rm -f $(DESTDIR)${bindir}/utils/cpupower
367 - rm -f $(DESTDIR)${confdir}cpupower-service.conf
368 - rm -f $(DESTDIR)${libexecdir}/cpupower
369 - rm -f $(DESTDIR)${unitdir}/cpupower.service
370 - rm -f $(DESTDIR)${mandir}/man1/cpupower.1
371 - rm -f $(DESTDIR)${mandir}/man1/cpupower-frequency-set.1
372 - rm -f $(DESTDIR)${mandir}/man1/cpupower-frequency-info.1
373 - rm -f $(DESTDIR)${mandir}/man1/cpupower-set.1
374 - rm -f $(DESTDIR)${mandir}/man1/cpupower-info.1
375 - rm -f $(DESTDIR)${mandir}/man1/cpupower-monitor.1
376 - rm -f $(DESTDIR)${mandir}/man1/cpupower-powercap-info.1
377 - for HLANG in $(LANGUAGES); do \
378 rm -f $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo; \
379 done;
380
381 help:
382 @echo 'Building targets:'
383 @echo ' all - Default target. Could be omitted. Put build artifacts'
384 @echo ' to "O" cmdline option dir (default: current dir)'
385 @echo ' install - Install previously built project files from the output'
386 @echo ' dir defined by "O" cmdline option (default: current dir)'
387 @echo ' to the install dir defined by "DESTDIR" cmdline or'
388 @echo ' Makefile config block option (default: "")'
389 @echo ' install-lib - Install previously built library binary from the output'
390 @echo ' dir defined by "O" cmdline option (default: current dir)'
391 @echo ' and library headers from "lib/" for userspace to the install'
392 @echo ' dir defined by "DESTDIR" cmdline (default: "")'
393 @echo ' install-tools - Install previously built "cpupower" util from the output'
394 @echo ' dir defined by "O" cmdline option (default: current dir) and'
395 @echo ' "cpupower-completion.sh" script from the src dir to the'
396 @echo ' install dir defined by "DESTDIR" cmdline or Makefile'
397 @echo ' config block option (default: "")'
398 @echo ' install-man - Install man pages from the "man" src subdir to the'
399 @echo ' install dir defined by "DESTDIR" cmdline or Makefile'
400 @echo ' config block option (default: "")'
401 @echo ' install-gmo - Install previously built language files from the output'
402 @echo ' dir defined by "O" cmdline option (default: current dir)'
403 @echo ' to the install dir defined by "DESTDIR" cmdline or Makefile'
404 @echo ' config block option (default: "")'
405 @echo ' install-bench - Install previously built "cpufreq-bench" util files from the'
406 @echo ' output dir defined by "O" cmdline option (default: current dir)'
407 @echo ' to the install dir defined by "DESTDIR" cmdline or Makefile'
408 @echo ' config block option (default: "")'
409 @echo ''
410 @echo 'Cleaning targets:'
411 @echo ' clean - Clean build artifacts from the dir defined by "O" cmdline'
412 @echo ' option (default: current dir)'
413 @echo ' uninstall - Remove previously installed files from the dir defined by "DESTDIR"'
414 @echo ' cmdline or Makefile config block option (default: "")'
415
416 .PHONY: all utils libcpupower update-po create-gmo install-lib install-systemd install-tools install-man install-gmo install uninstall clean help