]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
tools: Honour the O= flag when tool build called from a higher Makefile
authorDavid Howells <dhowells@redhat.com>
Mon, 5 Nov 2012 21:02:08 +0000 (21:02 +0000)
committerDavid Howells <dhowells@redhat.com>
Mon, 19 Nov 2012 22:10:30 +0000 (22:10 +0000)
Honour the O= flag that was passed to a higher level Makefile and then passed
down as part of a tool build.

To make this work, the top-level Makefile passes the original O= flag and
subdir=tools to the tools/Makefile, and that in turn passes
subdir=$(O)/$(subdir)/foodir when building tool foo in directory
$(O)/$(subdir)/foodir (where the intervening slashes aren't added if an
element is missing).

For example, take perf.  This is found in tools/perf/.  Assume we're building
into directory ~/zebra/, so we pass O=~/zebra to make.  Dependening on where
we run the build from, we see:

make run in dir $(OUTPUT) dir
======================= ==================
linux ~/zebra/tools/perf/
linux/tools ~/zebra/perf/
linux/tools/perf ~/zebra/

and if O= is not set, we get:

make run in dir $(OUTPUT) dir
======================= ==================
linux linux/tools/perf/
linux/tools linux/tools/perf/
linux/tools/perf linux/tools/perf/

The output directories are created by the descend function if they don't
already exist.

Signed-off-by: David Howells <dhowells@redhat.com>
Cc: Borislav Petkov <bp@amd64.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1378.1352379110@warthog.procyon.org.uk
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Makefile
tools/scripts/Makefile.include

index 42d0e56818ea8d5f9f7b713ca6b1ba7436dbf8b4..71dc31e41407926af9b88a048d6b04b006b683f9 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1321,10 +1321,12 @@ kernelversion:
 
 # Clear a bunch of variables before executing the submake
 tools/: FORCE
-       $(Q)$(MAKE) LDFLAGS= MAKEFLAGS= -C $(src)/tools/
+       $(Q)mkdir -p $(objtree)/tools
+       $(Q)$(MAKE) LDFLAGS= MAKEFLAGS= O=$(objtree) subdir=tools -C $(src)/tools/
 
 tools/%: FORCE
-       $(Q)$(MAKE) LDFLAGS= MAKEFLAGS= -C $(src)/tools/ $*
+       $(Q)mkdir -p $(objtree)/tools
+       $(Q)$(MAKE) LDFLAGS= MAKEFLAGS= O=$(objtree) subdir=tools -C $(src)/tools/ $*
 
 # Single targets
 # ---------------------------------------------------------------------------
index 4a9e3176f7437bebd37eabf82e65e0abcc3cbda8..87467b17e05c3d0ec6c317450f92278a53af8b65 100644 (file)
@@ -1,8 +1,11 @@
-ifeq ("$(origin O)", "command line")
+ifeq ($(origin O), command line)
        dummy := $(if $(shell test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
        ABSOLUTE_O := $(shell cd $(O) ; pwd)
-       OUTPUT := $(ABSOLUTE_O)/
+       OUTPUT := $(ABSOLUTE_O)/$(if $(subdir),$(subdir)/)
        COMMAND_O := O=$(ABSOLUTE_O)
+ifeq ($(objtree),)
+       objtree := $(O)
+endif
 endif
 
 ifneq ($(OUTPUT),)
@@ -47,9 +50,10 @@ endif
 # Call by doing: $(call descend,directory[,target])
 #
 descend = \
-       $(QUIET_SUBDIR0)$(1) $(QUIET_SUBDIR1) $(2)
+       +mkdir -p $(OUTPUT)$(1) && \
+       $(MAKE) $(COMMAND_O) subdir=$(if $(subdir),$(subdir)/$(1),$(1)) $(PRINT_DIR) -C $(1)
 
-QUIET_SUBDIR0  = +$(MAKE) -C # space to separate -C and subdir
+QUIET_SUBDIR0  = +$(MAKE) $(COMMAND_O) -C # space to separate -C and subdir
 QUIET_SUBDIR1  =
 
 ifneq ($(findstring $(MAKEFLAGS),s),s)
@@ -64,5 +68,10 @@ ifndef V
                         $(MAKE) $(PRINT_DIR) -C $$subdir
        QUIET_FLEX     = @echo '   ' FLEX $@;
        QUIET_BISON    = @echo '   ' BISON $@;
+
+       descend = \
+               @echo '   ' DESCEND $(1); \
+               mkdir -p $(OUTPUT)$(1) && \
+               $(MAKE) $(COMMAND_O) subdir=$(if $(subdir),$(subdir)/$(1),$(1)) $(PRINT_DIR) -C $(1)
 endif
 endif