]> git.hungrycats.org Git - linux/commitdiff
kbuild: Create Makefile in output directory if != kernel tree
authorSam Ravnborg <sam@mars.ravnborg.org>
Wed, 28 Jul 2004 01:54:53 +0000 (03:54 +0200)
committerSam Ravnborg <sam@mars.ravnborg.org>
Wed, 28 Jul 2004 01:54:53 +0000 (03:54 +0200)
When building a kernel using the O= syntax to save output
files in a separate output directory now create a small Makefile in
that same dir.
This Makefile allow one to use make in the output directory without
the hassle of going back to the kernel source tree.
The O= option is added by this Makefile stub.
Please note that the Makefile silently overwrite an old one, so changes
will be lost if modified.
If there is a need to tweak a Makefile in the output directory it is recommended
to use the filename 'makefile', which GNU Make will try first.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Makefile
scripts/mkmakefile [new file with mode: 0644]

index 5a1763e64726832c908e9363f053dffa4614fcde..3723c9ef5c3bd5f9ce314b740ae2c12124338da1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -631,14 +631,24 @@ $(vmlinux-dirs): prepare-all scripts
 # A multi level approach is used. prepare1 is updated first, then prepare0.
 # prepare-all is the collection point for the prepare targets.
 
-.PHONY: prepare-all prepare prepare0 prepare1
+.PHONY: prepare-all prepare prepare0 prepare1 prepare2
+
+# prepare 2 generate Makefile to be placed in output directory, if
+# using a seperate output directory. This allows convinient use
+# of make in output directory
+prepare2:
+       $(Q)if [ ! $(srctree) -ef $(objtree) ]; then       \
+       $(CONFIG_SHELL) $(srctree)/scripts/mkmakefile      \
+           $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL) \
+           > $(objtree)/Makefile;                         \
+       fi
 
 # prepare1 is used to check if we are building in a separate output directory,
 # and if so do:
 # 1) Check that make has not been executed in the kernel src $(srctree)
 # 2) Create the include2 directory, used for the second asm symlink
 
-prepare1:
+prepare1: prepare2
 ifneq ($(KBUILD_SRC),)
        @echo '  Using $(srctree) as source for kernel'
        $(Q)if [ -h $(srctree)/include/asm -o -f $(srctree)/.config ]; then \
diff --git a/scripts/mkmakefile b/scripts/mkmakefile
new file mode 100644 (file)
index 0000000..c4d621b
--- /dev/null
@@ -0,0 +1,31 @@
+#!/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
+# $3 - version
+# $4 - patchlevel
+
+
+cat << EOF
+# Automatically generated by $0: don't edit
+
+VERSION = $3
+PATCHLEVEL = $4
+
+KERNELSRC    := $1
+KERNELOUTPUT := $2
+
+MAKEFLAGS += --no-print-directory
+
+all:
+       \$(MAKE) -C \$(KERNELSRC) O=\$(KERNELOUTPUT)
+
+%::
+       \$(MAKE) -C \$(KERNELSRC) O=\$(KERNELOUTPUT) \$@
+
+EOF
+