Commit b98fa9f9 authored by Mariusz Tkaczyk's avatar Mariusz Tkaczyk Committed by Tomasz Zawadzki
Browse files

build: make ar configurable by AR



$CC, $CXX and $LD can be set. If we try compiliation with LTO and
non-default gcc version:
CC=gcc-13 CXX=g++-13 ./configure --enable-lto
Then compilation may fail because srcipts/detect_cc.sh is forcing
ar to system-default gcc-ar. Depending on version, gcc-ar may be
compatible or not.

Allow user to configure AR and rename CCAR present in Makefiles to AR.
If it is set by user then accept it uncoditionally.

When determining ar and --enable-lto is used, set it to gcc-ar only
if CC_TYPE="gcc" otherwise fallback to default "ar".
In case of regression, proper AR can be specified manually.

Change-Id: I5aea605f898bd67a28a330bf0111831a39ea814d
Signed-off-by: default avatarMariusz Tkaczyk <mariusz.tkaczyk@dell.com>
Reviewed-on: https://review.spdk.io/c/spdk/spdk/+/26095


Community-CI: Mellanox Build Bot
Reviewed-by: default avatarJim Harris <jim.harris@nvidia.com>
Tested-by: default avatarSPDK Automated Test System <spdkbot@gmail.com>
Reviewed-by: default avatarKonrad Sztyber <ksztyber@nvidia.com>
parent 6220191d
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ DIRS-$(CONFIG_GOLANG) += go/rpc
DIRS-y += python

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

# Workaround for ninja. See dpdkbuild/Makefile
@@ -143,6 +143,9 @@ cc_version: mk/cc.mk
cxx_version: mk/cc.mk
	$(Q)echo "SPDK using CXX=$(CXX)"; $(CXX) -v

ar_version: mk/cc.mk
	$(Q)echo "SPDK using AR=$(AR)"; $(AR) -v

.libs_only_other:
	$(Q)echo -n '$(SYS_LIBS) '
	$(Q)if [ "$(CONFIG_SHARED)" = "y" ]; then \
+2 −1
Original line number Diff line number Diff line
@@ -145,6 +145,7 @@ function usage() {
	echo "CFLAGS                     C compiler flags"
	echo "CXX                        C++ compiler"
	echo "CXXFLAGS                   C++ compiler flags"
	echo "AR                         Archiver to use"
	echo "LD                         Linker"
	echo "LDFLAGS                    Linker flags"
	echo "DESTDIR                    Destination for 'make install'"
@@ -176,7 +177,7 @@ for i in "$@"; do
done

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

mapfile -t cc < <(grep "=" "$rootdir/mk/cc.mk")
source <(printf '%q\n' "${cc[@]}")
+1 −1
Original line number Diff line number Diff line
@@ -438,7 +438,7 @@ LIB_C=\
	$(Q)echo "  LIB $(notdir $@)"; \
	rm -f $@; \
	mkdir -p $(dir $@); \
	$(CCAR) crDs $@ $(OBJS)
	$(AR) crDs $@ $(OBJS)

# Clean up generated files listed as arguments plus a default list
CLEAN_C=\
+13 −6
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ function usage() {
	err " -h, --help                Display this help and exit"
	err " --cc=path                 C compiler to use"
	err " --cxx=path                C++ compiler to use"
	err " --ar=path                 Archiver 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"
@@ -41,6 +42,11 @@ for i in "$@"; do
				CXX="${i#*=}"
			fi
			;;
		--ar=*)
			if [[ -n "${i#*=}" ]]; then
				AR="${i#*=}"
			fi
			;;
		--lto=*)
			if [[ -n "${i#*=}" ]]; then
				LTO="${i#*=}"
@@ -108,19 +114,20 @@ case "$LD_TYPE" in
		;;
esac

CCAR="ar"
if [ "$LTO" = "y" ]; then
if [[ "$LTO" = "y" && -z "$AR" ]]; then
	if [ "$CC_TYPE" = "clang" ]; then
		if [[ "$LD_TYPE" != "gold" && "$LD_TYPE" != "lld" ]]; then
			err "Using LTO with clang requires the gold or lld linker."
			exit 1
		fi
		CCAR="llvm-ar"
	else
		CCAR="gcc-ar"
		AR="llvm-ar"
	elif [ "$CC_TYPE" = "gcc" ]; then
		AR="gcc-ar"
	fi
fi

: ${AR="ar"}

if [ -n "$CROSS_PREFIX" ]; then
	expected_prefix=$($CC -dumpmachine)

@@ -176,11 +183,11 @@ function set_default() {
	echo ""
}

set_default AR "$AR"
set_default CC "$CC"
set_default CXX "$CXX"
set_default LD "$LD"

echo "CCAR=$CCAR"
echo "CC_TYPE=$CC_TYPE"
echo "LD_TYPE=$LD_TYPE"

+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ _ocf_precompile() {
	# So we precompile OCF now for further use as standalone static library
	"$rootdir/configure" $(echo $config_params | sed 's/--enable-coverage//g')
	$MAKE $MAKEFLAGS include/spdk/config.h
	CC=gcc CCAR=ar $MAKE $MAKEFLAGS -C "$rootdir/lib/env_ocf" exportlib O="$rootdir/ocf.a"
	CC=gcc AR=ar $MAKE $MAKEFLAGS -C "$rootdir/lib/env_ocf" exportlib O="$rootdir/ocf.a"
	# Set config to use precompiled library
	config_params="$config_params --with-ocf=/$rootdir/ocf.a"
	# need to reconfigure to avoid clearing ocf related files on future make clean.