Thu, 25 Jan 2024 22:01:12 +0100
add cx_array_add() + fix type of cx_array_default_reallocator
universe@753 | 1 | #!/bin/sh |
universe@753 | 2 | # |
universe@753 | 3 | # toolchain detection |
universe@753 | 4 | # |
universe@753 | 5 | |
universe@815 | 6 | if isplatform "bsd" && notisplatform "openbsd"; then |
universe@815 | 7 | C_COMPILERS="clang gcc cc" |
universe@815 | 8 | CPP_COMPILERS="clang++ g++ CC" |
universe@815 | 9 | else |
universe@815 | 10 | C_COMPILERS="gcc clang suncc cc" |
universe@815 | 11 | CPP_COMPILERS="g++ clang++ sunCC CC" |
universe@815 | 12 | fi |
universe@815 | 13 | unset TOOLCHAIN |
universe@753 | 14 | unset TOOLCHAIN_NAME |
universe@753 | 15 | unset TOOLCHAIN_CC |
universe@753 | 16 | unset TOOLCHAIN_CXX |
universe@753 | 17 | |
universe@753 | 18 | check_c_compiler() |
universe@753 | 19 | { |
universe@815 | 20 | cat > "$TEMP_DIR/test.c" << __EOF__ |
universe@753 | 21 | /* test file */ |
universe@753 | 22 | #include <stdio.h> |
universe@753 | 23 | int main(int argc, char **argv) { |
universe@815 | 24 | #if defined(_MSC_VER) |
universe@815 | 25 | printf("msc\n"); |
universe@815 | 26 | #elif defined(__clang__) |
universe@815 | 27 | printf("clang gnuc\n"); |
universe@753 | 28 | #elif defined(__GNUC__) |
universe@815 | 29 | printf("gcc gnuc\n"); |
universe@753 | 30 | #elif defined(__sun) |
universe@815 | 31 | printf("suncc\n"); |
universe@753 | 32 | #else |
universe@815 | 33 | printf("unknown\n"); |
universe@753 | 34 | #endif |
universe@815 | 35 | return 0; |
universe@753 | 36 | } |
universe@753 | 37 | __EOF__ |
universe@815 | 38 | rm -f "$TEMP_DIR/checkcc" |
universe@815 | 39 | $1 -o "$TEMP_DIR/checkcc" $CFLAGS $LDFLAGS "$TEMP_DIR/test.c" 2> /dev/null |
universe@753 | 40 | } |
universe@753 | 41 | |
universe@753 | 42 | check_cpp_compiler() |
universe@753 | 43 | { |
universe@815 | 44 | cat > "$TEMP_DIR/test.cpp" << __EOF__ |
universe@753 | 45 | /* test file */ |
universe@753 | 46 | #include <iostream> |
universe@753 | 47 | int main(int argc, char **argv) { |
universe@815 | 48 | #if defined(_MSC_VER) |
universe@815 | 49 | std::cout << "msc" << std::endl; |
universe@815 | 50 | #elif defined(__clang__) |
universe@815 | 51 | std::cout << "clang gnuc" << std::endl; |
universe@753 | 52 | #elif defined(__GNUC__) |
universe@815 | 53 | std::cout << "gcc gnuc" << std::endl; |
universe@753 | 54 | #elif defined(__sun) |
universe@815 | 55 | std::cout << "suncc" << std::endl; |
universe@753 | 56 | #else |
universe@815 | 57 | std::cout << "cc" << std::endl; |
universe@753 | 58 | #endif |
universe@815 | 59 | return 0; |
universe@753 | 60 | } |
universe@753 | 61 | __EOF__ |
universe@815 | 62 | rm -f "$TEMP_DIR/checkcc" |
universe@815 | 63 | $1 -o "$TEMP_DIR/checkcc" $CXXFLAGS $LDFLAGS "$TEMP_DIR/test.cpp" 2> /dev/null |
universe@753 | 64 | } |
universe@753 | 65 | |
universe@753 | 66 | create_libtest_source() |
universe@753 | 67 | { |
universe@753 | 68 | # $1: filename |
universe@753 | 69 | # $2: optional include |
universe@815 | 70 | cat > "$TEMP_DIR/$1" << __EOF__ |
universe@753 | 71 | /* libtest file */ |
universe@753 | 72 | int main(int argc, char **argv) { |
universe@815 | 73 | return 0; |
universe@753 | 74 | } |
universe@753 | 75 | __EOF__ |
universe@753 | 76 | if [ -n "$2" ]; then |
universe@753 | 77 | echo "#include <$2>" >> "$TEMP_DIR/$1" |
universe@753 | 78 | fi |
universe@753 | 79 | } |
universe@753 | 80 | |
universe@753 | 81 | check_c_lib() |
universe@753 | 82 | { |
universe@753 | 83 | # $1: libname |
universe@753 | 84 | # $2: optional include |
universe@753 | 85 | if [ -z "$TOOLCHAIN_CC" ]; then |
universe@753 | 86 | return 1 |
universe@753 | 87 | fi |
universe@753 | 88 | create_libtest_source "test.c" "$2" |
universe@753 | 89 | rm -f "$TEMP_DIR/checklib" |
universe@815 | 90 | $TOOLCHAIN_CC -o "$TEMP_DIR/checklib" $CFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.c" 2> /dev/null |
universe@753 | 91 | } |
universe@753 | 92 | |
universe@753 | 93 | check_cpp_lib() |
universe@753 | 94 | { |
universe@753 | 95 | # $1: libname |
universe@753 | 96 | # $2: optional include |
universe@753 | 97 | if [ -z "$TOOLCHAIN_CXX" ]; then |
universe@753 | 98 | return 1 |
universe@753 | 99 | fi |
universe@815 | 100 | create_libtest_source "test.cpp" "$2" |
universe@753 | 101 | rm -f "$TEMP_DIR/checklib" |
universe@815 | 102 | $TOOLCHAIN_CXX -o "$TEMP_DIR/checklib" $CXXFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.cpp" 2> /dev/null |
universe@753 | 103 | } |
universe@753 | 104 | |
universe@753 | 105 | check_lib() |
universe@753 | 106 | { |
universe@753 | 107 | # $1: libname |
universe@753 | 108 | # $2: optional include |
universe@815 | 109 | if [ -n "$TOOLCHAIN_CC" ]; then |
universe@815 | 110 | check_c_lib "$1" "$2" |
universe@815 | 111 | elif [ -n "$TOOLCHAIN_CXX" ]; then |
universe@815 | 112 | check_cpp_lib "$1" "$2" |
universe@815 | 113 | fi |
universe@753 | 114 | } |
universe@753 | 115 | |
universe@753 | 116 | detect_c_compiler() |
universe@753 | 117 | { |
universe@753 | 118 | if [ -n "$TOOLCHAIN_CC" ]; then |
universe@753 | 119 | return 0 |
universe@753 | 120 | fi |
universe@753 | 121 | printf "detect C compiler... " |
universe@753 | 122 | if [ -n "$CC" ]; then |
universe@753 | 123 | if check_c_compiler "$CC"; then |
universe@753 | 124 | TOOLCHAIN_CC=$CC |
universe@815 | 125 | TOOLCHAIN=`"$TEMP_DIR/checkcc"` |
universe@815 | 126 | TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` |
universe@753 | 127 | echo "$CC" |
universe@753 | 128 | return 0 |
universe@753 | 129 | else |
universe@753 | 130 | echo "$CC is not a working C compiler" |
universe@753 | 131 | return 1 |
universe@753 | 132 | fi |
universe@753 | 133 | else |
universe@753 | 134 | for COMP in $C_COMPILERS |
universe@753 | 135 | do |
universe@753 | 136 | if check_c_compiler "$COMP"; then |
universe@753 | 137 | TOOLCHAIN_CC=$COMP |
universe@815 | 138 | TOOLCHAIN=`"$TEMP_DIR/checkcc"` |
universe@815 | 139 | TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` |
universe@753 | 140 | echo "$COMP" |
universe@753 | 141 | return 0 |
universe@753 | 142 | fi |
universe@753 | 143 | done |
universe@753 | 144 | echo "not found" |
universe@753 | 145 | return 1 |
universe@753 | 146 | fi |
universe@753 | 147 | } |
universe@753 | 148 | |
universe@753 | 149 | detect_cpp_compiler() |
universe@753 | 150 | { |
universe@753 | 151 | if [ -n "$TOOLCHAIN_CXX" ]; then |
universe@753 | 152 | return 0 |
universe@753 | 153 | fi |
universe@753 | 154 | printf "detect C++ compiler... " |
universe@753 | 155 | |
universe@753 | 156 | if [ -n "$CXX" ]; then |
universe@753 | 157 | if check_cpp_compiler "$CXX"; then |
universe@753 | 158 | TOOLCHAIN_CXX=$CXX |
universe@815 | 159 | TOOLCHAIN=`"$TEMP_DIR/checkcc"` |
universe@815 | 160 | TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` |
universe@753 | 161 | echo "$CXX" |
universe@753 | 162 | return 0 |
universe@753 | 163 | else |
universe@753 | 164 | echo "$CXX is not a working C++ compiler" |
universe@753 | 165 | return 1 |
universe@753 | 166 | fi |
universe@753 | 167 | else |
universe@753 | 168 | for COMP in $CPP_COMPILERS |
universe@753 | 169 | do |
universe@753 | 170 | if check_cpp_compiler "$COMP"; then |
universe@753 | 171 | TOOLCHAIN_CXX=$COMP |
universe@815 | 172 | TOOLCHAIN=`"$TEMP_DIR/checkcc"` |
universe@815 | 173 | TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -` |
universe@753 | 174 | echo "$COMP" |
universe@753 | 175 | return 0 |
universe@753 | 176 | fi |
universe@753 | 177 | done |
universe@753 | 178 | echo "${TOOLCHAIN_CXX:-"not found"}" |
universe@753 | 179 | return 1 |
universe@753 | 180 | fi |
universe@753 | 181 | } |
universe@753 | 182 | |
universe@753 | 183 | write_toolchain_defaults() |
universe@753 | 184 | { |
universe@753 | 185 | echo "# toolchain" >> "$1" |
universe@753 | 186 | if [ -n "$TOOLCHAIN_CC" ]; then |
universe@753 | 187 | echo "CC = ${TOOLCHAIN_CC}" >> "$1" |
universe@753 | 188 | fi |
universe@753 | 189 | if [ -n "$TOOLCHAIN_CXX" ]; then |
universe@753 | 190 | echo "CXX = ${TOOLCHAIN_CXX}" >> "$1" |
universe@753 | 191 | fi |
universe@753 | 192 | echo >> "$1" |
universe@753 | 193 | if [ -f "make/${TOOLCHAIN_NAME}.mk" ]; then |
universe@753 | 194 | cat "make/${TOOLCHAIN_NAME}.mk" >> "$1" |
universe@753 | 195 | elif [ -f "make/cc.mk" ]; then |
universe@753 | 196 | cat "make/cc.mk" >> "$1" |
universe@753 | 197 | else |
universe@753 | 198 | echo "!!! WARNING !!! Default toolchain flags not found. Configuration might be incomplete." |
universe@753 | 199 | fi |
universe@753 | 200 | } |