From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Masahiro Yamada <masahiroy@kernel.org>,
Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] kbuild: Add environment variables for userprogs flags
Date: Thu, 27 Jul 2023 10:48:12 +0200 [thread overview]
Message-ID: <20230727084812.880438-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20230727084812.880438-1-a.fatoum@pengutronix.de>
From: Elliot Berman <quic_eberman@quicinc.com>
Build systems integrating barebox may want to pass compiler and linker
options for when barebox is building target tools. This is especially
important when the compiler toolchain is configured without a sysroot
like in Yocto and the --sysroot option must be used. As there was no
option explicitly meant for this, userccflags is sometimes abused and
set in the environment[1][2].
While this appears to work, it breaks when setting userccflags as make
option instead of an environment variable. Let's just provide USERCFLAGS
and USERLDFLAGS explicitly for this use case.
This is an adaptation of Linux commit:
| commit f67695c9962e5f444549b3437fb8d840ec6222c8
| Author: Elliot Berman <quic_eberman@quicinc.com>
| Date: Tue Feb 1 13:35:42 2022 -0800
|
| Allow additional arguments be passed to userprogs compilation.
| Reproducible clang builds need to provide a sysroot and gcc path to
| ensure the same toolchain is used across hosts. KCFLAGS is not currently
| used for any user programs compilation, so add new USERCFLAGS and
| USERLDFLAGS which serves similar purpose as HOSTCFLAGS/HOSTLDFLAGS.
|
| Clang might detect GCC installation on hosts which have it installed
| to a default location in /. With addition of these environment
| variables, you can specify flags such as:
|
| $ make USERCFLAGS=--sysroot=/path/to/sysroot
|
| This can also be used to specify different sysroots such as musl or
| bionic which may be installed on the host in paths that the compiler
| may not search by default.
|
| Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
[1]: https://github.com/pengutronix/meta-ptx/blob/38ada68c70/recipes-bsp/barebox/barebox.inc#L91
[2]: https://lore.kernel.org/all/20230331104025.1478393-3-ejo@pengutronix.de/
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Makefile | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile
index acf7b2006765..f935fd2604b2 100644
--- a/Makefile
+++ b/Makefile
@@ -386,11 +386,12 @@ HOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null)
HOSTCC = gcc
HOSTCXX = g++
-export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
+KBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
-O2 -fomit-frame-pointer -std=gnu89
-export KBUILD_USERLDFLAGS :=
+KBUILD_USERCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(USERCFLAGS)
+KBUILD_USERLDFLAGS := $(USERLDFLAGS)
-KBUILD_HOSTCFLAGS := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
+KBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)
KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
@@ -475,6 +476,7 @@ export CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL PYTHON3 UTS_MACHIN
export LEX YACC
export HOSTCXX CHECK CHECKFLAGS
export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
+export KBUILD_USERCFLAGS KBUILD_USERLDFLAGS
export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS
export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
--
2.39.2
next prev parent reply other threads:[~2023-07-27 8:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-27 8:48 [PATCH 1/2] Makefile: allow setting pkg-config binary via PKG_CONFIG Ahmad Fatoum
2023-07-27 8:48 ` Ahmad Fatoum [this message]
2023-07-28 5:51 ` Sascha Hauer
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=20230727084812.880438-2-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=masahiroy@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