Something went wrong. Try again.
Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417# SPDX-License-Identifier: GPL-2.0-only# Makefile for cpupower## Copyright (C) 2005,2006 Dominik Brodowski <linux@dominikbrodowski.net># Copyright (C) 2025 Francesco Poli <invernomuto@paranoici.org>## Based largely on the Makefile for udev by:## Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>#OUTPUT=./ifeq ("$(origin O)", "command line") OUTPUT := $(O)/endif
ifneq ($(OUTPUT),)# check that the output directory actually existsOUTDIR := $(shell cd $(OUTPUT) && pwd)$(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))endif
# --- CONFIGURATION BEGIN ---
# Set the following to `true' to make a unstripped, unoptimized# binary. Leave this set to `false' for production use.DEBUG ?= true
# make the build silent. Set this to something else to make it noisy again.V ?= false
# Internationalization support (output in different languages).# Requires gettext.NLS ?= true
# Set the following to 'true' to build/install the# cpufreq-bench benchmarking toolCPUFREQ_BENCH ?= true
# Build the code, including libraries, statically.export STATIC ?= false
# Prefix to the directories we're installing toDESTDIR ?=
# --- CONFIGURATION END ---
# Package-related definitions. Distributions can modify the version# and _should_ modify the PACKAGE_BUGREPORT definition
VERSION:= $(shell ./utils/version-gen.sh)LIB_FIX= 1LIB_MIN= 0LIB_MAJ= 1LIB_VER= $(LIB_MAJ).$(LIB_MIN).$(LIB_FIX)
PACKAGE = cpupowerPACKAGE_BUGREPORT = linux-pm@vger.kernel.orgLANGUAGES = de fr it cs pt ka zh_CN
# Directory definitions. These are default and most probably# do not need to be changed. Please note that DESTDIR is# added in front of any of them
bindir ?= /usr/binsbindir ?= /usr/sbinmandir ?= /usr/manlibdir ?= /usr/liblibexecdir ?= /usr/libexecunitdir ?= /usr/lib/systemd/systemincludedir ?= /usr/includelocaledir ?= /usr/share/localedocdir ?= /usr/share/doc/packages/cpupowerconfdir ?= /etc/bash_completion_dir ?= /usr/share/bash-completion/completions
# Toolchain: what tools do we use, and what options do they need:
CP = cp -fpRINSTALL = /usr/bin/install -cINSTALL_PROGRAM = ${INSTALL}INSTALL_DATA = ${INSTALL} -m 644SETPERM_DATA = chmod 644#bash completion scripts get sourced and so they should be rw only.INSTALL_SCRIPT = ${INSTALL} -m 644
# If you are running a cross compiler, you may want to set this# to something more interesting, like "arm-linux-". If you want# to compile vs uClibc, that can be done here as well.CROSS ?= #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-ifneq ($(CROSS), )CC = $(CROSS)gccLD = $(CROSS)gccAR = $(CROSS)arSTRIP = $(CROSS)stripRANLIB = $(CROSS)ranlibelseCC ?= $(CROSS)gccLD ?= $(CROSS)gccAR ?= $(CROSS)arSTRIP ?= $(CROSS)stripRANLIB ?= $(CROSS)ranlibendifHOSTCC = gccMKDIR = mkdir
# Now we set up the build system#
GMO_FILES = ${shell for HLANG in ${LANGUAGES}; do echo $(OUTPUT)po/$$HLANG.gmo; done;}
export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS
# check if compiler option is supportedcc-supports = ${shell if $(CC) ${1} -S -o /dev/null -x c /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;}
# use '-Os' optimization if available, else use -O2OPTIMIZATION := $(call cc-supports,-Os,-O2)
WARNINGS := -Wall -Wchar-subscripts -Wpointer-arith -Wsign-compareWARNINGS += $(call cc-supports,-Wno-pointer-sign)WARNINGS += $(call cc-supports,-Wdeclaration-after-statement)WARNINGS += -Wshadow
override CFLAGS += -DVERSION=\"$(VERSION)\" -DPACKAGE=\"$(PACKAGE)\" \ -DPACKAGE_BUGREPORT=\"$(PACKAGE_BUGREPORT)\" -D_GNU_SOURCE
UTIL_OBJS = utils/helpers/amd.o utils/helpers/msr.o \ utils/helpers/sysfs.o utils/helpers/misc.o utils/helpers/cpuid.o \ utils/helpers/pci.o utils/helpers/bitmask.o \ utils/idle_monitor/nhm_idle.o utils/idle_monitor/snb_idle.o \ utils/idle_monitor/hsw_ext_idle.o \ utils/idle_monitor/amd_fam14h_idle.o utils/idle_monitor/cpuidle_sysfs.o \ utils/idle_monitor/mperf_monitor.o utils/idle_monitor/cpupower-monitor.o \ utils/idle_monitor/rapl_monitor.o \ utils/cpupower.o utils/cpufreq-info.o utils/cpufreq-set.o \ utils/cpupower-set.o utils/cpupower-info.o utils/cpuidle-info.o \ utils/cpuidle-set.o utils/powercap-info.o
UTIL_SRC := $(UTIL_OBJS:.o=.c)
UTIL_OBJS := $(addprefix $(OUTPUT),$(UTIL_OBJS))
UTIL_HEADERS = utils/helpers/helpers.h utils/idle_monitor/cpupower-monitor.h \ utils/helpers/bitmask.h \ utils/idle_monitor/idle_monitors.h utils/idle_monitor/idle_monitors.def
LIB_HEADERS = lib/cpufreq.h lib/cpupower.h lib/cpuidle.h lib/acpi_cppc.h \ lib/powercap.hLIB_SRC = lib/cpufreq.c lib/cpupower.c lib/cpuidle.c lib/acpi_cppc.c \ lib/powercap.cLIB_OBJS = lib/cpufreq.o lib/cpupower.o lib/cpuidle.o lib/acpi_cppc.o \ lib/powercap.oLIB_OBJS := $(addprefix $(OUTPUT),$(LIB_OBJS))
override CFLAGS += -pipe
ifeq ($(strip $(NLS)),true) INSTALL_NLS += install-gmo COMPILE_NLS += create-gmo override CFLAGS += -DNLSendif
ifeq ($(strip $(CPUFREQ_BENCH)),true) INSTALL_BENCH += install-bench COMPILE_BENCH += compile-benchendif
ifeq ($(strip $(STATIC)),true) UTIL_OBJS += $(LIB_OBJS) UTIL_HEADERS += $(LIB_HEADERS) UTIL_SRC += $(LIB_SRC)endif
override CFLAGS += $(WARNINGS)
ifeq ($(strip $(V)),false) QUIET=@ ECHO=@echoelse QUIET= ECHO=@\#endifexport QUIET ECHO
# if DEBUG is enabled, then we do not strip or optimizeifeq ($(strip $(DEBUG)),true) override CFLAGS += -O1 -g -DDEBUG STRIPCMD = /bin/true -Since_we_are_debuggingelse override CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.commentendif
# the actual make rules
all: libcpupower $(OUTPUT)cpupower $(COMPILE_NLS) $(COMPILE_BENCH)
$(OUTPUT)lib/%.o: $(LIB_SRC) $(LIB_HEADERS) $(ECHO) " CC " $@ $(QUIET) $(CC) $(CFLAGS) -fPIC -o $@ -c lib/$*.c
ifeq ($(strip $(STATIC)),true)LIBCPUPOWER := libcpupower.aelseLIBCPUPOWER := libcpupower.so.$(LIB_VER)endif
$(OUTPUT)$(LIBCPUPOWER): $(LIB_OBJS)ifeq ($(strip $(STATIC)),true) $(ECHO) " AR " $@ $(QUIET) $(AR) rcs $@ $(LIB_OBJS)else $(ECHO) " LD " $@ $(QUIET) $(CC) -shared $(CFLAGS) $(LDFLAGS) -o $@ \ -Wl,-soname,libcpupower.so.$(LIB_MAJ) $(LIB_OBJS) @ln -sf $(@F) $(OUTPUT)libcpupower.so @ln -sf $(@F) $(OUTPUT)libcpupower.so.$(LIB_MAJ)endif
libcpupower: $(OUTPUT)$(LIBCPUPOWER)
# Let all .o files depend on its .c file and all headers# Might be worth to put this into utils/Makefile at some point of time$(UTIL_OBJS): $(UTIL_HEADERS)
$(OUTPUT)%.o: %.c $(ECHO) " CC " $@ $(QUIET) $(CC) $(CFLAGS) -I./lib -I ./utils -o $@ -c $*.c
$(OUTPUT)cpupower: $(UTIL_OBJS) $(OUTPUT)$(LIBCPUPOWER) $(ECHO) " CC " $@ifeq ($(strip $(STATIC)),true) $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) $(UTIL_OBJS) -lrt -lpci -L$(OUTPUT) -o $@else $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) $(UTIL_OBJS) -lcpupower -lrt -lpci -L$(OUTPUT) -o $@endif $(QUIET) $(STRIPCMD) $@
ifeq (, $(shell which xgettext))$(warning "Install xgettext to extract translatable strings.")else$(OUTPUT)po/$(PACKAGE).pot: $(UTIL_SRC) $(ECHO) " GETTEXT " $@ $(QUIET) xgettext --default-domain=$(PACKAGE) --add-comments \ --keyword=_ --keyword=N_ $(UTIL_SRC) -p $(@D) -o $(@F)endif
ifeq (, $(shell which msgfmt))$(warning "Install msgfmt to generate binary message catalogs.")else$(OUTPUT)po/%.gmo: po/%.po $(ECHO) " MSGFMT " $@ $(QUIET) msgfmt -o $@ po/$*.poendif
create-gmo: ${GMO_FILES}
ifeq (, $(shell which msgmerge))$(warning "Install msgmerge to merge translations.")elseupdate-po: $(OUTPUT)po/$(PACKAGE).pot $(ECHO) " MSGMRG " $@ $(QUIET) @for HLANG in $(LANGUAGES); do \ echo -n "Updating $$HLANG "; \ if msgmerge po/$$HLANG.po $< -o \ $(OUTPUT)po/$$HLANG.new.po; then \ mv -f $(OUTPUT)po/$$HLANG.new.po $(OUTPUT)po/$$HLANG.po; \ else \ echo "msgmerge for $$HLANG failed!"; \ rm -f $(OUTPUT)po/$$HLANG.new.po; \ fi; \ done;endif
compile-bench: $(OUTPUT)$(LIBCPUPOWER) @V=$(V) confdir=$(confdir) $(MAKE) -C bench O=$(OUTPUT)
# we compile into subdirectories. if the target directory is not the# source directory, they might not exists. So we depend the various# files onto their directories.DIRECTORY_DEPS = $(LIB_OBJS) $(UTIL_OBJS) $(GMO_FILES)$(DIRECTORY_DEPS): | $(sort $(dir $(DIRECTORY_DEPS)))
# In the second step, we make a rule to actually create these directories$(sort $(dir $(DIRECTORY_DEPS))): $(ECHO) " MKDIR " $@ $(QUIET) $(MKDIR) -p $@ 2>/dev/null
clean: -find $(OUTPUT) \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \ | xargs rm -f -rm -f $(OUTPUT)cpupower -rm -f $(OUTPUT)libcpupower.a -rm -f $(OUTPUT)libcpupower.so* -rm -rf $(OUTPUT)po/*.gmo -rm -rf $(OUTPUT)po/*.pot $(MAKE) -C bench O=$(OUTPUT) clean
install-lib: libcpupower $(INSTALL) -d $(DESTDIR)${libdir}ifeq ($(strip $(STATIC)),true) $(CP) $(OUTPUT)libcpupower.a $(DESTDIR)${libdir}/else $(CP) $(OUTPUT)libcpupower.so* $(DESTDIR)${libdir}/endif $(INSTALL) -d $(DESTDIR)${includedir} $(INSTALL_DATA) lib/cpufreq.h $(DESTDIR)${includedir}/cpufreq.h $(INSTALL_DATA) lib/cpuidle.h $(DESTDIR)${includedir}/cpuidle.h $(INSTALL_DATA) lib/powercap.h $(DESTDIR)${includedir}/powercap.h
# SYSTEMD=false disables installation of the systemd unit fileSYSTEMD ?= true
install-systemd: $(INSTALL) -d $(DESTDIR)${unitdir} sed 's|___CDIR___|${confdir}|; s|___LDIR___|${libexecdir}|' cpupower.service.in > '$(DESTDIR)${unitdir}/cpupower.service' $(SETPERM_DATA) '$(DESTDIR)${unitdir}/cpupower.service'
INSTALL_SYSTEMD := $(if $(filter true,$(strip $(SYSTEMD))),install-systemd)
install-tools: $(OUTPUT)cpupower $(INSTALL_SYSTEMD) $(INSTALL) -d $(DESTDIR)${bindir} $(INSTALL_PROGRAM) $(OUTPUT)cpupower $(DESTDIR)${bindir} $(INSTALL) -d $(DESTDIR)${bash_completion_dir} $(INSTALL_SCRIPT) cpupower-completion.sh '$(DESTDIR)${bash_completion_dir}/cpupower' $(INSTALL) -d $(DESTDIR)${confdir} $(INSTALL_DATA) cpupower-service.conf '$(DESTDIR)${confdir}' $(INSTALL) -d $(DESTDIR)${libexecdir} $(INSTALL_PROGRAM) cpupower.sh '$(DESTDIR)${libexecdir}/cpupower'
install-man: $(INSTALL_DATA) -D man/cpupower.1 $(DESTDIR)${mandir}/man1/cpupower.1 $(INSTALL_DATA) -D man/cpupower-frequency-set.1 $(DESTDIR)${mandir}/man1/cpupower-frequency-set.1 $(INSTALL_DATA) -D man/cpupower-frequency-info.1 $(DESTDIR)${mandir}/man1/cpupower-frequency-info.1 $(INSTALL_DATA) -D man/cpupower-idle-set.1 $(DESTDIR)${mandir}/man1/cpupower-idle-set.1 $(INSTALL_DATA) -D man/cpupower-idle-info.1 $(DESTDIR)${mandir}/man1/cpupower-idle-info.1 $(INSTALL_DATA) -D man/cpupower-set.1 $(DESTDIR)${mandir}/man1/cpupower-set.1 $(INSTALL_DATA) -D man/cpupower-info.1 $(DESTDIR)${mandir}/man1/cpupower-info.1 $(INSTALL_DATA) -D man/cpupower-monitor.1 $(DESTDIR)${mandir}/man1/cpupower-monitor.1 $(INSTALL_DATA) -D man/cpupower-powercap-info.1 $(DESTDIR)${mandir}/man1/cpupower-powercap-info.1
install-gmo: create-gmo $(INSTALL) -d $(DESTDIR)${localedir} for HLANG in $(LANGUAGES); do \ echo '$(INSTALL_DATA) -D $(OUTPUT)po/$$HLANG.gmo $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo'; \ $(INSTALL_DATA) -D $(OUTPUT)po/$$HLANG.gmo $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo; \ done;
install-bench: compile-bench @#DESTDIR must be set from outside to survive @sbindir=$(sbindir) bindir=$(bindir) docdir=$(docdir) confdir=$(confdir) $(MAKE) -C bench O=$(OUTPUT) install
install: all install-lib install-tools install-man $(INSTALL_NLS) $(INSTALL_BENCH)
uninstall: - rm -f $(DESTDIR)${libdir}/libcpupower.* - rm -f $(DESTDIR)${includedir}/cpufreq.h - rm -f $(DESTDIR)${includedir}/cpuidle.h - rm -f $(DESTDIR)${bindir}/utils/cpupower - rm -f $(DESTDIR)${confdir}cpupower-service.conf - rm -f $(DESTDIR)${libexecdir}/cpupower - rm -f $(DESTDIR)${unitdir}/cpupower.service - rm -f $(DESTDIR)${mandir}/man1/cpupower.1 - rm -f $(DESTDIR)${mandir}/man1/cpupower-frequency-set.1 - rm -f $(DESTDIR)${mandir}/man1/cpupower-frequency-info.1 - rm -f $(DESTDIR)${mandir}/man1/cpupower-set.1 - rm -f $(DESTDIR)${mandir}/man1/cpupower-info.1 - rm -f $(DESTDIR)${mandir}/man1/cpupower-monitor.1 - rm -f $(DESTDIR)${mandir}/man1/cpupower-powercap-info.1 - for HLANG in $(LANGUAGES); do \ rm -f $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo; \ done;
help: @echo 'Building targets:' @echo ' all - Default target. Could be omitted. Put build artifacts' @echo ' to "O" cmdline option dir (default: current dir)' @echo ' install - Install previously built project files from the output' @echo ' dir defined by "O" cmdline option (default: current dir)' @echo ' to the install dir defined by "DESTDIR" cmdline or' @echo ' Makefile config block option (default: "")' @echo ' install-lib - Install previously built library binary from the output' @echo ' dir defined by "O" cmdline option (default: current dir)' @echo ' and library headers from "lib/" for userspace to the install' @echo ' dir defined by "DESTDIR" cmdline (default: "")' @echo ' install-tools - Install previously built "cpupower" util from the output' @echo ' dir defined by "O" cmdline option (default: current dir) and' @echo ' "cpupower-completion.sh" script from the src dir to the' @echo ' install dir defined by "DESTDIR" cmdline or Makefile' @echo ' config block option (default: "")' @echo ' install-man - Install man pages from the "man" src subdir to the' @echo ' install dir defined by "DESTDIR" cmdline or Makefile' @echo ' config block option (default: "")' @echo ' install-gmo - Install previously built language files from the output' @echo ' dir defined by "O" cmdline option (default: current dir)' @echo ' to the install dir defined by "DESTDIR" cmdline or Makefile' @echo ' config block option (default: "")' @echo ' install-bench - Install previously built "cpufreq-bench" util files from the' @echo ' output dir defined by "O" cmdline option (default: current dir)' @echo ' to the install dir defined by "DESTDIR" cmdline or Makefile' @echo ' config block option (default: "")' @echo '' @echo 'Cleaning targets:' @echo ' clean - Clean build artifacts from the dir defined by "O" cmdline' @echo ' option (default: current dir)' @echo ' uninstall - Remove previously installed files from the dir defined by "DESTDIR"' @echo ' cmdline or Makefile config block option (default: "")'
.PHONY: all utils libcpupower update-po create-gmo install-lib install-systemd install-tools install-man install-gmo install uninstall clean help