Skip to contentSkip to conversation

Makefile: generate a Makefile wrapper in $(O)

PATCH New Yann E. MORIN 2 participants 3 messages Sep 21, 2010 – Sep 23, 2010 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Makefile: generate a Makefile wrapper in $(O)

If building out-of-tree, add a Makefile wrapper that calls-out to the real Makefile with proper args.

Avoids having to pass -C and O= every time we call make.

This is highly inspired from how the Linux kernel does it, and portions of it have been used.

---
 Makefile           |   18 +++++++++++++++-
 scripts/mkmakefile |   50 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 2 deletions(-)
Makefile +16 -2
index faa802b..ec425c6 100644
@@ -45,6 +45,7 @@ space:=$(empty) $(empty)
 ifneq ("$(origin O)", "command line")
 O:=output
 CONFIG_DIR:=$(TOPDIR)
+NEED_WRAPPER=
 else
 # other packages might also support Linux-style out of tree builds
 # with the O=<dir> syntax (E.G. Busybox does). As make automatically
@@ -60,6 +61,7 @@ override O:=$(O)
 CONFIG_DIR:=$(O)
 # we need to pass O= everywhere we call back into the toplevel makefile
 EXTRAMAKEARGS = O=$(O)
+NEED_WRAPPER=y
 endif
 
 # $(shell find . -name *_defconfig |sed 's/.*\///')
@@ -324,7 +326,7 @@ prepare: $(BUILD_DIR)/buildroot-config/auto.conf
 world: prepare dependencies dirs $(BASE_TARGETS) $(TARGETS_ALL)
 
 
-.PHONY: all world dirs clean distclean source \
+.PHONY: all world dirs clean distclean source outputmakefile \
 	$(BASE_TARGETS) $(TARGETS) $(TARGETS_ALL) \
 	$(TARGETS_CLEAN) $(TARGETS_DIRCLEAN) $(TARGETS_SOURCE) \
 	$(DL_DIR) $(TOOLCHAIN_DIR) $(BUILD_DIR) $(STAGING_DIR) $(TARGET_DIR) \
@@ -453,7 +455,7 @@ all: menuconfig
 HOSTCFLAGS=$(CFLAGS_FOR_BUILD)
 export HOSTCFLAGS
 
-$(BUILD_DIR)/buildroot-config/%onf:
+$(BUILD_DIR)/buildroot-config/%onf: |outputmakefile
 	mkdir -p $(@D)/lxdialog
 	$(MAKE) CC="$(HOSTCC)" obj=$(@D) -C $(CONFIG) -f Makefile.br $(@F)
 
@@ -559,6 +561,18 @@ endif # ifeq ($(BR2_HAVE_DOT_CONFIG),y)
 # Cleanup and misc junk
 #
 #############################################################
+
+ifeq ($(NEED_WRAPPER),y)
+# outputmakefile generates a Makefile in the output directory, if using a
+# separate output directory. This allows convenient use of make in the
+# output directory.
+outputmakefile:
+	$(Q)$(SHELL) $(TOPDIR)/scripts/mkmakefile $(CURDIR) $(O)
+else
+outputmakefile:
+	@true
+endif
+
 clean:
 	rm -rf $(STAGING_DIR) $(TARGET_DIR) $(BINARIES_DIR) $(HOST_DIR) \
 		$(STAMP_DIR) $(BUILD_DIR) $(TOOLCHAIN_DIR)
scripts/mkmakefile new file +50 -0

50 lines not on this page · raw message

Signature · 1 line
1.7.1
#1 lore raw

PATCH 1/1 Makefile: generate a Makefile wrapper in $(O)

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Yann" == Yann E MORIN <[email protected]> writes:

Yann> If building out-of-tree, add a Makefile wrapper that calls-out Yann> to the real Makefile with proper args.

Yann> Avoids having to pass -C and O= every time we call make.

Nice, looks good.

Yann> This is highly inspired from how the Linux kernel does it, and Yann> portions of it have been used.

Why only portions? Can't we use it all? That would make updating easier in the future. Related to this, mkmakefile got updated in the kernel back in August to support make 3.82, care to resync?

Signature · 1 line
Bye, Peter Korsgaard
#2 lore raw

PATCH 1/1 Makefile: generate a Makefile wrapper in $(O)

Peter, All,

Quoted 8 lines · On Thursday 23 September 2010 23:04:49 Peter Korsgaard wrote:

Yann> If building out-of-tree, add a Makefile wrapper that calls-out Yann> to the real Makefile with proper args.
Yann> Avoids having to pass -C and O= every time we call make. Yann> This is highly inspired from how the Linux kernel does it, and Yann> portions of it have been used.

Why only portions? Can't we use it all? That would make updating easier in the future.

Unfortunately, our 'out-of-tree' build in not similar to the one of the kernel. In fact, we always do out-of-tree in buildroot. Let me explain...

Let's assume that $(TOPDIR) is the directory that holds the top-level Makefile (of buildroot or the kernel).

In the Linux kernel, everything is output in $(O). The value of $(O) is by default $(TOPDIR), and they call that "in-tree build". When the user sets "O=blah" on the command line, then everything is put into that, and they call that "out-of-tree build".

Now, in buildroot, we always output everything in $(O). The value of $(O) is by default set to $(TOPDIR)/output, and we call that "in-tree build". When the user sets "O=blah" on the command line, then everything is put into that, and we call that "out-of-tree build".

See the slight difference in the "in-tree" case? That explains why I couldn't use the same construct in the top-level Makefile.

Then, I have updated the mkmakefile script to remove any kernel-related stuff. For example, we do not have a need for version and patchlevel, and we do not have a 'quiet' build (where commands are replaced with their beautified outputs, like CC foo/bar.o).

Next, in the Linux kernel, they always overwrite the wrapper Makefile at each run. Doing so in buildroot caused the kconfig stuff to be always rebuilt. So I added a check to only install the wrapper if its content changed since last time it was isntalled.

I hope this clarifies the reasons why I said "portions of it". Those "portions" would amount to 80-90% of this patch.

Quoted 2 lines

Related to this, mkmakefile got updated in the kernel back in August to support make 3.82, care to resync?

Will do, yes. Thanks for the review.

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'