mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: HONG Yifan <elsk@google.com>
To: Nathan Chancellor <nathan@kernel.org>,
	Nicolas Schier <nicolas.schier@linux.dev>
Cc: Masahiro Yamada <masahiroy@kernel.org>,
	HONG Yifan <elsk@google.com>,
	kernel-team@android.com,  linux-kbuild@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] kbuild: use $(obj)/ instead of $(src)/ for COPY
Date: Mon,  6 Oct 2025 19:38:38 +0000	[thread overview]
Message-ID: <20251006193839.1350626-1-elsk@google.com> (raw)

Similar to
commit 9a0ebe5011f4 ("kbuild: use $(obj)/ instead of $(src)/ for common pattern rules")

This change updates the COPY rule to use $(obj) instead of $(src). This
makes Kbuild rules like

    always-y += libfoo/.foo.o.cmd

work when the user provides libfoo/.foo.o.cmd_shipped, even when obj and
src is different and src is an absolute path. This is useful when foo.o
and .foo.o.cmd are checked-in as prebuilts.

(Admittedly, `always-y += libfoo/.foo.o.cmd` is not recommended in
kbuild/modules.rst, "Several Subdirectories".)

For example, if

    obj=.
    src=/some/path

then the original rule

    $(obj)/%: $(src)/%_shipped

expands to

    ./%: /some/path/%_shipped

And when matching against the above example, the stem is just `bar.o`
[^1] so the following is looked up:

    libfoo/.foo.o.cmd: libfoo//some/path/.foo.o.cmd_shipped

... and it cannot be matched.

With this change, the rule expands to

    ./%: ./%_shipped

... and it should work, at least for files that does not have a more
specific pattern rule.

NOTE: that after this change, code like

    bar-y += libfoo/foo.o

... with libfoo/foo.o_shipped provided still DOES NOT work, because
the pattern rule $(obj)/%.o takes priority. For .o_shipped files,
the user still needs an explicit `$(obj)/%.o: $(obj)/%.o_shipped` rule
in its own Kbuild file.

[^1]: https://www.gnu.org/software/make/manual/html_node/Pattern-Match.html

Signed-off-by: HONG Yifan <elsk@google.com>
---
 scripts/Makefile.lib | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 1d581ba5df66..e066b7b00bcc 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -272,7 +272,7 @@ endef
 quiet_cmd_copy = COPY    $@
       cmd_copy = cat $< > $@
 
-$(obj)/%: $(src)/%_shipped
+$(obj)/%: $(obj)/%_shipped
 	$(call cmd,copy)
 
 # Touch a file
-- 
2.51.0.618.g983fd99d29-goog


             reply	other threads:[~2025-10-06 19:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-06 19:38 HONG Yifan [this message]
2025-10-09  9:02 ` Nicolas Schier
2025-10-09 21:16   ` Hong, Yifan
2025-10-10 18:50     ` Nicolas Schier
2025-10-10 19:02       ` Hong, Yifan

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=20251006193839.1350626-1-elsk@google.com \
    --to=elsk@google.com \
    --cc=kernel-team@android.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=nathan@kernel.org \
    --cc=nicolas.schier@linux.dev \
    /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

all inboxes | Powered by JetHome®