提交 cc306abd 编写于 作者: M Masahiro Yamada

kbuild: fix and refactor single target build

The single target build has a subtle bug for the combination for
an individual file and a subdirectory.

[1] 'make kernel/fork.i' builds only kernel/fork.i

  $ make kernel/fork.i
    CALL    scripts/checksyscalls.sh
    DESCEND objtool
    CPP     kernel/fork.i

[2] 'make kernel/' builds only under the kernel/ directory.

  $ make kernel/
    CALL    scripts/checksyscalls.sh
    DESCEND objtool
    CC      kernel/fork.o
    CC      kernel/exec_domain.o
       [snip]
    CC      kernel/rseq.o
    AR      kernel/built-in.a

But, if you try to do [1] and [2] in a single command, you will get
only [1] with a weird log:

  $ make kernel/fork.i kernel/
    CALL    scripts/checksyscalls.sh
    DESCEND objtool
    CPP     kernel/fork.i
  make[2]: Nothing to be done for 'kernel/'.

With 'make kernel/fork.i kernel/', you should get both [1] and [2].

Rewrite the single target build.
Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
上级 033a52d0
...@@ -1819,11 +1819,11 @@ single_modpost: $(single-no-ko) modules_prepare ...@@ -1819,11 +1819,11 @@ single_modpost: $(single-no-ko) modules_prepare
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
$(Q)rm -f $(MODORDER) $(Q)rm -f $(MODORDER)
export KBUILD_SINGLE_TARGETS := $(addprefix $(extmod_prefix), $(single-no-ko)) single-goals := $(addprefix $(extmod_prefix), $(single-no-ko))
# trim unrelated directories # trim unrelated directories
build-dirs := $(foreach d, $(build-dirs), \ build-dirs := $(foreach d, $(build-dirs), \
$(if $(filter $(d)/%, $(KBUILD_SINGLE_TARGETS)), $(d))) $(if $(filter $d/%, $(single-goals)), $d))
endif endif
...@@ -1835,9 +1835,8 @@ endif ...@@ -1835,9 +1835,8 @@ endif
PHONY += descend $(build-dirs) PHONY += descend $(build-dirs)
descend: $(build-dirs) descend: $(build-dirs)
$(build-dirs): prepare $(build-dirs): prepare
$(Q)$(MAKE) $(build)=$@ \ $(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1 \
single-build=$(if $(filter-out $@/, $(filter $@/%, $(KBUILD_SINGLE_TARGETS))),1) \ $(filter $@/%, $(single-goals))
need-builtin=1 need-modorder=1
clean-dirs := $(addprefix _clean_, $(clean-dirs)) clean-dirs := $(addprefix _clean_, $(clean-dirs))
PHONY += $(clean-dirs) clean PHONY += $(clean-dirs) clean
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
src := $(obj) src := $(obj)
PHONY := __build PHONY := $(obj)/
__build: $(obj)/:
# Init all relevant variables used in kbuild files so # Init all relevant variables used in kbuild files so
# 1) they have correct type # 1) they have correct type
...@@ -323,7 +323,7 @@ $(obj)/%.o: $(src)/%.S FORCE ...@@ -323,7 +323,7 @@ $(obj)/%.o: $(src)/%.S FORCE
targets += $(filter-out $(subdir-builtin), $(real-obj-y)) targets += $(filter-out $(subdir-builtin), $(real-obj-y))
targets += $(filter-out $(subdir-modorder), $(real-obj-m)) targets += $(filter-out $(subdir-modorder), $(real-obj-m))
targets += $(real-dtb-y) $(lib-y) $(always-y) $(MAKECMDGOALS) targets += $(real-dtb-y) $(lib-y) $(always-y)
# Linker scripts preprocessor (.lds.S -> .lds) # Linker scripts preprocessor (.lds.S -> .lds)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
...@@ -400,8 +400,6 @@ $(multi-obj-m): %.o: %.mod FORCE ...@@ -400,8 +400,6 @@ $(multi-obj-m): %.o: %.mod FORCE
$(call if_changed_rule,ld_multi_m) $(call if_changed_rule,ld_multi_m)
$(call multi_depend, $(multi-obj-m), .o, -objs -y -m) $(call multi_depend, $(multi-obj-m), .o, -objs -y -m)
targets := $(filter-out $(PHONY), $(targets))
# Add intermediate targets: # Add intermediate targets:
# When building objects with specific suffix patterns, add intermediate # When building objects with specific suffix patterns, add intermediate
# targets that the final targets are derived from. # targets that the final targets are derived from.
...@@ -420,52 +418,29 @@ targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \ ...@@ -420,52 +418,29 @@ targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \
# Build # Build
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
ifdef single-build $(obj)/: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \
$(if $(KBUILD_MODULES), $(targets-for-modules)) \
KBUILD_SINGLE_TARGETS := $(filter $(obj)/%, $(KBUILD_SINGLE_TARGETS)) $(subdir-ym) $(always-y)
curdir-single := $(sort $(foreach x, $(KBUILD_SINGLE_TARGETS), \
$(if $(filter $(x) $(basename $(x)).o, $(targets)), $(x))))
# Handle single targets without any rule: show "Nothing to be done for ..." or
# "No rule to make target ..." depending on whether the target exists.
unknown-single := $(filter-out $(addsuffix /%, $(subdir-ym)), \
$(filter-out $(curdir-single), $(KBUILD_SINGLE_TARGETS)))
single-subdirs := $(foreach d, $(subdir-ym), \
$(if $(filter $(d)/%, $(KBUILD_SINGLE_TARGETS)), $(d)))
__build: $(curdir-single) $(single-subdirs)
ifneq ($(unknown-single),)
$(Q)$(MAKE) -f /dev/null $(unknown-single)
endif
@: @:
ifeq ($(curdir-single),) # Single targets
# Nothing to do in this directory. Do not include any .*.cmd file for speed-up # ---------------------------------------------------------------------------
targets :=
else
targets += $(curdir-single)
endif
else single-subdirs := $(foreach d, $(subdir-ym), $(if $(filter $d/%, $(MAKECMDGOALS)), $d))
single-subdir-goals := $(filter $(addsuffix /%, $(single-subdirs)), $(MAKECMDGOALS))
__build: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \ $(single-subdir-goals): $(single-subdirs)
$(if $(KBUILD_MODULES), $(targets-for-modules)) \
$(subdir-ym) $(always-y)
@: @:
endif
# Descending # Descending
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
PHONY += $(subdir-ym) PHONY += $(subdir-ym)
$(subdir-ym): $(subdir-ym):
$(Q)$(MAKE) $(build)=$@ \ $(Q)$(MAKE) $(build)=$@ \
$(if $(filter $@/, $(KBUILD_SINGLE_TARGETS)),single-build=) \
need-builtin=$(if $(filter $@/built-in.a, $(subdir-builtin)),1) \ need-builtin=$(if $(filter $@/built-in.a, $(subdir-builtin)),1) \
need-modorder=$(if $(filter $@/modules.order, $(subdir-modorder)),1) need-modorder=$(if $(filter $@/modules.order, $(subdir-modorder)),1) \
$(filter $@/%, $(single-subdir-goals))
# Add FORCE to the prequisites of a target to force it to be always rebuilt. # Add FORCE to the prequisites of a target to force it to be always rebuilt.
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
...@@ -474,6 +449,9 @@ PHONY += FORCE ...@@ -474,6 +449,9 @@ PHONY += FORCE
FORCE: FORCE:
targets += $(filter-out $(single-subdir-goals), $(MAKECMDGOALS))
targets := $(filter-out $(PHONY), $(targets))
# Read all saved command lines and dependencies for the $(targets) we # Read all saved command lines and dependencies for the $(targets) we
# may be building above, using $(if_changed{,_dep}). As an # may be building above, using $(if_changed{,_dep}). As an
# optimization, we don't need to read them if the target does not # optimization, we don't need to read them if the target does not
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册