kbuild: Separate output directory - core patch
# 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.1269 -> 1.1270
# scripts/Makefile.lib 1.20 -> 1.21
# scripts/Makefile.modpost 1.4 -> 1.5
# Makefile 1.421 -> 1.422
# scripts/Makefile.build 1.39 -> 1.40
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/08/19 [email protected] 1.1270
# kbuild: Separate output directory
#
# Enable the possibility to build a kernel in a separate output
# directory. This is useful when dealing with several kernel configurations
# based on the same src, or if you do not want to mix source code
# and output files.
#
# Usage is simple:
# make O=dir/to/kernel/src {usual make targets}
#
# This patch implements the core part of separate output directory
# --------------------------------------------
#
diff -Nru a/Makefile b/Makefile
--- a/Makefile Tue Aug 19 23:40:39 2003
+++ b/Makefile Tue Aug 19 23:40:39 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,85 @@ # descending is started. They are now explicitly listed as the # prepare rule.
+# To put more focus on warnings, be 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
+
+# kbuild support locating output files in a separate directory. +# To locate output files in a separate directory two syntax'es are supported. +# In both cases the working directory must 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_OUTPUT is set on invocation of make in OBJ directory +ifeq ($(KBUILD_OUTPUT),)
+
+# OK, Make called in directory where kernel src resides
+# Do we want to locate output files in a separate directory? +ifdef O
+ ifeq ("$(origin O)", "command line")
+ KBUILD_OBJ := $(O)
+ endif
+endif
+
+# Invoke a second make in the output directory, passing relevant variables +ifneq ($(KBUILD_OBJ),)
+ KBUILD_OBJ := $(shell cd $(KBUILD_OBJ); /bin/pwd)
+%:
+ @$(MAKE) -C $(KBUILD_OBJ) \
+ KBUILD_OUTPUT=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 # ifneq ($(KBUILD_OBJ),)
+endif # ifeq ($(KBUILD_OUTPUT),)
+
+# 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 +151,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 +191,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_OUTPUT
# Beautify output
# ---------------------------------------------------------------------------
@@ -185,14 +234,13 @@
export quiet Q KBUILD_VERBOSE
-# Paths to obj / src tree
+# Look for make include files relative to root of kernel src +MAKEFLAGS += --include-dir=$(srctree)
-src := .
-obj := .
-srctree := .
-objtree := .
+# For maximum performance (+ possibly random breakage, uncomment +# the following)
-export srctree objtree
+#MAKEFLAGS += -rR
# Make variables (CC, etc...)
@@ -222,13 +270,15 @@
NOSTDINC_FLAGS = -nostdinc -iwithprefix include
-CPPFLAGS := -D__KERNEL__ -Iinclude
+CPPFLAGS := -D__KERNEL__ -Iinclude \
+ $(if $(KBUILD_OUTPUT),-Iinclude2 -I$(srctree)/include)
+
CFLAGS := -Wall -Wstrict-prototypes -Wno-trigraphs -O2 \
-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
@@ -283,7 +333,7 @@
# Handle them one by one.
%:: FORCE
- $(Q)$(MAKE) $@
+ $(Q)$(MAKE) -C $(srctree) KBUILD_OUTPUT= $@
else
ifeq ($(config-targets),1)
@@ -311,7 +361,7 @@
-include .config
-include arch/$(ARCH)/Makefile
+include $(srctree)/arch/$(ARCH)/Makefile
# Let architecture Makefiles change CPPFLAGS if needed CFLAGS += $(CPPFLAGS) $(CFLAGS)
@@ -465,14 +515,34 @@
# 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 to do before we recursively start building the kernel +# or the modules are listed in "prepare-all".
+# 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
+
+# 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:
+ifneq ($(KBUILD_OUTPUT),)
+ @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)
@@ -483,6 +553,9 @@
endif
$(if $(CONFIG_MODULES),$(Q)mkdir -p $(MODVERDIR))
+# All the preparing..
+prepare-all: prepare0 prepare
+
# Leave this as default for preprocessing vmlinux.lds.S, which is now
# done in arch/$(ARCH)/kernel/Makefile
@@ -511,8 +584,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/*
@@ -570,7 +644,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
@@ -583,7 +657,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 @@ -660,7 +734,8 @@ $(MODVERDIR) \ .tmp_export-objs \ include/config \ - include/linux/modules + include/linux/modules \ + include2
# clean - Delete all intermediate files # @@ -794,6 +869,7 @@ echo ' No architecture specific help defined for $(ARCH)') @echo '' @echo ' make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build' + @echo ' make O=dir [targets] Locate all build output files in \'dir\', including .config' @echo ' make C=1 [targets] Check all c source with checker tool' @echo '' @echo 'Execute "make" or "make all" to build all targets marked with [*] ' @@ -824,7 +900,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_o_S = AS $@
@@ -882,6 +959,7 @@
define filechk
@set -e; \
echo ' CHK $@'; \
+ mkdir -p $(dir $@); \
$(filechk_$(1)) < $< > [email protected]; \
if [ -r $@ ] && cmp -s $@ [email protected]; then \
rm -f [email protected]; \
@@ -894,16 +972,18 @@
# 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_OUTPUT),$(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_OUTPUT),$(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_OUTPUT),$(srctree)/)scripts/Makefile.build obj=$(1) $(2) +
+endif # skip-makefile
FORCE:
scripts/Makefile.build +10 -0
@@ -14,6 +14,16 @@ include scripts/Makefile.lib +ifneq ($(KBUILD_OUTPUT),) +# Create output directory if not already present +_dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj)) + +# Create directories for object files if directory does not exist +# Needed when obj-y := dir/file.o syntax is used +_dummy := $(foreach d,$(obj-dirs), $(shell [ -d $(d) ] || mkdir -p $(d))) +endif + + ifdef EXTRA_TARGETS $(warning kbuild: $(obj)/Makefile - Usage of EXTRA_TARGETS is obsolete in 2.5. Please fix!) endif
scripts/Makefile.lib +46 -11
82 lines not on this page · raw message
scripts/Makefile.modpost +1 -1
@@ -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
Re: kbuild: Separate output directory - include patch
# 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.1272 -> 1.1273
# kernel/Makefile 1.32 -> 1.33
# scripts/genksyms/Makefile 1.3 -> 1.4
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/08/19 [email protected] 1.1273
# kbuild: Fix build with seperate output directory
#
# Build rule for ikconfig updated.
# Include directive for genksyms updated
# --------------------------------------------
#
kernel/Makefile +7 -4
@@ -20,8 +20,6 @@ obj-$(CONFIG_COMPAT) += compat.o obj-$(CONFIG_IKCONFIG) += configs.o -# files to be removed upon make clean -clean-files := ikconfig.h ifneq ($(CONFIG_IA64),y) # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
@@ -32,8 +30,13 @@ CFLAGS_sched.o := $(PROFILING) -fno-omit-frame-pointer endif -$(obj)/ikconfig.h: scripts/mkconfigs .config Makefile - $(CONFIG_SHELL) scripts/mkconfigs .config Makefile > $(obj)/ikconfig.h +quiet_cmd_ikconfig = IKCFG $@ + cmd_ikconfig = $(CONFIG_SHELL) $< .config $(srctree)/Makefile > $@ + +targets := ikconfig.h + +$(obj)/ikconfig.h: scripts/mkconfigs .config Makefile FORCE + $(call if_changed,ikconfig) $(obj)/configs.o: $(obj)/ikconfig.h $(obj)/configs.c \ include/linux/version.h include/linux/compile.h
scripts/genksyms/Makefile +4 -3
@@ -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
Re: kbuild: Separate output directory - i386+always patch
In reply to Sam Ravnborg# 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.1271 -> 1.1272
# scripts/Makefile.clean 1.12 -> 1.13
# arch/i386/boot/Makefile 1.26 -> 1.27
# scripts/Makefile.lib 1.21 -> 1.22
# (new) -> 1.1 arch/i386/boot/tools/Makefile
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/08/19 [email protected] 1.1272
# kbuild/i386: Fixes for separate output dir
#
# Update i386 makefiles so they support building a kernel in a seperate
# output directory. # This includes a new syntax for always :=, where a directory # may be specified # -------------------------------------------- # diff -Nru a/arch/i386/boot/Makefile b/arch/i386/boot/Makefile --- a/arch/i386/boot/Makefile Tue Aug 19 23:41:17 2003 +++ b/arch/i386/boot/Makefile Tue Aug 19 23:41:17 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 =
arch/i386/boot/tools/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +host-progs := build +always := $(host-progs)
scripts/Makefile.clean +5 -3
@@ -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_OUTPUT),$(srctree)/)scripts/Makefile.clean obj
scripts/Makefile.lib +1 -0
@@ -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)
Re: kbuild: Separate output directory - ieee patch
In reply to Sam Ravnborg# 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.1270 -> 1.1271
# drivers/ieee1394/Makefile 1.19 -> 1.20
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/08/19 [email protected] 1.1271
# ieee/kbuild: fix oui2c build rule
#
# 1) Refer to script in $(srctree), so separate output directory
# works with this Makefile # 2) Add oui.c to targets, so kbuild will detect changes in command line - done by 'if_changed' # 3) Add FORCE to prerequisites to make sure command-line is checked # -------------------------------------------- # diff -Nru a/drivers/ieee1394/Makefile b/drivers/ieee1394/Makefile --- a/drivers/ieee1394/Makefile Tue Aug 19 23:40:56 2003 +++ b/drivers/ieee1394/Makefile Tue Aug 19 23:40:56 2003 @@ -16,11 +16,10 @@ obj-$(CONFIG_IEEE1394_AMDTP) += amdtp.o obj-$(CONFIG_IEEE1394_CMP) += cmp.o
-clean-files := oui.c
-
quiet_cmd_oui2c = OUI2C $@
- cmd_oui2c = $(CONFIG_SHELL) $(obj)/oui2c.sh < $(obj)/oui.db > $@
+ cmd_oui2c = $(CONFIG_SHELL) $(srctree)/$(src)/oui2c.sh < $< > $@
-$(obj)/oui.o: $(obj)/oui.c
-$(obj)/oui.c: $(obj)/oui.db $(obj)/oui2c.sh +targets := oui.c
+$(obj)/oui.o: $(src)/oui.c
+$(obj)/oui.c: $(src)/oui.db $(src)/oui2c.sh FORCE
$(call if_changed,oui2c)