Tue, 28 Oct 2025 22:03:06 +0100
fix that dependencies for tools are always checked
| 0 | 1 | #!/bin/sh | 
| 2 | # | |
| 3 | # toolchain detection | |
| 4 | # | |
| 5 | ||
| 76 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 6 | if isplatform "bsd" && notisplatform "openbsd"; then | 
| 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 7 | C_COMPILERS="clang gcc cc" | 
| 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 8 | CPP_COMPILERS="clang++ g++ CC" | 
| 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 9 | else | 
| 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 10 | C_COMPILERS="gcc clang suncc cc" | 
| 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 11 | CPP_COMPILERS="g++ clang++ sunCC CC" | 
| 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 12 | fi | 
| 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 13 | unset TOOLCHAIN | 
| 0 | 14 | unset TOOLCHAIN_NAME | 
| 15 | unset TOOLCHAIN_CC | |
| 16 | unset TOOLCHAIN_CXX | |
| 17 | ||
| 18 | check_c_compiler() | |
| 19 | { | |
| 103 | 20 | command -v $1 2>&1 >/dev/null | 
| 21 | if [ $? -ne 0 ]; then | |
| 22 | return 1 | |
| 23 | fi | |
| 76 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 24 | cat > "$TEMP_DIR/test.c" << __EOF__ | 
| 0 | 25 | /* test file */ | 
| 26 | #include <stdio.h> | |
| 27 | int main(int argc, char **argv) { | |
| 76 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 28 | #if defined(_MSC_VER) | 
| 103 | 29 | printf("toolchain:msc\n"); | 
| 76 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 30 | #elif defined(__clang__) | 
| 103 | 31 | printf("toolchain:clang gnuc\n"); | 
| 0 | 32 | #elif defined(__GNUC__) | 
| 103 | 33 | printf("toolchain:gcc gnuc\n"); | 
| 0 | 34 | #elif defined(__sun) | 
| 103 | 35 | printf("toolchain:suncc\n"); | 
| 0 | 36 | #else | 
| 103 | 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__); | |
| 0 | 42 | #endif | 
| 76 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 43 | return 0; | 
| 0 | 44 | } | 
| 45 | __EOF__ | |
| 76 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 46 | rm -f "$TEMP_DIR/checkcc" | 
| 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 47 | $1 -o "$TEMP_DIR/checkcc" $CFLAGS $LDFLAGS "$TEMP_DIR/test.c" 2> /dev/null | 
| 0 | 48 | } | 
| 49 | ||
| 50 | check_cpp_compiler() | |
| 51 | { | |
| 103 | 52 | command -v $1 2>&1 >/dev/null | 
| 53 | if [ $? -ne 0 ]; then | |
| 54 | return 1 | |
| 55 | fi | |
| 76 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 56 | cat > "$TEMP_DIR/test.cpp" << __EOF__ | 
| 0 | 57 | /* test file */ | 
| 58 | #include <iostream> | |
| 59 | int main(int argc, char **argv) { | |
| 76 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 60 | #if defined(_MSC_VER) | 
| 103 | 61 | std::cout << "toolchain:msc" << std::endl; | 
| 76 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 62 | #elif defined(__clang__) | 
| 103 | 63 | std::cout << "toolchain:clang gnuc" << std::endl; | 
| 0 | 64 | #elif defined(__GNUC__) | 
| 103 | 65 | std::cout << "toolchain:gcc gnuc" << std::endl; | 
| 0 | 66 | #elif defined(__sun) | 
| 103 | 67 | std::cout << "toolchain:suncc" << std::endl; | 
| 0 | 68 | #else | 
| 103 | 69 | std::cout << "toolchain:unknown" << std::endl; | 
| 0 | 70 | #endif | 
| 103 | 71 | 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: 
0diff
changeset | 72 | return 0; | 
| 0 | 73 | } | 
| 74 | __EOF__ | |
| 76 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 75 | rm -f "$TEMP_DIR/checkcc" | 
| 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 76 | $1 -o "$TEMP_DIR/checkcc" $CXXFLAGS $LDFLAGS "$TEMP_DIR/test.cpp" 2> /dev/null | 
| 0 | 77 | } | 
| 78 | ||
| 79 | create_libtest_source() | |
| 80 | { | |
| 81 | # $1: filename | |
| 82 | # $2: optional include | |
| 76 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 83 | cat > "$TEMP_DIR/$1" << __EOF__ | 
| 0 | 84 | /* libtest file */ | 
| 85 | int main(int argc, char **argv) { | |
| 76 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 86 | return 0; | 
| 0 | 87 | } | 
| 88 | __EOF__ | |
| 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" | |
| 76 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 103 | $TOOLCHAIN_CC -o "$TEMP_DIR/checklib" $CFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.c" 2> /dev/null | 
| 0 | 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 | |
| 76 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 113 | create_libtest_source "test.cpp" "$2" | 
| 0 | 114 | rm -f "$TEMP_DIR/checklib" | 
| 76 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 115 | $TOOLCHAIN_CXX -o "$TEMP_DIR/checklib" $CXXFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.cpp" 2> /dev/null | 
| 0 | 116 | } | 
| 117 | ||
| 118 | check_lib() | |
| 119 | { | |
| 120 | # $1: libname | |
| 121 | # $2: optional include | |
| 76 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 122 | if [ -n "$TOOLCHAIN_CC" ]; then | 
| 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 123 | check_c_lib "$1" "$2" | 
| 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 124 | elif [ -n "$TOOLCHAIN_CXX" ]; then | 
| 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 125 | check_cpp_lib "$1" "$2" | 
| 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 126 | fi | 
| 0 | 127 | } | 
| 128 | ||
| 129 | detect_c_compiler() | |
| 130 | { | |
| 131 | if [ -n "$TOOLCHAIN_CC" ]; then | |
| 132 | return 0 | |
| 133 | fi | |
| 134 | printf "detect C compiler... " | |
| 135 | if [ -n "$CC" ]; then | |
| 136 | if check_c_compiler "$CC"; then | |
| 137 | TOOLCHAIN_CC=$CC | |
| 103 | 138 | "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" | 
| 139 | TOOLCHAIN=`grep '^toolchain:' "$TEMP_DIR/checkcc_out" | tail -c +11` | |
| 76 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 140 | TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` | 
| 103 | 141 | TOOLCHAIN_WSIZE=`grep '^wsize:' "$TEMP_DIR/checkcc_out" | tail -c +7` | 
| 142 | TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | tail -c +13` | |
| 0 | 143 | echo "$CC" | 
| 144 | return 0 | |
| 145 | else | |
| 146 | echo "$CC is not a working C compiler" | |
| 147 | return 1 | |
| 148 | fi | |
| 149 | else | |
| 150 | for COMP in $C_COMPILERS | |
| 151 | do | |
| 152 | if check_c_compiler "$COMP"; then | |
| 153 | TOOLCHAIN_CC=$COMP | |
| 103 | 154 | "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" | 
| 155 | TOOLCHAIN=`grep '^toolchain:' "$TEMP_DIR/checkcc_out" | tail -c +11` | |
| 76 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 156 | TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` | 
| 103 | 157 | TOOLCHAIN_WSIZE=`grep '^wsize:' "$TEMP_DIR/checkcc_out" | tail -c +7` | 
| 158 | TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | tail -c +13` | |
| 0 | 159 | echo "$COMP" | 
| 160 | return 0 | |
| 161 | fi | |
| 162 | done | |
| 163 | echo "not found" | |
| 164 | return 1 | |
| 165 | fi | |
| 166 | } | |
| 167 | ||
| 168 | detect_cpp_compiler() | |
| 169 | { | |
| 170 | if [ -n "$TOOLCHAIN_CXX" ]; then | |
| 171 | return 0 | |
| 172 | fi | |
| 173 | printf "detect C++ compiler... " | |
| 174 | ||
| 175 | if [ -n "$CXX" ]; then | |
| 176 | if check_cpp_compiler "$CXX"; then | |
| 177 | TOOLCHAIN_CXX=$CXX | |
| 103 | 178 | "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" | 
| 179 | TOOLCHAIN=`grep '^toolchain:' "$TEMP_DIR/checkcc_out" | tail -c +11` | |
| 76 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 180 | TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` | 
| 0 | 181 | echo "$CXX" | 
| 182 | return 0 | |
| 183 | else | |
| 184 | echo "$CXX is not a working C++ compiler" | |
| 185 | return 1 | |
| 186 | fi | |
| 187 | else | |
| 188 | for COMP in $CPP_COMPILERS | |
| 189 | do | |
| 190 | if check_cpp_compiler "$COMP"; then | |
| 191 | TOOLCHAIN_CXX=$COMP | |
| 103 | 192 | "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out" | 
| 193 | TOOLCHAIN=`grep '^toolchain:' "$TEMP_DIR/checkcc_out" | tail -c +11` | |
| 76 
eb16be99b0ad
update to newest versions of uwproj and ucx
 Mike Becker <universe@uap-core.de> parents: 
0diff
changeset | 194 | TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` | 
| 0 | 195 | echo "$COMP" | 
| 196 | return 0 | |
| 197 | fi | |
| 198 | done | |
| 199 | echo "${TOOLCHAIN_CXX:-"not found"}" | |
| 200 | return 1 | |
| 201 | fi | |
| 202 | } | |
| 203 | ||
| 204 | write_toolchain_defaults() | |
| 205 | { | |
| 206 | echo "# toolchain" >> "$1" | |
| 207 | if [ -n "$TOOLCHAIN_CC" ]; then | |
| 208 | echo "CC = ${TOOLCHAIN_CC}" >> "$1" | |
| 209 | fi | |
| 210 | if [ -n "$TOOLCHAIN_CXX" ]; then | |
| 211 | echo "CXX = ${TOOLCHAIN_CXX}" >> "$1" | |
| 212 | fi | |
| 213 | echo >> "$1" | |
| 214 | if [ -f "make/${TOOLCHAIN_NAME}.mk" ]; then | |
| 215 | cat "make/${TOOLCHAIN_NAME}.mk" >> "$1" | |
| 216 | elif [ -f "make/cc.mk" ]; then | |
| 217 | cat "make/cc.mk" >> "$1" | |
| 218 | else | |
| 219 | echo "!!! WARNING !!! Default toolchain flags not found. Configuration might be incomplete." | |
| 220 | fi | |
| 221 | } |