Sun, 30 Nov 2025 22:55:34 +0100
update uwproj
| 0 | 1 | #!/bin/sh |
| 2 | # | |
| 3 | # toolchain detection | |
| 4 | # | |
| 5 | ||
| 70 | 6 | TAIL="tail" |
| 0 | 7 | if isplatform "bsd" && notisplatform "openbsd"; then |
| 8 | C_COMPILERS="clang gcc cc" | |
| 9 | CPP_COMPILERS="clang++ g++ CC" | |
|
69
f70ba8f14b41
update uwproj (fixes configure on solaris)
Mike Becker <universe@uap-core.de>
parents:
45
diff
changeset
|
10 | elif isplatform "solaris"; then |
|
f70ba8f14b41
update uwproj (fixes configure on solaris)
Mike Becker <universe@uap-core.de>
parents:
45
diff
changeset
|
11 | C_COMPILERS="cc suncc gcc clang" |
|
f70ba8f14b41
update uwproj (fixes configure on solaris)
Mike Becker <universe@uap-core.de>
parents:
45
diff
changeset
|
12 | CPP_COMPILERS="CC sunCC g++ clang++" |
|
f70ba8f14b41
update uwproj (fixes configure on solaris)
Mike Becker <universe@uap-core.de>
parents:
45
diff
changeset
|
13 | if [ -f /usr/xpg4/bin/tail ]; then |
|
f70ba8f14b41
update uwproj (fixes configure on solaris)
Mike Becker <universe@uap-core.de>
parents:
45
diff
changeset
|
14 | TAIL=/usr/xpg4/bin/tail |
|
f70ba8f14b41
update uwproj (fixes configure on solaris)
Mike Becker <universe@uap-core.de>
parents:
45
diff
changeset
|
15 | fi |
| 0 | 16 | else |
|
69
f70ba8f14b41
update uwproj (fixes configure on solaris)
Mike Becker <universe@uap-core.de>
parents:
45
diff
changeset
|
17 | C_COMPILERS="gcc clang cc" |
|
f70ba8f14b41
update uwproj (fixes configure on solaris)
Mike Becker <universe@uap-core.de>
parents:
45
diff
changeset
|
18 | CPP_COMPILERS="g++ clang++ c++" |
| 0 | 19 | fi |
| 20 | unset TOOLCHAIN | |
| 21 | unset TOOLCHAIN_NAME | |
| 22 | unset TOOLCHAIN_CC | |
| 23 | unset TOOLCHAIN_CXX | |
| 24 | ||
| 25 | check_c_compiler() | |
| 26 | { | |
| 70 | 27 | if command -v "$1" >/dev/null 2>&1 ; then |
| 28 | : | |
| 29 | else | |
| 45 | 30 | return 1 |
| 31 | fi | |
| 0 | 32 | cat > "$TEMP_DIR/test.c" << __EOF__ |
| 33 | /* test file */ | |
| 34 | #include <stdio.h> | |
| 70 | 35 | int main(void) { |
| 0 | 36 | #if defined(_MSC_VER) |
| 45 | 37 | printf("toolchain:msc\n"); |
| 0 | 38 | #elif defined(__clang__) |
| 45 | 39 | printf("toolchain:clang gnuc\n"); |
| 0 | 40 | #elif defined(__GNUC__) |
| 45 | 41 | printf("toolchain:gcc gnuc\n"); |
| 0 | 42 | #elif defined(__sun) |
| 45 | 43 | printf("toolchain:suncc\n"); |
| 0 | 44 | #else |
| 45 | 45 | printf("toolchain:unknown\n"); |
| 46 | #endif | |
| 47 | printf("wsize:%d\n", (int)sizeof(void*)*8); | |
| 48 | #ifdef __STDC_VERSION__ | |
| 70 | 49 | printf("stdcversion:%ld\n", (long int)__STDC_VERSION__); |
| 0 | 50 | #endif |
| 51 | return 0; | |
| 52 | } | |
| 53 | __EOF__ | |
| 54 | rm -f "$TEMP_DIR/checkcc" | |
| 55 | $1 -o "$TEMP_DIR/checkcc" $CFLAGS $LDFLAGS "$TEMP_DIR/test.c" 2> /dev/null | |
| 56 | } | |
| 57 | ||
| 58 | check_cpp_compiler() | |
| 59 | { | |
| 70 | 60 | if command -v "$1" >/dev/null 2>&1 ; then |
| 61 | : | |
| 62 | else | |
| 45 | 63 | return 1 |
| 64 | fi | |
| 0 | 65 | cat > "$TEMP_DIR/test.cpp" << __EOF__ |
| 66 | /* test file */ | |
| 67 | #include <iostream> | |
| 70 | 68 | int main(void) { |
| 0 | 69 | #if defined(_MSC_VER) |
| 45 | 70 | std::cout << "toolchain:msc" << std::endl; |
| 0 | 71 | #elif defined(__clang__) |
| 45 | 72 | std::cout << "toolchain:clang gnuc" << std::endl; |
| 0 | 73 | #elif defined(__GNUC__) |
| 45 | 74 | std::cout << "toolchain:gcc gnuc" << std::endl; |
| 0 | 75 | #elif defined(__sun) |
| 45 | 76 | std::cout << "toolchain:suncc" << std::endl; |
| 0 | 77 | #else |
| 45 | 78 | std::cout << "toolchain:unknown" << std::endl; |
| 0 | 79 | #endif |
| 45 | 80 | std::cout << "wsize:" << sizeof(void*)*8 << std::endl; |
| 0 | 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 | ||
| 45 | 88 | parse_toolchain_properties() |
| 89 | { | |
| 90 | info_file="$1" | |
|
69
f70ba8f14b41
update uwproj (fixes configure on solaris)
Mike Becker <universe@uap-core.de>
parents:
45
diff
changeset
|
91 | TOOLCHAIN=`grep '^toolchain:' "$info_file" | $TAIL -c +11` |
| 45 | 92 | TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` |
|
69
f70ba8f14b41
update uwproj (fixes configure on solaris)
Mike Becker <universe@uap-core.de>
parents:
45
diff
changeset
|
93 | TOOLCHAIN_WSIZE=`grep '^wsize:' "$info_file" | $TAIL -c +7` |
| 45 | 94 | } |
| 95 | ||
| 0 | 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 | |
| 45 | 105 | "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" |
| 106 | parse_toolchain_properties "$TEMP_DIR/checkcc_out" | |
|
69
f70ba8f14b41
update uwproj (fixes configure on solaris)
Mike Becker <universe@uap-core.de>
parents:
45
diff
changeset
|
107 | TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | $TAIL -c +13` |
| 0 | 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 | |
| 45 | 119 | "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" |
| 120 | parse_toolchain_properties "$TEMP_DIR/checkcc_out" | |
|
69
f70ba8f14b41
update uwproj (fixes configure on solaris)
Mike Becker <universe@uap-core.de>
parents:
45
diff
changeset
|
121 | TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | $TAIL -c +13` |
| 0 | 122 | echo "$COMP" |
| 123 | return 0 | |
| 124 | fi | |
| 125 | done | |
| 126 | echo "not found" | |
| 127 | return 1 | |
| 128 | fi | |
| 129 | } | |
| 130 | ||
| 131 | detect_cpp_compiler() | |
| 132 | { | |
| 133 | if [ -n "$TOOLCHAIN_CXX" ]; then | |
| 134 | return 0 | |
| 135 | fi | |
| 136 | printf "detect C++ compiler... " | |
| 137 | ||
| 138 | if [ -n "$CXX" ]; then | |
| 139 | if check_cpp_compiler "$CXX"; then | |
| 140 | TOOLCHAIN_CXX=$CXX | |
| 45 | 141 | "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" |
| 142 | parse_toolchain_properties "$TEMP_DIR/checkcc_out" | |
| 0 | 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 | |
| 45 | 154 | "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" |
| 155 | parse_toolchain_properties "$TEMP_DIR/checkcc_out" | |
| 0 | 156 | echo "$COMP" |
| 157 | return 0 | |
| 158 | fi | |
| 159 | done | |
| 160 | echo "${TOOLCHAIN_CXX:-"not found"}" | |
| 161 | return 1 | |
| 162 | fi | |
| 163 | } | |
| 164 | ||
| 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 | } |