Commit 73439e6f authored by Ben Walker's avatar Ben Walker Committed by Jim Harris
Browse files

build: Detect compiler toolchain in configure



We need to know this up front.

Change-Id: I3a9ceb90cf62eacbf3fdf518a9ccb4c4978b3a05
Signed-off-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/463014


Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: default avatarPaul Luse <paul.e.luse@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent f89166c0
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ DIRS-$(CONFIG_TESTS) += test
DIRS-$(CONFIG_IPSEC_MB) += ipsecbuild
DIRS-$(CONFIG_ISAL) += isalbuild

.PHONY: all clean $(DIRS-y) include/spdk/config.h mk/config.mk mk/cc.mk \
.PHONY: all clean $(DIRS-y) include/spdk/config.h mk/config.mk \
	cc_version cxx_version .libs_only_other .ldflags ldflags install \
	uninstall

@@ -72,9 +72,8 @@ LIB += isalbuild
DPDK_DEPS += isalbuild
endif

all: $(DIRS-y)
all: mk/cc.mk $(DIRS-y)
clean: $(DIRS-y)
	$(Q)rm -f mk/cc.mk
	$(Q)rm -f include/spdk/config.h

install: all
@@ -95,12 +94,11 @@ examples: $(LIB)
pkgdep:
	sh ./scripts/pkgdep.sh

$(DIRS-y): mk/cc.mk include/spdk/config.h
$(DIRS-y): include/spdk/config.h

mk/cc.mk:
	$(Q)scripts/detect_cc.sh --cc="$(CC)" --cxx="$(CXX)" --lto="$(CONFIG_LTO)" --ld="$(LD)" > $@.tmp; \
	cmp -s $@.tmp $@ || mv $@.tmp $@ ; \
	rm -f $@.tmp
	$(Q)echo "Please run configure prior to make"
	false

include/spdk/config.h: mk/config.mk scripts/genconfig.py
	$(Q)PYCMD=$$(cat PYTHON_COMMAND 2>/dev/null) ; \
+11 −3
Original line number Diff line number Diff line
@@ -86,8 +86,11 @@ function usage()
	echo ""
	echo "Environment variables:"
	echo ""
	echo "CC                         C compiler"
	echo "CFLAGS                     C compiler flags"
	echo "CXX                        C++ compiler"
	echo "CXXFLAGS                   C++ compiler flags"
	echo "LD                         Linker"
	echo "LDFLAGS                    Linker flags"
	echo "DESTDIR                    Destination for 'make install'"
	echo ""
@@ -100,8 +103,6 @@ declare -A CONFIG
source CONFIG.sh
rm CONFIG.sh

BUILD_CMD="${CC:-cc} -o /dev/null -x c $CPPFLAGS $CFLAGS $LDFLAGS"

function check_dir() {
	arg="$1"
	dir="${arg#*=}"
@@ -340,6 +341,14 @@ for i in "$@"; do
	esac
done

# Detect the compiler toolchain
scripts/detect_cc.sh --cc="$CC" --cxx="$CXX" --lto="${CONFIG[LTO]}" --ld="$LD" > mk/cc.mk

CC=$(cat mk/cc.mk | grep "CC=" | cut -d "=" -f 2)
CC_TYPE=$(cat mk/cc.mk | grep "CC_TYPE=" | cut -d "=" -f 2)

BUILD_CMD="$CC -o /dev/null -x c $CPPFLAGS $CFLAGS $LDFLAGS"

# Detect architecture and force no isal if non x86 archtecture
arch=$(uname -m)
if [[ $arch != x86_64* ]]; then
@@ -625,7 +634,6 @@ if [[ "${CONFIG[PGO_CAPTURE]}" = "y" && "${CONFIG[PGO_USE]}" = "y" ]]; then
	echo "ERROR: --enable-pgo-capture and --enable-pgo-use are mutually exclusive."
	exit 1
elif [[ "${CONFIG[PGO_USE]}" = "y" ]]; then
	CC_TYPE=$($rootdir/scripts/detect_cc.sh --cc="$CC" --cxx="$CXX" --lto="${CONFIG[LTO]}" --ld="$LD" | grep "CC_TYPE" | cut -d "=" -f 2)
	if [[ "$CC_TYPE" = "clang" ]]; then
		# For clang we need to run an extra step on gathered profiling data.
		echo "Generating suitable profile data"
+0 −4
Original line number Diff line number Diff line
@@ -138,10 +138,6 @@ endif
ifeq ($(OS),FreeBSD)
SYS_LIBS += -L/usr/local/lib
COMMON_CFLAGS += -I/usr/local/include
# Default to lld on FreeBSD
ifeq ($(origin LD),default)
LD = ld.lld
endif
endif

# Attach only if PMDK lib specified with configure
+13 −2
Original line number Diff line number Diff line
@@ -61,11 +61,22 @@ for i in "$@"; do
	esac
done

OS=$(uname)

: ${CC=cc}
: ${CXX=c++}
: ${LD=ld}
: ${LD=}
: ${LTO=n}

if [ -z "$LD" ]; then
	if [ "$OS" = "Linux" ]; then
		LD=ld
	fi
	if [ "$OS" = "FreeBSD" ]; then
		LD=ld.lld
	fi
fi

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