All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] Makefile: add a Makefile wrapper in the $(O) dir - closes #2389
@ 2010-09-12 21:58 Yann E. MORIN
  0 siblings, 0 replies; only message in thread
From: Yann E. MORIN @ 2010-09-12 21:58 UTC (permalink / raw)
  To: buildroot

From: Yann E. MORIN <yann.morin.1998@anciens.enib.fr>

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.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
---
 Makefile           |   18 ++++++++++++++++--
 scripts/mkmakefile |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 2 deletions(-)
 create mode 100644 scripts/mkmakefile

diff --git a/Makefile b/Makefile
index 1ab446d..1f36fb8 100644
--- a/Makefile
+++ b/Makefile
@@ -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/.*\///')
@@ -335,7 +337,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) \
@@ -465,7 +467,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)
 
@@ -571,6 +573,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)
diff --git a/scripts/mkmakefile b/scripts/mkmakefile
new file mode 100644
index 0000000..b2b3555
--- /dev/null
+++ b/scripts/mkmakefile
@@ -0,0 +1,50 @@
+#!/bin/sh
+# Generates a small Makefile used in the root of the output
+# directory, to allow make to be started from there.
+# The Makefile also allow for more convinient build of external modules
+
+# Usage
+# $1 - Kernel src directory
+# $2 - Output directory
+
+
+test ! -r $2/Makefile -o -O $2/Makefile || exit 0
+# Only overwrite automatically generated Makefiles
+# (so we do not overwrite buildroot Makefile)
+if test -e $2/Makefile && ! grep -E "^# Buildroot Makefile wrapper$" $2/Makefile >/dev/null 2>&1
+then
+        exit 0
+fi
+
+cat << EOF > $2/.Makefile
+# Buildroot Makefile wrapper
+# Automatically generated by $0: don't edit
+
+lastword = \$(word \$(words \$(1)),\$(1))
+makedir := \$(dir \$(call lastword,\$(MAKEFILE_LIST)))
+
+MAKEARGS := -C $1
+MAKEARGS += O=\$(if \$(patsubst /%,,\$(makedir)),\$(CURDIR)/)\$(patsubst %/,%,\$(makedir))
+
+MAKEFLAGS += --no-print-directory
+
+.PHONY: all \$(MAKECMDGOALS)
+
+all     := \$(filter-out all Makefile,\$(MAKECMDGOALS))
+
+all:
+	\$(MAKE) \$(MAKEARGS) \$(all)
+
+Makefile:;
+
+\$(all) %/: all
+	@:
+EOF
+
+if ! cmp $2/.Makefile $2/Makefile >/dev/null 2>&1; then
+    echo "  GEN    Makefile"
+    rm -f $2/Makefile
+    mv $2/.Makefile $2/Makefile
+else
+    rm -f $2/.Makefile
+fi
-- 
1.7.1

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2010-09-12 21:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-12 21:58 [Buildroot] [PATCH] Makefile: add a Makefile wrapper in the $(O) dir - closes #2389 Yann E. MORIN

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.