Commit 78e9d59f authored by Kai Germaschewski's avatar Kai Germaschewski

kbuild: Clean up descending into subdirs

Rules.make now has three targets:
o default (a.k.a first_rule): The actual build. Deciding whether
  to build built-in or modular or both is decided by
  $(KBUILD_MODULES) and $(KBUILD_BUILTIN) now, instead of using
  different targets
o fastdep: doesn't actually dependencies anymore, only generates
  modversions
o modules_install: Well, you guess what that does.

Cleaned up descending, and no more differentiating between 
$(subdir-y) and $(subdir-m). That means $(mod-subdirs) can
go away now.
parent 81e93fe6
......@@ -46,6 +46,13 @@ all: vmlinux
#KBUILD_VERBOSE := 1
# Decide whether to build built-in, modular, or both
KBUILD_MODULES :=
KBUILD_BUILTIN := 1
export KBUILD_MODULES KBUILD_BUILTIN
# Beautify output
# ---------------------------------------------------------------------------
#
......@@ -379,11 +386,8 @@ MODFLAGS += -include $(HPATH)/linux/modversions.h
endif
.PHONY: modules
modules: $(patsubst %, _mod_%, $(SUBDIRS))
.PHONY: $(patsubst %, _mod_%, $(SUBDIRS))
$(patsubst %, _mod_%, $(SUBDIRS)) : include/linux/version.h include/config/MARKER
@$(MAKE) -C $(patsubst _mod_%, %, $@) modules
modules:
@$(MAKE) KBUILD_BUILTIN= KBUILD_MODULES=1 $(SUBDIRS)
# Install modules
......
......@@ -52,9 +52,8 @@ obj-m := $(filter-out %/, $(obj-m))
# add it to $(subdir-m)
both-m := $(filter $(mod-subdirs), $(subdir-y))
SUB_DIRS := $(subdir-y) $(if $(BUILD_MODULES),$(subdir-m))
MOD_SUB_DIRS := $(sort $(subdir-m) $(both-m))
ALL_SUB_DIRS := $(sort $(subdir-y) $(subdir-m) $(subdir-n) $(subdir-))
subdir-ym := $(sort $(subdir-y) $(subdir-m))
subdir-ymn := $(sort $(subdir-ym) $(subdir-n) $(subdir-))
# export.o is never a composite object, since $(export-objs) has a
# fixed meaning (== objects which EXPORT_SYMBOL())
......@@ -89,8 +88,16 @@ real-objs-m := $(foreach m, $(obj-m), $(if $($(m:.o=-objs)),$($(m:.o=-objs)),$(m
# Get things started.
# ==========================================================================
ifndef O_TARGET
ifndef L_TARGET
O_TARGET := built-in.o
endif
endif
# The echo suppresses the "Nothing to be done for first_rule"
first_rule: vmlinux $(if $(BUILD_MODULES),$(obj-m))
first_rule: $(if $(KBUILD_BUILTIN),$(O_TARGET) $(L_TARGET) $(EXTRA_TARGETS)) \
$(if $(KBUILD_MODULES),$(obj-m)) \
sub_dirs
@echo -n
# Compile C sources (.c)
......@@ -169,17 +176,9 @@ cmd_as_o_S = $(CC) -Wp,-MD,.$(subst /,_,$@).d $(a_flags) -c -o $@ $<
# If a Makefile does define neither O_TARGET nor L_TARGET,
# use a standard O_TARGET named "built-in.o"
ifndef O_TARGET
ifndef L_TARGET
O_TARGET := built-in.o
endif
endif
# Build the compiled-in targets
# ---------------------------------------------------------------------------
vmlinux: $(O_TARGET) $(L_TARGET) $(EXTRA_TARGETS) sub_dirs
# To build objects in subdirs, we need to descend into the directories
$(sort $(subdir-obj-y)): sub_dirs ;
......@@ -225,61 +224,48 @@ $(multi-used-y) : %.o: $(multi-objs-y) FORCE
$(multi-used-m) : %.o: $(multi-objs-m) FORCE
$(call if_changed,cmd_link_multi)
#
# This makes module versions
#
# Descending when making module versions
# ---------------------------------------------------------------------------
fastdep: FORCE
ifdef ALL_SUB_DIRS
@$(MAKE) $(patsubst %,_sfdep_%,$(ALL_SUB_DIRS)) _FASTDEP_ALL_SUB_DIRS="$(ALL_SUB_DIRS)"
endif
fastdep-list := $(addprefix _sfdep_,$(subdir-ymn))
.PHONY: fastdep $(fastdep-list)
fastdep: $(fastdep-list)
ifdef _FASTDEP_ALL_SUB_DIRS
$(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)):
$(fastdep-list):
@$(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep
endif
# Descending when building
# ---------------------------------------------------------------------------
#
# A rule to make subdirectories
#
subdir-list = $(sort $(patsubst %,_subdir_%,$(SUB_DIRS)))
sub_dirs: FORCE $(subdir-list)
subdir-list := $(addprefix _subdir_,$(subdir-ym))
.PHONY: sub_dirs $(subdir-list)
ifdef SUB_DIRS
$(subdir-list) : FORCE
sub_dirs: $(subdir-list)
$(subdir-list):
@$(MAKE) -C $(patsubst _subdir_%,%,$@)
endif
#
# A rule to make modules
#
ifneq "$(strip $(MOD_SUB_DIRS))" ""
.PHONY: $(patsubst %,_modsubdir_%,$(MOD_SUB_DIRS))
$(patsubst %,_modsubdir_%,$(MOD_SUB_DIRS)) : FORCE
@$(MAKE) -C $(patsubst _modsubdir_%,%,$@) modules
# Descending and installing modules
# ---------------------------------------------------------------------------
.PHONY: $(patsubst %,_modinst_%,$(MOD_SUB_DIRS))
$(patsubst %,_modinst_%,$(MOD_SUB_DIRS)) : FORCE
@$(MAKE) -C $(patsubst _modinst_%,%,$@) modules_install
endif
modinst-list := $(addprefix _modinst_,$(subdir-ym))
.PHONY: modules
modules: $(obj-m) FORCE $(patsubst %,_modsubdir_%,$(MOD_SUB_DIRS))
@echo -n
.PHONY: modules_install _modinst_ $(modinst-list)
.PHONY: _modinst__
_modinst__: FORCE
ifneq "$(strip $(obj-m))" ""
modules_install: $(modinst-list)
ifneq ($(obj-m),)
@echo Installing modules in $(MODLIB)/kernel/$(RELDIR)
@mkdir -p $(MODLIB)/kernel/$(RELDIR)
@cp $(obj-m) $(MODLIB)/kernel/$(RELDIR)
endif
.PHONY: modules_install
modules_install: _modinst__ $(patsubst %,_modinst_%,$(MOD_SUB_DIRS))
else
@echo -n
endif
$(modinst-list):
@$(MAKE) -C $(patsubst _modinst_%,%,$@) modules_install
# Add FORCE to the prequisites of a target to force it to be always rebuilt.
# ---------------------------------------------------------------------------
......
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