History

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.

David Howells committed 14 years ago

Commit bf351821 parent ca9dfc62 files · +17 −6Browse files

Showing the changes to tools/scripts/Makefile.include (1 of 2 files). Show all

Unified · Split

tools/scripts/Makefile.include+13−4
@@ -1,8 +1,11 @@
1ifeq ("$(origin O)", "command line")1ifeq ($(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)
6ifeq ($(objtree),)
7 objtree := $(O)
8endif
6endif9endif
7 10
8ifneq ($(OUTPUT),)11ifneq ($(OUTPUT),)
@@ -47,9 +50,10 @@ endif · 38 unmodified lines
47# Call by doing: $(call descend,directory[,target])50# Call by doing: $(call descend,directory[,target])
48#51#
49descend = \52descend = \
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
52QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir56QUIET_SUBDIR0 = +$(MAKE) $(COMMAND_O) -C # space to separate -C and subdir
53QUIET_SUBDIR1 =57QUIET_SUBDIR1 =
54 58
55ifneq ($(findstring $(MAKEFLAGS),s),s)59ifneq ($(findstring $(MAKEFLAGS),s),s)
@@ -64,5 +68,10 @@ ifndef V · 8 unmodified lines
64 $(MAKE) $(PRINT_DIR) -C $$subdir68 $(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)
67endif76endif
68endif77endif