make/toolchain.sh

changeset 285
dc13730ff1ec
parent 103
d9549dd8e9a9
--- a/make/toolchain.sh	Wed Oct 29 22:59:23 2025 +0100
+++ b/make/toolchain.sh	Thu Nov 13 22:09:53 2025 +0100
@@ -3,12 +3,19 @@
 # toolchain detection
 #
 
+TAIL="tail"
 if isplatform "bsd" && notisplatform "openbsd"; then
   C_COMPILERS="clang gcc cc"
   CPP_COMPILERS="clang++ g++ CC"
+elif isplatform "solaris"; then
+  C_COMPILERS="cc suncc gcc clang"
+  CPP_COMPILERS="CC sunCC g++ clang++"
+  if [ -f /usr/xpg4/bin/tail ]; then
+    TAIL=/usr/xpg4/bin/tail
+  fi
 else
-  C_COMPILERS="gcc clang suncc cc"
-  CPP_COMPILERS="g++ clang++ sunCC CC"
+  C_COMPILERS="gcc clang cc"
+  CPP_COMPILERS="g++ clang++ c++"
 fi
 unset TOOLCHAIN
 unset TOOLCHAIN_NAME
@@ -17,14 +24,13 @@
 
 check_c_compiler()
 {
-  command -v $1 2>&1 >/dev/null
-  if [ $? -ne 0 ]; then
+  if ! command -v "$1" >/dev/null 2>&1 ; then
     return 1
   fi
   cat > "$TEMP_DIR/test.c" << __EOF__
 /* test file */
 #include <stdio.h>
-int main(int argc, char **argv) {
+int main(void) {
 #if defined(_MSC_VER)
   printf("toolchain:msc\n");
 #elif defined(__clang__)
@@ -38,7 +44,7 @@
 #endif
   printf("wsize:%d\n", (int)sizeof(void*)*8);
 #ifdef __STDC_VERSION__
-  printf("stdcversion:%d\n", __STDC_VERSION__);
+  printf("stdcversion:%ld\n", (long int)__STDC_VERSION__);
 #endif
   return 0;
 }
@@ -49,14 +55,13 @@
 
 check_cpp_compiler()
 {
-  command -v $1 2>&1 >/dev/null
-  if [ $? -ne 0 ]; then
+  if ! command -v "$1" >/dev/null 2>&1 ; then
     return 1
   fi
   cat > "$TEMP_DIR/test.cpp" << __EOF__
 /* test file */
 #include <iostream>
-int main(int argc, char **argv) {
+int main(void) {
 #if defined(_MSC_VER)
   std::cout << "toolchain:msc" << std::endl;
 #elif defined(__clang__)
@@ -68,7 +73,7 @@
 #else
   std::cout << "toolchain:unknown" << std::endl;
 #endif
-  std:cout << "wsize:" << sizeof(void*)*8 << std::endl;
+  std::cout << "wsize:" << sizeof(void*)*8 << std::endl;
   return 0;
 }
 __EOF__
@@ -76,54 +81,12 @@
   $1 -o "$TEMP_DIR/checkcc" $CXXFLAGS $LDFLAGS "$TEMP_DIR/test.cpp" 2> /dev/null
 }
 
-create_libtest_source()
-{
-  # $1: filename
-  # $2: optional include
-  cat > "$TEMP_DIR/$1" << __EOF__
-/* libtest file */
-int main(int argc, char **argv) {
-  return 0;
-}
-__EOF__
-  if [ -n "$2" ]; then
-    echo "#include <$2>" >> "$TEMP_DIR/$1"
-  fi
-}
-
-check_c_lib()
+parse_toolchain_properties()
 {
-  # $1: libname
-  # $2: optional include
-  if [ -z "$TOOLCHAIN_CC" ]; then
-    return 1
-  fi
-  create_libtest_source "test.c" "$2"
-  rm -f "$TEMP_DIR/checklib"
-  $TOOLCHAIN_CC -o "$TEMP_DIR/checklib" $CFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.c" 2> /dev/null
-}
-
-check_cpp_lib()
-{
-  # $1: libname
-  # $2: optional include
-  if [ -z "$TOOLCHAIN_CXX" ]; then
-    return 1
-  fi
-  create_libtest_source "test.cpp" "$2"
-  rm -f "$TEMP_DIR/checklib"
-  $TOOLCHAIN_CXX -o "$TEMP_DIR/checklib" $CXXFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.cpp" 2> /dev/null
-}
-
-check_lib()
-{
-  # $1: libname
-  # $2: optional include
-  if [ -n "$TOOLCHAIN_CC" ]; then
-    check_c_lib "$1" "$2"
-  elif  [ -n "$TOOLCHAIN_CXX" ]; then
-    check_cpp_lib "$1" "$2"
-  fi
+  info_file="$1"
+  TOOLCHAIN=`grep '^toolchain:' "$info_file" | $TAIL -c +11`
+  TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -`
+  TOOLCHAIN_WSIZE=`grep '^wsize:' "$info_file" | $TAIL -c +7`
 }
 
 detect_c_compiler()
@@ -136,10 +99,8 @@
     if check_c_compiler "$CC"; then
       TOOLCHAIN_CC=$CC
       "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out"
-      TOOLCHAIN=`grep '^toolchain:' "$TEMP_DIR/checkcc_out" | tail -c +11`
-      TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -`
-      TOOLCHAIN_WSIZE=`grep '^wsize:' "$TEMP_DIR/checkcc_out" | tail -c +7`
-      TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | tail -c +13`
+      parse_toolchain_properties "$TEMP_DIR/checkcc_out"
+      TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | $TAIL -c +13`
       echo "$CC"
       return 0
     else
@@ -152,10 +113,8 @@
       if check_c_compiler "$COMP"; then
         TOOLCHAIN_CC=$COMP
         "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out"
-        TOOLCHAIN=`grep '^toolchain:' "$TEMP_DIR/checkcc_out" | tail -c +11`
-        TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -`
-        TOOLCHAIN_WSIZE=`grep '^wsize:' "$TEMP_DIR/checkcc_out" | tail -c +7`
-        TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | tail -c +13`
+        parse_toolchain_properties "$TEMP_DIR/checkcc_out"
+        TOOLCHAIN_CSTD=`grep '^stdcversion:' "$TEMP_DIR/checkcc_out" | $TAIL -c +13`
         echo "$COMP"
         return 0
       fi
@@ -176,8 +135,7 @@
     if check_cpp_compiler "$CXX"; then
       TOOLCHAIN_CXX=$CXX
       "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out"
-      TOOLCHAIN=`grep '^toolchain:' "$TEMP_DIR/checkcc_out" | tail -c +11`
-      TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -`
+      parse_toolchain_properties "$TEMP_DIR/checkcc_out"
       echo "$CXX"
       return 0
     else
@@ -190,8 +148,7 @@
       if check_cpp_compiler "$COMP"; then
         TOOLCHAIN_CXX=$COMP
         "$TEMP_DIR/checkcc" > "$TEMP_DIR/checkcc_out"
-        TOOLCHAIN=`grep '^toolchain:' "$TEMP_DIR/checkcc_out" | tail -c +11`
-        TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -`
+        parse_toolchain_properties "$TEMP_DIR/checkcc_out"
         echo "$COMP"
         return 0
       fi

mercurial