From 1e0115c194924959bd5d62696868e9d628e1548e Mon Sep 17 00:00:00 2001 From: Jesus Checa Hidalgo Date: Mon, 3 Jul 2023 14:26:14 +0200 Subject: [PATCH] gcc-clang-compatibility: Add support for gcc-toolset installations clang may use a gcc from gcc-toolset instead the system version. In that case we need to test the compatibility with that one, not with the system based gcc. --- gcc-clang-compatibility/test.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/gcc-clang-compatibility/test.sh b/gcc-clang-compatibility/test.sh index e2d4b0d..3480309 100755 --- a/gcc-clang-compatibility/test.sh +++ b/gcc-clang-compatibility/test.sh @@ -2,14 +2,25 @@ tmp=$(mktemp -d) +# clang not necessarily depends on system gcc. It might depend on gcc from +# gcc-toolset-XX, in such case we need to test the compatibility with that one. +# We can get that from `clang -v` output. +TOOLSET=$(clang -v |& grep "Selected GCC installation" | grep -P -o '(dev|gcc-)toolset-[0-9]*') ||: +if [[ "x" = "x${TOOLSET}" ]]; then + GCC="g++" +else + GCC="scl enable ${TOOLSET} -- g++" + echo "Testing with g++ from ${TOOLSET}" +fi + # Build the source with GCC, link it with clang -g++ -c hello.cpp -o ${tmp}/hello.o +${GCC} -c hello.cpp -o ${tmp}/hello.o clang++ -o ${tmp}/hello ${tmp}/hello.o ${tmp}/hello | grep "Hello world" rm -rf ${tmp}/* # Build the source with clang, link it with GCC clang++ -c hello.cpp -o ${tmp}/hello.o -g++ -o ${tmp}/hello ${tmp}/hello.o +${GCC} -o ${tmp}/hello ${tmp}/hello.o ${tmp}/hello | grep "Hello world" rm -rf ${tmp}/*