Skip to content

Commit cc306ab

Browse files
committed
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: Masahiro Yamada <[email protected]>
1 parent 033a52d commit cc306ab

File tree

2 files changed

+20
-43
lines changed

2 files changed

+20
-43
lines changed

Makefile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,11 +1819,11 @@ single_modpost: $(single-no-ko) modules_prepare
18191819
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
18201820
$(Q)rm -f $(MODORDER)
18211821

1822-
export KBUILD_SINGLE_TARGETS := $(addprefix $(extmod_prefix), $(single-no-ko))
1822+
single-goals := $(addprefix $(extmod_prefix), $(single-no-ko))
18231823

18241824
# trim unrelated directories
18251825
build-dirs := $(foreach d, $(build-dirs), \
1826-
$(if $(filter $(d)/%, $(KBUILD_SINGLE_TARGETS)), $(d)))
1826+
$(if $(filter $d/%, $(single-goals)), $d))
18271827

18281828
endif
18291829

@@ -1835,9 +1835,8 @@ endif
18351835
PHONY += descend $(build-dirs)
18361836
descend: $(build-dirs)
18371837
$(build-dirs): prepare
1838-
$(Q)$(MAKE) $(build)=$@ \
1839-
single-build=$(if $(filter-out $@/, $(filter $@/%, $(KBUILD_SINGLE_TARGETS))),1) \
1840-
need-builtin=1 need-modorder=1
1838+
$(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1 \
1839+
$(filter $@/%, $(single-goals))
18411840

18421841
clean-dirs := $(addprefix _clean_, $(clean-dirs))
18431842
PHONY += $(clean-dirs) clean

scripts/Makefile.build

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
src := $(obj)
77

8-
PHONY := __build
9-
__build:
8+
PHONY := $(obj)/
9+
$(obj)/:
1010

1111
# Init all relevant variables used in kbuild files so
1212
# 1) they have correct type
@@ -323,7 +323,7 @@ $(obj)/%.o: $(src)/%.S FORCE
323323

324324
targets += $(filter-out $(subdir-builtin), $(real-obj-y))
325325
targets += $(filter-out $(subdir-modorder), $(real-obj-m))
326-
targets += $(real-dtb-y) $(lib-y) $(always-y) $(MAKECMDGOALS)
326+
targets += $(real-dtb-y) $(lib-y) $(always-y)
327327

328328
# Linker scripts preprocessor (.lds.S -> .lds)
329329
# ---------------------------------------------------------------------------
@@ -400,8 +400,6 @@ $(multi-obj-m): %.o: %.mod FORCE
400400
$(call if_changed_rule,ld_multi_m)
401401
$(call multi_depend, $(multi-obj-m), .o, -objs -y -m)
402402

403-
targets := $(filter-out $(PHONY), $(targets))
404-
405403
# Add intermediate targets:
406404
# When building objects with specific suffix patterns, add intermediate
407405
# targets that the final targets are derived from.
@@ -420,52 +418,29 @@ targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \
420418
# Build
421419
# ---------------------------------------------------------------------------
422420

423-
ifdef single-build
424-
425-
KBUILD_SINGLE_TARGETS := $(filter $(obj)/%, $(KBUILD_SINGLE_TARGETS))
426-
427-
curdir-single := $(sort $(foreach x, $(KBUILD_SINGLE_TARGETS), \
428-
$(if $(filter $(x) $(basename $(x)).o, $(targets)), $(x))))
429-
430-
# Handle single targets without any rule: show "Nothing to be done for ..." or
431-
# "No rule to make target ..." depending on whether the target exists.
432-
unknown-single := $(filter-out $(addsuffix /%, $(subdir-ym)), \
433-
$(filter-out $(curdir-single), $(KBUILD_SINGLE_TARGETS)))
434-
435-
single-subdirs := $(foreach d, $(subdir-ym), \
436-
$(if $(filter $(d)/%, $(KBUILD_SINGLE_TARGETS)), $(d)))
437-
438-
__build: $(curdir-single) $(single-subdirs)
439-
ifneq ($(unknown-single),)
440-
$(Q)$(MAKE) -f /dev/null $(unknown-single)
441-
endif
421+
$(obj)/: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \
422+
$(if $(KBUILD_MODULES), $(targets-for-modules)) \
423+
$(subdir-ym) $(always-y)
442424
@:
443425

444-
ifeq ($(curdir-single),)
445-
# Nothing to do in this directory. Do not include any .*.cmd file for speed-up
446-
targets :=
447-
else
448-
targets += $(curdir-single)
449-
endif
426+
# Single targets
427+
# ---------------------------------------------------------------------------
450428

451-
else
429+
single-subdirs := $(foreach d, $(subdir-ym), $(if $(filter $d/%, $(MAKECMDGOALS)), $d))
430+
single-subdir-goals := $(filter $(addsuffix /%, $(single-subdirs)), $(MAKECMDGOALS))
452431

453-
__build: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \
454-
$(if $(KBUILD_MODULES), $(targets-for-modules)) \
455-
$(subdir-ym) $(always-y)
432+
$(single-subdir-goals): $(single-subdirs)
456433
@:
457434

458-
endif
459-
460435
# Descending
461436
# ---------------------------------------------------------------------------
462437

463438
PHONY += $(subdir-ym)
464439
$(subdir-ym):
465440
$(Q)$(MAKE) $(build)=$@ \
466-
$(if $(filter $@/, $(KBUILD_SINGLE_TARGETS)),single-build=) \
467441
need-builtin=$(if $(filter $@/built-in.a, $(subdir-builtin)),1) \
468-
need-modorder=$(if $(filter $@/modules.order, $(subdir-modorder)),1)
442+
need-modorder=$(if $(filter $@/modules.order, $(subdir-modorder)),1) \
443+
$(filter $@/%, $(single-subdir-goals))
469444

470445
# Add FORCE to the prequisites of a target to force it to be always rebuilt.
471446
# ---------------------------------------------------------------------------
@@ -474,6 +449,9 @@ PHONY += FORCE
474449

475450
FORCE:
476451

452+
targets += $(filter-out $(single-subdir-goals), $(MAKECMDGOALS))
453+
targets := $(filter-out $(PHONY), $(targets))
454+
477455
# Read all saved command lines and dependencies for the $(targets) we
478456
# may be building above, using $(if_changed{,_dep}). As an
479457
# optimization, we don't need to read them if the target does not

0 commit comments

Comments
 (0)