Makefile 8.4 KB

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