sslug-teknik team mailing list archive
-
sslug-teknik team
-
Mailing list archive
-
Message #66013
kbuild foredrag - patch for seperat output directory
Hej alle.
Ifbm. mit foredrag omkring kbuild omtalte jeg en patch til 2.6.0-test3
som giver mulighed for at builde kernen i et seperat output directory.
Primær gevinst ved dette er at det giver en nem mulighed for at builde
en kerne i flere konfigurationer ud fra samme sæt af source filer.
Overvej f.eks flg. directory struktur:
/home/sam/bk/linux-2.6 <= Source code til kernen
/home/sam/build/mars <= Min PC
/home/sam/build/pluto <= Min firewall PC
/home/sam/build/laptop <= Min Linux laptop som jeg mangler :-)
Dette kan nu nemt realiseres med følgende patch.
For at kompilere kernen skal man stå i det directory
hvor kilde koden til kernen ligger og udføre:
$ make O=../../build/mars
Herved bliver _alle_ output filer placeret i det specificerede directory.
Dette gælder også .config.
Følgende patch er til 2.6.0-test3 kernen. Kernen kan patches vha:
patch -p1 < denne_mail
Jeg har testet på mine typiske konfigurationer med held (kun i386).
Kommentarer modtages gerne.
Sam
# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
# ChangeSet 1.1135 -> 1.1136
# scripts/Makefile.clean 1.12 -> 1.13
# drivers/net/pcmcia/Makefile 1.15 -> 1.16
# arch/i386/kernel/Makefile 1.46 -> 1.47
# arch/i386/kernel/edd.c 1.16 -> 1.17
# arch/i386/Makefile 1.54 -> 1.55
# drivers/isdn/hisax/Makefile 1.23 -> 1.24
# arch/i386/boot/Makefile 1.26 -> 1.27
# scripts/Makefile.lib 1.20 -> 1.21
# scripts/Makefile.modpost 1.4 -> 1.5
# Makefile 1.420 -> 1.421
# scripts/Makefile.build 1.38 -> 1.39
# drivers/net/pcmcia/pcnet_cs.c 1.21 -> 1.22
# scripts/genksyms/Makefile 1.2 -> 1.3
# (new) -> 1.1 arch/i386/boot/tools/Makefile
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/08/13 sam@xxxxxxxxxxxxxxxxx 1.1136
# kbuild: Separate output directory
#
# Patch for SSLUG [TEKNIK]
# --------------------------------------------
#
diff -Nru a/Makefile b/Makefile
--- a/Makefile Wed Aug 13 20:26:09 2003
+++ b/Makefile Wed Aug 13 20:26:09 2003
@@ -9,6 +9,9 @@
# Comments in this file are targeted only to the developer, do not
# expect to learn how to build the kernel reading this file.
+# Do not print "Entering directory ..."
+MAKEFLAGS += --no-print-directory
+
# We are using a recursive build, so we need to do a little thinking
# to get the ordering right.
#
@@ -25,6 +28,82 @@
# descending is started. They are now explicitly listed as the
# prepare rule.
+# To put more focus on warnings, less verbose as default
+ifdef V
+ ifeq ("$(origin V)", "command line")
+ KBUILD_VERBOSE = $(V)
+ endif
+endif
+ifndef KBUILD_VERBOSE
+ KBUILD_VERBOSE = 0
+endif
+
+# Linus' sparse tool
+ifdef C
+ ifeq ("$(origin C)", "command line")
+ KBUILD_CHECKSRC = $(C)
+ endif
+endif
+ifndef KBUILD_CHECKSRC
+ KBUILD_CHECKSRC = 0
+endif
+
+# kbuild support building the kernel in a separate directory
+# from the kernel src.
+# To locate output files in a separate directory two syntax'es are supported.
+# In both cases the working directory shall be the root of the kernel src.
+# 1) O=
+# Use "make O=dir/to/store/output/files/"
+#
+# 2) Set KBUILD_OBJ
+# Set the environment variable KBUILD_OBJ to point to the directory
+# where the output files shall be placed.
+# export KBUILD_OBJ=dir/to/store/output/files/
+# make
+#
+# The O= assigment takes precedence over the KBUILD_OBJ environment variable.
+
+# KBUILD_SEPOBJ is set on invocation of Make in OBJ directory
+ifeq ($(KBUILD_SEPOBJ),)
+
+# OK, Make called in directory where kernel src resides
+# Do we want to build the kernel in a separate directory?
+ifdef O
+ ifeq ("$(origin O)", "command line")
+ KBUILD_OBJ := $(O)
+ endif
+endif
+
+# Invoke a second make in the OBJ directory, passing relevant variables
+ifneq ($(KBUILD_OBJ),)
+ KBUILD_OBJ := $(shell cd $(KBUILD_OBJ); /bin/pwd)
+%:
+ @$(MAKE) -C $(KBUILD_OBJ) \
+ KBUILD_SEPOBJ=1 \
+ KBUILD_SRC=$(CURDIR) \
+ KBUILD_VERBOSE=$(KBUILD_VERBOSE) \
+ KBUILD_CHECK=$(KBUILD_CHECK) \
+ -f $(CURDIR)/Makefile $(MAKECMDGOALS)
+
+# Leave processing to above invocation of make
+skip-makefile := 1
+endif # .. KBUILD_OBJ
+endif # .. KBUILD_SEPOBJ
+
+# We process the rest of the Makefile if this is the final invocation of make
+ifeq ($(skip-makefile),)
+
+srctree := $(if $(KBUILD_SRC),$(KBUILD_SRC),.)
+TOPDIR := $(srctree)
+# FIXME - TOPDIR is obsolete, use srctree/objtree
+objtree := $(CURDIR)
+src := $(srctree)
+obj := $(objtree)
+
+VPATH := $(srctree)
+
+export srctree objtree VPATH TOPDIR
+
KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
# SUBARCH tells the usermode build what the underlying arch is. That is set
@@ -69,7 +148,6 @@
CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
else if [ -x /bin/bash ]; then echo /bin/bash; \
else echo sh; fi ; fi)
-TOPDIR := $(CURDIR)
HOSTCC = gcc
HOSTCXX = g++
@@ -110,40 +188,8 @@
KBUILD_MODULES := 1
endif
-export KBUILD_MODULES KBUILD_BUILTIN KBUILD_VERBOSE KBUILD_CHECKSRC
-
-# To put more focus on warnings, less verbose as default
-# Use 'make V=1' to see the full commands
-
-ifdef V
- ifeq ("$(origin V)", "command line")
- KBUILD_VERBOSE = $(V)
- endif
-endif
-ifndef KBUILD_VERBOSE
- KBUILD_VERBOSE = 0
-endif
-
-# Call sparse as part of compilation of C files
-# Use 'make C=1' to enable sparse checking
-
-ifdef C
- ifeq ("$(origin C)", "command line")
- KBUILD_CHECKSRC = $(C)
- endif
-endif
-ifndef KBUILD_CHECKSRC
- KBUILD_CHECKSRC = 0
-endif
-
-# Do not print 'Entering directory ...'
-
-MAKEFLAGS += --no-print-directory
-
-# For maximum performance (+ possibly random breakage, uncomment
-# the following)
-
-#MAKEFLAGS += -rR
+export KBUILD_MODULES KBUILD_BUILTIN KBUILD_VERBOSE
+export KBUILD_CHECKSRC KBUILD_SEPOBJ
# Beautify output
# ---------------------------------------------------------------------------
@@ -185,14 +231,13 @@
export quiet Q KBUILD_VERBOSE
-# Paths to obj / src tree
-
-src := .
-obj := .
-srctree := .
-objtree := .
-
-export srctree objtree
+# Look for include files relative to root of kernel src
+MAKEFLAGS += --include-dir=$(srctree)
+
+# For maximum performance (+ possibly random breakage, uncomment
+# the following)
+
+#MAKEFLAGS += -rR
# Make variables (CC, etc...)
@@ -220,20 +265,20 @@
CFLAGS_KERNEL =
AFLAGS_KERNEL =
-NOSTDINC_FLAGS = -nostdinc -iwithprefix include
-
-CPPFLAGS := -D__KERNEL__ -Iinclude
+NOSTDINC_FLAGS := -nostdinc -iwithprefix include
+CPPFLAGS := -D__KERNEL__ -Iinclude \
+ $(if $(KBUILD_SEPOBJ),-Iinclude2 -I$(srctree)/include)
CFLAGS := -Wall -Wstrict-prototypes -Wno-trigraphs -O2 \
- -fno-strict-aliasing -fno-common
+ -fno-strict-aliasing -fno-common
AFLAGS := -D__ASSEMBLY__
export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION KERNELRELEASE ARCH \
- CONFIG_SHELL TOPDIR HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC \
+ CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC \
CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE \
HOSTCXX HOSTCXXFLAGS LDFLAGS_BLOB LDFLAGS_MODULE CHECK
export CPPFLAGS NOSTDINC_FLAGS OBJCOPYFLAGS LDFLAGS
-export CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
+export CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
export AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
export MODVERDIR := .tmp_versions
@@ -279,7 +324,7 @@
endif
-include arch/$(ARCH)/Makefile
+include $(srctree)/arch/$(ARCH)/Makefile
# Let architecture Makefiles change CPPFLAGS if needed
CFLAGS += $(CPPFLAGS) $(CFLAGS)
@@ -435,14 +480,36 @@
# Handle descending into subdirectories listed in $(SUBDIRS)
.PHONY: $(SUBDIRS)
-$(SUBDIRS): prepare
+$(SUBDIRS): prepare-all
$(Q)$(MAKE) $(build)=$@
-# Things we need done before we descend to build or make
-# module versions are listed in "prepare"
+# Things we need done before we recursively start buiding the kernel
+# or modules are listed in "prepare-all".
+# A multi level approach is used. prepare1 is updated first, then prepare0.
+# Targets listed in $(prepare-y) - to be used by arch specific makefiles -
+# are dependent on prepare0, thus allowing parrallel builds to work.
+# prepare-all is the collection point for the prepare targets.
+
+.PHONY: prepare-all prepare prepare0 prepare1
+
+# prepare1 is used to check is we are building in a seperate obj 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:
+ifneq ($(KBUILD_SEPOBJ),)
+ @echo ' Using $(srctree) as source for kernel'
+ $(Q)if [ -h $(srctree)/include/asm -o -f $(srctree)/.config ]; then \
+ echo " $(srctree) is not clean, please run 'make mrproper'";\
+ echo " in the '$(srctree)' directory.";\
+ /bin/false; \
+ fi;
+ $(Q)if [ ! -d include2 ]; then mkdir -p include2; fi;
+ $(Q)ln -fsn $(srctree)/include/asm-$(ARCH) include2/asm
+endif
-.PHONY: prepare
-prepare: include/linux/version.h include/asm include/config/MARKER
+prepare0: prepare1 include/linux/version.h include/asm include/config/MARKER
ifdef KBUILD_MODULES
ifeq ($(origin SUBDIRS),file)
$(Q)rm -rf $(MODVERDIR)
@@ -453,12 +520,15 @@
endif
$(if $(CONFIG_MODULES),$(Q)mkdir -p $(MODVERDIR))
+$(prepare-y): prepare0
+prepare-all: prepare0 prepare $(prepare-y)
+
# This can be used by arch/$ARCH/Makefile to preprocess
# their vmlinux.lds.S file
AFLAGS_vmlinux.lds.o += -P -C -U$(ARCH)
-arch/$(ARCH)/vmlinux.lds.s: %.s: %.S scripts FORCE
+arch/$(ARCH)/vmlinux.lds.s: %.s: %.S prepare-all scripts FORCE
$(call if_changed_dep,as_s_S)
targets += arch/$(ARCH)/vmlinux.lds.s
@@ -486,8 +556,9 @@
# before switching between archs anyway.
include/asm:
- @echo ' Making asm->asm-$(ARCH) symlink'
- @ln -s asm-$(ARCH) $@
+ @echo ' SYMLINK $@ -> include/asm-$(ARCH)'
+ $(Q)if [ ! -d include ]; then mkdir -p include; fi;
+ @ln -fsn asm-$(ARCH) $@
# Split autoconf.h into include/linux/config/*
@@ -545,7 +616,7 @@
.PHONY: modules
modules: $(SUBDIRS) $(if $(KBUILD_BUILTIN),vmlinux)
@echo ' Building modules, stage 2.';
- $(Q)$(MAKE) -rR -f scripts/Makefile.modpost
+ $(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost
# Install modules
@@ -558,7 +629,7 @@
@rm -f $(MODLIB)/build
@mkdir -p $(MODLIB)/kernel
@ln -s $(TOPDIR) $(MODLIB)/build
- $(Q)$(MAKE) -rR -f scripts/Makefile.modinst
+ $(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modinst
# If System.map exists, run depmod. This deliberately does not have a
# dependency on System.map since that would run the dependency tree on
@@ -701,7 +772,8 @@
$(MODVERDIR) \
.tmp_export-objs \
include/config \
- include/linux/modules
+ include/linux/modules \
+ include2
# clean - Delete all intermediate files
#
@@ -833,7 +905,7 @@
@echo ' tags/TAGS - Generate tags file for editors'
@echo ''
@echo 'Documentation targets:'
- @$(MAKE) --no-print-directory -f Documentation/DocBook/Makefile dochelp
+ @$(MAKE) -f $(srctree)/Documentation/DocBook/Makefile dochelp
@echo ''
@echo 'Architecture specific targets ($(ARCH)):'
@$(if $(archhelp),$(archhelp),\
@@ -841,6 +913,9 @@
@echo ''
@echo ' make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build'
@echo ' make C=1 [targets] Check all c source with checker tool'
+ifeq ($(MAKEFILE_LIST),)
+ @echo ' make S=kernelsrc dir Directory for kernel src'
+endif
@echo ''
@echo 'Execute "make" or "make all" to build all targets marked with [*] '
@echo 'For further info see the ./README file'
@@ -871,7 +946,7 @@
# ===========================================================================
%:: FORCE
- $(Q)$(MAKE) $@
+ $(Q)$(MAKE) -C $(srctree) KBUILD_SEPOBJ= $@
endif # ifeq ($(filter-out $(noconfig_targets),$(MAKECMDGOALS)),)
endif # ifdef include_config
@@ -879,7 +954,8 @@
# FIXME Should go into a make.lib or something
# ===========================================================================
-a_flags = -Wp,-MD,$(depfile) $(AFLAGS) $(AFLAGS_KERNEL) $(NOSTDINC_FLAGS) \
+a_flags = -Wp,-MD,$(depfile) $(AFLAGS) $(AFLAGS_KERNEL) \
+ $(NOSTDINC_FLAGS) $(CPPFLAGS) \
$(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)
quiet_cmd_as_s_S = CPP $@
@@ -900,7 +976,7 @@
# execute the command and also postprocess generated .d dependencies
# file
-if_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^)\
+if_changed_dep = $(if $(strip $? $(fil-er-out FORCE $(wildcard $^),$^)\
$(filter-out $(cmd_$(1)),$(cmd_$@))\
$(filter-out $(cmd_$@),$(cmd_$(1)))),\
@set -e; \
@@ -939,6 +1015,7 @@
define filechk
@set -e; \
echo ' CHK $@'; \
+ mkdir -p $(dir $@); \
$(filechk_$(1)) < $< > $@.tmp; \
if [ -r $@ ] && cmp -s $@ $@.tmp; then \
rm -f $@.tmp; \
@@ -951,16 +1028,19 @@
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=dir
# Usage:
# $(Q)$(MAKE) $(build)=dir
-build := -f scripts/Makefile.build obj
+build := -f $(if $(KBUILD_SEPOBJ),$(srctree)/)scripts/Makefile.build obj
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=dir
# Usage:
# $(Q)$(MAKE) $(clean)=dir
-clean := -f scripts/Makefile.clean obj
+clean := -f $(if $(KBUILD_SEPOBJ),$(srctree)/)scripts/Makefile.clean obj
# $(call descend,<dir>,<target>)
# Recursively call a sub-make in <dir> with target <target>
# Usage is deprecated, because make does not see this as an invocation of make.
-descend =$(Q)$(MAKE) -f scripts/Makefile.build obj=$(1) $(2)
+descend =$(Q)$(MAKE) -f $(if $(KBUILD_SEPOBJ),$(srctree)/)scripts/Makefile.build obj=$(1) $(2)
+
+endif # skip-makefile
FORCE:
+
diff -Nru a/arch/i386/Makefile b/arch/i386/Makefile
--- a/arch/i386/Makefile Wed Aug 13 20:26:09 2003
+++ b/arch/i386/Makefile Wed Aug 13 20:26:09 2003
@@ -122,7 +122,7 @@
install fdimage fdimage144 fdimage288: vmlinux
$(Q)$(MAKE) $(build)=$(boot) BOOTIMAGE=$(BOOTIMAGE) $@
-prepare: include/asm-$(ARCH)/asm_offsets.h
+prepare-y := include/asm-$(ARCH)/asm_offsets.h
CLEAN_FILES += include/asm-$(ARCH)/asm_offsets.h
arch/$(ARCH)/kernel/asm-offsets.s: include/asm include/linux/version.h \
diff -Nru a/arch/i386/boot/Makefile b/arch/i386/boot/Makefile
--- a/arch/i386/boot/Makefile Wed Aug 13 20:26:09 2003
+++ b/arch/i386/boot/Makefile Wed Aug 13 20:26:09 2003
@@ -27,9 +27,8 @@
targets := vmlinux.bin bootsect bootsect.o setup setup.o \
zImage bzImage
-subdir- := compressed
-
-host-progs := tools/build
+subdir- := compressed/
+always := tools/
# ---------------------------------------------------------------------------
@@ -44,7 +43,7 @@
$(obj)/vmlinux.bin $(ROOT_DEV) > $@
$(obj)/zImage $(obj)/bzImage: $(obj)/bootsect $(obj)/setup \
- $(obj)/vmlinux.bin $(obj)/tools/build FORCE
+ $(obj)/vmlinux.bin $(obj)/tools/ FORCE
$(call if_changed,image)
@echo 'Kernel: $@ is ready'
@@ -58,8 +57,7 @@
$(call if_changed,ld)
$(obj)/compressed/vmlinux: FORCE
- $(Q)$(MAKE) -f scripts/Makefile.build obj=$(obj)/compressed \
- IMAGE_OFFSET=$(IMAGE_OFFSET) $@
+ $(Q)$(MAKE) $(build)=$(obj)/compressed IMAGE_OFFSET=$(IMAGE_OFFSET) $@
# Set this if you want to pass append arguments to the zdisk/fdimage kernel
FDARGS =
diff -Nru a/arch/i386/boot/tools/Makefile b/arch/i386/boot/tools/Makefile
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/arch/i386/boot/tools/Makefile Wed Aug 13 20:26:09 2003
@@ -0,0 +1,2 @@
+host-progs := build
+always := $(host-progs)
diff -Nru a/arch/i386/kernel/Makefile b/arch/i386/kernel/Makefile
--- a/arch/i386/kernel/Makefile Wed Aug 13 20:26:09 2003
+++ b/arch/i386/kernel/Makefile Wed Aug 13 20:26:09 2003
@@ -28,6 +28,9 @@
obj-$(CONFIG_X86_NUMAQ) += numaq.o
obj-$(CONFIG_X86_SUMMIT) += summit.o
obj-$(CONFIG_EDD) += edd.o
+# FIXME: Needed to locate scsi headers in drivers/scsi
+# They will be moved to include/.. later
+CFLAGS_edd.o := -I.
obj-$(CONFIG_MODULES) += module.o
obj-y += sysenter.o vsyscall.o
obj-$(CONFIG_ACPI_SRAT) += srat.o
diff -Nru a/arch/i386/kernel/edd.c b/arch/i386/kernel/edd.c
--- a/arch/i386/kernel/edd.c Wed Aug 13 20:26:09 2003
+++ b/arch/i386/kernel/edd.c Wed Aug 13 20:26:09 2003
@@ -48,8 +48,8 @@
#include <linux/blkdev.h>
#include <asm/edd.h>
/* FIXME - this really belongs in include/scsi/scsi.h */
-#include <../drivers/scsi/scsi.h>
-#include <../drivers/scsi/hosts.h>
+#include <drivers/scsi/scsi.h>
+#include <drivers/scsi/hosts.h>
MODULE_AUTHOR("Matt Domsch <Matt_Domsch@xxxxxxxx>");
MODULE_DESCRIPTION("sysfs interface to BIOS EDD information");
diff -Nru a/drivers/isdn/hisax/Makefile b/drivers/isdn/hisax/Makefile
--- a/drivers/isdn/hisax/Makefile Wed Aug 13 20:26:09 2003
+++ b/drivers/isdn/hisax/Makefile Wed Aug 13 20:26:09 2003
@@ -57,5 +57,5 @@
hisax-$(CONFIG_HISAX_ENTERNOW_PCI) += enternow_pci.o amd7930_fn.o
#hisax-$(CONFIG_HISAX_TESTEMU) += testemu.o
-CERT := $(shell cd $(src); md5sum -c md5sums.asc > /dev/null 2> /dev/null ;echo $$?)
-CFLAGS_cert.o := -DCERTIFICATION=$(CERT)
+CERT = $(shell cd $(src); md5sum -c md5sums.asc > /dev/null 2> /dev/null ;echo $$?)
+CFLAGS_cert.o = -DCERTIFICATION=$(CERT)
diff -Nru a/drivers/net/pcmcia/Makefile b/drivers/net/pcmcia/Makefile
--- a/drivers/net/pcmcia/Makefile Wed Aug 13 20:26:09 2003
+++ b/drivers/net/pcmcia/Makefile Wed Aug 13 20:26:09 2003
@@ -8,6 +8,9 @@
obj-$(CONFIG_PCMCIA_FMVJ18X) += fmvj18x_cs.o
obj-$(CONFIG_PCMCIA_NMCLAN) += nmclan_cs.o
obj-$(CONFIG_PCMCIA_PCNET) += pcnet_cs.o
+# FIXME: Needed to include 8390.h from drivers/net
+CFLAGS_pcnet_cs.o := -I.
+
obj-$(CONFIG_PCMCIA_SMC91C92) += smc91c92_cs.o
obj-$(CONFIG_PCMCIA_XIRC2PS) += xirc2ps_cs.o
obj-$(CONFIG_ARCNET_COM20020_CS)+= com20020_cs.o
diff -Nru a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c
--- a/drivers/net/pcmcia/pcnet_cs.c Wed Aug 13 20:26:09 2003
+++ b/drivers/net/pcmcia/pcnet_cs.c Wed Aug 13 20:26:09 2003
@@ -38,7 +38,7 @@
#include <linux/delay.h>
#include <linux/ethtool.h>
#include <linux/netdevice.h>
-#include <../drivers/net/8390.h>
+#include <drivers/net/8390.h>
#include <pcmcia/version.h>
#include <pcmcia/cs_types.h>
diff -Nru a/scripts/Makefile.build b/scripts/Makefile.build
--- a/scripts/Makefile.build Wed Aug 13 20:26:09 2003
+++ b/scripts/Makefile.build Wed Aug 13 20:26:09 2003
@@ -12,8 +12,15 @@
endif
include $(obj)/Makefile
+ifneq ($(KBUILD_SEPOBJ),)
+_dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
+endif
include scripts/Makefile.lib
+
+# Create directories for object files if directory does not exist
+_dummy := $(foreach d,$(obj-dirs), $(shell [ -d $(d) ] || mkdir -p $(d)))
+
ifdef EXTRA_TARGETS
$(warning kbuild: $(obj)/Makefile - Usage of EXTRA_TARGETS is obsolete in 2.5. Please fix!)
diff -Nru a/scripts/Makefile.clean b/scripts/Makefile.clean
--- a/scripts/Makefile.clean Wed Aug 13 20:26:09 2003
+++ b/scripts/Makefile.clean Wed Aug 13 20:26:09 2003
@@ -13,6 +13,7 @@
# ==========================================================================
__subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y)))
+__subdir-y += $(patsubst %/,%,$(filter %/, $(always)))
subdir-y += $(__subdir-y)
__subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m)))
subdir-m += $(__subdir-m)
@@ -30,8 +31,9 @@
subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
__clean-files := $(wildcard $(addprefix $(obj)/, \
- $(extra-y) $(EXTRA_TARGETS) $(always) $(host-progs) \
- $(targets) $(clean-files)))
+ $(extra-y) $(EXTRA_TARGETS) \
+ $(filter-out %/, $(always)) \
+ $(host-progs) $(targets) $(clean-files)))
# ==========================================================================
@@ -63,4 +65,4 @@
# Shorthand for $(Q)$(MAKE) scripts/Makefile.clean obj=dir
# Usage:
# $(Q)$(MAKE) $(clean)=dir
-clean := -f scripts/Makefile.clean obj
+clean := -f $(if $(KBUILD_SEPOBJ),$(srctree)/)scripts/Makefile.clean obj
diff -Nru a/scripts/Makefile.lib b/scripts/Makefile.lib
--- a/scripts/Makefile.lib Wed Aug 13 20:26:09 2003
+++ b/scripts/Makefile.lib Wed Aug 13 20:26:09 2003
@@ -32,6 +32,7 @@
# and add the directory to the list of dirs to descend into: $(subdir-m)
__subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y)))
+__subdir-y += $(patsubst %/,%,$(filter %/, $(always)))
subdir-y += $(__subdir-y)
__subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m)))
subdir-m += $(__subdir-m)
@@ -58,6 +59,9 @@
# in the local directory
subdir-obj-y := $(foreach o,$(obj-y),$(if $(filter-out $(o),$(notdir $(o))),$(o)))
+# $(obj-dirs) is a list of directories that contain object files
+obj-dirs := $(filter-out ./, $(sort $(dir $(multi-objs) $(subdir-obj-y))))
+
# Replace multi-part objects by their individual parts, look at local dir only
real-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) $(extra-y)
real-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m)))
@@ -107,6 +111,7 @@
multi-objs-y := $(addprefix $(obj)/,$(multi-objs-y))
multi-objs-m := $(addprefix $(obj)/,$(multi-objs-m))
subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
+obj-dirs := $(addprefix $(obj)/,$(obj-dirs))
host-progs := $(addprefix $(obj)/,$(host-progs))
host-csingle := $(addprefix $(obj)/,$(host-csingle))
host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
@@ -129,15 +134,46 @@
# where foo and bar are the name of the modules.
basename_flags = -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F)))
modname_flags = $(if $(filter 1,$(words $(modname))),-DKBUILD_MODNAME=$(subst $(comma),_,$(subst -,_,$(modname))))
-c_flags = -Wp,-MD,$(depfile) $(CFLAGS) $(NOSTDINC_FLAGS) \
- $(modkern_cflags) $(EXTRA_CFLAGS) $(CFLAGS_$(*F).o) \
- $(basename_flags) $(modname_flags)
-a_flags = -Wp,-MD,$(depfile) $(AFLAGS) $(NOSTDINC_FLAGS)\
- $(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)
-hostc_flags = -Wp,-MD,$(depfile) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS)\
- $(HOSTCFLAGS_$(*F).o)
-hostcxx_flags = -Wp,-MD,$(depfile) $(HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS)\
- $(HOSTCXXFLAGS_$(*F).o)
+
+
+_c_flags = $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(*F).o)
+_a_flags = $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)
+_hostc_flags = $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS_$(*F).o)
+_hostcxx_flags = $(HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) $(HOSTCXXFLAGS_$(*F).o)
+
+
+# If building the kernel in a separate objtree expand all occurrences
+# of -Idir to -Idir -I$(srctree)/dir.
+# hereby allowing gcc to locate files in both trees. Local tree first.
+
+ifeq ($(KBUILD_SEPOBJ),)
+__c_flags = $(_c_flags)
+__a_flags = $(_a_flags)
+__hostc_flags = $(_hostc_flags)
+__hostcxx_flags = $(_hostcxx_flags)
+else
+flags = $(foreach o,$($(1)),\
+ $(if $(filter -I%,$(o)),$(patsubst -I%,-I$(srctree)/%,$(o)),$(o)))
+
+# -I$(obj) locate generated .h files
+# -I$(srctree)/$(src) locate .h files in srctree, from generated .c files
+# FIXME: Replace both with specific EXTRA_CFLAGS statements
+__c_flags = -I$(obj) -I$(srctree)/$(src) $(call flags,_c_flags)
+__a_flags = $(call flags,_a_flags)
+__hostc_flags = -I$(obj) $(call flags,_hostc_flags)
+__hostcxx_flags = $(call flags,_hostcxx_flags)
+endif
+
+c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(CPPFLAGS) \
+ $(__c_flags) $(modkern_cflags) \
+ $(basename_flags) $(modname_flags)
+
+a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(CPPFLAGS) \
+ $(__a_flags) $(modkern_aflags)
+
+hostc_flags = -Wp,-MD,$(depfile) $(__hostc_flags)
+hostcxx_flags = -Wp,-MD,$(depfile) $(__hostcxx_flags)
+
ld_flags = $(LDFLAGS) $(EXTRA_LDFLAGS)
# Finds the multi-part object the current object will be linked into
@@ -230,9 +266,9 @@
# $(call descend,<dir>,<target>)
# Recursively call a sub-make in <dir> with target <target>
# Usage is deprecated, because make do not see this as an invocation of make.
-descend =$(Q)$(MAKE) -f scripts/Makefile.build obj=$(1) $(2)
+descend =$(Q)$(MAKE) -f $(if $(KBUILD_SEPOBJ),$(srctree)/)scripts/Makefile.build obj=$(1) $(2)
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=
# Usage:
# $(Q)$(MAKE) $(build)=dir
-build := -f scripts/Makefile.build obj
+build := -f $(if $(KBUILD_SEPOBJ),$(srctree)/)scripts/Makefile.build obj
diff -Nru a/scripts/Makefile.modpost b/scripts/Makefile.modpost
--- a/scripts/Makefile.modpost Wed Aug 13 20:26:09 2003
+++ b/scripts/Makefile.modpost Wed Aug 13 20:26:09 2003
@@ -35,7 +35,7 @@
# Compile version info for unresolved symbols
quiet_cmd_cc_o_c = CC $@
- cmd_cc_o_c = $(CC) -Wp,-MD,$(depfile) $(CFLAGS) $(CFLAGS_MODULE) \
+ cmd_cc_o_c = $(CC) $(c_flags) $(CFLAGS_MODULE) \
-c -o $@ $<
$(modules:.ko=.mod.o): %.mod.o: %.mod.c FORCE
diff -Nru a/scripts/genksyms/Makefile b/scripts/genksyms/Makefile
--- a/scripts/genksyms/Makefile Wed Aug 13 20:26:09 2003
+++ b/scripts/genksyms/Makefile Wed Aug 13 20:26:09 2003
@@ -3,13 +3,14 @@
always := $(host-progs)
genksyms-objs := genksyms.o parse.o lex.o
-
-HOSTCFLAGS_parse.o := -Wno-uninitialized
+# -I needed for generated C source (shipped source)
+HOSTCFLAGS_parse.o := -Wno-uninitialized -I$(obj)
# dependencies on generated files need to be listed explicitly
$(obj)/lex.o: $(obj)/parse.h $(obj)/keywords.c
-
+# -I needed for generated C source (shipped source)
+HOSTCFLAGS_lex.o := -I$(obj)
ifdef GENERATE_PARSER