test/make/toolchain.sh

changeset 61
2c68549dabef
parent 54
2b8f40c58944
child 66
dc758dcd4645
--- a/test/make/toolchain.sh	Tue Sep 12 23:36:45 2023 +0200
+++ b/test/make/toolchain.sh	Sun Sep 17 12:40:12 2023 +0200
@@ -3,11 +3,13 @@
 # toolchain detection
 #
 
-C_COMPILERS="cc gcc clang suncc"
-CPP_COMPILERS="CC g++ clang++ sunCC"
-unset CC_ARG_CHECKED
-unset TOOLCHAIN_DETECTION_ERROR
+C_COMPILERS="gcc clang suncc cc"
+CPP_COMPILERS="g++ clang++ sunCC CC"
+unset TOOLCHAIN_ERROR
 unset TOOLCHAIN_NAME
+unset TOOLCHAIN_CC
+unset TOOLCHAIN_CXX
+unset TOOLCHAIN_LD
 
 check_c_compiler()
 {
@@ -29,11 +31,6 @@
 __EOF__
 	rm -f "$TEMP_DIR/checkcc"
 	$1 -o "$TEMP_DIR/checkcc" $CFLAGS $LDFLAGS "$TEMP_DIR/test.c" 2> /dev/null
-	
-	if [ $? -ne 0 ]; then
-		return 1
-	fi
-	return 0
 }
 
 check_cpp_compiler()
@@ -56,11 +53,6 @@
 __EOF__
 	rm -f "$TEMP_DIR/checkcc"
 	$1 -o "$TEMP_DIR/checkcc" $CXXFLAGS $LDFLAGS "$TEMP_DIR/test.cpp" 2> /dev/null
-	
-	if [ $? -ne 0 ]; then
-		return 1
-	fi
-	return 0
 }
 
 check_lib()
@@ -76,112 +68,63 @@
 __EOF__
 	rm -f "$TEMP_DIR/checklib"
 	$TOOLCHAIN_LD -o "$TEMP_DIR/checklib" $CFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.c" 2> /dev/null
-
-	if [ $? -ne 0 ]; then
-		return 1
-	fi
-	return 0
 }
 
 printf "detect C compiler... "
 
-for COMP in $C_COMPILERS
-do
-	check_c_compiler "$COMP"
-	if [ $? -ne 0 ]; then
-		if [ -n "$CC" ]; then
-			if [ "$COMP" = "$CC" ]; then
-				echo "$CC is not a working C compiler"
-				TOOLCHAIN_DETECTION_ERROR="error"
-				break
-			fi
-		fi
-	else
-		TOOLCHAIN_NAME=`$TEMP_DIR/checkcc`
-		USE_TOOLCHAIN=$TOOLCHAIN_NAME
-		if [ "$COMP" = "cc" ]; then
-			# we have found a working compiler, but in case
-			# the compiler is gcc or clang, we try to use
-			# these commands and not 'cc'
-			TOOLCHAIN_NAME=`$TEMP_DIR/checkcc`
-			if [ "$TOOLCHAIN_NAME" = "gcc" ]; then
-				check_c_compiler "gcc"
-				if [ $? -eq 0 ]; then
-					COMP=gcc
-					USE_TOOLCHAIN="gcc"
-				fi
-			fi
-			if [ "$TOOLCHAIN_NAME" = "clang" ]; then
-				check_c_compiler "clang"
-				if [ $? -eq 0 ]; then
-					COMP=clang
-					USE_TOOLCHAIN="clang"
-				fi
-			fi
-		fi
-		
-		TOOLCHAIN_NAME=$USE_TOOLCHAIN
-		TOOLCHAIN_CC=$COMP
-		echo $COMP
-		break
-	fi
-done
-if [ -z "$TOOLCHAIN_CC" ]; then
-	echo "not found"
+if [ -n "$CC" ]; then
+  if check_c_compiler "$CC"; then
+    TOOLCHAIN_CC=$CC
+    TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"`
+    echo $CC
+  else
+    echo "$CC is not a working C compiler"
+    TOOLCHAIN_ERROR="required C compiler not found"
+  fi
+else
+  for COMP in $C_COMPILERS
+  do
+    if check_c_compiler "$COMP"; then
+      TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"`
+      TOOLCHAIN_CC=$COMP
+      break
+    fi
+  done
+  echo ${TOOLCHAIN_CC:-"not found"}
 fi
 
 printf "detect C++ compiler... "
 
-for COMP in $CPP_COMPILERS
-do
-	check_cpp_compiler "$COMP"
-	if [ $? -ne 0 ]; then
-		if [ -n "$CXX" ]; then
-			if [ "$COMP" = "$CXX" ]; then
-				echo "$CXX is not a working C++ compiler"
-				TOOLCHAIN_DETECTION_ERROR="error"
-				break
-			fi
-		fi
-	else
-		if [ $COMP = "CC" ]; then
-			# we have found a working compiler, but in case
-			# the compiler is gcc or clang, we try to use
-			# these commands and not 'CC'
-			TOOLCHAIN_NAME=`$TEMP_DIR/checkcc`
-			USE_TOOLCHAIN=$TOOLCHAIN_NAME
-			if [ "$TOOLCHAIN_NAME" = "gcc" ]; then
-				check_cpp_compiler "g++"
-				if [ $? -eq 0 ]; then
-				   COMP=g++
-				   USE_TOOLCHAIN="gcc"
-				fi
-			fi
-			if [ "$TOOLCHAIN_NAME" = "clang" ]; then
-				check_cpp_compiler "clang++"
-				if [ $? -eq 0 ]; then
-				   COMP=clang++
-				   USE_TOOLCHAIN="clang"
-				fi
-			fi
-		fi
-		
-		TOOLCHAIN_NAME=$USE_TOOLCHAIN
-		TOOLCHAIN_CXX=$COMP
-		echo $COMP
-		break
-	fi
-done
-if [ -z "$TOOLCHAIN_CXX" ]; then
-	echo "not found"
+if [ -n "$CXX" ]; then
+  if check_cpp_compiler "$CXX"; then
+    TOOLCHAIN_CXX=$CXX
+    TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"`
+    echo $CXX
+  else
+    echo "$CXX is not a working C++ compiler"
+    TOOLCHAIN_ERROR="required C++ compiler not found"
+  fi
+else
+  for COMP in $CPP_COMPILERS
+  do
+    if check_cpp_compiler "$COMP"; then
+      TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"`
+      TOOLCHAIN_CXX=$COMP
+      break
+    fi
+  done
+  echo ${TOOLCHAIN_CXX:-"not found"}
 fi
 
+printf "detect linker... "
 TOOLCHAIN_LD=$TOOLCHAIN_CC
+echo "$TOOLCHAIN_LD"
 
 if [ -z "$TOOLCHAIN_NAME" ]; then
-	TOOLCHAIN_DETECTION_ERROR="error"
+  TOOLCHAIN_ERROR="no build tools detected"
 else
 	cat >> "$TEMP_DIR/config.mk" << __EOF__
+
 # toolchain
 __EOF__
 	echo "CC = ${TOOLCHAIN_CC}" >> "$TEMP_DIR/config.mk"

mercurial