From: Quentin Monnet <qmo@qmon.net>
To: Li Zhijian <lizhijian@fujitsu.com>, linux-kbuild@vger.kernel.org
Cc: Masahiro Yamada <masahiroy@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nicolas Schier <nicolas@fjasle.eu>,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
Shuah Khan <shuah@kernel.org>,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH RFC] Makefile: Export absolute srctree path for out-of-tree builds
Date: Fri, 20 Dec 2024 17:14:04 +0000 [thread overview]
Message-ID: <4e810697-dfb0-4729-a414-e5d545e61d90@qmon.net> (raw)
In-Reply-To: <20241217031052.69744-1-lizhijian@fujitsu.com>
2024-12-17 11:10 UTC+0800 ~ Li Zhijian <lizhijian@fujitsu.com>
> Fixes an issue where out-of-tree kselftest builds fail when building
> the BPF and bpftools components. The failure occurs because the top-level
> Makefile passes a relative srctree path ('..') to its sub-Makefiles, which
> leads to errors in locating necessary files.
>
> For example, the following error is encountered:
>
> ```
> $ make V=1 O=$build/ TARGETS=hid kselftest-all
> ...
> make -C ../tools/testing/selftests all
> make[4]: Entering directory '/path/to/linux/tools/testing/selftests/hid'
> make -C /path/to/linux/tools/testing/selftests/../../../tools/lib/bpf OUTPUT=/path/to/linux/O/kselftest/hid/tools/build/libbpf/ \
> EXTRA_CFLAGS='-g -O0' \
> DESTDIR=/path/to/linux/O/kselftest/hid/tools prefix= all install_headers
> make[5]: Entering directory '/path/to/linux/tools/lib/bpf'
> ...
> make[5]: Entering directory '/path/to/linux/tools/bpf/bpftool'
> Makefile:127: ../tools/build/Makefile.feature: No such file or directory
> make[5]: *** No rule to make target '../tools/build/Makefile.feature'. Stop.
> ```
Another condition to reproduce the failure above is to have have
$(srcroot) in the Makefile set to "." or "..", for example when your
$build is located right under the root of the repo [0].
[0] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Makefile?h=v6.13-rc3#n273
> To resolve this, the srctree is exported as an absolute path (abs_srctree)
> when performing an out-of-tree build. This ensures that all sub-Makefiles
> have the correct path to the source tree, preventing directory resolution
> errors.
>
> Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
> ---
> Request for Additional Testing
>
> We welcome all contributors and CI systems to test this change thoroughly.
> In theory, this change should not affect in-tree builds. However, to ensure
> stability and compatibility, we encourage testing across different
> configurations.
>
> What has been tested?
> - out-of-tree kernel build
> - out-of-tree kselftest-all
> ---
> Makefile | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/Makefile b/Makefile
> index e5b8a8832c0c..36e65806bb5e 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -275,7 +275,8 @@ else ifeq ($(srcroot)/,$(dir $(CURDIR)))
> srcroot := ..
> endif
>
> -export srctree := $(if $(KBUILD_EXTMOD),$(abs_srctree),$(srcroot))
> +srctree := $(if $(KBUILD_EXTMOD),$(abs_srctree),$(srcroot))
> +export srctree := $(if $(building_out_of_srctree),$(abs_srctree),$(srctree))
>
> ifdef building_out_of_srctree
> export VPATH := $(srcroot)
The patch does fix the issue in the case you reported.
Maybe I'd write the change differently, though; rather than potentially
overwriting $(srctree) before exporting it, let's unroll with ifdef's to
make it clearer?
ifdef building_out_of_srctree
srctree := $(abs_srctree)
else ifdef KBUILD_EXTMOD
srctree := $(abs_srctree)
else
srctree := $(srcroot)
endif
export srctree
(not tested)
Thanks,
Quentin
next prev parent reply other threads:[~2024-12-20 17:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-17 3:10 [PATCH RFC] Makefile: Export absolute srctree path for out-of-tree builds Li Zhijian
2024-12-20 17:14 ` Quentin Monnet [this message]
2024-12-23 1:00 ` Zhijian Li (Fujitsu)
2024-12-21 3:41 ` Masahiro Yamada
2024-12-23 0:57 ` Zhijian Li (Fujitsu)
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=4e810697-dfb0-4729-a414-e5d545e61d90@qmon.net \
--to=qmo@qmon.net \
--cc=bpf@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lizhijian@fujitsu.com \
--cc=masahiroy@kernel.org \
--cc=nathan@kernel.org \
--cc=nicolas@fjasle.eu \
--cc=shuah@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