build: Make detect_cc.sh handle --cross-prefix

This internal tool can now be passed an optional --cross-prefix,
which sets up the prefix used for a cross compiler.

Change-Id: Ia4bbbae3bd5a2e4ddc9da342cd03d600e9ee6099
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/463016
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Ben Walker 2019-07-23 10:33:36 -07:00 committed by Jim Harris
parent c510bd8830
commit 1a56982da3

View File

@ -21,6 +21,7 @@ function usage()
err " --cxx=path C++ compiler to use"
err " --ld=path Linker to use"
err " --lto=[y|n] Attempt to configure for LTO"
err " --cross-prefix=prefix Use the given prefix for the cross compiler toolchain"
}
@ -51,6 +52,11 @@ for i in "$@"; do
LD="${i#*=}"
fi
;;
--cross-prefix=*)
if [[ -n "${i#*=}" ]]; then
CROSS_PREFIX="${i#*=}"
fi
;;
--)
break
;;
@ -67,6 +73,7 @@ OS=$(uname)
: ${CXX=c++}
: ${LD=}
: ${LTO=n}
: ${CROSS_PREFIX=}
if [ -z "$LD" ]; then
if [ "$OS" = "Linux" ]; then
@ -113,6 +120,53 @@ if [ "$LTO" = "y" ]; then
fi
fi
if [ ! -z "$CROSS_PREFIX" ]; then
expected_prefix=$($CC -dumpmachine)
if [ ! "$expected_prefix" = "$CROSS_PREFIX" ]; then
err "Cross prefix specified ($CROSS_PREFIX) does not match prefix of $CC ($expected_prefix)."
# Try to fix this automatically. Maybe the user set CROSS_PREFIX but not CC.
CC=$CROSS_PREFIX-$CC
if hash $CC 2>/dev/null; then
expected_prefix=$($CC -dumpmachine)
if [ "$expected_prefix" = "$CROSS_PREFIX" ]; then
err "Automatically changed CC to $CC"
else
err "Set CC to the appropriate compiler."
exit 1
fi
else
err "Set CC to the appropriate compiler."
exit 1
fi
fi
expected_prefix=$($CXX -dumpmachine)
if [ ! "$expected_prefix" = "$CROSS_PREFIX" ]; then
err "Cross prefix specified ($CROSS_PREFIX) does not match prefix of $CXX ($expected_prefix)."
# Try to fix this automatically. Maybe the user set CROSS_PREFIX but not CXX.
CXX=$CROSS_PREFIX-$CXX
if hash $CXX 2>/dev/null; then
expected_prefix=$($CXX -dumpmachine)
if [ "$expected_prefix" = "$CROSS_PREFIX" ]; then
err "Automatically changed CXX to $CXX"
else
err "Set CXX to the appropriate compiler."
exit 1
fi
else
err "Set CXX to the appropriate compiler."
exit 1
fi
fi
fi
function set_default() {
echo "ifeq (\$(origin $1),default)"
echo "$1=$2"
@ -127,3 +181,7 @@ set_default LD $LD
echo "CCAR=$CCAR"
echo "CC_TYPE=$CC_TYPE"
echo "LD_TYPE=$LD_TYPE"
if [ ! -z "$CROSS_PREFIX" ]; then
echo "CROSS_PREFIX=$CROSS_PREFIX"
fi