Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cpupower tool: allow to build in a separate directory

This patch allows cpupower tool to generate its output files in a
seperate directory. This is now possible by passing the 'O=<path>' to
the command line.

This can be usefull for a normal user if the kernel source code is
located in a read only location.

This is patch stole some bits of the perf makefile.

[linux@dominikbrodowski.net: fix commit message]
Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>

authored by

Franck Bui-Huu and committed by
Dominik Brodowski
68bb2c3a 38271504

+71 -39
+56 -31
tools/power/cpupower/Makefile
··· 19 19 # along with this program; if not, write to the Free Software 20 20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 21 # 22 + OUTPUT=./ 23 + ifeq ("$(origin O)", "command line") 24 + OUTPUT := $(O)/ 25 + endif 26 + 27 + ifneq ($(OUTPUT),) 28 + # check that the output directory actually exists 29 + OUTDIR := $(shell cd $(OUTPUT) && /bin/pwd) 30 + $(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist)) 31 + endif 22 32 23 33 # --- CONFIGURATION BEGIN --- 24 34 ··· 97 87 STRIP = $(CROSS)strip 98 88 RANLIB = $(CROSS)ranlib 99 89 HOSTCC = gcc 90 + MKDIR = mkdir 100 91 101 92 102 93 # Now we set up the build system ··· 106 95 # set up PWD so that older versions of make will work with our build. 107 96 PWD = $(shell pwd) 108 97 109 - GMO_FILES = ${shell for HLANG in ${LANGUAGES}; do echo po/$$HLANG.gmo; done;} 98 + GMO_FILES = ${shell for HLANG in ${LANGUAGES}; do echo $(OUTPUT)po/$$HLANG.gmo; done;} 110 99 111 100 export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS 112 101 ··· 133 122 utils/cpupower.o utils/cpufreq-info.o utils/cpufreq-set.o \ 134 123 utils/cpupower-set.o utils/cpupower-info.o utils/cpuidle-info.o 135 124 125 + UTIL_SRC := $(UTIL_OBJS:.o=.c) 126 + 127 + UTIL_OBJS := $(addprefix $(OUTPUT),$(UTIL_OBJS)) 128 + 136 129 UTIL_HEADERS = utils/helpers/helpers.h utils/idle_monitor/cpupower-monitor.h \ 137 130 utils/helpers/bitmask.h \ 138 131 utils/idle_monitor/idle_monitors.h utils/idle_monitor/idle_monitors.def 139 132 140 - UTIL_SRC := $(UTIL_OBJS:.o=.c) 141 - 142 133 LIB_HEADERS = lib/cpufreq.h lib/sysfs.h 143 134 LIB_SRC = lib/cpufreq.c lib/sysfs.c 144 135 LIB_OBJS = lib/cpufreq.o lib/sysfs.o 136 + LIB_OBJS := $(addprefix $(OUTPUT),$(LIB_OBJS)) 145 137 146 138 CFLAGS += -pipe 147 139 ··· 182 168 183 169 # the actual make rules 184 170 185 - all: libcpupower cpupower $(COMPILE_NLS) $(COMPILE_BENCH) 171 + all: libcpupower $(OUTPUT)cpupower $(COMPILE_NLS) $(COMPILE_BENCH) 186 172 187 - lib/%.o: $(LIB_SRC) $(LIB_HEADERS) 173 + $(OUTPUT)lib/%.o: $(LIB_SRC) $(LIB_HEADERS) 188 174 $(ECHO) " CC " $@ 189 175 $(QUIET) $(CC) $(CFLAGS) -fPIC -o $@ -c lib/$*.c 190 176 191 - libcpupower.so.$(LIB_MAJ): $(LIB_OBJS) 177 + $(OUTPUT)libcpupower.so.$(LIB_MAJ): $(LIB_OBJS) 192 178 $(ECHO) " LD " $@ 193 179 $(QUIET) $(CC) -shared $(CFLAGS) $(LDFLAGS) -o $@ \ 194 180 -Wl,-soname,libcpupower.so.$(LIB_MIN) $(LIB_OBJS) 195 - @ln -sf $@ libcpupower.so 196 - @ln -sf $@ libcpupower.so.$(LIB_MIN) 181 + @ln -sf $(@F) $(OUTPUT)libcpupower.so 182 + @ln -sf $(@F) $(OUTPUT)libcpupower.so.$(LIB_MIN) 197 183 198 - libcpupower: libcpupower.so.$(LIB_MAJ) 184 + libcpupower: $(OUTPUT)libcpupower.so.$(LIB_MAJ) 199 185 200 186 # Let all .o files depend on its .c file and all headers 201 187 # Might be worth to put this into utils/Makefile at some point of time 202 188 $(UTIL_OBJS): $(UTIL_HEADERS) 203 189 204 - .c.o: 190 + $(OUTPUT)%.o: %.c 205 191 $(ECHO) " CC " $@ 206 192 $(QUIET) $(CC) $(CFLAGS) -I./lib -I ./utils -o $@ -c $*.c 207 193 208 - cpupower: $(UTIL_OBJS) libcpupower.so.$(LIB_MAJ) 194 + $(OUTPUT)cpupower: $(UTIL_OBJS) $(OUTPUT)libcpupower.so.$(LIB_MAJ) 209 195 $(ECHO) " CC " $@ 210 - $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) $(UTIL_OBJS) -lcpupower -lrt -lpci -L. -o $@ 196 + $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) $(UTIL_OBJS) -lcpupower -lrt -lpci -L$(OUTPUT) -o $@ 211 197 $(QUIET) $(STRIPCMD) $@ 212 198 213 - po/$(PACKAGE).pot: $(UTIL_SRC) 199 + $(OUTPUT)po/$(PACKAGE).pot: $(UTIL_SRC) 214 200 $(ECHO) " GETTEXT " $@ 215 201 $(QUIET) xgettext --default-domain=$(PACKAGE) --add-comments \ 216 202 --keyword=_ --keyword=N_ $(UTIL_SRC) -p $(@D) -o $(@F) 217 203 218 - po/%.gmo: po/%.po 204 + $(OUTPUT)po/%.gmo: po/%.po 219 205 $(ECHO) " MSGFMT " $@ 220 206 $(QUIET) msgfmt -o $@ po/$*.po 221 207 222 208 create-gmo: ${GMO_FILES} 223 209 224 - update-po: po/$(PACKAGE).pot 210 + update-po: $(OUTPUT)po/$(PACKAGE).pot 225 211 $(ECHO) " MSGMRG " $@ 226 212 $(QUIET) @for HLANG in $(LANGUAGES); do \ 227 213 echo -n "Updating $$HLANG "; \ 228 - if msgmerge po/$$HLANG.po po/$(PACKAGE).pot -o \ 229 - po/$$HLANG.new.po; then \ 230 - mv -f po/$$HLANG.new.po po/$$HLANG.po; \ 214 + if msgmerge po/$$HLANG.po $< -o \ 215 + $(OUTPUT)po/$$HLANG.new.po; then \ 216 + mv -f $(OUTPUT)po/$$HLANG.new.po $(OUTPUT)po/$$HLANG.po; \ 231 217 else \ 232 218 echo "msgmerge for $$HLANG failed!"; \ 233 - rm -f po/$$HLANG.new.po; \ 219 + rm -f $(OUTPUT)po/$$HLANG.new.po; \ 234 220 fi; \ 235 221 done; 236 222 237 - compile-bench: libcpupower.so.$(LIB_MAJ) 238 - @V=$(V) confdir=$(confdir) $(MAKE) -C bench 223 + compile-bench: $(OUTPUT)libcpupower.so.$(LIB_MAJ) 224 + @V=$(V) confdir=$(confdir) $(MAKE) -C bench O=$(OUTPUT) 225 + 226 + # we compile into subdirectories. if the target directory is not the 227 + # source directory, they might not exists. So we depend the various 228 + # files onto their directories. 229 + DIRECTORY_DEPS = $(LIB_OBJS) $(UTIL_OBJS) $(GMO_FILES) 230 + $(DIRECTORY_DEPS): | $(sort $(dir $(DIRECTORY_DEPS))) 231 + 232 + # In the second step, we make a rule to actually create these directories 233 + $(sort $(dir $(DIRECTORY_DEPS))): 234 + $(ECHO) " MKDIR " $@ 235 + $(QUIET) $(MKDIR) -p $@ 2>/dev/null 239 236 240 237 clean: 241 - -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \ 238 + -find $(OUTPUT) \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \ 242 239 | xargs rm -f 243 - -rm -f cpupower 244 - -rm -f libcpupower.so* 245 - -rm -rf po/*.gmo po/*.pot 246 - $(MAKE) -C bench clean 240 + -rm -f $(OUTPUT)cpupower 241 + -rm -f $(OUTPUT)libcpupower.so* 242 + -rm -rf $(OUTPUT)po/*.{gmo,pot} 243 + $(MAKE) -C bench O=$(OUTPUT) clean 247 244 248 245 249 246 install-lib: 250 247 $(INSTALL) -d $(DESTDIR)${libdir} 251 - $(CP) libcpupower.so* $(DESTDIR)${libdir}/ 248 + $(CP) $(OUTPUT)libcpupower.so* $(DESTDIR)${libdir}/ 252 249 $(INSTALL) -d $(DESTDIR)${includedir} 253 250 $(INSTALL_DATA) lib/cpufreq.h $(DESTDIR)${includedir}/cpufreq.h 254 251 255 252 install-tools: 256 253 $(INSTALL) -d $(DESTDIR)${bindir} 257 - $(INSTALL_PROGRAM) cpupower $(DESTDIR)${bindir} 254 + $(INSTALL_PROGRAM) $(OUTPUT)cpupower $(DESTDIR)${bindir} 258 255 259 256 install-man: 260 257 $(INSTALL_DATA) -D man/cpupower.1 $(DESTDIR)${mandir}/man1/cpupower.1 ··· 278 253 install-gmo: 279 254 $(INSTALL) -d $(DESTDIR)${localedir} 280 255 for HLANG in $(LANGUAGES); do \ 281 - echo '$(INSTALL_DATA) -D po/$$HLANG.gmo $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo'; \ 282 - $(INSTALL_DATA) -D po/$$HLANG.gmo $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo; \ 256 + echo '$(INSTALL_DATA) -D $(OUTPUT)po/$$HLANG.gmo $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo'; \ 257 + $(INSTALL_DATA) -D $(OUTPUT)po/$$HLANG.gmo $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo; \ 283 258 done; 284 259 285 260 install-bench: 286 261 @#DESTDIR must be set from outside to survive 287 - @sbindir=$(sbindir) bindir=$(bindir) docdir=$(docdir) confdir=$(confdir) $(MAKE) -C bench install 262 + @sbindir=$(sbindir) bindir=$(bindir) docdir=$(docdir) confdir=$(confdir) $(MAKE) -C bench O=$(OUTPUT) install 288 263 289 264 install: all install-lib install-tools install-man $(INSTALL_NLS) $(INSTALL_BENCH) 290 265
+15 -8
tools/power/cpupower/bench/Makefile
··· 1 - LIBS = -L../ -lm -lcpupower 1 + OUTPUT := ./ 2 + ifeq ("$(origin O)", "command line") 3 + ifneq ($(O),) 4 + OUTPUT := $(O)/ 5 + endif 6 + endif 2 7 3 - OBJS = main.o parse.o system.o benchmark.o 8 + LIBS = -L../ -L$(OUTPUT) -lm -lcpupower 9 + 10 + OBJS = $(OUTPUT)main.o $(OUTPUT)parse.o $(OUTPUT)system.o $(OUTPUT)benchmark.o 4 11 CFLAGS += -D_GNU_SOURCE -I../lib -DDEFAULT_CONFIG_FILE=\"$(confdir)/cpufreq-bench.conf\" 5 12 6 - %.o : %.c 13 + $(OUTPUT)%.o : %.c 7 14 $(ECHO) " CC " $@ 8 15 $(QUIET) $(CC) -c $(CFLAGS) $< -o $@ 9 16 10 - cpufreq-bench: $(OBJS) 17 + $(OUTPUT)cpufreq-bench: $(OBJS) 11 18 $(ECHO) " CC " $@ 12 19 $(QUIET) $(CC) -o $@ $(CFLAGS) $(OBJS) $(LIBS) 13 20 14 - all: cpufreq-bench 21 + all: $(OUTPUT)cpufreq-bench 15 22 16 23 install: 17 24 mkdir -p $(DESTDIR)/$(sbindir) 18 25 mkdir -p $(DESTDIR)/$(bindir) 19 26 mkdir -p $(DESTDIR)/$(docdir) 20 27 mkdir -p $(DESTDIR)/$(confdir) 21 - install -m 755 cpufreq-bench $(DESTDIR)/$(sbindir)/cpufreq-bench 28 + install -m 755 $(OUTPUT)cpufreq-bench $(DESTDIR)/$(sbindir)/cpufreq-bench 22 29 install -m 755 cpufreq-bench_plot.sh $(DESTDIR)/$(bindir)/cpufreq-bench_plot.sh 23 30 install -m 644 README-BENCH $(DESTDIR)/$(docdir)/README-BENCH 24 31 install -m 755 cpufreq-bench_script.sh $(DESTDIR)/$(docdir)/cpufreq-bench_script.sh 25 32 install -m 644 example.cfg $(DESTDIR)/$(confdir)/cpufreq-bench.conf 26 33 27 34 clean: 28 - rm -f *.o 29 - rm -f cpufreq-bench 35 + rm -f $(OUTPUT)*.o 36 + rm -f $(OUTPUT)cpufreq-bench