Makefile 11 KB

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