Sun, 07 Dec 2025 20:16:02 +0100
update uwproj
|
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 | |
| 656 | 6 | TAIL="tail" |
| 515 | 7 | if isplatform "bsd" && notisplatform "openbsd"; then |
| 8 | C_COMPILERS="clang gcc cc" | |
| 9 | CPP_COMPILERS="clang++ g++ CC" | |
| 656 | 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 | |
| 515 | 16 | else |
| 656 | 17 | C_COMPILERS="gcc clang cc" |
| 18 | CPP_COMPILERS="g++ clang++ c++" | |
| 515 | 19 | fi |
| 20 | unset TOOLCHAIN | |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | unset TOOLCHAIN_NAME |
| 515 | 22 | unset TOOLCHAIN_CC |
| 23 | unset TOOLCHAIN_CXX | |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | check_c_compiler() |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | { |
| 656 | 27 | if command -v "$1" >/dev/null 2>&1 ; then |
| 28 | : | |
| 29 | else | |
| 615 | 30 | return 1 |
| 31 | fi | |
| 515 | 32 | cat > "$TEMP_DIR/test.c" << __EOF__ |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | /* test file */ |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #include <stdio.h> |
| 656 | 35 | int main(void) { |
| 515 | 36 | #if defined(_MSC_VER) |
| 615 | 37 | printf("toolchain:msc\n"); |
| 515 | 38 | #elif defined(__clang__) |
| 615 | 39 | printf("toolchain:clang gnuc\n"); |
|
260
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
40 | #elif defined(__GNUC__) |
| 615 | 41 | printf("toolchain:gcc gnuc\n"); |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | #elif defined(__sun) |
| 615 | 43 | printf("toolchain:suncc\n"); |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | #else |
| 615 | 45 | printf("toolchain:unknown\n"); |
| 46 | #endif | |
| 47 | printf("wsize:%d\n", (int)sizeof(void*)*8); | |
| 48 | #ifdef __STDC_VERSION__ | |
| 656 | 49 | printf("stdcversion:%ld\n", (long int)__STDC_VERSION__); |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | #endif |
| 515 | 51 | return 0; |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | } |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | __EOF__ |
| 515 | 54 | rm -f "$TEMP_DIR/checkcc" |
| 55 | $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
|
56 | } |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | check_cpp_compiler() |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | { |
| 656 | 60 | if command -v "$1" >/dev/null 2>&1 ; then |
| 61 | : | |
| 62 | else | |
| 615 | 63 | return 1 |
| 64 | fi | |
| 515 | 65 | cat > "$TEMP_DIR/test.cpp" << __EOF__ |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | /* test file */ |
|
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | #include <iostream> |
| 656 | 68 | int main(void) { |
| 515 | 69 | #if defined(_MSC_VER) |
| 615 | 70 | std::cout << "toolchain:msc" << std::endl; |
| 515 | 71 | #elif defined(__clang__) |
| 615 | 72 | std::cout << "toolchain:clang gnuc" << std::endl; |
|
260
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
209
diff
changeset
|
73 | #elif defined(__GNUC__) |
| 615 | 74 | std::cout << "toolchain:gcc gnuc" << std::endl; |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | #elif defined(__sun) |
| 615 | 76 | std::cout << "toolchain:suncc" << std::endl; |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | #else |
| 615 | 78 | std::cout << "toolchain:unknown" << std::endl; |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | #endif |
| 615 | 80 | std::cout << "wsize:" << sizeof(void*)*8 << std::endl; |
| 515 | 81 | return 0; |
| 82 | } | |
| 83 | __EOF__ | |
| 84 | rm -f "$TEMP_DIR/checkcc" | |
| 85 | $1 -o "$TEMP_DIR/checkcc" $CXXFLAGS $LDFLAGS "$TEMP_DIR/test.cpp" 2> /dev/null | |
| 86 | } | |
| 87 | ||
| 615 | 88 | parse_toolchain_properties() |
| 89 | { | |
| 90 | info_file="$1" | |
| 656 | 91 | TOOLCHAIN=`grep '^toolchain:' "$info_file" | $TAIL -c +11` |
| 615 | 92 | TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` |
| 656 | 93 | TOOLCHAIN_WSIZE=`grep '^wsize:' "$info_file" | $TAIL -c +7` |
| 615 | 94 | } |
| 95 | ||
| 515 | 96 | detect_c_compiler() |
| 97 | { | |
| 98 | if [ -n "$TOOLCHAIN_CC" ]; then | |
| 99 | return 0 | |
| 100 | fi | |
| 101 | printf "detect C compiler... " | |
| 102 | if [ -n "$CC" ]; then | |
| 103 | if check_c_compiler "$CC"; then | |
| 104 | TOOLCHAIN_CC=$CC | |
| 615 | 105 | "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" |
| 106 | parse_toolchain_properties "$TEMP_DIR/checkcc_out" | |
| 656 | 107 | TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | $TAIL -c +13` |
| 515 | 108 | echo "$CC" |
| 109 | return 0 | |
| 110 | else | |
| 111 | echo "$CC is not a working C compiler" | |
| 112 | return 1 | |
| 113 | fi | |
| 114 | else | |
| 115 | for COMP in $C_COMPILERS | |
| 116 | do | |
| 117 | if check_c_compiler "$COMP"; then | |
| 118 | TOOLCHAIN_CC=$COMP | |
| 615 | 119 | "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" |
| 120 | parse_toolchain_properties "$TEMP_DIR/checkcc_out" | |
| 656 | 121 | TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | $TAIL -c +13` |
| 515 | 122 | echo "$COMP" |
| 123 | return 0 | |
| 124 | fi | |
| 125 | done | |
| 126 | echo "not found" | |
| 127 | return 1 | |
| 128 | fi | |
| 129 | } | |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | |
| 515 | 131 | detect_cpp_compiler() |
| 132 | { | |
| 133 | if [ -n "$TOOLCHAIN_CXX" ]; then | |
| 134 | return 0 | |
| 135 | fi | |
| 136 | printf "detect C++ compiler... " | |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | |
| 515 | 138 | if [ -n "$CXX" ]; then |
| 139 | if check_cpp_compiler "$CXX"; then | |
| 140 | TOOLCHAIN_CXX=$CXX | |
| 615 | 141 | "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" |
| 142 | parse_toolchain_properties "$TEMP_DIR/checkcc_out" | |
| 515 | 143 | echo "$CXX" |
| 144 | return 0 | |
| 145 | else | |
| 146 | echo "$CXX is not a working C++ compiler" | |
| 147 | return 1 | |
| 148 | fi | |
| 149 | else | |
| 150 | for COMP in $CPP_COMPILERS | |
| 151 | do | |
| 152 | if check_cpp_compiler "$COMP"; then | |
| 153 | TOOLCHAIN_CXX=$COMP | |
| 615 | 154 | "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" |
| 155 | parse_toolchain_properties "$TEMP_DIR/checkcc_out" | |
| 515 | 156 | echo "$COMP" |
| 157 | return 0 | |
| 158 | fi | |
| 159 | done | |
| 160 | echo "${TOOLCHAIN_CXX:-"not found"}" | |
| 161 | return 1 | |
| 162 | fi | |
| 163 | } | |
|
204
e870a7c8f223
replace old build system with uwproj
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | |
| 515 | 165 | write_toolchain_defaults() |
| 166 | { | |
| 167 | echo "# toolchain" >> "$1" | |
| 168 | if [ -n "$TOOLCHAIN_CC" ]; then | |
| 169 | echo "CC = ${TOOLCHAIN_CC}" >> "$1" | |
| 170 | fi | |
| 171 | if [ -n "$TOOLCHAIN_CXX" ]; then | |
| 172 | echo "CXX = ${TOOLCHAIN_CXX}" >> "$1" | |
| 173 | fi | |
| 174 | echo >> "$1" | |
| 175 | if [ -f "make/${TOOLCHAIN_NAME}.mk" ]; then | |
| 176 | cat "make/${TOOLCHAIN_NAME}.mk" >> "$1" | |
| 177 | elif [ -f "make/cc.mk" ]; then | |
| 178 | cat "make/cc.mk" >> "$1" | |
| 179 | else | |
| 180 | echo "!!! WARNING !!! Default toolchain flags not found. Configuration might be incomplete." | |
| 181 | fi | |
| 182 | } |