* [PATCH] Documentation: kbuild: Add note about using (subst m,y)
@ 2023-02-28 3:13 David Gow
2023-02-28 8:30 ` Masahiro Yamada
0 siblings, 1 reply; 4+ messages in thread
From: David Gow @ 2023-02-28 3:13 UTC (permalink / raw)
To: Masahiro Yamada, Nathan Chancellor, Nick Desaulniers,
Nicolas Schier, Jonathan Corbet
Cc: Sadiya Kazi, Linus Torvalds, Brendan Higgins, linux-kbuild,
linux-doc, linux-kernel, David Gow
THe kbuild documentation already notes that, where there's an obj-y
target in a subdirectory, it will be orphaned if the subdirectory uses
obj-m. Suggest a way of forcing the directory to obj-y when it's based
on a config option which could be 'm'.
Linus made several suggestions as to how this is usually done here:
https://lore.kernel.org/linux-kselftest/CAHk-=wgK07PQ_DBBbAbSJ41t__6de1xZ6q7RRu-JS=2SU0wqLQ@mail.gmail.com/
This only documents the first one, which seems most common.
Signed-off-by: David Gow <davidgow@google.com>
---
Documentation/kbuild/makefiles.rst | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst
index e67eb261c9b0..d9eb24799f52 100644
--- a/Documentation/kbuild/makefiles.rst
+++ b/Documentation/kbuild/makefiles.rst
@@ -254,6 +254,17 @@ from that directory will be linked into vmlinux. If the Makefile in
that directory specifies obj-y, those objects will be left orphan.
It is very likely a bug of the Makefile or of dependencies in Kconfig.
+This means that, if a directory contains both obj-y and obj-m targets,
+it should be added with obj-y. If this directory nevertheless should
+only be built when a config option is enabled (typically to support
+a module which requires one or two files to nevertheless be built-in),
+'subst m,y' can be used to ensure obj-y is used.
+
+Example::
+
+ #drivers/Makefile
+ obj-$(subst m,y,$(CONFIG_HYPERV)) += hv/
+
Kbuild also supports dedicated syntax, subdir-y and subdir-m, for
descending into subdirectories. It is a good fit when you know they
do not contain kernel-space objects at all. A typical usage is to let
--
2.39.2.722.g9855ee24e9-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Documentation: kbuild: Add note about using (subst m,y)
2023-02-28 3:13 [PATCH] Documentation: kbuild: Add note about using (subst m,y) David Gow
@ 2023-02-28 8:30 ` Masahiro Yamada
2023-02-28 15:15 ` Alexander Lobakin
0 siblings, 1 reply; 4+ messages in thread
From: Masahiro Yamada @ 2023-02-28 8:30 UTC (permalink / raw)
To: David Gow
Cc: Nathan Chancellor, Nick Desaulniers, Nicolas Schier,
Jonathan Corbet, Sadiya Kazi, Linus Torvalds, Brendan Higgins,
linux-kbuild, linux-doc, linux-kernel
On Tue, Feb 28, 2023 at 12:13 PM David Gow <davidgow@google.com> wrote:
>
> THe kbuild documentation already notes that, where there's an obj-y
> target in a subdirectory, it will be orphaned if the subdirectory uses
> obj-m. Suggest a way of forcing the directory to obj-y when it's based
> on a config option which could be 'm'.
>
> Linus made several suggestions as to how this is usually done here:
> https://lore.kernel.org/linux-kselftest/CAHk-=wgK07PQ_DBBbAbSJ41t__6de1xZ6q7RRu-JS=2SU0wqLQ@mail.gmail.com/
>
> This only documents the first one, which seems most common.
>
> Signed-off-by: David Gow <davidgow@google.com>
> ---
> Documentation/kbuild/makefiles.rst | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst
> index e67eb261c9b0..d9eb24799f52 100644
> --- a/Documentation/kbuild/makefiles.rst
> +++ b/Documentation/kbuild/makefiles.rst
> @@ -254,6 +254,17 @@ from that directory will be linked into vmlinux. If the Makefile in
> that directory specifies obj-y, those objects will be left orphan.
> It is very likely a bug of the Makefile or of dependencies in Kconfig.
>
> +This means that, if a directory contains both obj-y and obj-m targets,
> +it should be added with obj-y. If this directory nevertheless should
> +only be built when a config option is enabled (typically to support
> +a module which requires one or two files to nevertheless be built-in),
> +'subst m,y' can be used to ensure obj-y is used.
> +
> +Example::
> +
> + #drivers/Makefile
> + obj-$(subst m,y,$(CONFIG_HYPERV)) += hv/
> +
I think many subsystems simply do
obj-y += hv/
I do not think we need to advertise hyperv's way
since it does not look very pretty.
Mostly, it looks like this:
obj-y += kunit/
and
obj-$(CONFIG_KUNIT_HOOK) += hook.o
Bikeshed:
I think Linus' suggestion is OK, but
the BSD style seems less ugly,
of course, that is just a matter of style.
obj-$(CONFIG_HYPERV:m=y) += kunit/
> Kbuild also supports dedicated syntax, subdir-y and subdir-m, for
> descending into subdirectories. It is a good fit when you know they
> do not contain kernel-space objects at all. A typical usage is to let
> --
> 2.39.2.722.g9855ee24e9-goog
>
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Documentation: kbuild: Add note about using (subst m,y)
2023-02-28 8:30 ` Masahiro Yamada
@ 2023-02-28 15:15 ` Alexander Lobakin
2023-02-28 16:25 ` Masahiro Yamada
0 siblings, 1 reply; 4+ messages in thread
From: Alexander Lobakin @ 2023-02-28 15:15 UTC (permalink / raw)
To: Masahiro Yamada, David Gow
Cc: Nathan Chancellor, Nick Desaulniers, Nicolas Schier,
Jonathan Corbet, Sadiya Kazi, Linus Torvalds, Brendan Higgins,
linux-kbuild, linux-doc, linux-kernel
From: Masahiro Yamada <masahiroy@kernel.org>
Date: Tue, 28 Feb 2023 17:30:09 +0900
> On Tue, Feb 28, 2023 at 12:13 PM David Gow <davidgow@google.com> wrote:
[...]
>> +Example::
>> +
>> + #drivers/Makefile
>> + obj-$(subst m,y,$(CONFIG_HYPERV)) += hv/
>> +
>
>
> I think many subsystems simply do
>
> obj-y += hv/
This creates a ton of empty built-in.a, each of them is listed in the
Kbuild output. Someone may think that if a directory contains
built-in.a, then something was built there. Sure it's their problems,
but I'd prefer to not pollute the log and built-in.a contents when
possible (empty files are still listed there IIRC).
>
>
> I do not think we need to advertise hyperv's way
> since it does not look very pretty.
>
>
>
>
>
>
>
> Mostly, it looks like this:
>
>
> obj-y += kunit/
>
> and
>
> obj-$(CONFIG_KUNIT_HOOK) += hook.o
>
>
>
>
>
>
>
> Bikeshed:
>
> I think Linus' suggestion is OK, but
> the BSD style seems less ugly,
> of course, that is just a matter of style.
>
>
> obj-$(CONFIG_HYPERV:m=y) += kunit/
I'd vote for this one, it's compact and readable.
>
>
>
>
>> Kbuild also supports dedicated syntax, subdir-y and subdir-m, for
>> descending into subdirectories. It is a good fit when you know they
>> do not contain kernel-space objects at all. A typical usage is to let
>> --
>> 2.39.2.722.g9855ee24e9-goog
>>
>
>
> --
> Best Regards
> Masahiro Yamada
>
Thanks,
Olek
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Documentation: kbuild: Add note about using (subst m,y)
2023-02-28 15:15 ` Alexander Lobakin
@ 2023-02-28 16:25 ` Masahiro Yamada
0 siblings, 0 replies; 4+ messages in thread
From: Masahiro Yamada @ 2023-02-28 16:25 UTC (permalink / raw)
To: Alexander Lobakin
Cc: David Gow, Nathan Chancellor, Nick Desaulniers, Nicolas Schier,
Jonathan Corbet, Sadiya Kazi, Linus Torvalds, Brendan Higgins,
linux-kbuild, linux-doc, linux-kernel
On Wed, Mar 1, 2023 at 12:16 AM Alexander Lobakin
<aleksander.lobakin@intel.com> wrote:
>
> From: Masahiro Yamada <masahiroy@kernel.org>
> Date: Tue, 28 Feb 2023 17:30:09 +0900
>
> > On Tue, Feb 28, 2023 at 12:13 PM David Gow <davidgow@google.com> wrote:
>
> [...]
>
> >> +Example::
> >> +
> >> + #drivers/Makefile
> >> + obj-$(subst m,y,$(CONFIG_HYPERV)) += hv/
> >> +
> >
> >
> > I think many subsystems simply do
> >
> > obj-y += hv/
>
> This creates a ton of empty built-in.a, each of them is listed in the
> Kbuild output. Someone may think that if a directory contains
> built-in.a, then something was built there. Sure it's their problems,
> but I'd prefer to not pollute the log and built-in.a contents when
> possible (empty files are still listed there IIRC).
You can choose whichever you like.
Up to each subsystem maintainer.
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-02-28 16:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-28 3:13 [PATCH] Documentation: kbuild: Add note about using (subst m,y) David Gow
2023-02-28 8:30 ` Masahiro Yamada
2023-02-28 15:15 ` Alexander Lobakin
2023-02-28 16:25 ` Masahiro Yamada
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox