diff mbox series

[v4] Makefile: detect HOST_ARCH properly when CROSS_COMPILE is multi-word

Message ID 20241114102138.1977060-1-jerome.forissier@linaro.org
State New
Headers show
Series [v4] Makefile: detect HOST_ARCH properly when CROSS_COMPILE is multi-word | expand

Commit Message

Jerome Forissier Nov. 14, 2024, 10:21 a.m. UTC
When CROSS_COMPILE contains multiple words, HOST_ARCH is not properly
detected and the build may fail. It typically happens when using
ccache. For example:

 $ make qemu_arm64_defconfig
 $ make CROSS_COMPILE="ccache aarch64-linux-gnu-"
   CC      lib/efi_loader/efi_helper.o
 lib/efi_loader/efi_helper.c:26:15: error: operator '==' has no left operand
    26 | #if HOST_ARCH == HOST_ARCH_X86_64
       |               ^~
 [...]

Fix the issue by considering only the last word in $(CROSS_COMPILE).

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Note that this patch was already proposed to fix an issue with the
sandbox build, which was addressed in a different manner [1].
Now the problem crops up again and I bisected it down to commit
7506c1566998 ("sandbox: Report host default-filename in native mode").
In any case there is no reason to have an invalid HOST_ARCH and
this patch does fix it.

[1] https://lore.kernel.org/u-boot/f06b0774-d47c-4414-9974-89d2ebbf1902@linaro.org/

Comments

Quentin Schulz Nov. 14, 2024, 10:49 a.m. UTC | #1
Hi Jerome,

On 11/14/24 11:21 AM, Jerome Forissier wrote:
> When CROSS_COMPILE contains multiple words, HOST_ARCH is not properly
> detected and the build may fail. It typically happens when using
> ccache. For example:
> 
>   $ make qemu_arm64_defconfig
>   $ make CROSS_COMPILE="ccache aarch64-linux-gnu-"
>     CC      lib/efi_loader/efi_helper.o
>   lib/efi_loader/efi_helper.c:26:15: error: operator '==' has no left operand
>      26 | #if HOST_ARCH == HOST_ARCH_X86_64
>         |               ^~
>   [...]
> 
> Fix the issue by considering only the last word in $(CROSS_COMPILE).
> 

I suggested another fix here: 
https://lore.kernel.org/u-boot/20241111-mk_arch-ccache-v1-1-e27f5f605bc4@cherry.de/

We just need one or the other, in in time for v2025.01 :)

Tested-by: Quentin Schulz <quentin.schulz@cherry.de>
Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de>

Thanks!
Quentin
Jerome Forissier Nov. 14, 2024, 10:58 a.m. UTC | #2
On 11/14/24 11:49, Quentin Schulz wrote:
> Hi Jerome,
> 
> On 11/14/24 11:21 AM, Jerome Forissier wrote:
>> When CROSS_COMPILE contains multiple words, HOST_ARCH is not properly
>> detected and the build may fail. It typically happens when using
>> ccache. For example:
>>
>>   $ make qemu_arm64_defconfig
>>   $ make CROSS_COMPILE="ccache aarch64-linux-gnu-"
>>     CC      lib/efi_loader/efi_helper.o
>>   lib/efi_loader/efi_helper.c:26:15: error: operator '==' has no left operand
>>      26 | #if HOST_ARCH == HOST_ARCH_X86_64
>>         |               ^~
>>   [...]
>>
>> Fix the issue by considering only the last word in $(CROSS_COMPILE).
>>
> 
> I suggested another fix here: https://lore.kernel.org/u-boot/20241111-mk_arch-ccache-v1-1-e27f5f605bc4@cherry.de/

Ah, missed that, sorry.

> We just need one or the other, in in time for v2025.01 :)

Agreed. I would argue my version is a bit more flexible as
it does not assume "ccache", but yours is certainly good enough!

> Tested-by: Quentin Schulz <quentin.schulz@cherry.de>
> Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de>
> 
> Thanks!
> Quentin

Thanks,
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index da742ceae76..fbc876c1b83 100644
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,7 @@  include include/host_arch.h
 ifeq ("", "$(CROSS_COMPILE)")
   MK_ARCH="${shell uname -m}"
 else
-  MK_ARCH="${shell echo $(CROSS_COMPILE) | sed -n 's/^[[:space:]]*\([^\/]*\/\)*\([^-]*\)-[^[:space:]]*/\2/p'}"
+  MK_ARCH="${shell echo ${lastword $(CROSS_COMPILE)} | sed -n 's/^[[:space:]]*\([^\/]*\/\)*\([^-]*\)-[^[:space:]]*/\2/p'}"
 endif
 unexport HOST_ARCH
 ifeq ("x86_64", $(MK_ARCH))