Makefile 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. # Makefile for cpupower
  2. #
  3. # Copyright (C) 2005,2006 Dominik Brodowski <linux@dominikbrodowski.net>
  4. #
  5. # Based largely on the Makefile for udev by:
  6. #
  7. # Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; version 2 of the License.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. # General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. #
  22. OUTPUT=./
  23. ifeq ("$(origin O)", "command line")
  24. OUTPUT := $(O)/
  25. endif
  26. ifneq ($(OUTPUT),)
  27. # check that the output directory actually exists
  28. OUTDIR := $(shell cd $(OUTPUT) && pwd)
  29. $(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
  30. endif
  31. include ../../scripts/Makefile.arch
  32. # --- CONFIGURATION BEGIN ---
  33. # Set the following to `true' to make a unstripped, unoptimized
  34. # binary. Leave this set to `false' for production use.
  35. DEBUG ?= true
  36. # make the build silent. Set this to something else to make it noisy again.
  37. V ?= false
  38. # Internationalization support (output in different languages).
  39. # Requires gettext.
  40. NLS ?= true
  41. # Set the following to 'true' to build/install the
  42. # cpufreq-bench benchmarking tool
  43. CPUFREQ_BENCH ?= true
  44. # Do not build libraries, but build the code in statically
  45. # Libraries are still built, otherwise the Makefile code would
  46. # be rather ugly.
  47. export STATIC ?= false
  48. # Prefix to the directories we're installing to
  49. DESTDIR ?=
  50. # --- CONFIGURATION END ---
  51. # Package-related definitions. Distributions can modify the version
  52. # and _should_ modify the PACKAGE_BUGREPORT definition
  53. VERSION= $(shell ./utils/version-gen.sh)
  54. LIB_MAJ= 0.0.1
  55. LIB_MIN= 1
  56. PACKAGE = cpupower
  57. PACKAGE_BUGREPORT = linux-pm@vger.kernel.org
  58. LANGUAGES = de fr it cs pt
  59. # Directory definitions. These are default and most probably
  60. # do not need to be changed. Please note that DESTDIR is
  61. # added in front of any of them
  62. bindir ?= /usr/bin
  63. sbindir ?= /usr/sbin
  64. mandir ?= /usr/man
  65. includedir ?= /usr/include
  66. ifeq ($(IS_64_BIT), 1)
  67. libdir ?= /usr/lib64
  68. else
  69. libdir ?= /usr/lib
  70. endif
  71. localedir ?= /usr/share/locale
  72. docdir ?= /usr/share/doc/packages/cpupower
  73. confdir ?= /etc/
  74. # Toolchain: what tools do we use, and what options do they need:
  75. CP = cp -fpR
  76. INSTALL = /usr/bin/install -c
  77. INSTALL_PROGRAM = ${INSTALL}
  78. INSTALL_DATA = ${INSTALL} -m 644
  79. INSTALL_SCRIPT = ${INSTALL_PROGRAM}
  80. # If you are running a cross compiler, you may want to set this
  81. # to something more interesting, like "arm-linux-". If you want
  82. # to compile vs uClibc, that can be done here as well.
  83. CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
  84. CC = $(CROSS)gcc
  85. LD = $(CROSS)gcc
  86. AR = $(CROSS)ar
  87. STRIP = $(CROSS)strip
  88. RANLIB = $(CROSS)ranlib
  89. HOSTCC = gcc
  90. MKDIR = mkdir
  91. # Now we set up the build system
  92. #
  93. GMO_FILES = ${shell for HLANG in ${LANGUAGES}; do echo $(OUTPUT)po/$$HLANG.gmo; done;}
  94. export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS
  95. # check if compiler option is supported
  96. cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -x c /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;}
  97. # use '-Os' optimization if available, else use -O2
  98. OPTIMIZATION := $(call cc-supports,-Os,-O2)
  99. WARNINGS := -Wall -Wchar-subscripts -Wpointer-arith -Wsign-compare
  100. WARNINGS += $(call cc-supports,-Wno-pointer-sign)
  101. WARNINGS += $(call cc-supports,-Wdeclaration-after-statement)
  102. WARNINGS += -Wshadow
  103. CFLAGS += -DVERSION=\"$(VERSION)\" -DPACKAGE=\"$(PACKAGE)\" \
  104. -DPACKAGE_BUGREPORT=\"$(PACKAGE_BUGREPORT)\" -D_GNU_SOURCE
  105. UTIL_OBJS = utils/helpers/amd.o utils/helpers/msr.o \
  106. utils/helpers/sysfs.o utils/helpers/misc.o utils/helpers/cpuid.o \
  107. utils/helpers/pci.o utils/helpers/bitmask.o \
  108. utils/idle_monitor/nhm_idle.o utils/idle_monitor/snb_idle.o \
  109. utils/idle_monitor/hsw_ext_idle.o \
  110. utils/idle_monitor/amd_fam14h_idle.o utils/idle_monitor/cpuidle_sysfs.o \
  111. utils/idle_monitor/mperf_monitor.o utils/idle_monitor/cpupower-monitor.o \
  112. utils/cpupower.o utils/cpufreq-info.o utils/cpufreq-set.o \
  113. utils/cpupower-set.o utils/cpupower-info.o utils/cpuidle-info.o \
  114. utils/cpuidle-set.o
  115. UTIL_SRC := $(UTIL_OBJS:.o=.c)
  116. UTIL_OBJS := $(addprefix $(OUTPUT),$(UTIL_OBJS))
  117. UTIL_HEADERS = utils/helpers/helpers.h utils/idle_monitor/cpupower-monitor.h \
  118. utils/helpers/bitmask.h \
  119. utils/idle_monitor/idle_monitors.h utils/idle_monitor/idle_monitors.def
  120. LIB_HEADERS = lib/cpufreq.h lib/cpupower.h lib/cpuidle.h
  121. LIB_SRC = lib/cpufreq.c lib/cpupower.c lib/cpuidle.c
  122. LIB_OBJS = lib/cpufreq.o lib/cpupower.o lib/cpuidle.o
  123. LIB_OBJS := $(addprefix $(OUTPUT),$(LIB_OBJS))
  124. CFLAGS += -pipe
  125. ifeq ($(strip $(NLS)),true)
  126. INSTALL_NLS += install-gmo
  127. COMPILE_NLS += create-gmo
  128. CFLAGS += -DNLS
  129. endif
  130. ifeq ($(strip $(CPUFREQ_BENCH)),true)
  131. INSTALL_BENCH += install-bench
  132. COMPILE_BENCH += compile-bench
  133. endif
  134. ifeq ($(strip $(STATIC)),true)
  135. UTIL_OBJS += $(LIB_OBJS)
  136. UTIL_HEADERS += $(LIB_HEADERS)
  137. UTIL_SRC += $(LIB_SRC)
  138. endif
  139. CFLAGS += $(WARNINGS)
  140. ifeq ($(strip $(V)),false)
  141. QUIET=@
  142. ECHO=@echo
  143. else
  144. QUIET=
  145. ECHO=@\#
  146. endif
  147. export QUIET ECHO
  148. # if DEBUG is enabled, then we do not strip or optimize
  149. ifeq ($(strip $(DEBUG)),true)
  150. CFLAGS += -O1 -g -DDEBUG
  151. STRIPCMD = /bin/true -Since_we_are_debugging
  152. else
  153. CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer
  154. STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
  155. endif
  156. # the actual make rules
  157. all: libcpupower $(OUTPUT)cpupower $(COMPILE_NLS) $(COMPILE_BENCH)
  158. $(OUTPUT)lib/%.o: $(LIB_SRC) $(LIB_HEADERS)
  159. $(ECHO) " CC " $@
  160. $(QUIET) $(CC) $(CFLAGS) -fPIC -o $@ -c lib/$*.c
  161. $(OUTPUT)libcpupower.so.$(LIB_MAJ): $(LIB_OBJS)
  162. $(ECHO) " LD " $@
  163. $(QUIET) $(CC) -shared $(CFLAGS) $(LDFLAGS) -o $@ \
  164. -Wl,-soname,libcpupower.so.$(LIB_MIN) $(LIB_OBJS)
  165. @ln -sf $(@F) $(OUTPUT)libcpupower.so
  166. @ln -sf $(@F) $(OUTPUT)libcpupower.so.$(LIB_MIN)
  167. libcpupower: $(OUTPUT)libcpupower.so.$(LIB_MAJ)
  168. # Let all .o files depend on its .c file and all headers
  169. # Might be worth to put this into utils/Makefile at some point of time
  170. $(UTIL_OBJS): $(UTIL_HEADERS)
  171. $(OUTPUT)%.o: %.c
  172. $(ECHO) " CC " $@
  173. $(QUIET) $(CC) $(CFLAGS) -I./lib -I ./utils -o $@ -c $*.c
  174. $(OUTPUT)cpupower: $(UTIL_OBJS) $(OUTPUT)libcpupower.so.$(LIB_MAJ)
  175. $(ECHO) " CC " $@
  176. ifeq ($(strip $(STATIC)),true)
  177. $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) $(UTIL_OBJS) -lrt -lpci -L$(OUTPUT) -o $@
  178. else
  179. $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) $(UTIL_OBJS) -lcpupower -lrt -lpci -L$(OUTPUT) -o $@
  180. endif
  181. $(QUIET) $(STRIPCMD) $@
  182. $(OUTPUT)po/$(PACKAGE).pot: $(UTIL_SRC)
  183. $(ECHO) " GETTEXT " $@
  184. $(QUIET) xgettext --default-domain=$(PACKAGE) --add-comments \
  185. --keyword=_ --keyword=N_ $(UTIL_SRC) -p $(@D) -o $(@F)
  186. $(OUTPUT)po/%.gmo: po/%.po
  187. $(ECHO) " MSGFMT " $@
  188. $(QUIET) msgfmt -o $@ po/$*.po
  189. create-gmo: ${GMO_FILES}
  190. update-po: $(OUTPUT)po/$(PACKAGE).pot
  191. $(ECHO) " MSGMRG " $@
  192. $(QUIET) @for HLANG in $(LANGUAGES); do \
  193. echo -n "Updating $$HLANG "; \
  194. if msgmerge po/$$HLANG.po $< -o \
  195. $(OUTPUT)po/$$HLANG.new.po; then \
  196. mv -f $(OUTPUT)po/$$HLANG.new.po $(OUTPUT)po/$$HLANG.po; \
  197. else \
  198. echo "msgmerge for $$HLANG failed!"; \
  199. rm -f $(OUTPUT)po/$$HLANG.new.po; \
  200. fi; \
  201. done;
  202. compile-bench: $(OUTPUT)libcpupower.so.$(LIB_MAJ)
  203. @V=$(V) confdir=$(confdir) $(MAKE) -C bench O=$(OUTPUT)
  204. # we compile into subdirectories. if the target directory is not the
  205. # source directory, they might not exists. So we depend the various
  206. # files onto their directories.
  207. DIRECTORY_DEPS = $(LIB_OBJS) $(UTIL_OBJS) $(GMO_FILES)
  208. $(DIRECTORY_DEPS): | $(sort $(dir $(DIRECTORY_DEPS)))
  209. # In the second step, we make a rule to actually create these directories
  210. $(sort $(dir $(DIRECTORY_DEPS))):
  211. $(ECHO) " MKDIR " $@
  212. $(QUIET) $(MKDIR) -p $@ 2>/dev/null
  213. clean:
  214. -find $(OUTPUT) \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
  215. | xargs rm -f
  216. -rm -f $(OUTPUT)cpupower
  217. -rm -f $(OUTPUT)libcpupower.so*
  218. -rm -rf $(OUTPUT)po/*.gmo
  219. -rm -rf $(OUTPUT)po/*.pot
  220. $(MAKE) -C bench O=$(OUTPUT) clean
  221. install-lib:
  222. $(INSTALL) -d $(DESTDIR)${libdir}
  223. $(CP) $(OUTPUT)libcpupower.so* $(DESTDIR)${libdir}/
  224. $(INSTALL) -d $(DESTDIR)${includedir}
  225. $(INSTALL_DATA) lib/cpufreq.h $(DESTDIR)${includedir}/cpufreq.h
  226. $(INSTALL_DATA) lib/cpuidle.h $(DESTDIR)${includedir}/cpuidle.h
  227. install-tools:
  228. $(INSTALL) -d $(DESTDIR)${bindir}
  229. $(INSTALL_PROGRAM) $(OUTPUT)cpupower $(DESTDIR)${bindir}
  230. install-man:
  231. $(INSTALL_DATA) -D man/cpupower.1 $(DESTDIR)${mandir}/man1/cpupower.1
  232. $(INSTALL_DATA) -D man/cpupower-frequency-set.1 $(DESTDIR)${mandir}/man1/cpupower-frequency-set.1
  233. $(INSTALL_DATA) -D man/cpupower-frequency-info.1 $(DESTDIR)${mandir}/man1/cpupower-frequency-info.1
  234. $(INSTALL_DATA) -D man/cpupower-idle-set.1 $(DESTDIR)${mandir}/man1/cpupower-idle-set.1
  235. $(INSTALL_DATA) -D man/cpupower-idle-info.1 $(DESTDIR)${mandir}/man1/cpupower-idle-info.1
  236. $(INSTALL_DATA) -D man/cpupower-set.1 $(DESTDIR)${mandir}/man1/cpupower-set.1
  237. $(INSTALL_DATA) -D man/cpupower-info.1 $(DESTDIR)${mandir}/man1/cpupower-info.1
  238. $(INSTALL_DATA) -D man/cpupower-monitor.1 $(DESTDIR)${mandir}/man1/cpupower-monitor.1
  239. install-gmo:
  240. $(INSTALL) -d $(DESTDIR)${localedir}
  241. for HLANG in $(LANGUAGES); do \
  242. echo '$(INSTALL_DATA) -D $(OUTPUT)po/$$HLANG.gmo $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo'; \
  243. $(INSTALL_DATA) -D $(OUTPUT)po/$$HLANG.gmo $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo; \
  244. done;
  245. install-bench:
  246. @#DESTDIR must be set from outside to survive
  247. @sbindir=$(sbindir) bindir=$(bindir) docdir=$(docdir) confdir=$(confdir) $(MAKE) -C bench O=$(OUTPUT) install
  248. ifeq ($(strip $(STATIC)),true)
  249. install: all install-tools install-man $(INSTALL_NLS) $(INSTALL_BENCH)
  250. else
  251. install: all install-lib install-tools install-man $(INSTALL_NLS) $(INSTALL_BENCH)
  252. endif
  253. uninstall:
  254. - rm -f $(DESTDIR)${libdir}/libcpupower.*
  255. - rm -f $(DESTDIR)${includedir}/cpufreq.h
  256. - rm -f $(DESTDIR)${includedir}/cpuidle.h
  257. - rm -f $(DESTDIR)${bindir}/utils/cpupower
  258. - rm -f $(DESTDIR)${mandir}/man1/cpupower.1
  259. - rm -f $(DESTDIR)${mandir}/man1/cpupower-frequency-set.1
  260. - rm -f $(DESTDIR)${mandir}/man1/cpupower-frequency-info.1
  261. - rm -f $(DESTDIR)${mandir}/man1/cpupower-set.1
  262. - rm -f $(DESTDIR)${mandir}/man1/cpupower-info.1
  263. - rm -f $(DESTDIR)${mandir}/man1/cpupower-monitor.1
  264. - for HLANG in $(LANGUAGES); do \
  265. rm -f $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo; \
  266. done;
  267. .PHONY: all utils libcpupower update-po create-gmo install-lib install-tools install-man install-gmo install uninstall clean