15 unset TOOLCHAIN_CC |
15 unset TOOLCHAIN_CC |
16 unset TOOLCHAIN_CXX |
16 unset TOOLCHAIN_CXX |
17 |
17 |
18 check_c_compiler() |
18 check_c_compiler() |
19 { |
19 { |
|
20 command -v $1 2>&1 >/dev/null |
|
21 if [ $? -ne 0 ]; then |
|
22 return 1 |
|
23 fi |
20 cat > "$TEMP_DIR/test.c" << __EOF__ |
24 cat > "$TEMP_DIR/test.c" << __EOF__ |
21 /* test file */ |
25 /* test file */ |
22 #include <stdio.h> |
26 #include <stdio.h> |
23 int main(int argc, char **argv) { |
27 int main(int argc, char **argv) { |
24 #if defined(_MSC_VER) |
28 #if defined(_MSC_VER) |
25 printf("msc\n"); |
29 printf("toolchain:msc\n"); |
26 #elif defined(__clang__) |
30 #elif defined(__clang__) |
27 printf("clang gnuc\n"); |
31 printf("toolchain:clang gnuc\n"); |
28 #elif defined(__GNUC__) |
32 #elif defined(__GNUC__) |
29 printf("gcc gnuc\n"); |
33 printf("toolchain:gcc gnuc\n"); |
30 #elif defined(__sun) |
34 #elif defined(__sun) |
31 printf("suncc\n"); |
35 printf("toolchain:suncc\n"); |
32 #else |
36 #else |
33 printf("unknown\n"); |
37 printf("toolchain:unknown\n"); |
|
38 #endif |
|
39 printf("wsize:%d\n", (int)sizeof(void*)*8); |
|
40 #ifdef __STDC_VERSION__ |
|
41 printf("stdcversion:%d\n", __STDC_VERSION__); |
34 #endif |
42 #endif |
35 return 0; |
43 return 0; |
36 } |
44 } |
37 __EOF__ |
45 __EOF__ |
38 rm -f "$TEMP_DIR/checkcc" |
46 rm -f "$TEMP_DIR/checkcc" |
39 $1 -o "$TEMP_DIR/checkcc" $CFLAGS $LDFLAGS "$TEMP_DIR/test.c" 2> /dev/null |
47 $1 -o "$TEMP_DIR/checkcc" $CFLAGS $LDFLAGS "$TEMP_DIR/test.c" 2> /dev/null |
40 } |
48 } |
41 |
49 |
42 check_cpp_compiler() |
50 check_cpp_compiler() |
43 { |
51 { |
|
52 command -v $1 2>&1 >/dev/null |
|
53 if [ $? -ne 0 ]; then |
|
54 return 1 |
|
55 fi |
44 cat > "$TEMP_DIR/test.cpp" << __EOF__ |
56 cat > "$TEMP_DIR/test.cpp" << __EOF__ |
45 /* test file */ |
57 /* test file */ |
46 #include <iostream> |
58 #include <iostream> |
47 int main(int argc, char **argv) { |
59 int main(int argc, char **argv) { |
48 #if defined(_MSC_VER) |
60 #if defined(_MSC_VER) |
49 std::cout << "msc" << std::endl; |
61 std::cout << "toolchain:msc" << std::endl; |
50 #elif defined(__clang__) |
62 #elif defined(__clang__) |
51 std::cout << "clang gnuc" << std::endl; |
63 std::cout << "toolchain:clang gnuc" << std::endl; |
52 #elif defined(__GNUC__) |
64 #elif defined(__GNUC__) |
53 std::cout << "gcc gnuc" << std::endl; |
65 std::cout << "toolchain:gcc gnuc" << std::endl; |
54 #elif defined(__sun) |
66 #elif defined(__sun) |
55 std::cout << "suncc" << std::endl; |
67 std::cout << "toolchain:suncc" << std::endl; |
56 #else |
68 #else |
57 std::cout << "cc" << std::endl; |
69 std::cout << "toolchain:unknown" << std::endl; |
58 #endif |
70 #endif |
|
71 std:cout << "wsize:" << sizeof(void*)*8 << std::endl; |
59 return 0; |
72 return 0; |
60 } |
73 } |
61 __EOF__ |
74 __EOF__ |
62 rm -f "$TEMP_DIR/checkcc" |
75 rm -f "$TEMP_DIR/checkcc" |
63 $1 -o "$TEMP_DIR/checkcc" $CXXFLAGS $LDFLAGS "$TEMP_DIR/test.cpp" 2> /dev/null |
76 $1 -o "$TEMP_DIR/checkcc" $CXXFLAGS $LDFLAGS "$TEMP_DIR/test.cpp" 2> /dev/null |
120 fi |
133 fi |
121 printf "detect C compiler... " |
134 printf "detect C compiler... " |
122 if [ -n "$CC" ]; then |
135 if [ -n "$CC" ]; then |
123 if check_c_compiler "$CC"; then |
136 if check_c_compiler "$CC"; then |
124 TOOLCHAIN_CC=$CC |
137 TOOLCHAIN_CC=$CC |
125 TOOLCHAIN=`"$TEMP_DIR/checkcc"` |
138 "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" |
|
139 TOOLCHAIN=`grep '^toolchain:' "$TEMP_DIR/checkcc_out" | tail -c +11` |
126 TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` |
140 TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` |
|
141 TOOLCHAIN_WSIZE=`grep '^wsize:' "$TEMP_DIR/checkcc_out" | tail -c +7` |
|
142 TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | tail -c +13` |
127 echo "$CC" |
143 echo "$CC" |
128 return 0 |
144 return 0 |
129 else |
145 else |
130 echo "$CC is not a working C compiler" |
146 echo "$CC is not a working C compiler" |
131 return 1 |
147 return 1 |
133 else |
149 else |
134 for COMP in $C_COMPILERS |
150 for COMP in $C_COMPILERS |
135 do |
151 do |
136 if check_c_compiler "$COMP"; then |
152 if check_c_compiler "$COMP"; then |
137 TOOLCHAIN_CC=$COMP |
153 TOOLCHAIN_CC=$COMP |
138 TOOLCHAIN=`"$TEMP_DIR/checkcc"` |
154 "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" |
|
155 TOOLCHAIN=`grep '^toolchain:' "$TEMP_DIR/checkcc_out" | tail -c +11` |
139 TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` |
156 TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` |
|
157 TOOLCHAIN_WSIZE=`grep '^wsize:' "$TEMP_DIR/checkcc_out" | tail -c +7` |
|
158 TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | tail -c +13` |
140 echo "$COMP" |
159 echo "$COMP" |
141 return 0 |
160 return 0 |
142 fi |
161 fi |
143 done |
162 done |
144 echo "not found" |
163 echo "not found" |
154 printf "detect C++ compiler... " |
173 printf "detect C++ compiler... " |
155 |
174 |
156 if [ -n "$CXX" ]; then |
175 if [ -n "$CXX" ]; then |
157 if check_cpp_compiler "$CXX"; then |
176 if check_cpp_compiler "$CXX"; then |
158 TOOLCHAIN_CXX=$CXX |
177 TOOLCHAIN_CXX=$CXX |
159 TOOLCHAIN=`"$TEMP_DIR/checkcc"` |
178 "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" |
|
179 TOOLCHAIN=`grep '^toolchain:' "$TEMP_DIR/checkcc_out" | tail -c +11` |
160 TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` |
180 TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` |
161 echo "$CXX" |
181 echo "$CXX" |
162 return 0 |
182 return 0 |
163 else |
183 else |
164 echo "$CXX is not a working C++ compiler" |
184 echo "$CXX is not a working C++ compiler" |