From 5a670e8e7673da31981c36ed20fb5c57645e3400 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Tue, 12 Feb 2019 12:43:49 -0700 Subject: [PATCH] detect_cc: Handle empty arguments When called from scripts, sometimes the arguments passed will be empty. Change-Id: I2f9fa1daa173eecc7b20928cd359284bb6f74ff3 Signed-off-by: Ben Walker Reviewed-on: https://review.gerrithub.io/c/444278 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Darek Stojaczyk --- scripts/detect_cc.sh | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/scripts/detect_cc.sh b/scripts/detect_cc.sh index 063ab507b..e0f4bcc7f 100755 --- a/scripts/detect_cc.sh +++ b/scripts/detect_cc.sh @@ -23,10 +23,7 @@ function usage() err " --lto=[y|n] Attempt to configure for LTO" } -CC=cc -CXX=c++ -LD=ld -LTO=n + for i in "$@"; do case "$i" in @@ -35,16 +32,24 @@ for i in "$@"; do exit 0 ;; --cc=*) - CC="${i#*=}" + if [[ -n "${i#*=}" ]]; then + CC="${i#*=}" + fi ;; --cxx=*) - CXX="${i#*=}" + if [[ -n "${i#*=}" ]]; then + CXX="${i#*=}" + fi ;; --lto=*) - LTO="${i#*=}" + if [[ -n "${i#*=}" ]]; then + LTO="${i#*=}" + fi ;; --ld=*) - LD="${i#*=}" + if [[ -n "${i#*=}" ]]; then + LD="${i#*=}" + fi ;; --) break @@ -56,6 +61,11 @@ for i in "$@"; do esac done +: ${CC=cc} +: ${CXX=c++} +: ${LD=ld} +: ${LTO=n} + CC_TYPE=$($CC -v 2>&1 | grep -o -E '\w+ version' | head -1 | awk '{ print $1 }') CXX_TYPE=$($CXX -v 2>&1 | grep -o -E '\w+ version' | head -1 | awk '{ print $1 }') if [ "$CC_TYPE" != "$CXX_TYPE" ]; then