summaryrefslogtreecommitdiffstats
path: root/scripts/mkmakefile
diff options
context:
space:
mode:
authorYann E. MORIN <yann.morin.1998@anciens.enib.fr>2010-09-26 10:56:12 +0200
committerPeter Korsgaard <jacmet@sunsite.dk>2010-09-26 23:47:07 +0200
commitaefad5317f2fd1645ace5a62b6b9643143093173 (patch)
tree198b95f1bd194ccda765dd97b7ff6006075a77f8 /scripts/mkmakefile
parent0f9da87c1d18598f308ed129d027f65cdffcde77 (diff)
downloadbuildroot-novena-aefad5317f2fd1645ace5a62b6b9643143093173.tar.gz
buildroot-novena-aefad5317f2fd1645ace5a62b6b9643143093173.zip
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. We can't use exactly the same implementation as the kernel does, because: - the script writing the wrapper has been expunged of the few lines that were too kernel-related: in buildroot we do not need the version string in the wrapper, and we do not have a patchlevel version; - "in-tree build" does not have the same meaning for the kernel and for buildroot: for the kernel, $(O) point to the $(TOPDIR), while for buildroot $(O) points to $(TOPDIR)/output. For more complete explanations, see: http://lists.busybox.net/pipermail/buildroot/2010-September/037815.html [Peter: minor tweaks] Signed-off-by: "Yann E. MORIN" <yann.morin.1998 at anciens.enib.fr> Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk>
Diffstat (limited to 'scripts/mkmakefile')
-rwxr-xr-xscripts/mkmakefile47
1 files changed, 47 insertions, 0 deletions
diff --git a/scripts/mkmakefile b/scripts/mkmakefile
new file mode 100755
index 000000000..38d826853
--- /dev/null
+++ b/scripts/mkmakefile
@@ -0,0 +1,47 @@
+#!/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 -q Automatically $2/Makefile
+then
+ exit 0
+fi
+if [ "${quiet}" != "silent_" ]; then
+ echo " GEN $2/Makefile"
+fi
+
+cat << EOF > $2/Makefile
+# 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
+ @:
+
+%/: all
+ @:
+EOF