Sun, 30 Nov 2025 16:52:33 +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 | { | |
| 289 | 27 | if command -v "$1" >/dev/null 2>&1 ; then |
| 28 | : | |
| 29 | else | |
| 103 | 30 | return 1 |
| 31 | fi | |
|
76
eb16be99b0ad
update to newest versions of uwproj and ucx
Mike Becker <universe@uap-core.de>
parents:
0
diff
changeset
|
32 | cat > "$TEMP_DIR/test.c" << __EOF__ |
| 0 | 33 | /* test file */ |
| 34 | #include <stdio.h> | |
| 285 | 35 | int main(void) { |
|
76
eb16be99b0ad
update to newest versions of uwproj and ucx
Mike Becker <universe@uap-core.de>
parents:
0
diff
changeset
|
36 | #if defined(_MSC_VER) |
| 103 | 37 | printf("toolchain:msc\n"); |
|
76
eb16be99b0ad
update to newest versions of uwproj and ucx
Mike Becker <universe@uap-core.de>
parents:
0
diff
changeset
|
38 | #elif defined(__clang__) |
| 103 | 39 | printf("toolchain:clang gnuc\n"); |
| 0 | 40 | #elif defined(__GNUC__) |
| 103 | 41 | printf("toolchain:gcc gnuc\n"); |
| 0 | 42 | #elif defined(__sun) |
| 103 | 43 | printf("toolchain:suncc\n"); |
| 0 | 44 | #else |
| 103 | 45 | printf("toolchain:unknown\n"); |
| 46 | #endif | |
| 47 | printf("wsize:%d\n", (int)sizeof(void*)*8); | |
| 48 | #ifdef __STDC_VERSION__ | |
| 285 | 49 | printf("stdcversion:%ld\n", (long int)__STDC_VERSION__); |
| 0 | 50 | #endif |
|
76
eb16be99b0ad
update to newest versions of uwproj and ucx
Mike Becker <universe@uap-core.de>
parents:
0
diff
changeset
|
51 | return 0; |
| 0 | 52 | } |
| 53 | __EOF__ | |
|
76
eb16be99b0ad
update to newest versions of uwproj and ucx
Mike Becker <universe@uap-core.de>
parents:
0
diff
changeset
|
54 | rm -f "$TEMP_DIR/checkcc" |
|
eb16be99b0ad
update to newest versions of uwproj and ucx
Mike Becker <universe@uap-core.de>
parents:
0
diff
changeset
|
55 | $1 -o "$TEMP_DIR/checkcc" $CFLAGS $LDFLAGS "$TEMP_DIR/test.c" 2> /dev/null |
| 0 | 56 | } |
| 57 | ||
| 58 | check_cpp_compiler() | |
| 59 | { | |
| 289 | 60 | if command -v "$1" >/dev/null 2>&1 ; then |
| 61 | : | |
| 62 | else | |
| 103 | 63 | return 1 |
| 64 | fi | |
|
76
eb16be99b0ad
update to newest versions of uwproj and ucx
Mike Becker <universe@uap-core.de>
parents:
0
diff
changeset
|
65 | cat > "$TEMP_DIR/test.cpp" << __EOF__ |
| 0 | 66 | /* test file */ |
| 67 | #include <iostream> | |
| 285 | 68 | int main(void) { |
|
76
eb16be99b0ad
update to newest versions of uwproj and ucx
Mike Becker <universe@uap-core.de>
parents:
0
diff
changeset
|
69 | #if defined(_MSC_VER) |
| 103 | 70 | 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
|
71 | #elif defined(__clang__) |
| 103 | 72 | std::cout << "toolchain:clang gnuc" << std::endl; |
| 0 | 73 | #elif defined(__GNUC__) |
| 103 | 74 | std::cout << "toolchain:gcc gnuc" << std::endl; |
| 0 | 75 | #elif defined(__sun) |
| 103 | 76 | std::cout << "toolchain:suncc" << std::endl; |
| 0 | 77 | #else |
| 103 | 78 | std::cout << "toolchain:unknown" << std::endl; |
| 0 | 79 | #endif |
| 285 | 80 | 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
|
81 | return 0; |
| 0 | 82 | } |
| 83 | __EOF__ | |
|
76
eb16be99b0ad
update to newest versions of uwproj and ucx
Mike Becker <universe@uap-core.de>
parents:
0
diff
changeset
|
84 | rm -f "$TEMP_DIR/checkcc" |
|
eb16be99b0ad
update to newest versions of uwproj and ucx
Mike Becker <universe@uap-core.de>
parents:
0
diff
changeset
|
85 | $1 -o "$TEMP_DIR/checkcc" $CXXFLAGS $LDFLAGS "$TEMP_DIR/test.cpp" 2> /dev/null |
| 0 | 86 | } |
| 87 | ||
| 285 | 88 | parse_toolchain_properties() |
| 0 | 89 | { |
| 285 | 90 | info_file="$1" |
| 91 | TOOLCHAIN=`grep '^toolchain:' "$info_file" | $TAIL -c +11` | |
| 92 | TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` | |
| 93 | TOOLCHAIN_WSIZE=`grep '^wsize:' "$info_file" | $TAIL -c +7` | |
| 0 | 94 | } |
| 95 | ||
| 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 | |
| 103 | 105 | "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" |
| 285 | 106 | parse_toolchain_properties "$TEMP_DIR/checkcc_out" |
| 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 | |
| 103 | 119 | "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" |
| 285 | 120 | parse_toolchain_properties "$TEMP_DIR/checkcc_out" |
| 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 | |
| 103 | 141 | "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" |
| 285 | 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 | |
| 103 | 154 | "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" |
| 285 | 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 | } |