package/llvm-project: fix gcc-install-dir in clang

The previous method used to determine the --gcc-install-dir relied on
'ls' over the gcc installation path, which was fragile and failed in
cases where the external toolchain contained multiple gcc versions or
paths [1].

We replace it a more reliable approach using:
$(TARGET_CC) -print-search-dirs

This helps setup to register the desired GCC architecture if a
given toolchain packages includes multiple GCC architecture
installations. Which isn't possible using the actual method using 'ls'.

For example from James's report:

    └── /opt/container/my-toolchain-2025.01.01.12345/lib/gcc/
        ├── aarch64-example-linux-gnu/
        │   └── ...
        ├── i686-example-linux-gnu/
        │   └── ...
        └── x86_64-example-linux-gnu/
            └── ...

Thanks to Romain Naour for suggesting this improved method.

[1] https://lore.kernel.org/buildroot/d1c773dc-8346-4077-946a-0d3b4e30a6c8@smile.fr/T/#t

Reported by: James Knight <git@jdknight.me>
Signed-off-by: El Mehdi YOUNES <elmehdi.younes@smile.fr>
Tested-by: James Knight <jdknight@jdknight.me>
Tested-by: James Knight <git@jdknight.me>
Signed-off-by: Romain Naour <romain.naour@smile.fr>
This commit is contained in:
El Mehdi YOUNES
2025-07-03 16:59:55 +02:00
committed by Romain Naour
parent 117ccb6cc4
commit cbe67e4b11

View File

@@ -115,8 +115,7 @@ CLANG_CONF_OPTS += -DLLVM_DYLIB_COMPONENTS=all
ifeq ($(BR2_TOOLCHAIN_EXTERNAL),y)
define HOST_CLANG_INSTALL_CONFIG_FILE
mkdir -p $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)
touch $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)/$(GNU_TARGET_NAME).cfg
echo "--gcc-install-dir=$(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/$$(ls $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/)/$$(ls $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/$$(ls $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/)/)" > $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)/$(GNU_TARGET_NAME).cfg
echo "--gcc-install-dir=$$($(TARGET_CC) -print-search-dirs | awk -F ': ' '$$1=="install" {print $$2}')" > $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)/$(GNU_TARGET_NAME).cfg
echo "--target=$(GNU_TARGET_NAME)" >> $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)/$(GNU_TARGET_NAME).cfg
endef