363 lines · plain
1# SPDX-License-Identifier: GPL-2.0-only2# Makefile for cpupower3#4# Copyright (C) 2005,2006 Dominik Brodowski <linux@dominikbrodowski.net>5#6# Based largely on the Makefile for udev by:7#8# Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>9#10OUTPUT=./11ifeq ("$(origin O)", "command line")12 OUTPUT := $(O)/13endif14 15ifneq ($(OUTPUT),)16# check that the output directory actually exists17OUTDIR := $(shell cd $(OUTPUT) && pwd)18$(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))19endif20 21 22# --- CONFIGURATION BEGIN ---23 24# Set the following to `true' to make a unstripped, unoptimized25# binary. Leave this set to `false' for production use.26DEBUG ?= true27 28# make the build silent. Set this to something else to make it noisy again.29V ?= false30 31# Internationalization support (output in different languages).32# Requires gettext.33NLS ?= true34 35# Set the following to 'true' to build/install the36# cpufreq-bench benchmarking tool37CPUFREQ_BENCH ?= true38 39# Do not build libraries, but build the code in statically40# Libraries are still built, otherwise the Makefile code would41# be rather ugly.42export STATIC ?= false43 44# Prefix to the directories we're installing to45DESTDIR ?=46 47# --- CONFIGURATION END ---48 49 50 51# Package-related definitions. Distributions can modify the version52# and _should_ modify the PACKAGE_BUGREPORT definition53 54VERSION:= $(shell ./utils/version-gen.sh)55LIB_MAJ= 0.0.156LIB_MIN= 157 58PACKAGE = cpupower59PACKAGE_BUGREPORT = linux-pm@vger.kernel.org60LANGUAGES = de fr it cs pt ka61 62 63# Directory definitions. These are default and most probably64# do not need to be changed. Please note that DESTDIR is65# added in front of any of them66 67bindir ?= /usr/bin68sbindir ?= /usr/sbin69mandir ?= /usr/man70libdir ?= /usr/lib71includedir ?= /usr/include72localedir ?= /usr/share/locale73docdir ?= /usr/share/doc/packages/cpupower74confdir ?= /etc/75bash_completion_dir ?= /usr/share/bash-completion/completions76 77# Toolchain: what tools do we use, and what options do they need:78 79CP = cp -fpR80INSTALL = /usr/bin/install -c81INSTALL_PROGRAM = ${INSTALL}82INSTALL_DATA = ${INSTALL} -m 64483#bash completion scripts get sourced and so they should be rw only.84INSTALL_SCRIPT = ${INSTALL} -m 64485 86# If you are running a cross compiler, you may want to set this87# to something more interesting, like "arm-linux-". If you want88# to compile vs uClibc, that can be done here as well.89CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-90CC = $(CROSS)gcc91LD = $(CROSS)gcc92AR = $(CROSS)ar93STRIP = $(CROSS)strip94RANLIB = $(CROSS)ranlib95HOSTCC = gcc96MKDIR = mkdir97 98# Now we set up the build system99#100 101GMO_FILES = ${shell for HLANG in ${LANGUAGES}; do echo $(OUTPUT)po/$$HLANG.gmo; done;}102 103export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS104 105# check if compiler option is supported106cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -x c /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;}107 108# use '-Os' optimization if available, else use -O2109OPTIMIZATION := $(call cc-supports,-Os,-O2)110 111WARNINGS := -Wall -Wchar-subscripts -Wpointer-arith -Wsign-compare112WARNINGS += $(call cc-supports,-Wno-pointer-sign)113WARNINGS += $(call cc-supports,-Wdeclaration-after-statement)114WARNINGS += -Wshadow115 116override CFLAGS += -DVERSION=\"$(VERSION)\" -DPACKAGE=\"$(PACKAGE)\" \117 -DPACKAGE_BUGREPORT=\"$(PACKAGE_BUGREPORT)\" -D_GNU_SOURCE118 119UTIL_OBJS = utils/helpers/amd.o utils/helpers/msr.o \120 utils/helpers/sysfs.o utils/helpers/misc.o utils/helpers/cpuid.o \121 utils/helpers/pci.o utils/helpers/bitmask.o \122 utils/idle_monitor/nhm_idle.o utils/idle_monitor/snb_idle.o \123 utils/idle_monitor/hsw_ext_idle.o \124 utils/idle_monitor/amd_fam14h_idle.o utils/idle_monitor/cpuidle_sysfs.o \125 utils/idle_monitor/mperf_monitor.o utils/idle_monitor/cpupower-monitor.o \126 utils/idle_monitor/rapl_monitor.o \127 utils/cpupower.o utils/cpufreq-info.o utils/cpufreq-set.o \128 utils/cpupower-set.o utils/cpupower-info.o utils/cpuidle-info.o \129 utils/cpuidle-set.o utils/powercap-info.o130 131UTIL_SRC := $(UTIL_OBJS:.o=.c)132 133UTIL_OBJS := $(addprefix $(OUTPUT),$(UTIL_OBJS))134 135UTIL_HEADERS = utils/helpers/helpers.h utils/idle_monitor/cpupower-monitor.h \136 utils/helpers/bitmask.h \137 utils/idle_monitor/idle_monitors.h utils/idle_monitor/idle_monitors.def138 139LIB_HEADERS = lib/cpufreq.h lib/cpupower.h lib/cpuidle.h lib/acpi_cppc.h \140 lib/powercap.h141LIB_SRC = lib/cpufreq.c lib/cpupower.c lib/cpuidle.c lib/acpi_cppc.c \142 lib/powercap.c143LIB_OBJS = lib/cpufreq.o lib/cpupower.o lib/cpuidle.o lib/acpi_cppc.o \144 lib/powercap.o145LIB_OBJS := $(addprefix $(OUTPUT),$(LIB_OBJS))146 147override CFLAGS += -pipe148 149ifeq ($(strip $(NLS)),true)150 INSTALL_NLS += install-gmo151 COMPILE_NLS += create-gmo152 override CFLAGS += -DNLS153endif154 155ifeq ($(strip $(CPUFREQ_BENCH)),true)156 INSTALL_BENCH += install-bench157 COMPILE_BENCH += compile-bench158endif159 160ifeq ($(strip $(STATIC)),true)161 UTIL_OBJS += $(LIB_OBJS)162 UTIL_HEADERS += $(LIB_HEADERS)163 UTIL_SRC += $(LIB_SRC)164endif165 166override CFLAGS += $(WARNINGS)167 168ifeq ($(strip $(V)),false)169 QUIET=@170 ECHO=@echo171else172 QUIET=173 ECHO=@\#174endif175export QUIET ECHO176 177# if DEBUG is enabled, then we do not strip or optimize178ifeq ($(strip $(DEBUG)),true)179 override CFLAGS += -O1 -g -DDEBUG180 STRIPCMD = /bin/true -Since_we_are_debugging181else182 override CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer183 STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment184endif185 186 187# the actual make rules188 189all: libcpupower $(OUTPUT)cpupower $(COMPILE_NLS) $(COMPILE_BENCH)190 191$(OUTPUT)lib/%.o: $(LIB_SRC) $(LIB_HEADERS)192 $(ECHO) " CC " $@193 $(QUIET) $(CC) $(CFLAGS) -fPIC -o $@ -c lib/$*.c194 195$(OUTPUT)libcpupower.so.$(LIB_MAJ): $(LIB_OBJS)196 $(ECHO) " LD " $@197 $(QUIET) $(CC) -shared $(CFLAGS) $(LDFLAGS) -o $@ \198 -Wl,-soname,libcpupower.so.$(LIB_MIN) $(LIB_OBJS)199 @ln -sf $(@F) $(OUTPUT)libcpupower.so200 @ln -sf $(@F) $(OUTPUT)libcpupower.so.$(LIB_MIN)201 202libcpupower: $(OUTPUT)libcpupower.so.$(LIB_MAJ)203 204# Let all .o files depend on its .c file and all headers205# Might be worth to put this into utils/Makefile at some point of time206$(UTIL_OBJS): $(UTIL_HEADERS)207 208$(OUTPUT)%.o: %.c209 $(ECHO) " CC " $@210 $(QUIET) $(CC) $(CFLAGS) -I./lib -I ./utils -o $@ -c $*.c211 212$(OUTPUT)cpupower: $(UTIL_OBJS) $(OUTPUT)libcpupower.so.$(LIB_MAJ)213 $(ECHO) " CC " $@214ifeq ($(strip $(STATIC)),true)215 $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) $(UTIL_OBJS) -lrt -lpci -L$(OUTPUT) -o $@216else217 $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) $(UTIL_OBJS) -lcpupower -lrt -lpci -L$(OUTPUT) -o $@218endif219 $(QUIET) $(STRIPCMD) $@220 221$(OUTPUT)po/$(PACKAGE).pot: $(UTIL_SRC)222 $(ECHO) " GETTEXT " $@223 $(QUIET) xgettext --default-domain=$(PACKAGE) --add-comments \224 --keyword=_ --keyword=N_ $(UTIL_SRC) -p $(@D) -o $(@F)225 226$(OUTPUT)po/%.gmo: po/%.po227 $(ECHO) " MSGFMT " $@228 $(QUIET) msgfmt -o $@ po/$*.po229 230create-gmo: ${GMO_FILES}231 232update-po: $(OUTPUT)po/$(PACKAGE).pot233 $(ECHO) " MSGMRG " $@234 $(QUIET) @for HLANG in $(LANGUAGES); do \235 echo -n "Updating $$HLANG "; \236 if msgmerge po/$$HLANG.po $< -o \237 $(OUTPUT)po/$$HLANG.new.po; then \238 mv -f $(OUTPUT)po/$$HLANG.new.po $(OUTPUT)po/$$HLANG.po; \239 else \240 echo "msgmerge for $$HLANG failed!"; \241 rm -f $(OUTPUT)po/$$HLANG.new.po; \242 fi; \243 done;244 245compile-bench: $(OUTPUT)libcpupower.so.$(LIB_MAJ)246 @V=$(V) confdir=$(confdir) $(MAKE) -C bench O=$(OUTPUT)247 248# we compile into subdirectories. if the target directory is not the249# source directory, they might not exists. So we depend the various250# files onto their directories.251DIRECTORY_DEPS = $(LIB_OBJS) $(UTIL_OBJS) $(GMO_FILES)252$(DIRECTORY_DEPS): | $(sort $(dir $(DIRECTORY_DEPS)))253 254# In the second step, we make a rule to actually create these directories255$(sort $(dir $(DIRECTORY_DEPS))):256 $(ECHO) " MKDIR " $@257 $(QUIET) $(MKDIR) -p $@ 2>/dev/null258 259clean:260 -find $(OUTPUT) \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \261 | xargs rm -f262 -rm -f $(OUTPUT)cpupower263 -rm -f $(OUTPUT)libcpupower.so*264 -rm -rf $(OUTPUT)po/*.gmo265 -rm -rf $(OUTPUT)po/*.pot266 $(MAKE) -C bench O=$(OUTPUT) clean267 268 269install-lib: libcpupower270 $(INSTALL) -d $(DESTDIR)${libdir}271 $(CP) $(OUTPUT)libcpupower.so* $(DESTDIR)${libdir}/272 $(INSTALL) -d $(DESTDIR)${includedir}273 $(INSTALL_DATA) lib/cpufreq.h $(DESTDIR)${includedir}/cpufreq.h274 $(INSTALL_DATA) lib/cpuidle.h $(DESTDIR)${includedir}/cpuidle.h275 $(INSTALL_DATA) lib/powercap.h $(DESTDIR)${includedir}/powercap.h276 277install-tools: $(OUTPUT)cpupower278 $(INSTALL) -d $(DESTDIR)${bindir}279 $(INSTALL_PROGRAM) $(OUTPUT)cpupower $(DESTDIR)${bindir}280 $(INSTALL) -d $(DESTDIR)${bash_completion_dir}281 $(INSTALL_SCRIPT) cpupower-completion.sh '$(DESTDIR)${bash_completion_dir}/cpupower'282 283install-man:284 $(INSTALL_DATA) -D man/cpupower.1 $(DESTDIR)${mandir}/man1/cpupower.1285 $(INSTALL_DATA) -D man/cpupower-frequency-set.1 $(DESTDIR)${mandir}/man1/cpupower-frequency-set.1286 $(INSTALL_DATA) -D man/cpupower-frequency-info.1 $(DESTDIR)${mandir}/man1/cpupower-frequency-info.1287 $(INSTALL_DATA) -D man/cpupower-idle-set.1 $(DESTDIR)${mandir}/man1/cpupower-idle-set.1288 $(INSTALL_DATA) -D man/cpupower-idle-info.1 $(DESTDIR)${mandir}/man1/cpupower-idle-info.1289 $(INSTALL_DATA) -D man/cpupower-set.1 $(DESTDIR)${mandir}/man1/cpupower-set.1290 $(INSTALL_DATA) -D man/cpupower-info.1 $(DESTDIR)${mandir}/man1/cpupower-info.1291 $(INSTALL_DATA) -D man/cpupower-monitor.1 $(DESTDIR)${mandir}/man1/cpupower-monitor.1292 $(INSTALL_DATA) -D man/cpupower-powercap-info.1 $(DESTDIR)${mandir}/man1/cpupower-powercap-info.1293 294install-gmo: create-gmo295 $(INSTALL) -d $(DESTDIR)${localedir}296 for HLANG in $(LANGUAGES); do \297 echo '$(INSTALL_DATA) -D $(OUTPUT)po/$$HLANG.gmo $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo'; \298 $(INSTALL_DATA) -D $(OUTPUT)po/$$HLANG.gmo $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo; \299 done;300 301install-bench: compile-bench302 @#DESTDIR must be set from outside to survive303 @sbindir=$(sbindir) bindir=$(bindir) docdir=$(docdir) confdir=$(confdir) $(MAKE) -C bench O=$(OUTPUT) install304 305ifeq ($(strip $(STATIC)),true)306install: all install-tools install-man $(INSTALL_NLS) $(INSTALL_BENCH)307else308install: all install-lib install-tools install-man $(INSTALL_NLS) $(INSTALL_BENCH)309endif310 311uninstall:312 - rm -f $(DESTDIR)${libdir}/libcpupower.*313 - rm -f $(DESTDIR)${includedir}/cpufreq.h314 - rm -f $(DESTDIR)${includedir}/cpuidle.h315 - rm -f $(DESTDIR)${bindir}/utils/cpupower316 - rm -f $(DESTDIR)${mandir}/man1/cpupower.1317 - rm -f $(DESTDIR)${mandir}/man1/cpupower-frequency-set.1318 - rm -f $(DESTDIR)${mandir}/man1/cpupower-frequency-info.1319 - rm -f $(DESTDIR)${mandir}/man1/cpupower-set.1320 - rm -f $(DESTDIR)${mandir}/man1/cpupower-info.1321 - rm -f $(DESTDIR)${mandir}/man1/cpupower-monitor.1322 - rm -f $(DESTDIR)${mandir}/man1/cpupower-powercap-info.1323 - for HLANG in $(LANGUAGES); do \324 rm -f $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo; \325 done;326 327help:328 @echo 'Building targets:'329 @echo ' all - Default target. Could be omitted. Put build artifacts'330 @echo ' to "O" cmdline option dir (default: current dir)'331 @echo ' install - Install previously built project files from the output'332 @echo ' dir defined by "O" cmdline option (default: current dir)'333 @echo ' to the install dir defined by "DESTDIR" cmdline or'334 @echo ' Makefile config block option (default: "")'335 @echo ' install-lib - Install previously built library binary from the output'336 @echo ' dir defined by "O" cmdline option (default: current dir)'337 @echo ' and library headers from "lib/" for userspace to the install'338 @echo ' dir defined by "DESTDIR" cmdline (default: "")'339 @echo ' install-tools - Install previously built "cpupower" util from the output'340 @echo ' dir defined by "O" cmdline option (default: current dir) and'341 @echo ' "cpupower-completion.sh" script from the src dir to the'342 @echo ' install dir defined by "DESTDIR" cmdline or Makefile'343 @echo ' config block option (default: "")'344 @echo ' install-man - Install man pages from the "man" src subdir to the'345 @echo ' install dir defined by "DESTDIR" cmdline or Makefile'346 @echo ' config block option (default: "")'347 @echo ' install-gmo - Install previously built language files from the output'348 @echo ' dir defined by "O" cmdline option (default: current dir)'349 @echo ' to the install dir defined by "DESTDIR" cmdline or Makefile'350 @echo ' config block option (default: "")'351 @echo ' install-bench - Install previously built "cpufreq-bench" util files from the'352 @echo ' output dir defined by "O" cmdline option (default: current dir)'353 @echo ' to the install dir defined by "DESTDIR" cmdline or Makefile'354 @echo ' config block option (default: "")'355 @echo ''356 @echo 'Cleaning targets:'357 @echo ' clean - Clean build artifacts from the dir defined by "O" cmdline'358 @echo ' option (default: current dir)'359 @echo ' uninstall - Remove previously installed files from the dir defined by "DESTDIR"'360 @echo ' cmdline or Makefile config block option (default: "")'361 362.PHONY: all utils libcpupower update-po create-gmo install-lib install-tools install-man install-gmo install uninstall clean help363