[PATCH 2/2] kbuild: Add environment variables for userprogs flags

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Elliot Berman <quic_eberman@xxxxxxxxxxx>

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@xxxxxxxxxxx>
    | 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@xxxxxxxxxxx>

[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@xxxxxxxxxxxxxx/

Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
 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





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux