make/toolchain.sh

changeset 1470
c1a144db699f
parent 1331
caa66055b025
equal deleted inserted replaced
1469:9b2b40a3c9f0 1470:c1a144db699f
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
89 if [ -n "$2" ]; then 96 if [ -n "$2" ]; then
90 echo "#include <$2>" >> "$TEMP_DIR/$1" 97 echo "#include <$2>" >> "$TEMP_DIR/$1"
91 fi 98 fi
92 } 99 }
93 100
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() 101 parse_toolchain_properties()
130 { 102 {
131 info_file="$1" 103 info_file="$1"
132 TOOLCHAIN=`grep '^toolchain:' "$info_file" | tail -c +11` 104 TOOLCHAIN=`grep '^toolchain:' "$info_file" | $TAIL -c +11`
133 TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` 105 TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -`
134 TOOLCHAIN_WSIZE=`grep '^wsize:' "$info_file" | tail -c +7` 106 TOOLCHAIN_WSIZE=`grep '^wsize:' "$info_file" | $TAIL -c +7`
135 } 107 }
136 108
137 detect_c_compiler() 109 detect_c_compiler()
138 { 110 {
139 if [ -n "$TOOLCHAIN_CC" ]; then 111 if [ -n "$TOOLCHAIN_CC" ]; then
143 if [ -n "$CC" ]; then 115 if [ -n "$CC" ]; then
144 if check_c_compiler "$CC"; then 116 if check_c_compiler "$CC"; then
145 TOOLCHAIN_CC=$CC 117 TOOLCHAIN_CC=$CC
146 "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" 118 "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out"
147 parse_toolchain_properties "$TEMP_DIR/checkcc_out" 119 parse_toolchain_properties "$TEMP_DIR/checkcc_out"
148 TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | tail -c +13` 120 TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | $TAIL -c +13`
149 echo "$CC" 121 echo "$CC"
150 return 0 122 return 0
151 else 123 else
152 echo "$CC is not a working C compiler" 124 echo "$CC is not a working C compiler"
153 return 1 125 return 1
157 do 129 do
158 if check_c_compiler "$COMP"; then 130 if check_c_compiler "$COMP"; then
159 TOOLCHAIN_CC=$COMP 131 TOOLCHAIN_CC=$COMP
160 "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" 132 "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out"
161 parse_toolchain_properties "$TEMP_DIR/checkcc_out" 133 parse_toolchain_properties "$TEMP_DIR/checkcc_out"
162 TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | tail -c +13` 134 TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | $TAIL -c +13`
163 echo "$COMP" 135 echo "$COMP"
164 return 0 136 return 0
165 fi 137 fi
166 done 138 done
167 echo "not found" 139 echo "not found"

mercurial