make/toolchain.sh

Fri, 22 Sep 2023 23:26:23 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 22 Sep 2023 23:26:23 +0200
changeset 68
ae763178ee1e
permissions
-rw-r--r--

replace autoconf with uwproj

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

mercurial