Fri, 19 Jan 2024 21:14:22 +0100
prioritize clang on bsd that is not openbsd
fixes #364
src/main/resources/make/toolchain.sh | file | annotate | diff | comparison | revisions | |
test/make/toolchain.sh | file | annotate | diff | comparison | revisions |
--- a/src/main/resources/make/toolchain.sh Fri Jan 19 21:12:08 2024 +0100 +++ b/src/main/resources/make/toolchain.sh Fri Jan 19 21:14:22 2024 +0100 @@ -3,8 +3,13 @@ # toolchain detection # -C_COMPILERS="gcc clang suncc cc" -CPP_COMPILERS="g++ clang++ sunCC CC" +if isplatform "bsd" && notisplatform "openbsd"; then + C_COMPILERS="clang gcc cc" + CPP_COMPILERS="clang++ g++ CC" +else + C_COMPILERS="gcc clang suncc cc" + CPP_COMPILERS="g++ clang++ sunCC CC" +fi unset TOOLCHAIN_NAME unset TOOLCHAIN_CC unset TOOLCHAIN_CXX
--- a/test/make/toolchain.sh Fri Jan 19 21:12:08 2024 +0100 +++ b/test/make/toolchain.sh Fri Jan 19 21:14:22 2024 +0100 @@ -3,64 +3,69 @@ # toolchain detection # -C_COMPILERS="gcc clang suncc cc" -CPP_COMPILERS="g++ clang++ sunCC CC" +if isplatform "bsd" && notisplatform "openbsd"; then + C_COMPILERS="clang gcc cc" + CPP_COMPILERS="clang++ g++ CC" +else + C_COMPILERS="gcc clang suncc cc" + CPP_COMPILERS="g++ clang++ sunCC CC" +fi unset TOOLCHAIN_NAME unset TOOLCHAIN_CC unset TOOLCHAIN_CXX check_c_compiler() { - cat > "$TEMP_DIR/test.c" << __EOF__ + cat > "$TEMP_DIR/test.c" << __EOF__ /* test file */ #include <stdio.h> int main(int argc, char **argv) { #if defined(__clang__) - printf("clang\n"); + printf("clang\n"); #elif defined(__GNUC__) - printf("gcc\n"); + printf("gcc\n"); #elif defined(__sun) - printf("suncc\n"); + printf("suncc\n"); #else - printf("unknown\n"); + printf("unknown\n"); #endif - return 0; + return 0; } __EOF__ - rm -f "$TEMP_DIR/checkcc" - $1 -o "$TEMP_DIR/checkcc" $CFLAGS $LDFLAGS "$TEMP_DIR/test.c" 2> /dev/null + rm -f "$TEMP_DIR/checkcc" + $1 -o "$TEMP_DIR/checkcc" $CFLAGS $LDFLAGS "$TEMP_DIR/test.c" 2> /dev/null } check_cpp_compiler() { - cat > "$TEMP_DIR/test.cpp" << __EOF__ + cat > "$TEMP_DIR/test.cpp" << __EOF__ /* test file */ #include <iostream> int main(int argc, char **argv) { #if defined(__clang__) - std::cout << "clang" << std::endl; + std::cout << "clang" << std::endl; #elif defined(__GNUC__) - std::cout << "gcc" << std::endl; + std::cout << "gcc" << std::endl; #elif defined(__sun) - std::cout << "suncc" << std::endl; + std::cout << "suncc" << std::endl; #else - std::cout << "cc" << std::endl; + std::cout << "cc" << std::endl; #endif - return 0; + return 0; } __EOF__ - rm -f "$TEMP_DIR/checkcc" - $1 -o "$TEMP_DIR/checkcc" $CXXFLAGS $LDFLAGS "$TEMP_DIR/test.cpp" 2> /dev/null + rm -f "$TEMP_DIR/checkcc" + $1 -o "$TEMP_DIR/checkcc" $CXXFLAGS $LDFLAGS "$TEMP_DIR/test.cpp" 2> /dev/null } create_libtest_source() { # $1: filename # $2: optional include - cat > "$TEMP_DIR/$1" << __EOF__ + cat > "$TEMP_DIR/$1" << __EOF__ /* libtest file */ int main(int argc, char **argv) { - return 0; + return 0; } __EOF__ if [ -n "$2" ]; then @@ -77,7 +82,7 @@ fi create_libtest_source "test.c" "$2" rm -f "$TEMP_DIR/checklib" - $TOOLCHAIN_CC -o "$TEMP_DIR/checklib" $CFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.c" 2> /dev/null + $TOOLCHAIN_CC -o "$TEMP_DIR/checklib" $CFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.c" 2> /dev/null } check_cpp_lib() @@ -87,20 +92,20 @@ if [ -z "$TOOLCHAIN_CXX" ]; then return 1 fi - create_libtest_source "test.cpp" "$2" + create_libtest_source "test.cpp" "$2" rm -f "$TEMP_DIR/checklib" - $TOOLCHAIN_CXX -o "$TEMP_DIR/checklib" $CXXFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.cpp" 2> /dev/null + $TOOLCHAIN_CXX -o "$TEMP_DIR/checklib" $CXXFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.cpp" 2> /dev/null } check_lib() { # $1: libname # $2: optional include - if [ -n "$TOOLCHAIN_CC" ]; then - check_c_lib "$1" "$2" - elif [ -n "$TOOLCHAIN_CXX" ]; then - check_cpp_lib "$1" "$2" - fi + if [ -n "$TOOLCHAIN_CC" ]; then + check_c_lib "$1" "$2" + elif [ -n "$TOOLCHAIN_CXX" ]; then + check_cpp_lib "$1" "$2" + fi } detect_c_compiler()