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}/*