From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
Masahiro Yamada <masahiroy@kernel.org>
Subject: [PATCH v2 1/8] kbuild: fix and refactor single target build
Date: Tue, 6 Sep 2022 15:13:06 +0900 [thread overview]
Message-ID: <20220906061313.1445810-2-masahiroy@kernel.org> (raw)
In-Reply-To: <20220906061313.1445810-1-masahiroy@kernel.org>
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 <masahiroy@kernel.org>
---
Changes in v2:
- New
Makefile | 9 ++++---
scripts/Makefile.build | 54 +++++++++++++-----------------------------
2 files changed, 20 insertions(+), 43 deletions(-)
diff --git a/Makefile b/Makefile
index 0af9dd405fb1..373cd2f0f49e 100644
--- a/Makefile
+++ b/Makefile
@@ -1824,11 +1824,11 @@ single_modpost: $(single-no-ko) modules_prepare
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
$(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
build-dirs := $(foreach d, $(build-dirs), \
- $(if $(filter $(d)/%, $(KBUILD_SINGLE_TARGETS)), $(d)))
+ $(if $(filter $d/%, $(single-goals)), $d))
endif
@@ -1840,9 +1840,8 @@ endif
PHONY += descend $(build-dirs)
descend: $(build-dirs)
$(build-dirs): prepare
- $(Q)$(MAKE) $(build)=$@ \
- single-build=$(if $(filter-out $@/, $(filter $@/%, $(KBUILD_SINGLE_TARGETS))),1) \
- need-builtin=1 need-modorder=1
+ $(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1 \
+ $(filter $@/%, $(single-goals))
clean-dirs := $(addprefix _clean_, $(clean-dirs))
PHONY += $(clean-dirs) clean
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 0df488d0bbb0..91d2e5461a3e 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -5,8 +5,8 @@
src := $(obj)
-PHONY := __build
-__build:
+PHONY := $(obj)/
+$(obj)/:
# Init all relevant variables used in kbuild files so
# 1) they have correct type
@@ -323,7 +323,7 @@ $(obj)/%.o: $(src)/%.S FORCE
targets += $(filter-out $(subdir-builtin), $(real-obj-y))
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)
# ---------------------------------------------------------------------------
@@ -400,8 +400,6 @@ $(multi-obj-m): %.o: %.mod FORCE
$(call if_changed_rule,ld_multi_m)
$(call multi_depend, $(multi-obj-m), .o, -objs -y -m)
-targets := $(filter-out $(PHONY), $(targets))
-
# Add intermediate targets:
# When building objects with specific suffix patterns, add intermediate
# targets that the final targets are derived from.
@@ -420,52 +418,29 @@ targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \
# Build
# ---------------------------------------------------------------------------
-ifdef single-build
-
-KBUILD_SINGLE_TARGETS := $(filter $(obj)/%, $(KBUILD_SINGLE_TARGETS))
-
-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
+$(obj)/: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \
+ $(if $(KBUILD_MODULES), $(targets-for-modules)) \
+ $(subdir-ym) $(always-y)
@:
-ifeq ($(curdir-single),)
-# Nothing to do in this directory. Do not include any .*.cmd file for speed-up
-targets :=
-else
-targets += $(curdir-single)
-endif
+# Single targets
+# ---------------------------------------------------------------------------
-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)) \
- $(if $(KBUILD_MODULES), $(targets-for-modules)) \
- $(subdir-ym) $(always-y)
+$(single-subdir-goals): $(single-subdirs)
@:
-endif
-
# Descending
# ---------------------------------------------------------------------------
PHONY += $(subdir-ym)
$(subdir-ym):
$(Q)$(MAKE) $(build)=$@ \
- $(if $(filter $@/, $(KBUILD_SINGLE_TARGETS)),single-build=) \
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.
# ---------------------------------------------------------------------------
@@ -474,6 +449,9 @@ PHONY += 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
# may be building above, using $(if_changed{,_dep}). As an
# optimization, we don't need to read them if the target does not
--
2.34.1
next prev parent reply other threads:[~2022-09-06 6:14 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-06 6:13 [PATCH v2 0/8] kbuild: various cleanups Masahiro Yamada
2022-09-06 6:13 ` Masahiro Yamada [this message]
2022-09-06 6:13 ` [PATCH v2 2/8] kbuild: rename modules.order in sub-directories to .modules.order Masahiro Yamada
2022-09-06 6:13 ` [PATCH v2 3/8] kbuild: move core-y and drivers-y to ./Kbuild Masahiro Yamada
2022-09-21 4:39 ` Guenter Roeck
[not found] ` <CGME20220922121655eucas1p11822db5dbd1455bcbdba901f543b8e6b@eucas1p1.samsung.com>
2022-09-22 12:16 ` Marek Szyprowski
[not found] ` <CGME20220923113907eucas1p2b33fa5cf73646401089f96a69cf9b745@eucas1p2.samsung.com>
2022-09-23 11:39 ` Marek Szyprowski
2022-09-23 11:41 ` Masahiro Yamada
2022-09-23 12:09 ` Masahiro Yamada
2022-09-06 6:13 ` [PATCH v2 4/8] kbuild: move .vmlinux.objs rule to Makefile.modpost Masahiro Yamada
2022-09-06 6:13 ` [PATCH v2 5/8] kbuild: move vmlinux.o rule to the top Makefile Masahiro Yamada
2022-09-06 6:13 ` [PATCH v2 6/8] kbuild: unify two modpost invocations Masahiro Yamada
2022-09-06 6:13 ` [PATCH v2 7/8] kbuild: use obj-y instead extra-y for objects placed at the head Masahiro Yamada
2022-09-08 7:15 ` Masahiro Yamada
2022-09-19 8:10 ` Geert Uytterhoeven
2022-09-19 12:17 ` Masahiro Yamada
2022-09-19 12:28 ` Geert Uytterhoeven
2022-09-19 22:50 ` Guenter Roeck
2022-09-20 6:56 ` Geert Uytterhoeven
2022-09-20 13:33 ` Guenter Roeck
2022-09-06 6:13 ` [PATCH v2 8/8] kbuild: remove head-y syntax Masahiro Yamada
2022-09-06 7:59 ` Arnd Bergmann
2022-09-06 8:16 ` Ard Biesheuvel
2022-09-06 9:08 ` Masahiro Yamada
2022-09-07 20:15 ` [PATCH v2 0/8] kbuild: various cleanups Nicolas Schier
2022-09-07 20:18 ` Nicolas Schier
2022-09-08 2:00 ` Masahiro Yamada
2022-09-24 18:05 ` Masahiro Yamada
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220906061313.1445810-2-masahiroy@kernel.org \
--to=masahiroy@kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).