diff options
author | David Howells <dhowells@redhat.com> | 2012-11-05 16:02:08 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-11-14 14:53:22 -0500 |
commit | 9db48cd5ccd0d127e991c15509a0241a18043e91 (patch) | |
tree | 6955e5c1fdfcd8961a638982cc517aa281147564 | |
parent | 0bca6cff89c6e7d1e383993cccf0f59146874a34 (diff) |
tools: Honour the O= flag when tool build called from a higher Makefile
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>
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | tools/scripts/Makefile.include | 17 |
2 files changed, 17 insertions, 6 deletions
@@ -1321,10 +1321,12 @@ kernelversion: | |||
1321 | 1321 | ||
1322 | # Clear a bunch of variables before executing the submake | 1322 | # Clear a bunch of variables before executing the submake |
1323 | tools/: FORCE | 1323 | tools/: FORCE |
1324 | $(Q)$(MAKE) LDFLAGS= MAKEFLAGS= -C $(src)/tools/ | 1324 | $(Q)mkdir -p $(objtree)/tools |
1325 | $(Q)$(MAKE) LDFLAGS= MAKEFLAGS= O=$(objtree) subdir=tools -C $(src)/tools/ | ||
1325 | 1326 | ||
1326 | tools/%: FORCE | 1327 | tools/%: FORCE |
1327 | $(Q)$(MAKE) LDFLAGS= MAKEFLAGS= -C $(src)/tools/ $* | 1328 | $(Q)mkdir -p $(objtree)/tools |
1329 | $(Q)$(MAKE) LDFLAGS= MAKEFLAGS= O=$(objtree) subdir=tools -C $(src)/tools/ $* | ||
1328 | 1330 | ||
1329 | # Single targets | 1331 | # Single targets |
1330 | # --------------------------------------------------------------------------- | 1332 | # --------------------------------------------------------------------------- |
diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include index 4a9e3176f743..87467b17e05c 100644 --- a/tools/scripts/Makefile.include +++ b/tools/scripts/Makefile.include | |||
@@ -1,8 +1,11 @@ | |||
1 | ifeq ("$(origin O)", "command line") | 1 | ifeq ($(origin O), command line) |
2 | dummy := $(if $(shell test -d $(O) || echo $(O)),$(error O=$(O) does not exist),) | 2 | dummy := $(if $(shell test -d $(O) || echo $(O)),$(error O=$(O) does not exist),) |
3 | ABSOLUTE_O := $(shell cd $(O) ; pwd) | 3 | ABSOLUTE_O := $(shell cd $(O) ; pwd) |
4 | OUTPUT := $(ABSOLUTE_O)/ | 4 | OUTPUT := $(ABSOLUTE_O)/$(if $(subdir),$(subdir)/) |
5 | COMMAND_O := O=$(ABSOLUTE_O) | 5 | COMMAND_O := O=$(ABSOLUTE_O) |
6 | ifeq ($(objtree),) | ||
7 | objtree := $(O) | ||
8 | endif | ||
6 | endif | 9 | endif |
7 | 10 | ||
8 | ifneq ($(OUTPUT),) | 11 | ifneq ($(OUTPUT),) |
@@ -47,9 +50,10 @@ endif | |||
47 | # Call by doing: $(call descend,directory[,target]) | 50 | # Call by doing: $(call descend,directory[,target]) |
48 | # | 51 | # |
49 | descend = \ | 52 | descend = \ |
50 | $(QUIET_SUBDIR0)$(1) $(QUIET_SUBDIR1) $(2) | 53 | +mkdir -p $(OUTPUT)$(1) && \ |
54 | $(MAKE) $(COMMAND_O) subdir=$(if $(subdir),$(subdir)/$(1),$(1)) $(PRINT_DIR) -C $(1) | ||
51 | 55 | ||
52 | QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir | 56 | QUIET_SUBDIR0 = +$(MAKE) $(COMMAND_O) -C # space to separate -C and subdir |
53 | QUIET_SUBDIR1 = | 57 | QUIET_SUBDIR1 = |
54 | 58 | ||
55 | ifneq ($(findstring $(MAKEFLAGS),s),s) | 59 | ifneq ($(findstring $(MAKEFLAGS),s),s) |
@@ -64,5 +68,10 @@ ifndef V | |||
64 | $(MAKE) $(PRINT_DIR) -C $$subdir | 68 | $(MAKE) $(PRINT_DIR) -C $$subdir |
65 | QUIET_FLEX = @echo ' ' FLEX $@; | 69 | QUIET_FLEX = @echo ' ' FLEX $@; |
66 | QUIET_BISON = @echo ' ' BISON $@; | 70 | QUIET_BISON = @echo ' ' BISON $@; |
71 | |||
72 | descend = \ | ||
73 | @echo ' ' DESCEND $(1); \ | ||
74 | mkdir -p $(OUTPUT)$(1) && \ | ||
75 | $(MAKE) $(COMMAND_O) subdir=$(if $(subdir),$(subdir)/$(1),$(1)) $(PRINT_DIR) -C $(1) | ||
67 | endif | 76 | endif |
68 | endif | 77 | endif |