test/make/toolchain.sh

changeset 61
2c68549dabef
parent 54
2b8f40c58944
child 66
dc758dcd4645
equal deleted inserted replaced
51:5c12e9e29733 61:2c68549dabef
1 #!/bin/sh 1 #!/bin/sh
2 # 2 #
3 # toolchain detection 3 # toolchain detection
4 # 4 #
5 5
6 C_COMPILERS="cc gcc clang suncc" 6 C_COMPILERS="gcc clang suncc cc"
7 CPP_COMPILERS="CC g++ clang++ sunCC" 7 CPP_COMPILERS="g++ clang++ sunCC CC"
8 unset CC_ARG_CHECKED 8 unset TOOLCHAIN_ERROR
9 unset TOOLCHAIN_DETECTION_ERROR
10 unset TOOLCHAIN_NAME 9 unset TOOLCHAIN_NAME
10 unset TOOLCHAIN_CC
11 unset TOOLCHAIN_CXX
12 unset TOOLCHAIN_LD
11 13
12 check_c_compiler() 14 check_c_compiler()
13 { 15 {
14 cat > "$TEMP_DIR/test.c" << __EOF__ 16 cat > "$TEMP_DIR/test.c" << __EOF__
15 /* test file */ 17 /* test file */
27 return 0; 29 return 0;
28 } 30 }
29 __EOF__ 31 __EOF__
30 rm -f "$TEMP_DIR/checkcc" 32 rm -f "$TEMP_DIR/checkcc"
31 $1 -o "$TEMP_DIR/checkcc" $CFLAGS $LDFLAGS "$TEMP_DIR/test.c" 2> /dev/null 33 $1 -o "$TEMP_DIR/checkcc" $CFLAGS $LDFLAGS "$TEMP_DIR/test.c" 2> /dev/null
32
33 if [ $? -ne 0 ]; then
34 return 1
35 fi
36 return 0
37 } 34 }
38 35
39 check_cpp_compiler() 36 check_cpp_compiler()
40 { 37 {
41 cat > "$TEMP_DIR/test.cpp" << __EOF__ 38 cat > "$TEMP_DIR/test.cpp" << __EOF__
54 return 0; 51 return 0;
55 } 52 }
56 __EOF__ 53 __EOF__
57 rm -f "$TEMP_DIR/checkcc" 54 rm -f "$TEMP_DIR/checkcc"
58 $1 -o "$TEMP_DIR/checkcc" $CXXFLAGS $LDFLAGS "$TEMP_DIR/test.cpp" 2> /dev/null 55 $1 -o "$TEMP_DIR/checkcc" $CXXFLAGS $LDFLAGS "$TEMP_DIR/test.cpp" 2> /dev/null
59
60 if [ $? -ne 0 ]; then
61 return 1
62 fi
63 return 0
64 } 56 }
65 57
66 check_lib() 58 check_lib()
67 { 59 {
68 if [ -z "$TOOLCHAIN_LD" ]; then 60 if [ -z "$TOOLCHAIN_LD" ]; then
74 return 0; 66 return 0;
75 } 67 }
76 __EOF__ 68 __EOF__
77 rm -f "$TEMP_DIR/checklib" 69 rm -f "$TEMP_DIR/checklib"
78 $TOOLCHAIN_LD -o "$TEMP_DIR/checklib" $CFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.c" 2> /dev/null 70 $TOOLCHAIN_LD -o "$TEMP_DIR/checklib" $CFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.c" 2> /dev/null
79
80 if [ $? -ne 0 ]; then
81 return 1
82 fi
83 return 0
84 } 71 }
85 72
86 printf "detect C compiler... " 73 printf "detect C compiler... "
87 74
88 for COMP in $C_COMPILERS 75 if [ -n "$CC" ]; then
89 do 76 if check_c_compiler "$CC"; then
90 check_c_compiler "$COMP" 77 TOOLCHAIN_CC=$CC
91 if [ $? -ne 0 ]; then 78 TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"`
92 if [ -n "$CC" ]; then 79 echo $CC
93 if [ "$COMP" = "$CC" ]; then 80 else
94 echo "$CC is not a working C compiler" 81 echo "$CC is not a working C compiler"
95 TOOLCHAIN_DETECTION_ERROR="error" 82 TOOLCHAIN_ERROR="required C compiler not found"
96 break 83 fi
97 fi 84 else
98 fi 85 for COMP in $C_COMPILERS
99 else 86 do
100 TOOLCHAIN_NAME=`$TEMP_DIR/checkcc` 87 if check_c_compiler "$COMP"; then
101 USE_TOOLCHAIN=$TOOLCHAIN_NAME 88 TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"`
102 if [ "$COMP" = "cc" ]; then 89 TOOLCHAIN_CC=$COMP
103 # we have found a working compiler, but in case 90 break
104 # the compiler is gcc or clang, we try to use 91 fi
105 # these commands and not 'cc' 92 done
106 TOOLCHAIN_NAME=`$TEMP_DIR/checkcc` 93 echo ${TOOLCHAIN_CC:-"not found"}
107 if [ "$TOOLCHAIN_NAME" = "gcc" ]; then
108 check_c_compiler "gcc"
109 if [ $? -eq 0 ]; then
110 COMP=gcc
111 USE_TOOLCHAIN="gcc"
112 fi
113 fi
114 if [ "$TOOLCHAIN_NAME" = "clang" ]; then
115 check_c_compiler "clang"
116 if [ $? -eq 0 ]; then
117 COMP=clang
118 USE_TOOLCHAIN="clang"
119 fi
120 fi
121 fi
122
123 TOOLCHAIN_NAME=$USE_TOOLCHAIN
124 TOOLCHAIN_CC=$COMP
125 echo $COMP
126 break
127 fi
128 done
129 if [ -z "$TOOLCHAIN_CC" ]; then
130 echo "not found"
131 fi 94 fi
132 95
133 printf "detect C++ compiler... " 96 printf "detect C++ compiler... "
134 97
135 for COMP in $CPP_COMPILERS 98 if [ -n "$CXX" ]; then
136 do 99 if check_cpp_compiler "$CXX"; then
137 check_cpp_compiler "$COMP" 100 TOOLCHAIN_CXX=$CXX
138 if [ $? -ne 0 ]; then 101 TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"`
139 if [ -n "$CXX" ]; then 102 echo $CXX
140 if [ "$COMP" = "$CXX" ]; then 103 else
141 echo "$CXX is not a working C++ compiler" 104 echo "$CXX is not a working C++ compiler"
142 TOOLCHAIN_DETECTION_ERROR="error" 105 TOOLCHAIN_ERROR="required C++ compiler not found"
143 break 106 fi
144 fi 107 else
145 fi 108 for COMP in $CPP_COMPILERS
146 else 109 do
147 if [ $COMP = "CC" ]; then 110 if check_cpp_compiler "$COMP"; then
148 # we have found a working compiler, but in case 111 TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"`
149 # the compiler is gcc or clang, we try to use 112 TOOLCHAIN_CXX=$COMP
150 # these commands and not 'CC' 113 break
151 TOOLCHAIN_NAME=`$TEMP_DIR/checkcc` 114 fi
152 USE_TOOLCHAIN=$TOOLCHAIN_NAME 115 done
153 if [ "$TOOLCHAIN_NAME" = "gcc" ]; then 116 echo ${TOOLCHAIN_CXX:-"not found"}
154 check_cpp_compiler "g++"
155 if [ $? -eq 0 ]; then
156 COMP=g++
157 USE_TOOLCHAIN="gcc"
158 fi
159 fi
160 if [ "$TOOLCHAIN_NAME" = "clang" ]; then
161 check_cpp_compiler "clang++"
162 if [ $? -eq 0 ]; then
163 COMP=clang++
164 USE_TOOLCHAIN="clang"
165 fi
166 fi
167 fi
168
169 TOOLCHAIN_NAME=$USE_TOOLCHAIN
170 TOOLCHAIN_CXX=$COMP
171 echo $COMP
172 break
173 fi
174 done
175 if [ -z "$TOOLCHAIN_CXX" ]; then
176 echo "not found"
177 fi 117 fi
178 118
119 printf "detect linker... "
179 TOOLCHAIN_LD=$TOOLCHAIN_CC 120 TOOLCHAIN_LD=$TOOLCHAIN_CC
121 echo "$TOOLCHAIN_LD"
180 122
181 if [ -z "$TOOLCHAIN_NAME" ]; then 123 if [ -z "$TOOLCHAIN_NAME" ]; then
182 TOOLCHAIN_DETECTION_ERROR="error" 124 TOOLCHAIN_ERROR="no build tools detected"
183 else 125 else
184 cat >> "$TEMP_DIR/config.mk" << __EOF__ 126 cat >> "$TEMP_DIR/config.mk" << __EOF__
127
185 # toolchain 128 # toolchain
186 __EOF__ 129 __EOF__
187 echo "CC = ${TOOLCHAIN_CC}" >> "$TEMP_DIR/config.mk" 130 echo "CC = ${TOOLCHAIN_CC}" >> "$TEMP_DIR/config.mk"
188 if [ -n "$TOOLCHAIN_CXX" ]; then 131 if [ -n "$TOOLCHAIN_CXX" ]; then
189 echo "CXX = ${TOOLCHAIN_CXX}" >> "$TEMP_DIR/config.mk" 132 echo "CXX = ${TOOLCHAIN_CXX}" >> "$TEMP_DIR/config.mk"

mercurial