| 1 #!/bin/sh |
1 #!/bin/sh |
| 2 # |
2 # |
| 3 # toolchain detection |
3 # toolchain detection |
| 4 # |
4 # |
| 5 |
5 |
| |
6 TAIL="tail" |
| 6 if isplatform "bsd" && notisplatform "openbsd"; then |
7 if isplatform "bsd" && notisplatform "openbsd"; then |
| 7 C_COMPILERS="clang gcc cc" |
8 C_COMPILERS="clang gcc cc" |
| 8 CPP_COMPILERS="clang++ g++ CC" |
9 CPP_COMPILERS="clang++ g++ CC" |
| |
10 elif isplatform "solaris"; then |
| |
11 C_COMPILERS="cc suncc gcc clang" |
| |
12 CPP_COMPILERS="CC sunCC g++ clang++" |
| |
13 if [ -f /usr/xpg4/bin/tail ]; then |
| |
14 TAIL=/usr/xpg4/bin/tail |
| |
15 fi |
| 9 else |
16 else |
| 10 C_COMPILERS="gcc clang suncc cc" |
17 C_COMPILERS="gcc clang cc" |
| 11 CPP_COMPILERS="g++ clang++ sunCC CC" |
18 CPP_COMPILERS="g++ clang++ c++" |
| 12 fi |
19 fi |
| 13 unset TOOLCHAIN |
20 unset TOOLCHAIN |
| 14 unset TOOLCHAIN_NAME |
21 unset TOOLCHAIN_NAME |
| 15 unset TOOLCHAIN_CC |
22 unset TOOLCHAIN_CC |
| 16 unset TOOLCHAIN_CXX |
23 unset TOOLCHAIN_CXX |
| 17 |
24 |
| 18 check_c_compiler() |
25 check_c_compiler() |
| 19 { |
26 { |
| 20 command -v $1 2>&1 >/dev/null |
27 command -v "$1" >/dev/null 2>&1 |
| 21 if [ $? -ne 0 ]; then |
28 if [ $? -ne 0 ] ; then |
| 22 return 1 |
29 return 1 |
| 23 fi |
30 fi |
| 24 cat > "$TEMP_DIR/test.c" << __EOF__ |
31 cat > "$TEMP_DIR/test.c" << __EOF__ |
| 25 /* test file */ |
32 /* test file */ |
| 26 #include <stdio.h> |
33 #include <stdio.h> |
| 27 int main(int argc, char **argv) { |
34 int main(void) { |
| 28 #if defined(_MSC_VER) |
35 #if defined(_MSC_VER) |
| 29 printf("toolchain:msc\n"); |
36 printf("toolchain:msc\n"); |
| 30 #elif defined(__clang__) |
37 #elif defined(__clang__) |
| 31 printf("toolchain:clang gnuc\n"); |
38 printf("toolchain:clang gnuc\n"); |
| 32 #elif defined(__GNUC__) |
39 #elif defined(__GNUC__) |
| 36 #else |
43 #else |
| 37 printf("toolchain:unknown\n"); |
44 printf("toolchain:unknown\n"); |
| 38 #endif |
45 #endif |
| 39 printf("wsize:%d\n", (int)sizeof(void*)*8); |
46 printf("wsize:%d\n", (int)sizeof(void*)*8); |
| 40 #ifdef __STDC_VERSION__ |
47 #ifdef __STDC_VERSION__ |
| 41 printf("stdcversion:%d\n", __STDC_VERSION__); |
48 printf("stdcversion:%ld\n", (long int)__STDC_VERSION__); |
| 42 #endif |
49 #endif |
| 43 return 0; |
50 return 0; |
| 44 } |
51 } |
| 45 __EOF__ |
52 __EOF__ |
| 46 rm -f "$TEMP_DIR/checkcc" |
53 rm -f "$TEMP_DIR/checkcc" |
| 47 $1 -o "$TEMP_DIR/checkcc" $CFLAGS $LDFLAGS "$TEMP_DIR/test.c" 2> /dev/null |
54 $1 -o "$TEMP_DIR/checkcc" $CFLAGS $LDFLAGS "$TEMP_DIR/test.c" 2> /dev/null |
| 48 } |
55 } |
| 49 |
56 |
| 50 check_cpp_compiler() |
57 check_cpp_compiler() |
| 51 { |
58 { |
| 52 command -v $1 2>&1 >/dev/null |
59 command -v "$1" >/dev/null 2>&1 |
| 53 if [ $? -ne 0 ]; then |
60 if [ $? -ne 0 ] ; then |
| 54 return 1 |
61 return 1 |
| 55 fi |
62 fi |
| 56 cat > "$TEMP_DIR/test.cpp" << __EOF__ |
63 cat > "$TEMP_DIR/test.cpp" << __EOF__ |
| 57 /* test file */ |
64 /* test file */ |
| 58 #include <iostream> |
65 #include <iostream> |
| 59 int main(int argc, char **argv) { |
66 int main(void) { |
| 60 #if defined(_MSC_VER) |
67 #if defined(_MSC_VER) |
| 61 std::cout << "toolchain:msc" << std::endl; |
68 std::cout << "toolchain:msc" << std::endl; |
| 62 #elif defined(__clang__) |
69 #elif defined(__clang__) |
| 63 std::cout << "toolchain:clang gnuc" << std::endl; |
70 std::cout << "toolchain:clang gnuc" << std::endl; |
| 64 #elif defined(__GNUC__) |
71 #elif defined(__GNUC__) |
| 74 __EOF__ |
81 __EOF__ |
| 75 rm -f "$TEMP_DIR/checkcc" |
82 rm -f "$TEMP_DIR/checkcc" |
| 76 $1 -o "$TEMP_DIR/checkcc" $CXXFLAGS $LDFLAGS "$TEMP_DIR/test.cpp" 2> /dev/null |
83 $1 -o "$TEMP_DIR/checkcc" $CXXFLAGS $LDFLAGS "$TEMP_DIR/test.cpp" 2> /dev/null |
| 77 } |
84 } |
| 78 |
85 |
| 79 create_libtest_source() |
|
| 80 { |
|
| 81 # $1: filename |
|
| 82 # $2: optional include |
|
| 83 cat > "$TEMP_DIR/$1" << __EOF__ |
|
| 84 /* libtest file */ |
|
| 85 int main(int argc, char **argv) { |
|
| 86 return 0; |
|
| 87 } |
|
| 88 __EOF__ |
|
| 89 if [ -n "$2" ]; then |
|
| 90 echo "#include <$2>" >> "$TEMP_DIR/$1" |
|
| 91 fi |
|
| 92 } |
|
| 93 |
|
| 94 check_c_lib() |
|
| 95 { |
|
| 96 # $1: libname |
|
| 97 # $2: optional include |
|
| 98 if [ -z "$TOOLCHAIN_CC" ]; then |
|
| 99 return 1 |
|
| 100 fi |
|
| 101 create_libtest_source "test.c" "$2" |
|
| 102 rm -f "$TEMP_DIR/checklib" |
|
| 103 $TOOLCHAIN_CC -o "$TEMP_DIR/checklib" $CFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.c" 2> /dev/null |
|
| 104 } |
|
| 105 |
|
| 106 check_cpp_lib() |
|
| 107 { |
|
| 108 # $1: libname |
|
| 109 # $2: optional include |
|
| 110 if [ -z "$TOOLCHAIN_CXX" ]; then |
|
| 111 return 1 |
|
| 112 fi |
|
| 113 create_libtest_source "test.cpp" "$2" |
|
| 114 rm -f "$TEMP_DIR/checklib" |
|
| 115 $TOOLCHAIN_CXX -o "$TEMP_DIR/checklib" $CXXFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.cpp" 2> /dev/null |
|
| 116 } |
|
| 117 |
|
| 118 check_lib() |
|
| 119 { |
|
| 120 # $1: libname |
|
| 121 # $2: optional include |
|
| 122 if [ -n "$TOOLCHAIN_CC" ]; then |
|
| 123 check_c_lib "$1" "$2" |
|
| 124 elif [ -n "$TOOLCHAIN_CXX" ]; then |
|
| 125 check_cpp_lib "$1" "$2" |
|
| 126 fi |
|
| 127 } |
|
| 128 |
|
| 129 parse_toolchain_properties() |
86 parse_toolchain_properties() |
| 130 { |
87 { |
| 131 info_file="$1" |
88 info_file="$1" |
| 132 TOOLCHAIN=`grep '^toolchain:' "$info_file" | tail -c +11` |
89 TOOLCHAIN=`grep '^toolchain:' "$info_file" | $TAIL -c +11` |
| 133 TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` |
90 TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` |
| 134 TOOLCHAIN_WSIZE=`grep '^wsize:' "$info_file" | tail -c +7` |
91 TOOLCHAIN_WSIZE=`grep '^wsize:' "$info_file" | $TAIL -c +7` |
| 135 } |
92 } |
| 136 |
93 |
| 137 detect_c_compiler() |
94 detect_c_compiler() |
| 138 { |
95 { |
| 139 if [ -n "$TOOLCHAIN_CC" ]; then |
96 if [ -n "$TOOLCHAIN_CC" ]; then |
| 143 if [ -n "$CC" ]; then |
100 if [ -n "$CC" ]; then |
| 144 if check_c_compiler "$CC"; then |
101 if check_c_compiler "$CC"; then |
| 145 TOOLCHAIN_CC=$CC |
102 TOOLCHAIN_CC=$CC |
| 146 "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" |
103 "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" |
| 147 parse_toolchain_properties "$TEMP_DIR/checkcc_out" |
104 parse_toolchain_properties "$TEMP_DIR/checkcc_out" |
| 148 TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | tail -c +13` |
105 TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | $TAIL -c +13` |
| 149 echo "$CC" |
106 echo "$CC" |
| 150 return 0 |
107 return 0 |
| 151 else |
108 else |
| 152 echo "$CC is not a working C compiler" |
109 echo "$CC is not a working C compiler" |
| 153 return 1 |
110 return 1 |