make/toolchain.sh

changeset 86
db21aab20169
parent 85
6960d25eb0ba
equal deleted inserted replaced
85:6960d25eb0ba 86:db21aab20169
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
66 #elif defined(__sun) 73 #elif defined(__sun)
67 std::cout << "toolchain:suncc" << std::endl; 74 std::cout << "toolchain:suncc" << std::endl;
68 #else 75 #else
69 std::cout << "toolchain:unknown" << std::endl; 76 std::cout << "toolchain:unknown" << std::endl;
70 #endif 77 #endif
71 std:cout << "wsize:" << sizeof(void*)*8 << std::endl; 78 std::cout << "wsize:" << sizeof(void*)*8 << std::endl;
72 return 0; 79 return 0;
73 } 80 }
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
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() 101 parse_toolchain_properties()
95 { 102 {
96 # $1: libname 103 info_file="$1"
97 # $2: optional include 104 TOOLCHAIN=`grep '^toolchain:' "$info_file" | $TAIL -c +11`
98 if [ -z "$TOOLCHAIN_CC" ]; then 105 TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -`
99 return 1 106 TOOLCHAIN_WSIZE=`grep '^wsize:' "$info_file" | $TAIL -c +7`
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 } 107 }
128 108
129 detect_c_compiler() 109 detect_c_compiler()
130 { 110 {
131 if [ -n "$TOOLCHAIN_CC" ]; then 111 if [ -n "$TOOLCHAIN_CC" ]; then
134 printf "detect C compiler... " 114 printf "detect C compiler... "
135 if [ -n "$CC" ]; then 115 if [ -n "$CC" ]; then
136 if check_c_compiler "$CC"; then 116 if check_c_compiler "$CC"; then
137 TOOLCHAIN_CC=$CC 117 TOOLCHAIN_CC=$CC
138 "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" 118 "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out"
139 TOOLCHAIN=`grep '^toolchain:' "$TEMP_DIR/checkcc_out" | tail -c +11` 119 parse_toolchain_properties "$TEMP_DIR/checkcc_out"
140 TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` 120 TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | $TAIL -c +13`
141 TOOLCHAIN_WSIZE=`grep '^wsize:' "$TEMP_DIR/checkcc_out" | tail -c +7`
142 TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | tail -c +13`
143 echo "$CC" 121 echo "$CC"
144 return 0 122 return 0
145 else 123 else
146 echo "$CC is not a working C compiler" 124 echo "$CC is not a working C compiler"
147 return 1 125 return 1
150 for COMP in $C_COMPILERS 128 for COMP in $C_COMPILERS
151 do 129 do
152 if check_c_compiler "$COMP"; then 130 if check_c_compiler "$COMP"; then
153 TOOLCHAIN_CC=$COMP 131 TOOLCHAIN_CC=$COMP
154 "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" 132 "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out"
155 TOOLCHAIN=`grep '^toolchain:' "$TEMP_DIR/checkcc_out" | tail -c +11` 133 parse_toolchain_properties "$TEMP_DIR/checkcc_out"
156 TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` 134 TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | $TAIL -c +13`
157 TOOLCHAIN_WSIZE=`grep '^wsize:' "$TEMP_DIR/checkcc_out" | tail -c +7`
158 TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | tail -c +13`
159 echo "$COMP" 135 echo "$COMP"
160 return 0 136 return 0
161 fi 137 fi
162 done 138 done
163 echo "not found" 139 echo "not found"
174 150
175 if [ -n "$CXX" ]; then 151 if [ -n "$CXX" ]; then
176 if check_cpp_compiler "$CXX"; then 152 if check_cpp_compiler "$CXX"; then
177 TOOLCHAIN_CXX=$CXX 153 TOOLCHAIN_CXX=$CXX
178 "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" 154 "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out"
179 TOOLCHAIN=`grep '^toolchain:' "$TEMP_DIR/checkcc_out" | tail -c +11` 155 parse_toolchain_properties "$TEMP_DIR/checkcc_out"
180 TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -`
181 echo "$CXX" 156 echo "$CXX"
182 return 0 157 return 0
183 else 158 else
184 echo "$CXX is not a working C++ compiler" 159 echo "$CXX is not a working C++ compiler"
185 return 1 160 return 1
188 for COMP in $CPP_COMPILERS 163 for COMP in $CPP_COMPILERS
189 do 164 do
190 if check_cpp_compiler "$COMP"; then 165 if check_cpp_compiler "$COMP"; then
191 TOOLCHAIN_CXX=$COMP 166 TOOLCHAIN_CXX=$COMP
192 "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" 167 "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out"
193 TOOLCHAIN=`grep '^toolchain:' "$TEMP_DIR/checkcc_out" | tail -c +11` 168 parse_toolchain_properties "$TEMP_DIR/checkcc_out"
194 TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -`
195 echo "$COMP" 169 echo "$COMP"
196 return 0 170 return 0
197 fi 171 fi
198 done 172 done
199 echo "${TOOLCHAIN_CXX:-"not found"}" 173 echo "${TOOLCHAIN_CXX:-"not found"}"

mercurial