Commit dc5b8833 authored by Kai Germaschewski's avatar Kai Germaschewski

kbuild: Don't cd into subdirs during build

Instead of using make -C <subdir>, just use make -f <subdir>/Makefile.
This means we now call gcc/ld/... always from the topdir.

Advantages are:
o We don't need to use -I$(TOPDIR)/include and the like, just 
  -Iinclude works.
o __FILE__ gives the correct relative path from the topdir instead
  of an absolute path, as it did before for included headers
o gcc errors/warnings give the correct relative path from the topdir
o takes us a step closer to a non-recursive build (though that's probably
  as close as it gets)

The changes to Rules.make were done in a way which only uses the new way
for the standard recursive build (which remains recursive, just without
cd), all the archs do make -C arch/$(ARCH)/boot ..., which should keep
working as before. However, of course this should be converted eventually,
it's possible to do so piecemeal arch by arch.

It seems to work fine for most of the standard kernel. Potential places
which need changing are added -I flags to the command line, which now
need to have the path relative to the topdir and explicit rules for
generating files, which need to properly use $(obj) / $(src) to work
correctly.
parent e22be929
......@@ -25,22 +25,20 @@ ifdef list-multi
$(warning kbuild: list-multi ($(list-multi)) is obsolete in 2.5. Please fix!)
endif
# Figure out paths
# Some paths for the Makefiles to use
# ---------------------------------------------------------------------------
# Find the path relative to the toplevel dir, $(RELDIR), and express
# the toplevel dir as a relative path from this dir, $(TOPDIR_REL)
ifeq ($(findstring $(TOPDIR),$(CURDIR)),)
# Can only happen when something is built out of tree
RELDIR := $(CURDIR)
TOPDIR_REL := $(TOPDIR)
else
RELDIR := $(subst $(TOPDIR)/,,$(CURDIR))
TOPDIR_REL := $(subst $(space),,$(foreach d,$(subst /, ,$(RELDIR)),../))
# FIXME. For now, we leave it possible to use make -C or make -f
# to do work in subdirs.
ifndef obj
obj = .
CFLAGS := $(patsubst -I%,-I$(TOPDIR)/%,$(patsubst -I$(TOPDIR)/%,-I%,$(CFLAGS)))
AFLAGS := $(patsubst -I%,-I$(TOPDIR)/%,$(patsubst -I$(TOPDIR)/%,-I%,$(AFLAGS)))
endif
# Some paths for the Makefiles to use
# ---------------------------------------------------------------------------
# For use in the quiet output
echo_target = $@
# Usage:
#
......@@ -58,12 +56,7 @@ endif
# We don't support separate source / object yet, so these are just
# placeholders for now
obj := .
src := .
# For use in the quiet output
echo_target = $(RELDIR)/$@
src := $(obj)
# Figure out what we need to build from the various variables
# ===========================================================================
......@@ -120,6 +113,21 @@ real-objs-m := $(foreach m, $(obj-m), $(if $($(m:.o=-objs)),$($(m:.o=-objs)),$(m
# Only build module versions for files which are selected to be built
export-objs := $(filter $(export-objs),$(real-objs-y) $(real-objs-m))
# Add subdir path
EXTRA_TARGETS := $(addprefix $(obj)/,$(EXTRA_TARGETS))
obj-y := $(addprefix $(obj)/,$(obj-y))
obj-m := $(addprefix $(obj)/,$(obj-m))
export-objs := $(addprefix $(obj)/,$(export-objs))
subdir-obj-y := $(addprefix $(obj)/,$(subdir-obj-y))
real-objs-y := $(addprefix $(obj)/,$(real-objs-y))
real-objs-m := $(addprefix $(obj)/,$(real-objs-m))
multi-used-y := $(addprefix $(obj)/,$(multi-used-y))
multi-used-m := $(addprefix $(obj)/,$(multi-used-m))
multi-objs-y := $(addprefix $(obj)/,$(multi-objs-y))
multi-objs-m := $(addprefix $(obj)/,$(multi-objs-m))
subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
# The temporary file to save gcc -MD generated dependencies must not
# contain a comma
depfile = $(subst $(comma),_,$(@D)/.$(@F).d)
......@@ -153,7 +161,7 @@ else
# This sets version suffixes on exported symbols
# ---------------------------------------------------------------------------
MODVERDIR := $(TOPDIR)/include/linux/modules/$(RELDIR)
MODVERDIR := include/linux/modules/$(obj)
#
# Added the SMP separator to stop module accidents between uniprocessor
......@@ -183,7 +191,7 @@ c_flags = -Wp,-MD,$(depfile) $(CFLAGS) $(NOSTDINC_FLAGS) \
# files (fix-dep filters them), so touch modversions.h if any of the .ver
# files changes
quiet_cmd_cc_ver_c = MKVER include/linux/modules/$(RELDIR)/$*.ver
quiet_cmd_cc_ver_c = MKVER include/linux/modules/$(obj)/$*.ver
cmd_cc_ver_c = $(CPP) $(c_flags) $< | $(GENKSYMS) $(genksyms_smp_prefix) \
-k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp
......@@ -216,8 +224,8 @@ $(MODVERDIR)/%.ver: %.c FORCE
targets := $(addprefix $(MODVERDIR)/,$(export-objs:.o=.ver))
fastdep: $(targets) $(subdir-ym)
@mkdir -p $(dir $(addprefix $(TOPDIR)/.tmp_export-objs/modules/$(RELDIR),$(export-objs:.o=.ver)))
@touch $(addprefix $(TOPDIR)/.tmp_export-objs/modules/$(RELDIR)/,$(export-objs:.o=.ver))
@mkdir -p $(dir $(addprefix .tmp_export-objs/modules/,$(export-objs:.o=.ver)))
@touch $(addprefix .tmp_export-objs/modules/,$(export-objs:.o=.ver))
endif # export-objs
......@@ -228,13 +236,15 @@ ifeq ($(MAKECMDGOALS),modules_install)
# Installing modules
# ==========================================================================
quiet_cmd_modules_install = INSTALL $(obj-m)
cmd_modules_install = mkdir -p $(MODLIB)/kernel/$(obj); \
cp $(obj-m) $(MODLIB)/kernel/$(obj)
.PHONY: modules_install
modules_install: $(subdir-ym)
ifneq ($(obj-m),)
@echo Installing modules in $(MODLIB)/kernel/$(RELDIR)
@mkdir -p $(MODLIB)/kernel/$(RELDIR)
@cp $(obj-m) $(MODLIB)/kernel/$(RELDIR)
$(call cmd,modules_install)
else
@/bin/true
endif
......@@ -250,8 +260,12 @@ else # ! modules_install
ifndef O_TARGET
ifndef L_TARGET
O_TARGET := built-in.o
O_TARGET := $(obj)/built-in.o
endif
endif
ifdef L_TARGET
L_TARGET := $(obj)/$(L_TARGET)
endif
first_rule: $(if $(KBUILD_BUILTIN),$(O_TARGET) $(L_TARGET) $(EXTRA_TARGETS)) \
......@@ -368,7 +382,7 @@ endif
#
quiet_cmd_link_multi = LD $(echo_target)
cmd_link_multi = $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) -r -o $@ $(filter $($(basename $@)-objs),$^)
cmd_link_multi = $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(addprefix $(obj)/,$($(subst $(obj)/,,$(@:.o=-objs)))),$^)
# We would rather have a list of rules like
# foo.o: $(foo-objs)
......@@ -388,6 +402,9 @@ targets += $(multi-used-y) $(multi-used-m)
host-progs-single := $(foreach m,$(host-progs),$(if $($(m)-objs),,$(m)))
host-progs-multi := $(foreach m,$(host-progs),$(if $($(m)-objs),$(m)))
host-progs-multi-objs := $(foreach m,$(host-progs-multi),$($(m)-objs))
host-progs-single := $(addprefix $(obj)/,$(host-progs-single))
host-progs-multi := $(addprefix $(obj)/,$(host-progs-multi))
host-progs-multi-objs := $(addprefix $(obj)/,$(host-progs-multi-objs))
quiet_cmd_host_cc__c = HOSTCC $(echo_target)
cmd_host_cc__c = $(HOSTCC) -Wp,-MD,$(depfile) \
......@@ -405,7 +422,7 @@ $(host-progs-multi-objs): %.o: %.c FORCE
$(call if_changed_dep,host_cc_o_c)
quiet_cmd_host_cc__o = HOSTLD $(echo_target)
cmd_host_cc__o = $(HOSTCC) $(HOSTLDFLAGS) -o $@ $($@-objs) \
cmd_host_cc__o = $(HOSTCC) $(HOSTLDFLAGS) -o $@ $(addprefix $(obj)/,$($(subst $(obj)/,,$@)-objs)) \
$(HOST_LOADLIBES)
$(host-progs-multi): %: $(host-progs-multi-objs) FORCE
......@@ -583,5 +600,7 @@ endef
# $(call descend,<dir>,<target>)
# Recursively call a sub-make in <dir> with target <target>
descend = $(MAKE) -C $(1) $(2)
ifeq ($(KBUILD_VERBOSE),1)
descend = echo '$(MAKE) -f $(1)/Makefile $(2)';
endif
descend += $(MAKE) -f $(1)/Makefile obj=$(1) $(2)
......@@ -98,8 +98,8 @@ core-y += arch/i386/kernel/ arch/i386/mm/ arch/i386/$(MACHINE)/
drivers-$(CONFIG_MATH_EMULATION) += arch/i386/math-emu/
drivers-$(CONFIG_PCI) += arch/i386/pci/
CFLAGS += -I$(TOPDIR)/arch/i386/$(MACHINE)
AFLAGS += -I$(TOPDIR)/arch/i386/$(MACHINE)
CFLAGS += -Iarch/i386/$(MACHINE)
AFLAGS += -Iarch/i386/$(MACHINE)
MAKEBOOT = +$(MAKE) -C arch/$(ARCH)/boot
......
......@@ -44,7 +44,7 @@ bzImage: IMAGE_OFFSET := 0x100000
bzImage: EXTRA_AFLAGS := -traditional $(SVGA_MODE) $(RAMDISK) -D__BIG_KERNEL__
bzImage: BUILDFLAGS := -b
quiet_cmd_image = BUILD $(RELDIR)/$@
quiet_cmd_image = BUILD $(echo_target)
cmd_image = tools/build $(BUILDFLAGS) bootsect setup vmlinux.bin \
$(ROOT_DEV) > $@
......
......@@ -4,7 +4,7 @@
export ACPI_CFLAGS
ACPI_CFLAGS := -D_LINUX -I$(CURDIR)/include
ACPI_CFLAGS := -D_LINUX -Idrivers/acpi/include
ifdef CONFIG_ACPI_DEBUG
ACPI_CFLAGS += -DACPI_DEBUG_OUTPUT
......
......@@ -2,6 +2,6 @@
obj-$(CONFIG_BLK_DEV_IDE_ICSIDE) += icside.o
obj-$(CONFIG_BLK_DEV_IDE_RAPIDE) += rapide.o
EXTRA_CFLAGS := -I../
EXTRA_CFLAGS := -Idrivers/ide
include $(TOPDIR)/Rules.make
......@@ -17,6 +17,6 @@ obj-$(CONFIG_BLK_DEV_IDECS) += ide-cs.o
# Last of all
obj-$(CONFIG_BLK_DEV_HD) += hd.o
EXTRA_CFLAGS := -I../
EXTRA_CFLAGS := -Idrivers/ide
include $(TOPDIR)/Rules.make
......@@ -31,6 +31,6 @@ obj-$(CONFIG_BLK_DEV_VIA82CXXX) += via82cxxx.o
# Must appear at the end of the block
obj-$(CONFIG_BLK_DEV_GENERIC) += generic.o
EXTRA_CFLAGS := -I../
EXTRA_CFLAGS := -Idrivers/ide
include $(TOPDIR)/Rules.make
......@@ -3,6 +3,6 @@ obj-$(CONFIG_BLK_DEV_MPC8xx_IDE) += mpc8xx.o
obj-$(CONFIG_BLK_DEV_IDE_PMAC) += pmac.o
obj-$(CONFIG_BLK_DEV_IDE_SWARM) += swarm.o
EXTRA_CFLAGS := -I../
EXTRA_CFLAGS := -Idrivers/ide
include $(TOPDIR)/Rules.make
......@@ -13,7 +13,7 @@
# # sparc64
#EXTRA_CFLAGS += -gstabs+
EXTRA_CFLAGS += -I. ${MPT_CFLAGS}
EXTRA_CFLAGS += ${MPT_CFLAGS}
# Fusion MPT drivers; recognized debug defines...
# MPT general:
......
......@@ -55,7 +55,7 @@ endif
# SK_DBGCAT_DRV_INT_SRC 0x04000000 interrupts sources
# SK_DBGCAT_DRV_EVENT 0x08000000 driver events
EXTRA_CFLAGS += -I. -DSK_USE_CSUM $(DBGDEF)
EXTRA_CFLAGS += -Idrivers/net/sk98lin -DSK_USE_CSUM $(DBGDEF)
include $(TOPDIR)/Rules.make
......@@ -17,7 +17,7 @@ skfp-objs := skfddi.o hwmtm.o fplustm.o smt.o cfm.o \
# projects. To keep the source common for all those drivers (and
# thus simplify fixes to it), please do not clean it up!
EXTRA_CFLAGS += -I. -DPCI -DMEM_MAPPED_IO -Wno-strict-prototypes
EXTRA_CFLAGS += -Idrivers/net/skfp -DPCI -DMEM_MAPPED_IO -Wno-strict-prototypes
include $(TOPDIR)/Rules.make
......@@ -3,7 +3,5 @@
sym53c8xx-objs := sym_fw.o sym_glue.o sym_hipd.o sym_malloc.o sym_misc.o sym_nvram.o
obj-$(CONFIG_SCSI_SYM53C8XX_2) := sym53c8xx.o
EXTRA_CFLAGS += -I.
include $(TOPDIR)/Rules.make
......@@ -5,7 +5,7 @@
# Rewritten to use lists instead of if-statements.
#
EXTRA_CFLAGS := -I../../scsi/
EXTRA_CFLAGS := -Idrivers/scsi
obj-$(CONFIG_USB_STORAGE) += usb-storage.o
......
......@@ -32,10 +32,10 @@
# Makefile for XFS on Linux.
#
# This needs -I. because everything does #include <xfs.h> instead of "xfs.h".
# This needs -I because everything does #include <xfs.h> instead of "xfs.h".
# The code is wrong, local files should be included using "xfs.h", not <xfs.h>
# but I am not going to change every file at the moment.
EXTRA_CFLAGS += -I. -funsigned-char
EXTRA_CFLAGS += -Ifs/xfs -funsigned-char
ifeq ($(CONFIG_XFS_DEBUG),y)
EXTRA_CFLAGS += -g -DSTATIC="" -DDEBUG -DXFSDEBUG
......@@ -154,6 +154,6 @@ ifneq ($(CONFIG_KDB_MODULES),)
endif
endif
CFLAGS_xfsidbg.o += -I $(TOPDIR)/arch/$(ARCH)/kdb
CFLAGS_xfsidbg.o += -Iarch/$(ARCH)/kdb
include $(TOPDIR)/Rules.make
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment