Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 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 | |
| 23 | # --- CONFIGURATION BEGIN --- |
| 24 | |
| 25 | # Set the following to `true' to make a unstripped, unoptimized |
| 26 | # binary. Leave this set to `false' for production use. |
Dominik Brodowski | 7443af9 | 2011-04-19 09:03:52 +0200 | [diff] [blame] | 27 | DEBUG ?= false |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 28 | |
| 29 | # make the build silent. Set this to something else to make it noisy again. |
| 30 | V ?= false |
| 31 | |
| 32 | # Internationalization support (output in different languages). |
| 33 | # Requires gettext. |
| 34 | NLS ?= true |
| 35 | |
| 36 | # Set the following to 'true' to build/install the |
| 37 | # cpufreq-bench benchmarking tool |
| 38 | CPUFRQ_BENCH ?= true |
| 39 | |
| 40 | # Prefix to the directories we're installing to |
Dominik Brodowski | 02af3cb | 2011-04-19 19:20:12 +0200 | [diff] [blame^] | 41 | DESTDIR ?= |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 42 | |
| 43 | # --- CONFIGURATION END --- |
| 44 | |
| 45 | |
| 46 | |
| 47 | # Package-related definitions. Distributions can modify the version |
| 48 | # and _should_ modify the PACKAGE_BUGREPORT definition |
| 49 | |
| 50 | VERSION = 009p1 |
| 51 | LIB_MAJ= 0.0.0 |
| 52 | LIB_MIN= 0 |
| 53 | |
| 54 | PACKAGE = cpupowerutils |
| 55 | PACKAGE_BUGREPORT = cpufreq@vger.kernel.org |
| 56 | LANGUAGES = de fr it cs pt |
| 57 | |
| 58 | |
| 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 | |
| 63 | bindir ?= /usr/bin |
| 64 | sbindir ?= /usr/sbin |
| 65 | mandir ?= /usr/man |
| 66 | includedir ?= /usr/include |
| 67 | libdir ?= /usr/lib |
| 68 | localedir ?= /usr/share/locale |
| 69 | docdir ?= /usr/share/doc/packages/cpupowerutils |
| 70 | confdir ?= /etc/ |
| 71 | |
| 72 | # Toolchain: what tools do we use, and what options do they need: |
| 73 | |
| 74 | CP = cp -fpR |
| 75 | INSTALL = /usr/bin/install -c |
| 76 | INSTALL_PROGRAM = ${INSTALL} |
| 77 | INSTALL_DATA = ${INSTALL} -m 644 |
| 78 | INSTALL_SCRIPT = ${INSTALL_PROGRAM} |
| 79 | |
| 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 | |
| 91 | |
| 92 | # Now we set up the build system |
| 93 | # |
| 94 | |
| 95 | # set up PWD so that older versions of make will work with our build. |
| 96 | PWD = $(shell pwd) |
| 97 | |
Dominik Brodowski | f5ac064 | 2011-04-19 18:52:44 +0200 | [diff] [blame] | 98 | GMO_FILES = ${shell for HLANG in ${LANGUAGES}; do echo po/$$HLANG.gmo; done;} |
| 99 | |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 100 | export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS |
| 101 | |
| 102 | # check if compiler option is supported |
| 103 | cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;} |
| 104 | |
| 105 | # use '-Os' optimization if available, else use -O2 |
| 106 | OPTIMIZATION := $(call cc-supports,-Os,-O2) |
| 107 | |
| 108 | WARNINGS := -Wall -Wchar-subscripts -Wpointer-arith -Wsign-compare |
| 109 | WARNINGS += $(call cc-supports,-Wno-pointer-sign) |
| 110 | WARNINGS += $(call cc-supports,-Wdeclaration-after-statement) |
| 111 | WARNINGS += -Wshadow |
| 112 | |
| 113 | CPPFLAGS += -DVERSION=\"$(VERSION)\" -DPACKAGE=\"$(PACKAGE)\" \ |
| 114 | -DPACKAGE_BUGREPORT=\"$(PACKAGE_BUGREPORT)\" -D_GNU_SOURCE |
| 115 | |
| 116 | UTIL_OBJS = utils/helpers/amd.o utils/helpers/topology.o utils/helpers/msr.o \ |
| 117 | utils/helpers/sysfs.o utils/helpers/misc.o utils/helpers/cpuid.o \ |
| 118 | utils/helpers/pci.o utils/helpers/bitmask.o \ |
| 119 | utils/idle_monitor/nhm_idle.o utils/idle_monitor/snb_idle.o \ |
| 120 | utils/idle_monitor/amd_fam14h_idle.o utils/idle_monitor/cpuidle_sysfs.o \ |
| 121 | utils/idle_monitor/mperf_monitor.o utils/idle_monitor/cpupower-monitor.o \ |
| 122 | utils/cpupower.o utils/cpufreq-info.o utils/cpufreq-set.o \ |
| 123 | utils/cpupower-set.o utils/cpupower-info.o utils/cpuidle-info.o |
| 124 | |
| 125 | UTIL_HEADERS = utils/helpers/helpers.h utils/idle_monitor/cpupower-monitor.h \ |
| 126 | utils/helpers/bitmask.h \ |
| 127 | utils/idle_monitor/idle_monitors.h utils/idle_monitor/idle_monitors.def |
| 128 | |
| 129 | UTIL_SRC := $(UTIL_OBJS:.o=.c) |
| 130 | |
| 131 | LIB_HEADERS = lib/cpufreq.h lib/sysfs.h |
| 132 | LIB_SRC = lib/cpufreq.c lib/sysfs.c |
| 133 | LIB_OBJS = lib/cpufreq.o lib/sysfs.o |
| 134 | |
| 135 | CFLAGS += -pipe |
| 136 | |
| 137 | ifeq ($(strip $(NLS)),true) |
| 138 | INSTALL_NLS += install-gmo |
Dominik Brodowski | f5ac064 | 2011-04-19 18:52:44 +0200 | [diff] [blame] | 139 | COMPILE_NLS += create-gmo |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 140 | endif |
| 141 | |
| 142 | ifeq ($(strip $(CPUFRQ_BENCH)),true) |
| 143 | INSTALL_BENCH += install-bench |
| 144 | COMPILE_BENCH += compile-bench |
| 145 | endif |
| 146 | |
| 147 | CFLAGS += $(WARNINGS) |
| 148 | |
| 149 | ifeq ($(strip $(V)),false) |
Dominik Brodowski | 7443af9 | 2011-04-19 09:03:52 +0200 | [diff] [blame] | 150 | QUIET=@ |
| 151 | ECHO=@echo |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 152 | else |
| 153 | QUIET= |
Dominik Brodowski | 7443af9 | 2011-04-19 09:03:52 +0200 | [diff] [blame] | 154 | ECHO=@\# |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 155 | endif |
Dominik Brodowski | 7443af9 | 2011-04-19 09:03:52 +0200 | [diff] [blame] | 156 | export QUIET ECHO |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 157 | |
| 158 | # if DEBUG is enabled, then we do not strip or optimize |
| 159 | ifeq ($(strip $(DEBUG)),true) |
| 160 | CFLAGS += -O1 -g |
| 161 | CPPFLAGS += -DDEBUG |
| 162 | STRIPCMD = /bin/true -Since_we_are_debugging |
| 163 | else |
| 164 | CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer |
| 165 | STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment |
| 166 | endif |
| 167 | |
| 168 | |
| 169 | # the actual make rules |
| 170 | |
Dominik Brodowski | 7443af9 | 2011-04-19 09:03:52 +0200 | [diff] [blame] | 171 | all: libcpufreq cpupower $(COMPILE_NLS) $(COMPILE_BENCH) |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 172 | |
Dominik Brodowski | 7443af9 | 2011-04-19 09:03:52 +0200 | [diff] [blame] | 173 | lib/%.o: $(LIB_SRC) $(LIB_HEADERS) |
| 174 | $(ECHO) " CC " $@ |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 175 | $(QUIET) $(CC) $(CPPFLAGS) $(CFLAGS) -fPIC -o $@ -c lib/$*.c |
| 176 | |
| 177 | libcpufreq.so.$(LIB_MAJ): $(LIB_OBJS) |
Dominik Brodowski | 7443af9 | 2011-04-19 09:03:52 +0200 | [diff] [blame] | 178 | $(ECHO) " LD " $@ |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 179 | $(QUIET) $(CC) -shared $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \ |
| 180 | -Wl,-soname,libcpufreq.so.$(LIB_MIN) $(LIB_OBJS) |
| 181 | @ln -sf $@ libcpufreq.so |
| 182 | @ln -sf $@ libcpufreq.so.$(LIB_MIN) |
| 183 | |
| 184 | libcpufreq: libcpufreq.so.$(LIB_MAJ) |
| 185 | |
| 186 | # Let all .o files depend on its .c file and all headers |
| 187 | # Might be worth to put this into utils/Makefile at some point of time |
| 188 | $(UTIL_OBJS): $(UTIL_HEADERS) |
| 189 | |
| 190 | .c.o: |
Dominik Brodowski | 7443af9 | 2011-04-19 09:03:52 +0200 | [diff] [blame] | 191 | $(ECHO) " CC " $@ |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 192 | $(QUIET) $(CC) $(CFLAGS) $(CPPFLAGS) -I./lib -I ./utils -o $@ -c $*.c |
| 193 | |
Dominik Brodowski | 7443af9 | 2011-04-19 09:03:52 +0200 | [diff] [blame] | 194 | cpupower: $(UTIL_OBJS) libcpufreq.so.$(LIB_MAJ) |
| 195 | $(ECHO) " CC " $@ |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 196 | $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) -lcpufreq -lrt -lpci -L. -o $@ $(UTIL_OBJS) |
Dominik Brodowski | 7443af9 | 2011-04-19 09:03:52 +0200 | [diff] [blame] | 197 | $(QUIET) $(STRIPCMD) $@ |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 198 | |
| 199 | po/$(PACKAGE).pot: $(UTIL_SRC) |
Dominik Brodowski | f5ac064 | 2011-04-19 18:52:44 +0200 | [diff] [blame] | 200 | $(ECHO) " GETTEXT " $@ |
| 201 | $(QUIET) xgettext --default-domain=$(PACKAGE) --add-comments \ |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 202 | --keyword=_ --keyword=N_ $(UTIL_SRC) && \ |
| 203 | test -f $(PACKAGE).po && \ |
| 204 | mv -f $(PACKAGE).po po/$(PACKAGE).pot |
| 205 | |
Dominik Brodowski | f5ac064 | 2011-04-19 18:52:44 +0200 | [diff] [blame] | 206 | po/%.gmo: po/%.po |
| 207 | $(ECHO) " MSGFMT " $@ |
| 208 | $(QUIET) msgfmt -o $@ po/$*.po |
| 209 | |
| 210 | create-gmo: ${GMO_FILES} |
| 211 | |
| 212 | update-po: po/$(PACKAGE).pot |
| 213 | $(ECHO) " MSGMRG " $@ |
| 214 | $(QUIET) @for HLANG in $(LANGUAGES); do \ |
| 215 | echo -n "Updating $$HLANG "; \ |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 216 | if msgmerge po/$$HLANG.po po/$(PACKAGE).pot -o \ |
| 217 | po/$$HLANG.new.po; then \ |
| 218 | mv -f po/$$HLANG.new.po po/$$HLANG.po; \ |
| 219 | else \ |
| 220 | echo "msgmerge for $$HLANG failed!"; \ |
| 221 | rm -f po/$$HLANG.new.po; \ |
| 222 | fi; \ |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 223 | done; |
| 224 | |
| 225 | compile-bench: libcpufreq.so.$(LIB_MAJ) |
| 226 | @V=$(V) confdir=$(confdir) $(MAKE) -C bench |
| 227 | |
| 228 | clean: |
| 229 | -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \ |
| 230 | | xargs rm -f |
| 231 | -rm -f $(UTIL_BINS) |
| 232 | -rm -f $(IDLE_OBJS) |
| 233 | -rm -f cpupower |
| 234 | -rm -f libcpufreq.so* |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 235 | -rm -rf po/*.gmo po/*.pot |
| 236 | $(MAKE) -C bench clean |
| 237 | |
| 238 | |
| 239 | install-lib: |
| 240 | $(INSTALL) -d $(DESTDIR)${libdir} |
| 241 | $(CP) libcpufreq.so* $(DESTDIR)${libdir}/ |
| 242 | $(INSTALL) -d $(DESTDIR)${includedir} |
| 243 | $(INSTALL_DATA) lib/cpufreq.h $(DESTDIR)${includedir}/cpufreq.h |
| 244 | |
| 245 | install-tools: |
| 246 | $(INSTALL) -d $(DESTDIR)${bindir} |
| 247 | $(INSTALL_PROGRAM) cpupower $(DESTDIR)${bindir} |
| 248 | |
| 249 | install-man: |
| 250 | $(INSTALL_DATA) -D man/cpupower.1 $(DESTDIR)${mandir}/man1/cpupower.1 |
| 251 | $(INSTALL_DATA) -D man/cpupower-frequency-set.1 $(DESTDIR)${mandir}/man1/cpupower-frequency-set.1 |
| 252 | $(INSTALL_DATA) -D man/cpupower-frequency-info.1 $(DESTDIR)${mandir}/man1/cpupower-frequency-info.1 |
| 253 | $(INSTALL_DATA) -D man/cpupower-set.1 $(DESTDIR)${mandir}/man1/cpupower-set.1 |
| 254 | $(INSTALL_DATA) -D man/cpupower-info.1 $(DESTDIR)${mandir}/man1/cpupower-info.1 |
| 255 | $(INSTALL_DATA) -D man/cpupower-monitor.1 $(DESTDIR)${mandir}/man1/cpupower-monitor.1 |
| 256 | |
| 257 | install-gmo: |
| 258 | $(INSTALL) -d $(DESTDIR)${localedir} |
| 259 | for HLANG in $(LANGUAGES); do \ |
| 260 | echo '$(INSTALL_DATA) -D po/$$HLANG.gmo $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupowerutils.mo'; \ |
| 261 | $(INSTALL_DATA) -D po/$$HLANG.gmo $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupowerutils.mo; \ |
| 262 | done; |
| 263 | |
| 264 | install-bench: |
| 265 | @#DESTDIR must be set from outside to survive |
| 266 | @sbindir=$(sbindir) bindir=$(bindir) docdir=$(docdir) confdir=$(confdir) $(MAKE) -C bench install |
Dominik Brodowski | 7443af9 | 2011-04-19 09:03:52 +0200 | [diff] [blame] | 267 | |
Dominik Brodowski | 7fe2f63 | 2011-03-30 16:30:11 +0200 | [diff] [blame] | 268 | install: all install-lib install-tools install-man $(INSTALL_NLS) $(INSTALL_BENCH) |
| 269 | |
| 270 | uninstall: |
| 271 | - rm -f $(DESTDIR)${libdir}/libcpufreq.* |
| 272 | - rm -f $(DESTDIR)${includedir}/cpufreq.h |
| 273 | - rm -f $(DESTDIR)${bindir}/utils/cpupower |
| 274 | - rm -f $(DESTDIR)${mandir}/man1/cpufreq-set.1 |
| 275 | - rm -f $(DESTDIR)${mandir}/man1/cpufreq-info.1 |
| 276 | - for HLANG in $(LANGUAGES); do \ |
| 277 | rm -f $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupowerutils.mo; \ |
| 278 | done; |
| 279 | |
Dominik Brodowski | 02af3cb | 2011-04-19 19:20:12 +0200 | [diff] [blame^] | 280 | .PHONY: all utils libcpufreq update-po create-gmo install-lib install-tools install-man install-gmo install uninstall clean |