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