6 C_COMPILERS="cc gcc clang suncc"
7 CPP_COMPILERS="CC g++ clang++ sunCC"
9 unset TOOLCHAIN_DETECTION_ERROR
14 cat > $TEMP_DIR/test.c << __EOF__
17 int main(int argc, char **argv) {
18 #if defined(__clang__)
20 #elif defined(__GNUC__)
30 rm -f $TEMP_DIR/checkcc
31 $1 -o $TEMP_DIR/checkcc $CFLAGS $LDFLAGS $TEMP_DIR/test.c 2> /dev/null
41 cat > $TEMP_DIR/test.cpp << __EOF__
44 int main(int argc, char **argv) {
45 #if defined(__clang__)
46 std::cout << "clang" << std::endl;
47 #elif defined(__GNUC__)
48 std::cout << "gcc" << std::endl;
50 std::cout << "suncc" << std::endl;
52 std::cout << "unknown" << std::endl;
57 rm -f $TEMP_DIR/checkcc
58 $1 -o $TEMP_DIR/checkcc $CXXFLAGS $LDFLAGS $TEMP_DIR/test.cpp 2> /dev/null
66 printf "detect C compiler... "
68 for COMP in $C_COMPILERS
70 check_c_compiler $COMP
72 if [ ! -z "$CC" ]; then
73 if [ $COMP = $CC ]; then
74 echo "$CC is not a working C Compiler"
75 TOOLCHAIN_DETECTION_ERROR="error"
80 TOOLCHAIN_NAME=`$TEMP_DIR/checkcc`
81 USE_TOOLCHAIN=$TOOLCHAIN_NAME
82 if [ $COMP = "cc" ]; then
83 # we have found a working compiler, but in case
84 # the compiler is gcc or clang, we try to use
85 # these commands and not 'cc'
86 TOOLCHAIN_NAME=`$TEMP_DIR/checkcc`
87 if [ $TOOLCHAIN_NAME = "gcc" ]; then
88 check_c_compiler "gcc"
94 if [ $TOOLCHAIN_NAME = "clang" ]; then
95 check_c_compiler "clang"
103 TOOLCHAIN_NAME=$USE_TOOLCHAIN
109 if [ -z $TOOLCHAIN_CC ]; then
113 printf "detect C++ compiler... "
115 for COMP in $CPP_COMPILERS
117 check_cpp_compiler $COMP
118 if [ $? -ne 0 ]; then
119 if [ ! -z "$CXX" ]; then
120 if [ $COMP = $CXX ]; then
121 echo "$CC is not a working C++ Compiler"
122 TOOLCHAIN_DETECTION_ERROR="error"
127 if [ $COMP = "CC" ]; then
128 # we have found a working compiler, but in case
129 # the compiler is gcc or clang, we try to use
130 # these commands and not 'cc'
131 TOOLCHAIN_NAME=`$TEMP_DIR/checkcc`
132 USE_TOOLCHAIN=$TOOLCHAIN_NAME
133 if [ $TOOLCHAIN_NAME = "gcc" ]; then
134 check_cpp_compiler "g++"
135 if [ $? -eq 0 ]; then
140 if [ $TOOLCHAIN_NAME = "clang" ]; then
141 check_cpp_compiler "clang++"
142 if [ $? -eq 0 ]; then
144 USE_TOOLCHAIN="clang"
149 TOOLCHAIN_NAME=$USE_TOOLCHAIN
155 if [ -z $TOOLCHAIN_CXX ]; then
159 TOOLCHAIN_LD=$TOOLCHAIN_CC
161 if [ -z "$TOOLCHAIN_NAME" ]; then
162 TOOLCHAIN_DETECTION_ERROR="error"
164 cat >> $TEMP_DIR/config.mk << __EOF__
167 echo "CC = ${TOOLCHAIN_CC}" >> $TEMP_DIR/config.mk
168 if [ ! -z "$TOOLCHAIN_CXX" ]; then
169 echo "CXX = ${TOOLCHAIN_CXX}" >> $TEMP_DIR/config.mk
171 echo "LD = ${TOOLCHAIN_LD}" >> $TEMP_DIR/config.mk
172 echo >> $TEMP_DIR/config.mk
174 cat "make/${TOOLCHAIN_NAME}.mk" > /dev/null 2>&1
175 if [ $? -eq 0 ]; then
176 echo "include \$(BUILD_ROOT)/make/${TOOLCHAIN_NAME}.mk" >> $TEMP_DIR/config.mk
178 echo "SHLIB_CFLAGS = -fPIC" >> $TEMP_DIR/config.mk
179 echo "SHLIB_LDFLAGS = -shared" >> $TEMP_DIR/config.mk