kbuild: Separate build directory

Sam Ravnborg (sam@ravnborg.org)
Fri, 27 Dec 2002 14:59:53 +0100


I have updated the patch to support separate build directory to
kernel 2.5.53.
o Roman Zippel has updated and merged to chenges to kconfig,
therefore this patch is rather small.
o Also introduced comments from Kai with respect to -I option
handling for gcc.
o Introduced a Makefile for arch/i386/boot/tools to force the directory
to be created by kbuild.
Has the side-effect that host-progs := .../... now adhere to
normal kbuild rules, where a Makefile is always present.
Furthermore allow host-progs to be used for composite objects in
subdirectories now.
o Updated ppc and X86_64 to use a Makefile for their tools.
ppc actually had a non-used Makefile.

A new script 'kbuild' is located in the top-level directory
of the kernel srctree. To try out this patch just do

cd ~/build
../path/to/kernel/src/kbuild

This will locate all generated files, including
the kernel configuration, in ~/build.

One obvious usage for this is when you have several configs.
One config in each build directory, and all src stored in a central place.

This patch has been tested with i386 and defconfig.

Kai, please apply and forward to Linus.

Sam

You can import this changeset into BK by piping this whole message to:
'| bk receive [path to repository]' or apply the patch as usual.

===================================================================

ChangeSet@1.954, 2002-12-27 14:42:40+01:00, sam@mars.ravnborg.org
kbuild: Support for separate build directory

See usage description in the kbuild script located in the top-level kernel src directory.
Utilising the VPATH feature of make, support for separate build directory is introduced.
The -I options to gcc is preprocessed to point both to the kernel src and to the
objtree where generated files lives.
the top-level Makefile is modified to locate values for srctree and objtree from the file
kbuild.config (if present) - this file is generated by the kbuild script.

The kbuild scripts obtains the location of the kernel src tree from it's own
location, and therefore cannot be moved somewhere else.

Based on concept by Kai Germaschewski, which has also made the preparations throughout the makefiles.

ChangeSet@1.953, 2002-12-25 21:15:27+01:00, sam@mars.ravnborg.org
kbuild: X86_64+ppc, Makefile for tools

Added (X86_64) and corrected (ppc) makefile for tools in arch specific directory.
This makes all architectures compatible with change in semantic of host-progs.

ChangeSet@1.952, 2002-12-25 21:08:40+01:00, sam@mars.ravnborg.org
kbuild: host-progs specifying a subdirectory now assumes a Makefile

When including subdirectories in a host-progs line for example:
host-progs := tools/build
then adhere to nomal behaviour, and use a makefile present in that directory.
Add makefile for build executable for i386

Makefile | 27 ++++++++++++++++-------
arch/ppc/boot/utils/Makefile | 15 ++-----------
arch/x86_64/boot/tools/Makefile | 4 +++
kbuild | 46 ++++++++++++++++++++++++++++++++++++++++
scripts/Makefile.build | 30 +++++++++++++++++---------
5 files changed, 92 insertions(+), 30 deletions(-)

diff -Nru a/Makefile b/Makefile
--- a/Makefile Fri Dec 27 14:45:32 2002
+++ b/Makefile Fri Dec 27 14:45:32 2002
@@ -136,13 +136,19 @@
export quiet Q KBUILD_VERBOSE

# Paths to obj / src tree
-
-src := .
-obj := .
+ifneq ($(wildcard kbuild.config),)
+include kbuild.config
+src := $(srctree)
+obj := .
+VPATH := $(srctree)
+else
+src := .
+obj := .
srctree := .
objtree := .
+endif

-export srctree objtree
+export srctree objtree VPATH

# Make variables (CC, etc...)

@@ -313,7 +319,7 @@
set -e
$(if $(filter .tmp_kallsyms%,$^),,
echo ' Generating build number'
- . scripts/mkversion > .tmp_version
+ . $(src)/scripts/mkversion > .tmp_version
mv -f .tmp_version .version
$(Q)$(MAKE) -f scripts/Makefile.build obj=init
)
@@ -329,7 +335,7 @@
ifdef CONFIG_SMP
define rule_vmlinux
$(rule_vmlinux_no_percpu)
- $(AWK) -f scripts/per-cpu-check.awk < System.map
+ $(AWK) -f $(srctree)/scripts/per-cpu-check.awk < System.map
endef
else
define rule_vmlinux
@@ -426,7 +432,11 @@

include/asm:
@echo ' Making asm->asm-$(ARCH) symlink'
+ifeq ($(srctree),$(objtree))
@ln -s asm-$(ARCH) $@
+else
+ @ln -s $(src)/include/asm-$(ARCH) $@
+endif

# Split autoconf.h into include/linux/config/*

@@ -451,6 +461,7 @@
uts_len := 64

include/linux/version.h: Makefile
+ @mkdir -p $(dir $@)
@if expr length "$(KERNELRELEASE)" \> $(uts_len) >/dev/null ; then \
echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \
exit 1; \
@@ -619,7 +630,7 @@
tar -cvz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(KERNELPATH)/. ; \
rm $(KERNELPATH) ; \
cd $(TOPDIR) ; \
- . scripts/mkversion > .version ; \
+ $(CONFIG_SHELL) $(srctree)/scripts/mkversion > .version ; \
rpm -ta $(TOPDIR)/../$(KERNELPATH).tar.gz ; \
rm $(TOPDIR)/../$(KERNELPATH).tar.gz

@@ -706,7 +717,7 @@
include/asm \
.hdepend include/linux/modversions.h \
tags TAGS kernel.spec \
- .tmp*
+ .tmp* kbuild.config

# Directories removed with 'make mrproper'
MRPROPER_DIRS += \
diff -Nru a/arch/ppc/boot/utils/Makefile b/arch/ppc/boot/utils/Makefile
--- a/arch/ppc/boot/utils/Makefile Fri Dec 27 14:45:32 2002
+++ b/arch/ppc/boot/utils/Makefile Fri Dec 27 14:45:32 2002
@@ -5,16 +5,7 @@
# License. See the file "COPYING" in the main directory of this archive
# for more details.

-HOSTCFLAGS += -I$(TOPDIR)/arch/$(ARCH)/boot/include
+host-progs := addnote hack-coff mkprep mknote mkbugboot mktree \
+ addSystemMap addRamdDisk

-all: FORCE
-
-# Simple programs with 1 file and no extra CFLAGS
-UTILS = addnote hack-coff mkprep mknote mkbugboot mktree \
- addSystemMap addRamdDisk
-
-$(UTILS):
- $(HOSTCC) $(HOSTCFLAGS) -o $@ $@.c
-
-clean:
- rm -f $(UTILS)
+build-targets := $(host-progs)
diff -Nru a/arch/x86_64/boot/tools/Makefile b/arch/x86_64/boot/tools/Makefile
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/arch/x86_64/boot/tools/Makefile Fri Dec 27 14:45:32 2002
@@ -0,0 +1,4 @@
+# Makefile for X86_64 tools
+
+host-progs := build
+build-targets := $(host-progs)