Skip to content

Commit bf35182

Browse files
committed
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 <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent ca9dfc6 commit bf35182

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,10 +1321,12 @@ kernelversion:
13211321

13221322
# Clear a bunch of variables before executing the submake
13231323
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/
13251326

13261327
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/ $*
13281330

13291331
# Single targets
13301332
# ---------------------------------------------------------------------------

tools/scripts/Makefile.include

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
ifeq ("$(origin O)", "command line")
1+
ifeq ($(origin O), command line)
22
dummy := $(if $(shell test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
33
ABSOLUTE_O := $(shell cd $(O) ; pwd)
4-
OUTPUT := $(ABSOLUTE_O)/
4+
OUTPUT := $(ABSOLUTE_O)/$(if $(subdir),$(subdir)/)
55
COMMAND_O := O=$(ABSOLUTE_O)
6+
ifeq ($(objtree),)
7+
objtree := $(O)
8+
endif
69
endif
710

811
ifneq ($(OUTPUT),)
@@ -47,9 +50,10 @@ endif
4750
# Call by doing: $(call descend,directory[,target])
4851
#
4952
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)
5155

52-
QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir
56+
QUIET_SUBDIR0 = +$(MAKE) $(COMMAND_O) -C # space to separate -C and subdir
5357
QUIET_SUBDIR1 =
5458

5559
ifneq ($(findstring $(MAKEFLAGS),s),s)
@@ -64,5 +68,10 @@ ifndef V
6468
$(MAKE) $(PRINT_DIR) -C $$subdir
6569
QUIET_FLEX = @echo ' ' FLEX $@;
6670
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)
6776
endif
6877
endif

0 commit comments

Comments
 (0)