Skip to content

Commit

Permalink
scripts/ext-toolchain: implement external GCC version detection
Browse files Browse the repository at this point in the history
Some package may needs to enable compatibility option based on the GCC
version.

Currently the GCC version is set based on the default value and doesn't
actually reflect the real value provided by the external toolchain if
used.

Fix this by correctly detecting the GCC version in the external
toolchain and set the correct value in CONFIG_GCC_VERSION.

A new option is added in menuconfig to manually set the GCC version if
needed.

Signed-off-by: Christian Marangi <[email protected]>
  • Loading branch information
Ansuel committed Oct 20, 2023
1 parent c0e30b1 commit 28420cd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
22 changes: 22 additions & 0 deletions scripts/ext-toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ CFLAGS=""
TOOLCHAIN="."

LIBC_TYPE=""
GCC_VERSION=""


# Library specs
Expand Down Expand Up @@ -199,6 +200,19 @@ find_bins() {
return 1
}

find_gcc_version() {
if [ -f $TOOLCHAIN/info.mk ]; then
GCC_VERSION=$(grep GCC_VERSION $TOOLCHAIN/info.mk | sed 's/GCC_VERSION=//')
return 0
fi

echo "Warning! Can't find info.mk, trying to detect with alternative way."

# Very fragile detection
GCC_VERSION=$(find $TOOLCHAIN/bin | grep -oE "gcc-[0-9]+\.[0-9]+\.[0-9]+$" | \
head -1 | sed 's/gcc-//')
}


wrap_bin_cc() {
local out="$1"
Expand Down Expand Up @@ -383,6 +397,13 @@ print_config() {
return 1
fi

if [ -n "$GCC_VERSION" ]; then
echo "CONFIG_EXTERNAL_GCC_VERSION=\"$GCC_VERSION\"" >> "$config"
else
echo "Can't detect GCC version. Aborting!" >&2
return 1
fi

local lib
for lib in C RT PTHREAD GCC STDCPP SSP GFORTRAN GOMP; do
local file
Expand Down Expand Up @@ -564,6 +585,7 @@ while [ -n "$1" ]; do
--config)
if probe_cc; then
probe_libc
find_gcc_version
print_config "$1"
exit $?
fi
Expand Down
8 changes: 8 additions & 0 deletions toolchain/Config.in
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ menuconfig EXTERNAL_TOOLCHAIN

endchoice

config EXTERNAL_GCC_VERSION
string
prompt "External Toolchain GCC Version" if DEVEL
depends on EXTERNAL_TOOLCHAIN && !NATIVE_TOOLCHAIN
help
Manually specify the GCC version used by the selected
external toolchain.

config TOOLCHAIN_LIBC
string
depends on EXTERNAL_TOOLCHAIN && !NATIVE_TOOLCHAIN
Expand Down
1 change: 1 addition & 0 deletions toolchain/gcc/Config.version
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ config GCC_VERSION_13

config GCC_VERSION
string
default EXTERNAL_GCC_VERSION if EXTERNAL_TOOLCHAIN && !NATIVE_TOOLCHAIN
default "11.3.0" if GCC_VERSION_11
default "13.2.0" if GCC_VERSION_13
default "12.3.0"

0 comments on commit 28420cd

Please sign in to comment.