Wed, 10 Apr 2024 19:20:44 +0200
use new scale2d function in text update
0 | 1 | #!/bin/sh |
2 | # | |
3 | # toolchain detection | |
4 | # | |
5 | ||
6 | C_COMPILERS="gcc clang suncc cc" | |
7 | CPP_COMPILERS="g++ clang++ sunCC CC" | |
8 | unset TOOLCHAIN_NAME | |
9 | unset TOOLCHAIN_CC | |
10 | unset TOOLCHAIN_CXX | |
11 | ||
12 | check_c_compiler() | |
13 | { | |
14 | cat > "$TEMP_DIR/test.c" << __EOF__ | |
15 | /* test file */ | |
16 | #include <stdio.h> | |
17 | int main(int argc, char **argv) { | |
18 | #if defined(__clang__) | |
19 | printf("clang\n"); | |
20 | #elif defined(__GNUC__) | |
21 | printf("gcc\n"); | |
22 | #elif defined(__sun) | |
23 | printf("suncc\n"); | |
24 | #else | |
25 | printf("unknown\n"); | |
26 | #endif | |
27 | return 0; | |
28 | } | |
29 | __EOF__ | |
30 | rm -f "$TEMP_DIR/checkcc" | |
31 | $1 -o "$TEMP_DIR/checkcc" $CFLAGS $LDFLAGS "$TEMP_DIR/test.c" 2> /dev/null | |
32 | } | |
33 | ||
34 | check_cpp_compiler() | |
35 | { | |
36 | cat > "$TEMP_DIR/test.cpp" << __EOF__ | |
37 | /* test file */ | |
38 | #include <iostream> | |
39 | int main(int argc, char **argv) { | |
40 | #if defined(__clang__) | |
41 | std::cout << "clang" << std::endl; | |
42 | #elif defined(__GNUC__) | |
43 | std::cout << "gcc" << std::endl; | |
44 | #elif defined(__sun) | |
45 | std::cout << "suncc" << std::endl; | |
46 | #else | |
47 | std::cout << "cc" << std::endl; | |
48 | #endif | |
49 | return 0; | |
50 | } | |
51 | __EOF__ | |
52 | rm -f "$TEMP_DIR/checkcc" | |
53 | $1 -o "$TEMP_DIR/checkcc" $CXXFLAGS $LDFLAGS "$TEMP_DIR/test.cpp" 2> /dev/null | |
54 | } | |
55 | ||
56 | create_libtest_source() | |
57 | { | |
58 | # $1: filename | |
59 | # $2: optional include | |
60 | cat > "$TEMP_DIR/$1" << __EOF__ | |
61 | /* libtest file */ | |
62 | int main(int argc, char **argv) { | |
63 | return 0; | |
64 | } | |
65 | __EOF__ | |
66 | if [ -n "$2" ]; then | |
67 | echo "#include <$2>" >> "$TEMP_DIR/$1" | |
68 | fi | |
69 | } | |
70 | ||
71 | check_c_lib() | |
72 | { | |
73 | # $1: libname | |
74 | # $2: optional include | |
75 | if [ -z "$TOOLCHAIN_CC" ]; then | |
76 | return 1 | |
77 | fi | |
78 | create_libtest_source "test.c" "$2" | |
79 | rm -f "$TEMP_DIR/checklib" | |
80 | $TOOLCHAIN_CC -o "$TEMP_DIR/checklib" $CFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.c" 2> /dev/null | |
81 | } | |
82 | ||
83 | check_cpp_lib() | |
84 | { | |
85 | # $1: libname | |
86 | # $2: optional include | |
87 | if [ -z "$TOOLCHAIN_CXX" ]; then | |
88 | return 1 | |
89 | fi | |
90 | create_libtest_source "test.cpp" "$2" | |
91 | rm -f "$TEMP_DIR/checklib" | |
92 | $TOOLCHAIN_CXX -o "$TEMP_DIR/checklib" $CXXFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.cpp" 2> /dev/null | |
93 | } | |
94 | ||
95 | check_lib() | |
96 | { | |
97 | # $1: libname | |
98 | # $2: optional include | |
99 | if [ -n "$TOOLCHAIN_CC" ]; then | |
100 | check_c_lib "$1" "$2" | |
101 | elif [ -n "$TOOLCHAIN_CXX" ]; then | |
102 | check_cpp_lib "$1" "$2" | |
103 | fi | |
104 | } | |
105 | ||
106 | detect_c_compiler() | |
107 | { | |
108 | if [ -n "$TOOLCHAIN_CC" ]; then | |
109 | return 0 | |
110 | fi | |
111 | printf "detect C compiler... " | |
112 | if [ -n "$CC" ]; then | |
113 | if check_c_compiler "$CC"; then | |
114 | TOOLCHAIN_CC=$CC | |
115 | TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"` | |
116 | echo "$CC" | |
117 | return 0 | |
118 | else | |
119 | echo "$CC is not a working C compiler" | |
120 | return 1 | |
121 | fi | |
122 | else | |
123 | for COMP in $C_COMPILERS | |
124 | do | |
125 | if check_c_compiler "$COMP"; then | |
126 | TOOLCHAIN_CC=$COMP | |
127 | TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"` | |
128 | echo "$COMP" | |
129 | return 0 | |
130 | fi | |
131 | done | |
132 | echo "not found" | |
133 | return 1 | |
134 | fi | |
135 | } | |
136 | ||
137 | detect_cpp_compiler() | |
138 | { | |
139 | if [ -n "$TOOLCHAIN_CXX" ]; then | |
140 | return 0 | |
141 | fi | |
142 | printf "detect C++ compiler... " | |
143 | ||
144 | if [ -n "$CXX" ]; then | |
145 | if check_cpp_compiler "$CXX"; then | |
146 | TOOLCHAIN_CXX=$CXX | |
147 | TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"` | |
148 | echo "$CXX" | |
149 | return 0 | |
150 | else | |
151 | echo "$CXX is not a working C++ compiler" | |
152 | return 1 | |
153 | fi | |
154 | else | |
155 | for COMP in $CPP_COMPILERS | |
156 | do | |
157 | if check_cpp_compiler "$COMP"; then | |
158 | TOOLCHAIN_CXX=$COMP | |
159 | TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"` | |
160 | echo "$COMP" | |
161 | return 0 | |
162 | fi | |
163 | done | |
164 | echo "${TOOLCHAIN_CXX:-"not found"}" | |
165 | return 1 | |
166 | fi | |
167 | } | |
168 | ||
169 | write_toolchain_defaults() | |
170 | { | |
171 | echo "# toolchain" >> "$1" | |
172 | if [ -n "$TOOLCHAIN_CC" ]; then | |
173 | echo "CC = ${TOOLCHAIN_CC}" >> "$1" | |
174 | fi | |
175 | if [ -n "$TOOLCHAIN_CXX" ]; then | |
176 | echo "CXX = ${TOOLCHAIN_CXX}" >> "$1" | |
177 | fi | |
178 | echo >> "$1" | |
179 | if [ -f "make/${TOOLCHAIN_NAME}.mk" ]; then | |
180 | cat "make/${TOOLCHAIN_NAME}.mk" >> "$1" | |
181 | elif [ -f "make/cc.mk" ]; then | |
182 | cat "make/cc.mk" >> "$1" | |
183 | else | |
184 | echo "!!! WARNING !!! Default toolchain flags not found. Configuration might be incomplete." | |
185 | fi | |
186 | } |