1 # SPDX-License-Identifier: GPL-2.0-only 2 # Makefile for cpupower 3 # 4 # Copyright (C) 2005,2006 Dominik Brodowski <li 5 # 6 # Based largely on the Makefile for udev by: 7 # 8 # Copyright (C) 2003,2004 Greg Kroah-Hartman <g 9 # 10 OUTPUT=./ 11 ifeq ("$(origin O)", "command line") 12 OUTPUT := $(O)/ 13 endif 14 15 ifneq ($(OUTPUT),) 16 # check that the output directory actually exi 17 OUTDIR := $(shell cd $(OUTPUT) && pwd) 18 $(if $(OUTDIR),, $(error output directory "$(O 19 endif 20 21 22 # --- CONFIGURATION BEGIN --- 23 24 # Set the following to `true' to make a unstri 25 # binary. Leave this set to `false' for produc 26 DEBUG ?= true 27 28 # make the build silent. Set this to something 29 V ?= false 30 31 # Internationalization support (output in diff 32 # Requires gettext. 33 NLS ?= true 34 35 # Set the following to 'true' to build/install 36 # cpufreq-bench benchmarking tool 37 CPUFREQ_BENCH ?= true 38 39 # Do not build libraries, but build the code i 40 # Libraries are still built, otherwise the Mak 41 # be rather ugly. 42 export STATIC ?= false 43 44 # Prefix to the directories we're installing t 45 DESTDIR ?= 46 47 # --- CONFIGURATION END --- 48 49 50 51 # Package-related definitions. Distributions c 52 # and _should_ modify the PACKAGE_BUGREPORT de 53 54 VERSION:= $(shell ./util 55 LIB_MAJ= 0.0.1 56 LIB_MIN= 1 57 58 PACKAGE = cpupower 59 PACKAGE_BUGREPORT = linux-pm@vger. 60 LANGUAGES = de fr it cs pt 61 62 63 # Directory definitions. These are default and 64 # do not need to be changed. Please note that 65 # added in front of any of them 66 67 bindir ?= /usr/bin 68 sbindir ?= /usr/sbin 69 mandir ?= /usr/man 70 libdir ?= /usr/lib 71 includedir ?= /usr/include 72 localedir ?= /usr/share/locale 73 docdir ?= /usr/share/doc/packages/cpupow 74 confdir ?= /etc/ 75 bash_completion_dir ?= /usr/share/bash-complet 76 77 # Toolchain: what tools do we use, and what op 78 79 CP = cp -fpR 80 INSTALL = /usr/bin/install -c 81 INSTALL_PROGRAM = ${INSTALL} 82 INSTALL_DATA = ${INSTALL} -m 644 83 #bash completion scripts get sourced and so th 84 INSTALL_SCRIPT = ${INSTALL} -m 644 85 86 # If you are running a cross compiler, you may 87 # to something more interesting, like "arm-lin 88 # to compile vs uClibc, that can be done here 89 CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-u 90 CC = $(CROSS)gcc 91 LD = $(CROSS)gcc 92 AR = $(CROSS)ar 93 STRIP = $(CROSS)strip 94 RANLIB = $(CROSS)ranlib 95 HOSTCC = gcc 96 MKDIR = mkdir 97 98 # Now we set up the build system 99 # 100 101 GMO_FILES = ${shell for HLANG in ${LANGUAGES}; 102 103 export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS 104 105 # check if compiler option is supported 106 cc-supports = ${shell if $(CC) ${1} -S -o /dev 107 108 # use '-Os' optimization if available, else us 109 OPTIMIZATION := $(call cc-supports,-Os,-O2) 110 111 WARNINGS := -Wall -Wchar-subscripts -Wpointer- 112 WARNINGS += $(call cc-supports,-Wno-pointer-si 113 WARNINGS += $(call cc-supports,-Wdeclaration-a 114 WARNINGS += -Wshadow 115 116 override CFLAGS += -DVERSION=\"$(VERSION)\" -D 117 -DPACKAGE_BUGREPORT=\"$(PACKAG 118 119 UTIL_OBJS = utils/helpers/amd.o utils/helpers 120 utils/helpers/sysfs.o utils/helpers/mi 121 utils/helpers/pci.o utils/helpers/bitm 122 utils/idle_monitor/nhm_idle.o utils/id 123 utils/idle_monitor/hsw_ext_idle.o \ 124 utils/idle_monitor/amd_fam14h_idle.o u 125 utils/idle_monitor/mperf_monitor.o uti 126 utils/idle_monitor/rapl_monitor.o \ 127 utils/cpupower.o utils/cpufreq-info.o 128 utils/cpupower-set.o utils/cpupower-in 129 utils/cpuidle-set.o utils/powercap-inf 130 131 UTIL_SRC := $(UTIL_OBJS:.o=.c) 132 133 UTIL_OBJS := $(addprefix $(OUTPUT),$(UTIL_OBJS 134 135 UTIL_HEADERS = utils/helpers/helpers.h utils/i 136 utils/helpers/bitmask.h \ 137 utils/idle_monitor/idle_monitors.h uti 138 139 LIB_HEADERS = lib/cpufreq.h lib/cpupower.h l 140 lib/powercap.h 141 LIB_SRC = lib/cpufreq.c lib/cpupower.c l 142 lib/powercap.c 143 LIB_OBJS = lib/cpufreq.o lib/cpupower.o l 144 lib/powercap.o 145 LIB_OBJS := $(addprefix $(OUTPUT),$(LIB_OB 146 147 override CFLAGS += -pipe 148 149 ifeq ($(strip $(NLS)),true) 150 INSTALL_NLS += install-gmo 151 COMPILE_NLS += create-gmo 152 override CFLAGS += -DNLS 153 endif 154 155 ifeq ($(strip $(CPUFREQ_BENCH)),true) 156 INSTALL_BENCH += install-bench 157 COMPILE_BENCH += compile-bench 158 endif 159 160 ifeq ($(strip $(STATIC)),true) 161 UTIL_OBJS += $(LIB_OBJS) 162 UTIL_HEADERS += $(LIB_HEADERS) 163 UTIL_SRC += $(LIB_SRC) 164 endif 165 166 override CFLAGS += $(WARNINGS) 167 168 ifeq ($(strip $(V)),false) 169 QUIET=@ 170 ECHO=@echo 171 else 172 QUIET= 173 ECHO=@\# 174 endif 175 export QUIET ECHO 176 177 # if DEBUG is enabled, then we do not strip or 178 ifeq ($(strip $(DEBUG)),true) 179 override CFLAGS += -O1 -g -DDEBUG 180 STRIPCMD = /bin/true -Since_we_are_deb 181 else 182 override CFLAGS += $(OPTIMIZATION) -fo 183 STRIPCMD = $(STRIP) -s --remove-sectio 184 endif 185 186 187 # the actual make rules 188 189 all: libcpupower $(OUTPUT)cpupower $(COMPILE_N 190 191 $(OUTPUT)lib/%.o: $(LIB_SRC) $(LIB_HEADERS) 192 $(ECHO) " CC " $@ 193 $(QUIET) $(CC) $(CFLAGS) -fPIC -o $@ - 194 195 $(OUTPUT)libcpupower.so.$(LIB_MAJ): $(LIB_OBJS 196 $(ECHO) " LD " $@ 197 $(QUIET) $(CC) -shared $(CFLAGS) $(LDF 198 -Wl,-soname,libcpupower.so.$(L 199 @ln -sf $(@F) $(OUTPUT)libcpupower.so 200 @ln -sf $(@F) $(OUTPUT)libcpupower.so. 201 202 libcpupower: $(OUTPUT)libcpupower.so.$(LIB_MAJ 203 204 # Let all .o files depend on its .c file and a 205 # Might be worth to put this into utils/Makefi 206 $(UTIL_OBJS): $(UTIL_HEADERS) 207 208 $(OUTPUT)%.o: %.c 209 $(ECHO) " CC " $@ 210 $(QUIET) $(CC) $(CFLAGS) -I./lib -I ./ 211 212 $(OUTPUT)cpupower: $(UTIL_OBJS) $(OUTPUT)libcp 213 $(ECHO) " CC " $@ 214 ifeq ($(strip $(STATIC)),true) 215 $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) $( 216 else 217 $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) $( 218 endif 219 $(QUIET) $(STRIPCMD) $@ 220 221 $(OUTPUT)po/$(PACKAGE).pot: $(UTIL_SRC) 222 $(ECHO) " GETTEXT " $@ 223 $(QUIET) xgettext --default-domain=$(P 224 --keyword=_ --keyword=N_ $(UTI 225 226 $(OUTPUT)po/%.gmo: po/%.po 227 $(ECHO) " MSGFMT " $@ 228 $(QUIET) msgfmt -o $@ po/$*.po 229 230 create-gmo: ${GMO_FILES} 231 232 update-po: $(OUTPUT)po/$(PACKAGE).pot 233 $(ECHO) " MSGMRG " $@ 234 $(QUIET) @for HLANG in $(LANGUAGES); d 235 echo -n "Updating $$HLANG "; \ 236 if msgmerge po/$$HLANG.po $< - 237 $(OUTPUT)po/$$HLANG.new.po; 238 mv -f $(OUTPUT)po/$$HL 239 else \ 240 echo "msgmerge for $$H 241 rm -f $(OUTPUT)po/$$HL 242 fi; \ 243 done; 244 245 compile-bench: $(OUTPUT)libcpupower.so.$(LIB_M 246 @V=$(V) confdir=$(confdir) $(MAKE) -C 247 248 # we compile into subdirectories. if the targe 249 # source directory, they might not exists. So 250 # files onto their directories. 251 DIRECTORY_DEPS = $(LIB_OBJS) $(UTIL_OBJS) $(GM 252 $(DIRECTORY_DEPS): | $(sort $(dir $(DIRECTORY_ 253 254 # In the second step, we make a rule to actual 255 $(sort $(dir $(DIRECTORY_DEPS))): 256 $(ECHO) " MKDIR " $@ 257 $(QUIET) $(MKDIR) -p $@ 2>/dev/null 258 259 clean: 260 -find $(OUTPUT) \( -not -type d \) -an 261 | xargs rm -f 262 -rm -f $(OUTPUT)cpupower 263 -rm -f $(OUTPUT)libcpupower.so* 264 -rm -rf $(OUTPUT)po/*.gmo 265 -rm -rf $(OUTPUT)po/*.pot 266 $(MAKE) -C bench O=$(OUTPUT) clean 267 268 269 install-lib: libcpupower 270 $(INSTALL) -d $(DESTDIR)${libdir} 271 $(CP) $(OUTPUT)libcpupower.so* $(DESTD 272 $(INSTALL) -d $(DESTDIR)${includedir} 273 $(INSTALL_DATA) lib/cpufreq.h $(DESTDI 274 $(INSTALL_DATA) lib/cpuidle.h $(DESTDI 275 $(INSTALL_DATA) lib/powercap.h $(DESTD 276 277 install-tools: $(OUTPUT)cpupower 278 $(INSTALL) -d $(DESTDIR)${bindir} 279 $(INSTALL_PROGRAM) $(OUTPUT)cpupower $ 280 $(INSTALL) -d $(DESTDIR)${bash_complet 281 $(INSTALL_SCRIPT) cpupower-completion. 282 283 install-man: 284 $(INSTALL_DATA) -D man/cpupower.1 $(DE 285 $(INSTALL_DATA) -D man/cpupower-freque 286 $(INSTALL_DATA) -D man/cpupower-freque 287 $(INSTALL_DATA) -D man/cpupower-idle-s 288 $(INSTALL_DATA) -D man/cpupower-idle-i 289 $(INSTALL_DATA) -D man/cpupower-set.1 290 $(INSTALL_DATA) -D man/cpupower-info.1 291 $(INSTALL_DATA) -D man/cpupower-monito 292 $(INSTALL_DATA) -D man/cpupower-powerc 293 294 install-gmo: create-gmo 295 $(INSTALL) -d $(DESTDIR)${localedir} 296 for HLANG in $(LANGUAGES); do \ 297 echo '$(INSTALL_DATA) -D $(OUT 298 $(INSTALL_DATA) -D $(OUTPUT)po 299 done; 300 301 install-bench: compile-bench 302 @#DESTDIR must be set from outside to 303 @sbindir=$(sbindir) bindir=$(bindir) d 304 305 ifeq ($(strip $(STATIC)),true) 306 install: all install-tools install-man $(INSTA 307 else 308 install: all install-lib install-tools install 309 endif 310 311 uninstall: 312 - rm -f $(DESTDIR)${libdir}/libcpupowe 313 - rm -f $(DESTDIR)${includedir}/cpufre 314 - rm -f $(DESTDIR)${includedir}/cpuidl 315 - rm -f $(DESTDIR)${bindir}/utils/cpup 316 - rm -f $(DESTDIR)${mandir}/man1/cpupo 317 - rm -f $(DESTDIR)${mandir}/man1/cpupo 318 - rm -f $(DESTDIR)${mandir}/man1/cpupo 319 - rm -f $(DESTDIR)${mandir}/man1/cpupo 320 - rm -f $(DESTDIR)${mandir}/man1/cpupo 321 - rm -f $(DESTDIR)${mandir}/man1/cpupo 322 - rm -f $(DESTDIR)${mandir}/man1/cpupo 323 - for HLANG in $(LANGUAGES); do \ 324 rm -f $(DESTDIR)${localedir}/$ 325 done; 326 327 help: 328 @echo 'Building targets:' 329 @echo ' all - Default ta 330 @echo ' to "O" cmd 331 @echo ' install - Install pr 332 @echo ' dir define 333 @echo ' to the ins 334 @echo ' Makefile c 335 @echo ' install-lib - Install pr 336 @echo ' dir define 337 @echo ' and librar 338 @echo ' dir defin 339 @echo ' install-tools - Install pr 340 @echo ' dir define 341 @echo ' "cpupower- 342 @echo ' install di 343 @echo ' config blo 344 @echo ' install-man - Install ma 345 @echo ' install di 346 @echo ' config blo 347 @echo ' install-gmo - Install pr 348 @echo ' dir define 349 @echo ' to the ins 350 @echo ' config blo 351 @echo ' install-bench - Install pr 352 @echo ' output dir 353 @echo ' to the ins 354 @echo ' config blo 355 @echo '' 356 @echo 'Cleaning targets:' 357 @echo ' clean - Clean buil 358 @echo ' option (de 359 @echo ' uninstall - Remove pre 360 @echo ' cmdline or 361 362 .PHONY: all utils libcpupower update-po create
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.