universe@753: #!/bin/sh universe@753: # universe@753: # toolchain detection universe@753: # universe@753: universe@815: if isplatform "bsd" && notisplatform "openbsd"; then universe@815: C_COMPILERS="clang gcc cc" universe@815: CPP_COMPILERS="clang++ g++ CC" universe@815: else universe@815: C_COMPILERS="gcc clang suncc cc" universe@815: CPP_COMPILERS="g++ clang++ sunCC CC" universe@815: fi universe@815: unset TOOLCHAIN universe@753: unset TOOLCHAIN_NAME universe@753: unset TOOLCHAIN_CC universe@753: unset TOOLCHAIN_CXX universe@753: universe@753: check_c_compiler() universe@753: { universe@815: cat > "$TEMP_DIR/test.c" << __EOF__ universe@753: /* test file */ universe@753: #include universe@753: int main(int argc, char **argv) { universe@815: #if defined(_MSC_VER) universe@815: printf("msc\n"); universe@815: #elif defined(__clang__) universe@815: printf("clang gnuc\n"); universe@753: #elif defined(__GNUC__) universe@815: printf("gcc gnuc\n"); universe@753: #elif defined(__sun) universe@815: printf("suncc\n"); universe@753: #else universe@815: printf("unknown\n"); universe@753: #endif universe@815: return 0; universe@753: } universe@753: __EOF__ universe@815: rm -f "$TEMP_DIR/checkcc" universe@815: $1 -o "$TEMP_DIR/checkcc" $CFLAGS $LDFLAGS "$TEMP_DIR/test.c" 2> /dev/null universe@753: } universe@753: universe@753: check_cpp_compiler() universe@753: { universe@815: cat > "$TEMP_DIR/test.cpp" << __EOF__ universe@753: /* test file */ universe@753: #include universe@753: int main(int argc, char **argv) { universe@815: #if defined(_MSC_VER) universe@815: std::cout << "msc" << std::endl; universe@815: #elif defined(__clang__) universe@815: std::cout << "clang gnuc" << std::endl; universe@753: #elif defined(__GNUC__) universe@815: std::cout << "gcc gnuc" << std::endl; universe@753: #elif defined(__sun) universe@815: std::cout << "suncc" << std::endl; universe@753: #else universe@815: std::cout << "cc" << std::endl; universe@753: #endif universe@815: return 0; universe@753: } universe@753: __EOF__ universe@815: rm -f "$TEMP_DIR/checkcc" universe@815: $1 -o "$TEMP_DIR/checkcc" $CXXFLAGS $LDFLAGS "$TEMP_DIR/test.cpp" 2> /dev/null universe@753: } universe@753: universe@753: create_libtest_source() universe@753: { universe@753: # $1: filename universe@753: # $2: optional include universe@815: cat > "$TEMP_DIR/$1" << __EOF__ universe@753: /* libtest file */ universe@753: int main(int argc, char **argv) { universe@815: return 0; universe@753: } universe@753: __EOF__ universe@753: if [ -n "$2" ]; then universe@753: echo "#include <$2>" >> "$TEMP_DIR/$1" universe@753: fi universe@753: } universe@753: universe@753: check_c_lib() universe@753: { universe@753: # $1: libname universe@753: # $2: optional include universe@753: if [ -z "$TOOLCHAIN_CC" ]; then universe@753: return 1 universe@753: fi universe@753: create_libtest_source "test.c" "$2" universe@753: rm -f "$TEMP_DIR/checklib" universe@815: $TOOLCHAIN_CC -o "$TEMP_DIR/checklib" $CFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.c" 2> /dev/null universe@753: } universe@753: universe@753: check_cpp_lib() universe@753: { universe@753: # $1: libname universe@753: # $2: optional include universe@753: if [ -z "$TOOLCHAIN_CXX" ]; then universe@753: return 1 universe@753: fi universe@815: create_libtest_source "test.cpp" "$2" universe@753: rm -f "$TEMP_DIR/checklib" universe@815: $TOOLCHAIN_CXX -o "$TEMP_DIR/checklib" $CXXFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.cpp" 2> /dev/null universe@753: } universe@753: universe@753: check_lib() universe@753: { universe@753: # $1: libname universe@753: # $2: optional include universe@815: if [ -n "$TOOLCHAIN_CC" ]; then universe@815: check_c_lib "$1" "$2" universe@815: elif [ -n "$TOOLCHAIN_CXX" ]; then universe@815: check_cpp_lib "$1" "$2" universe@815: fi universe@753: } universe@753: universe@753: detect_c_compiler() universe@753: { universe@753: if [ -n "$TOOLCHAIN_CC" ]; then universe@753: return 0 universe@753: fi universe@753: printf "detect C compiler... " universe@753: if [ -n "$CC" ]; then universe@753: if check_c_compiler "$CC"; then universe@753: TOOLCHAIN_CC=$CC universe@815: TOOLCHAIN=`"$TEMP_DIR/checkcc"` universe@815: TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` universe@753: echo "$CC" universe@753: return 0 universe@753: else universe@753: echo "$CC is not a working C compiler" universe@753: return 1 universe@753: fi universe@753: else universe@753: for COMP in $C_COMPILERS universe@753: do universe@753: if check_c_compiler "$COMP"; then universe@753: TOOLCHAIN_CC=$COMP universe@815: TOOLCHAIN=`"$TEMP_DIR/checkcc"` universe@815: TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` universe@753: echo "$COMP" universe@753: return 0 universe@753: fi universe@753: done universe@753: echo "not found" universe@753: return 1 universe@753: fi universe@753: } universe@753: universe@753: detect_cpp_compiler() universe@753: { universe@753: if [ -n "$TOOLCHAIN_CXX" ]; then universe@753: return 0 universe@753: fi universe@753: printf "detect C++ compiler... " universe@753: universe@753: if [ -n "$CXX" ]; then universe@753: if check_cpp_compiler "$CXX"; then universe@753: TOOLCHAIN_CXX=$CXX universe@815: TOOLCHAIN=`"$TEMP_DIR/checkcc"` universe@815: TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` universe@753: echo "$CXX" universe@753: return 0 universe@753: else universe@753: echo "$CXX is not a working C++ compiler" universe@753: return 1 universe@753: fi universe@753: else universe@753: for COMP in $CPP_COMPILERS universe@753: do universe@753: if check_cpp_compiler "$COMP"; then universe@753: TOOLCHAIN_CXX=$COMP universe@815: TOOLCHAIN=`"$TEMP_DIR/checkcc"` universe@815: TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` universe@753: echo "$COMP" universe@753: return 0 universe@753: fi universe@753: done universe@753: echo "${TOOLCHAIN_CXX:-"not found"}" universe@753: return 1 universe@753: fi universe@753: } universe@753: universe@753: write_toolchain_defaults() universe@753: { universe@753: echo "# toolchain" >> "$1" universe@753: if [ -n "$TOOLCHAIN_CC" ]; then universe@753: echo "CC = ${TOOLCHAIN_CC}" >> "$1" universe@753: fi universe@753: if [ -n "$TOOLCHAIN_CXX" ]; then universe@753: echo "CXX = ${TOOLCHAIN_CXX}" >> "$1" universe@753: fi universe@753: echo >> "$1" universe@753: if [ -f "make/${TOOLCHAIN_NAME}.mk" ]; then universe@753: cat "make/${TOOLCHAIN_NAME}.mk" >> "$1" universe@753: elif [ -f "make/cc.mk" ]; then universe@753: cat "make/cc.mk" >> "$1" universe@753: else universe@753: echo "!!! WARNING !!! Default toolchain flags not found. Configuration might be incomplete." universe@753: fi universe@753: }