Tue, 02 Dec 2025 19:35:29 +0100
add test for rewrite_rule_create
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | #!/bin/sh |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | # |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | # toolchain detection |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | # |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | |
| 515 | 6 | if isplatform "bsd" && notisplatform "openbsd"; then |
| 7 | C_COMPILERS="clang gcc cc" | |
| 8 | CPP_COMPILERS="clang++ g++ CC" | |
| 9 | else | |
| 10 | C_COMPILERS="gcc clang suncc cc" | |
| 11 | CPP_COMPILERS="g++ clang++ sunCC CC" | |
| 12 | fi | |
| 13 | unset TOOLCHAIN | |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | unset TOOLCHAIN_NAME |
| 515 | 15 | unset TOOLCHAIN_CC |
| 16 | unset TOOLCHAIN_CXX | |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | check_c_compiler() |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | { |
| 615 | 20 | command -v $1 2>&1 >/dev/null |
| 21 | if [ $? -ne 0 ]; then | |
| 22 | return 1 | |
| 23 | fi | |
| 515 | 24 | cat > "$TEMP_DIR/test.c" << __EOF__ |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | /* test file */ |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | #include <stdio.h> |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | int main(int argc, char **argv) { |
| 515 | 28 | #if defined(_MSC_VER) |
| 615 | 29 | printf("toolchain:msc\n"); |
| 515 | 30 | #elif defined(__clang__) |
| 615 | 31 | printf("toolchain:clang gnuc\n"); |
|
260
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
32 | #elif defined(__GNUC__) |
| 615 | 33 | printf("toolchain:gcc gnuc\n"); |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #elif defined(__sun) |
| 615 | 35 | printf("toolchain:suncc\n"); |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #else |
| 615 | 37 | printf("toolchain:unknown\n"); |
| 38 | #endif | |
| 39 | printf("wsize:%d\n", (int)sizeof(void*)*8); | |
| 40 | #ifdef __STDC_VERSION__ | |
| 41 | printf("stdcversion:%d\n", __STDC_VERSION__); | |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | #endif |
| 515 | 43 | return 0; |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | } |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | __EOF__ |
| 515 | 46 | rm -f "$TEMP_DIR/checkcc" |
| 47 | $1 -o "$TEMP_DIR/checkcc" $CFLAGS $LDFLAGS "$TEMP_DIR/test.c" 2> /dev/null | |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | } |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | check_cpp_compiler() |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | { |
| 615 | 52 | command -v $1 2>&1 >/dev/null |
| 53 | if [ $? -ne 0 ]; then | |
| 54 | return 1 | |
| 55 | fi | |
| 515 | 56 | cat > "$TEMP_DIR/test.cpp" << __EOF__ |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | /* test file */ |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | #include <iostream> |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | int main(int argc, char **argv) { |
| 515 | 60 | #if defined(_MSC_VER) |
| 615 | 61 | std::cout << "toolchain:msc" << std::endl; |
| 515 | 62 | #elif defined(__clang__) |
| 615 | 63 | std::cout << "toolchain:clang gnuc" << std::endl; |
|
260
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
64 | #elif defined(__GNUC__) |
| 615 | 65 | std::cout << "toolchain:gcc gnuc" << std::endl; |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | #elif defined(__sun) |
| 615 | 67 | std::cout << "toolchain:suncc" << std::endl; |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | #else |
| 615 | 69 | std::cout << "toolchain:unknown" << std::endl; |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | #endif |
| 615 | 71 | std::cout << "wsize:" << sizeof(void*)*8 << std::endl; |
| 515 | 72 | return 0; |
| 73 | } | |
| 74 | __EOF__ | |
| 75 | rm -f "$TEMP_DIR/checkcc" | |
| 76 | $1 -o "$TEMP_DIR/checkcc" $CXXFLAGS $LDFLAGS "$TEMP_DIR/test.cpp" 2> /dev/null | |
| 77 | } | |
| 78 | ||
| 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; | |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | } |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | __EOF__ |
| 515 | 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 | |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | } |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | |
| 615 | 129 | parse_toolchain_properties() |
| 130 | { | |
| 131 | info_file="$1" | |
| 132 | TOOLCHAIN=`grep '^toolchain:' "$info_file" | tail -c +11` | |
| 133 | TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` | |
| 134 | TOOLCHAIN_WSIZE=`grep '^wsize:' "$info_file" | tail -c +7` | |
| 135 | } | |
| 136 | ||
| 515 | 137 | detect_c_compiler() |
| 138 | { | |
| 139 | if [ -n "$TOOLCHAIN_CC" ]; then | |
| 140 | return 0 | |
| 141 | fi | |
| 142 | printf "detect C compiler... " | |
| 143 | if [ -n "$CC" ]; then | |
| 144 | if check_c_compiler "$CC"; then | |
| 145 | TOOLCHAIN_CC=$CC | |
| 615 | 146 | "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" |
| 147 | parse_toolchain_properties "$TEMP_DIR/checkcc_out" | |
| 148 | TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | tail -c +13` | |
| 515 | 149 | echo "$CC" |
| 150 | return 0 | |
| 151 | else | |
| 152 | echo "$CC is not a working C compiler" | |
| 153 | return 1 | |
| 154 | fi | |
| 155 | else | |
| 156 | for COMP in $C_COMPILERS | |
| 157 | do | |
| 158 | if check_c_compiler "$COMP"; then | |
| 159 | TOOLCHAIN_CC=$COMP | |
| 615 | 160 | "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" |
| 161 | parse_toolchain_properties "$TEMP_DIR/checkcc_out" | |
| 162 | TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | tail -c +13` | |
| 515 | 163 | echo "$COMP" |
| 164 | return 0 | |
| 165 | fi | |
| 166 | done | |
| 167 | echo "not found" | |
| 168 | return 1 | |
| 169 | fi | |
| 170 | } | |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | |
| 515 | 172 | detect_cpp_compiler() |
| 173 | { | |
| 174 | if [ -n "$TOOLCHAIN_CXX" ]; then | |
| 175 | return 0 | |
| 176 | fi | |
| 177 | printf "detect C++ compiler... " | |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | |
| 515 | 179 | if [ -n "$CXX" ]; then |
| 180 | if check_cpp_compiler "$CXX"; then | |
| 181 | TOOLCHAIN_CXX=$CXX | |
| 615 | 182 | "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" |
| 183 | parse_toolchain_properties "$TEMP_DIR/checkcc_out" | |
| 515 | 184 | echo "$CXX" |
| 185 | return 0 | |
| 186 | else | |
| 187 | echo "$CXX is not a working C++ compiler" | |
| 188 | return 1 | |
| 189 | fi | |
| 190 | else | |
| 191 | for COMP in $CPP_COMPILERS | |
| 192 | do | |
| 193 | if check_cpp_compiler "$COMP"; then | |
| 194 | TOOLCHAIN_CXX=$COMP | |
| 615 | 195 | "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" |
| 196 | parse_toolchain_properties "$TEMP_DIR/checkcc_out" | |
| 515 | 197 | echo "$COMP" |
| 198 | return 0 | |
| 199 | fi | |
| 200 | done | |
| 201 | echo "${TOOLCHAIN_CXX:-"not found"}" | |
| 202 | return 1 | |
| 203 | fi | |
| 204 | } | |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | |
| 515 | 206 | write_toolchain_defaults() |
| 207 | { | |
| 208 | echo "# toolchain" >> "$1" | |
| 209 | if [ -n "$TOOLCHAIN_CC" ]; then | |
| 210 | echo "CC = ${TOOLCHAIN_CC}" >> "$1" | |
| 211 | fi | |
| 212 | if [ -n "$TOOLCHAIN_CXX" ]; then | |
| 213 | echo "CXX = ${TOOLCHAIN_CXX}" >> "$1" | |
| 214 | fi | |
| 215 | echo >> "$1" | |
| 216 | if [ -f "make/${TOOLCHAIN_NAME}.mk" ]; then | |
| 217 | cat "make/${TOOLCHAIN_NAME}.mk" >> "$1" | |
| 218 | elif [ -f "make/cc.mk" ]; then | |
| 219 | cat "make/cc.mk" >> "$1" | |
| 220 | else | |
| 221 | echo "!!! WARNING !!! Default toolchain flags not found. Configuration might be incomplete." | |
| 222 | fi | |
| 223 | } |