linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 3/8] kbuild: move core-y and drivers-y to ./Kbuild
Date: Tue,  6 Sep 2022 15:13:08 +0900	[thread overview]
Message-ID: <20220906061313.1445810-4-masahiroy@kernel.org> (raw)
In-Reply-To: <20220906061313.1445810-1-masahiroy@kernel.org>

Use the ordinary obj-y to list subdirectories.

Note1:
GNU Make seems to transform './.modules.order' to '.modules.order'
before matching it against the target pattern. Split ./.modules.order
to a dedicated rule to avoid "doesn't match the target pattern"
warning. [1]

Note2:
Previously, the link order of lib-y depended on CONFIG_MODULES; lib-y
was linked before drivers-y when CONFIG_MODULES=y, otherwise after
drivers-y. This was a bug of commit 7273ad2b08f8 ("kbuild: link lib-y
objects to vmlinux forcibly when CONFIG_MODULES=y"), but it was not a
big deal after all. Now, libs-y (all objects that come from lib/ and
arch/*/lib/) is linked last, irrespective of CONFIG_MODULES.

Note3:
Now, the single target build in arch/*/lib/ works correctly. There was
a bug report about this. [2]

  $ make ARCH=arm arch/arm/lib/findbit.o
    CALL    scripts/checksyscalls.sh
    AS      arch/arm/lib/findbit.o

[1]: https://lists.gnu.org/archive/html/bug-make/2022-08/msg00059.html
[2]: https://lore.kernel.org/linux-kbuild/YvUQOwL6lD4%2F5%2FU6@shell.armlinux.org.uk/

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

Changes in v2:
  - Move all core-y and drivers-y
  - Fix single target build

 Kbuild               | 23 +++++++++++++++++++++++
 Makefile             | 29 +++++++++++++----------------
 scripts/Makefile.lib |  2 ++
 3 files changed, 38 insertions(+), 16 deletions(-)

diff --git a/Kbuild b/Kbuild
index 0b9e8a16a621..8854e88e0619 100644
--- a/Kbuild
+++ b/Kbuild
@@ -72,3 +72,26 @@ $(atomic-checks): $(obj)/.checked-%: include/linux/atomic/%  FORCE
 PHONY += prepare
 prepare: $(offsets-file) missing-syscalls $(atomic-checks)
 	@:
+
+# Ordinary directory descending
+# ---------------------------------------------------------------------------
+
+obj-y			+= init/
+obj-y			+= usr/
+obj-y			+= arch/$(SRCARCH)/
+obj-y			+= $(ARCH_CORE)
+obj-y			+= kernel/
+obj-y			+= certs/
+obj-y			+= mm/
+obj-y			+= fs/
+obj-y			+= ipc/
+obj-y			+= security/
+obj-y			+= crypto/
+obj-$(CONFIG_BLOCK)	+= block/
+obj-$(CONFIG_IO_URING)	+= io_uring/
+obj-y			+= drivers/
+obj-y			+= sound/
+obj-$(CONFIG_SAMPLES)	+= samples/
+obj-$(CONFIG_NET)	+= net/
+obj-y			+= virt/
+obj-y			+= $(ARCH_DRIVERS)
diff --git a/Makefile b/Makefile
index 552ade93ca1d..ef0621d55ebb 100644
--- a/Makefile
+++ b/Makefile
@@ -676,11 +676,8 @@ endif
 
 ifeq ($(KBUILD_EXTMOD),)
 # Objects we will link into vmlinux / subdirs we need to visit
-core-y		:= init/ usr/ arch/$(SRCARCH)/
-drivers-y	:= drivers/ sound/
-drivers-$(CONFIG_SAMPLES) += samples/
-drivers-$(CONFIG_NET) += net/
-drivers-y	+= virt/
+core-y		:=
+drivers-y	:=
 libs-y		:= lib/
 endif # KBUILD_EXTMOD
 
@@ -1101,23 +1098,20 @@ export MODORDER := $(extmod_prefix)modules.order
 export MODULES_NSDEPS := $(extmod_prefix)modules.nsdeps
 
 ifeq ($(KBUILD_EXTMOD),)
-core-y			+= kernel/ certs/ mm/ fs/ ipc/ security/ crypto/
-core-$(CONFIG_BLOCK)	+= block/
-core-$(CONFIG_IO_URING)	+= io_uring/
 
-vmlinux-dirs	:= $(patsubst %/,%,$(filter %/, \
-		     $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
-		     $(libs-y) $(libs-m)))
+vmlinux-dirs	:= . $(patsubst %/,%,$(filter %/, $(libs-y) $(libs-m)))
 
-vmlinux-alldirs	:= $(sort $(vmlinux-dirs) Documentation . \
+vmlinux-alldirs	:= $(sort $(vmlinux-dirs) Documentation \
 		     $(patsubst %/,%,$(filter %/, $(core-) \
 			$(drivers-) $(libs-))))
 
 build-dirs	:= $(vmlinux-dirs)
 clean-dirs	:= $(vmlinux-alldirs)
 
+export ARCH_CORE	:= $(core-y)
+export ARCH_DRIVERS	:= $(drivers-y)
 # Externally visible symbols (used by link-vmlinux.sh)
-KBUILD_VMLINUX_OBJS := $(head-y) $(patsubst %/,%/built-in.a, $(core-y))
+KBUILD_VMLINUX_OBJS := $(head-y) ./built-in.a
 KBUILD_VMLINUX_OBJS += $(addsuffix built-in.a, $(filter %/, $(libs-y)))
 ifdef CONFIG_MODULES
 KBUILD_VMLINUX_OBJS += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y)))
@@ -1125,7 +1119,6 @@ KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y))
 else
 KBUILD_VMLINUX_LIBS := $(patsubst %/,%/lib.a, $(libs-y))
 endif
-KBUILD_VMLINUX_OBJS += $(patsubst %/,%/built-in.a, $(drivers-y))
 
 export KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LIBS
 export KBUILD_LDS          := arch/$(SRCARCH)/kernel/vmlinux.lds
@@ -1752,7 +1745,10 @@ ifdef CONFIG_MODULES
 
 subdir-modorder := $(addsuffix /.modules.order, $(build-dirs))
 
-$(sort $(subdir-modorder)): %/.modules.order: % ;
+# Split ./.modules.order into a dedicate target to avoid
+# "doesn't match the target pattern" warning
+./.modules.order: . ;
+$(sort $(filter-out ./.modules.order, $(subdir-modorder))): %/.modules.order: % ;
 
 cmd_modules_order = cat $(real-prereqs) > $@
 
@@ -1823,7 +1819,8 @@ single_modpost: $(single-no-ko) modules_prepare
 	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
 	$(Q)rm -f $(MODORDER)
 
-single-goals := $(addprefix $(extmod_prefix), $(single-no-ko))
+single-goals := $(foreach x, $(addprefix $(extmod_prefix), $(single-no-ko)), \
+		$(if $(filter $(addsuffix /%, $(build-dirs)), $x),,./)$x)
 
 # trim unrelated directories
 build-dirs := $(foreach d, $(build-dirs), \
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index b594705d571a..9bdc9ed37f49 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -89,6 +89,7 @@ always-y			+= $(dtb-y)
 
 # Add subdir path
 
+ifneq ($(obj),.)
 extra-y		:= $(addprefix $(obj)/,$(extra-y))
 always-y	:= $(addprefix $(obj)/,$(always-y))
 targets		:= $(addprefix $(obj)/,$(targets))
@@ -100,6 +101,7 @@ multi-obj-m	:= $(addprefix $(obj)/, $(multi-obj-m))
 multi-dtb-y	:= $(addprefix $(obj)/, $(multi-dtb-y))
 real-dtb-y	:= $(addprefix $(obj)/, $(real-dtb-y))
 subdir-ym	:= $(addprefix $(obj)/,$(subdir-ym))
+endif
 
 # Finds the multi-part object the current object will be linked into.
 # If the object belongs to two or more multi-part objects, list them all.
-- 
2.34.1


  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 ` [PATCH v2 1/8] kbuild: fix and refactor single target build Masahiro Yamada
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 ` Masahiro Yamada [this message]
2022-09-21  4:39   ` [PATCH v2 3/8] kbuild: move core-y and drivers-y to ./Kbuild 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-4-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).