improve toolchain detection

Sat, 20 Jan 2024 15:47:39 +0100

author
Mike Becker <universe@uap-core.de>
date
Sat, 20 Jan 2024 15:47:39 +0100
changeset 105
4b3e655339cb
parent 104
ea36fd802446
child 106
7aa59deee50c

improve toolchain detection

relates to #347

src/main/resources/make/configure.vm file | annotate | diff | comparison | revisions
src/main/resources/make/toolchain.sh file | annotate | diff | comparison | revisions
test/configure file | annotate | diff | comparison | revisions
test/configure2 file | annotate | diff | comparison | revisions
test/make/configure.vm file | annotate | diff | comparison | revisions
test/make/toolchain.sh file | annotate | diff | comparison | revisions
--- a/src/main/resources/make/configure.vm	Sat Jan 20 15:37:16 2024 +0100
+++ b/src/main/resources/make/configure.vm	Sat Jan 20 15:47:39 2024 +0100
@@ -272,7 +272,6 @@
 
 # toolchain detection utilities
 . make/toolchain.sh
-TOOLCHAIN="${D}{TOOLCHAIN_NAME}"
 
 #
 # DEPENDENCIES
--- a/src/main/resources/make/toolchain.sh	Sat Jan 20 15:37:16 2024 +0100
+++ b/src/main/resources/make/toolchain.sh	Sat Jan 20 15:47:39 2024 +0100
@@ -10,6 +10,7 @@
   C_COMPILERS="gcc clang suncc cc"
   CPP_COMPILERS="g++ clang++ sunCC CC"
 fi
+unset TOOLCHAIN
 unset TOOLCHAIN_NAME
 unset TOOLCHAIN_CC
 unset TOOLCHAIN_CXX
@@ -20,10 +21,12 @@
 /* test file */
 #include <stdio.h>
 int main(int argc, char **argv) {
-#if defined(__clang__)
-  printf("clang\n");
+#if defined(_MSC_VER)
+  printf("msc\n");
+#elif defined(__clang__)
+  printf("clang gnuc\n");
 #elif defined(__GNUC__)
-  printf("gcc\n");
+  printf("gcc gnuc\n");
 #elif defined(__sun)
   printf("suncc\n");
 #else
@@ -42,10 +45,12 @@
 /* test file */
 #include <iostream>
 int main(int argc, char **argv) {
-#if defined(__clang__)
-  std::cout << "clang" << std::endl;
+#if defined(_MSC_VER)
+  std::cout << "msc" << std::endl;
+#elif defined(__clang__)
+  std::cout << "clang gnuc" << std::endl;
 #elif defined(__GNUC__)
-  std::cout << "gcc" << std::endl;
+  std::cout << "gcc gnuc" << std::endl;
 #elif defined(__sun)
   std::cout << "suncc" << std::endl;
 #else
@@ -117,7 +122,8 @@
   if [ -n "$CC" ]; then
     if check_c_compiler "$CC"; then
       TOOLCHAIN_CC=$CC
-      TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"`
+      TOOLCHAIN=`"$TEMP_DIR/checkcc"`
+      TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -`
       echo "$CC"
       return 0
     else
@@ -129,7 +135,8 @@
     do
       if check_c_compiler "$COMP"; then
         TOOLCHAIN_CC=$COMP
-        TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"`
+        TOOLCHAIN=`"$TEMP_DIR/checkcc"`
+        TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -`
         echo "$COMP"
         return 0
       fi
@@ -149,7 +156,8 @@
   if [ -n "$CXX" ]; then
     if check_cpp_compiler "$CXX"; then
       TOOLCHAIN_CXX=$CXX
-      TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"`
+      TOOLCHAIN=`"$TEMP_DIR/checkcc"`
+      TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -`
       echo "$CXX"
       return 0
     else
@@ -161,7 +169,8 @@
     do
       if check_cpp_compiler "$COMP"; then
         TOOLCHAIN_CXX=$COMP
-        TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"`
+        TOOLCHAIN=`"$TEMP_DIR/checkcc"`
+        TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -`
         echo "$COMP"
         return 0
       fi
--- a/test/configure	Sat Jan 20 15:37:16 2024 +0100
+++ b/test/configure	Sat Jan 20 15:47:39 2024 +0100
@@ -176,8 +176,6 @@
 PLATFORM_NAME=`echo "$PLATFORM" | cut -f1 -d' ' -`
 echo "$PLATFORM_NAME"
 
-TOOLCHAIN=
-
 isplatform()
 {
     for p in $PLATFORM
@@ -259,7 +257,6 @@
 if detect_c_compiler ; then
     lang_c=1
 fi
-TOOLCHAIN=$TOOLCHAIN_NAME
 
 # create buffer for make variables required by dependencies
 echo > "$TEMP_DIR/make.mk"
@@ -330,12 +327,9 @@
 dependency_error_openssl()
 {
     print_check_msg "$dep_checked_openssl" "checking for openssl... "
-    # dependency openssl toolchain="clang"
+    # dependency openssl
     while true
     do
-        if notistoolchain "clang"; then
-            break
-        fi
         if [ -z "$lang_c" ] ; then
             break
         fi
@@ -460,9 +454,6 @@
 done
 while true
 do
-    if notistoolchain "gcc"; then
-        break
-    fi
     while true
     do
 
@@ -473,9 +464,6 @@
 done
 while true
 do
-    if notistoolchain "clang"; then
-        break
-    fi
     while true
     do
 
--- a/test/configure2	Sat Jan 20 15:37:16 2024 +0100
+++ b/test/configure2	Sat Jan 20 15:47:39 2024 +0100
@@ -206,6 +206,26 @@
     done
     return 0
 }
+istoolchain()
+{
+    for t in $TOOLCHAIN
+    do
+        if [ "$t" = "$1" ]; then
+            return 0
+        fi
+    done
+    return 1
+}
+notistoolchain()
+{
+    for t in $TOOLCHAIN
+    do
+        if [ "$t" = "$1" ]; then
+            return 1
+        fi
+    done
+    return 0
+}
 
 
 # generate vars.mk
@@ -401,7 +421,7 @@
         if notisplatform "bsd"; then
             break
         fi
-        if isplatform "macos"; then
+        if isplatform "macos" || istoolchain "macos"; then
             break
         fi
         TEMP_CFLAGS="$TEMP_CFLAGS -DBSD"
--- a/test/make/configure.vm	Sat Jan 20 15:37:16 2024 +0100
+++ b/test/make/configure.vm	Sat Jan 20 15:47:39 2024 +0100
@@ -272,7 +272,6 @@
 
 # toolchain detection utilities
 . make/toolchain.sh
-TOOLCHAIN="${D}{TOOLCHAIN_NAME}"
 
 #
 # DEPENDENCIES
--- a/test/make/toolchain.sh	Sat Jan 20 15:37:16 2024 +0100
+++ b/test/make/toolchain.sh	Sat Jan 20 15:47:39 2024 +0100
@@ -10,6 +10,7 @@
   C_COMPILERS="gcc clang suncc cc"
   CPP_COMPILERS="g++ clang++ sunCC CC"
 fi
+unset TOOLCHAIN
 unset TOOLCHAIN_NAME
 unset TOOLCHAIN_CC
 unset TOOLCHAIN_CXX
@@ -20,10 +21,12 @@
 /* test file */
 #include <stdio.h>
 int main(int argc, char **argv) {
-#if defined(__clang__)
-  printf("clang\n");
+#if defined(_MSC_VER)
+  printf("msc\n");
+#elif defined(__clang__)
+  printf("clang gnuc\n");
 #elif defined(__GNUC__)
-  printf("gcc\n");
+  printf("gcc gnuc\n");
 #elif defined(__sun)
   printf("suncc\n");
 #else
@@ -42,10 +45,12 @@
 /* test file */
 #include <iostream>
 int main(int argc, char **argv) {
-#if defined(__clang__)
-  std::cout << "clang" << std::endl;
+#if defined(_MSC_VER)
+  std::cout << "msc" << std::endl;
+#elif defined(__clang__)
+  std::cout << "clang gnuc" << std::endl;
 #elif defined(__GNUC__)
-  std::cout << "gcc" << std::endl;
+  std::cout << "gcc gnuc" << std::endl;
 #elif defined(__sun)
   std::cout << "suncc" << std::endl;
 #else
@@ -117,7 +122,8 @@
   if [ -n "$CC" ]; then
     if check_c_compiler "$CC"; then
       TOOLCHAIN_CC=$CC
-      TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"`
+      TOOLCHAIN=`"$TEMP_DIR/checkcc"`
+      TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -`
       echo "$CC"
       return 0
     else
@@ -129,7 +135,8 @@
     do
       if check_c_compiler "$COMP"; then
         TOOLCHAIN_CC=$COMP
-        TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"`
+        TOOLCHAIN=`"$TEMP_DIR/checkcc"`
+        TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -`
         echo "$COMP"
         return 0
       fi
@@ -149,7 +156,8 @@
   if [ -n "$CXX" ]; then
     if check_cpp_compiler "$CXX"; then
       TOOLCHAIN_CXX=$CXX
-      TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"`
+      TOOLCHAIN=`"$TEMP_DIR/checkcc"`
+      TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -`
       echo "$CXX"
       return 0
     else
@@ -161,7 +169,8 @@
     do
       if check_cpp_compiler "$COMP"; then
         TOOLCHAIN_CXX=$COMP
-        TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"`
+        TOOLCHAIN=`"$TEMP_DIR/checkcc"`
+        TOOLCHAIN_NAME=`echo "$TOOLCHAIN" | cut -f1 -d' ' -`
         echo "$COMP"
         return 0
       fi

mercurial