[vlc-devel] [PATCH 2/4] contrib: guess the native C/C++ compiler by default if not provided at bootstrap

Steve Lhomme robux4 at ycbcr.xyz
Thu Feb 14 18:19:38 CET 2019


Many GNU tools rely on these values but they don't do a good job at guessing.

We detect the values similar to BUILDCC in the VLC configure.

As a bonus we can use this compiler to guess the build system rather than CC which
can be set to the cross compiler in a script. If the build system is set then we
use that first to find compiler.
---
 contrib/bootstrap | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/contrib/bootstrap b/contrib/bootstrap
index 96c59f71fa..0f9b9eac3c 100755
--- a/contrib/bootstrap
+++ b/contrib/bootstrap
@@ -23,6 +23,8 @@ usage()
 	echo "Usage: $0 [--build=BUILD] [--host=HOST] [--prefix=PREFIX]"
 	echo "  --build=BUILD    configure for building on BUILD"
 	echo "  --host=HOST      cross-compile to build to run on HOST"
+	echo "  --cc-for-build=CC    C compiler to use for binraries to run on BUILD"
+	echo "  --cxx-for-build=CXX  C++ compiler to use for binraries to run on BUILD"
 	echo "  --prefix=PREFIX  install files in PREFIX"
 	echo "  --disable-FOO    configure to not build package FOO"
 	echo "  --enable-FOO     configure to build package FOO"
@@ -39,6 +41,8 @@ usage()
 
 BUILD=
 HOST=
+CC_FOR_BUILD=
+CXX_FOR_BUILD=
 PREFIX=
 PKGS_ENABLE=
 PKGS_DISABLE=
@@ -69,6 +73,12 @@ do
 		--host=*)
 			HOST="${1#--host=}"
 			;;
+		--cc-for-build=*)
+			CC_FOR_BUILD="${1#--cc-for-build=}"
+			;;
+		--cxx-for-build=*)
+			CXX_FOR_BUILD="${1#--cxx-for-build=}"
+			;;
 		--prefix=*)
 			PREFIX="${1#--prefix=}"
 			;;
@@ -117,10 +127,29 @@ then
 	exit 1
 fi
 
+if test -z "$CC_FOR_BUILD"
+then
+	echo -n "Guessing build C compiler...  "
+	for compiler in $BUILD-gcc c11-gcc c11 c99-gcc c99 gcc clang cc; do
+		TEST_PROG=`which $compiler 2> /dev/null`
+		if test -n "$TEST_PROG"
+		then
+			CC_FOR_BUILD=$compiler
+			echo $CC_FOR_BUILD
+			break
+		fi
+	done
+fi
+
 if test -z "$BUILD"
 then
 	echo -n "Guessing build system... "
-	BUILD="`${CC:-cc} -dumpmachine | sed s/windows-gnu/mingw32/`"
+	if test -n "$CC_FOR_BUILD"
+	then
+		BUILD="`${CC_FOR_BUILD:-cc} -dumpmachine | sed s/windows-gnu/mingw32/`"
+	else
+		BUILD="`${CC:-cc} -dumpmachine | sed s/windows-gnu/mingw32/`"
+	fi
 	if test -z "$BUILD"; then
 		echo "FAIL!"
 		exit 1
@@ -128,6 +157,20 @@ then
 	echo "$BUILD"
 fi
 
+if test -z "$CXX_FOR_BUILD"
+then
+	echo -n "Guessing build C++ compiler...  "
+	for compiler in $BUILD-g++ g++ clang++ c++; do
+		TEST_PROG=`which $compiler 2> /dev/null`
+		if test -n "$TEST_PROG"
+		then
+			CXX_FOR_BUILD=$compiler
+			echo $CXX_FOR_BUILD
+			break
+		fi
+	done
+fi
+
 if test -z "$HOST"
 then
 	echo -n "Guessing host system...  "
@@ -257,6 +300,8 @@ check_tizen_sdk()
 }
 
 test -z "$PREFIX" || add_make "PREFIX := $PREFIX"
+test -z "CC_FOR_BUILD" || add_make "CC_FOR_BUILD := $CC_FOR_BUILD"
+test -z "CXX_FOR_BUILD" || add_make "CXX_FOR_BUILD := $CXX_FOR_BUILD"
 test -z "$BUILD_DISCS" || add_make_enabled "BUILD_DISCS"
 test -z "$BUILD_ENCODERS" || add_make_enabled "BUILD_ENCODERS"
 test -z "$BUILD_NETWORK" || add_make_enabled "BUILD_NETWORK"
-- 
2.17.1



More information about the vlc-devel mailing list