2017-05-26 04:48:44 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
2019-07-30 07:41:42 +08:00
|
|
|
OPTIONS=''
|
|
|
|
|
2019-08-01 09:17:46 +08:00
|
|
|
# Get compiler version and major version
|
|
|
|
COMPILER_VER=$("${CC}" -dumpversion)
|
|
|
|
COMPILER_MAJVER="${COMPILER_VER%%\.*}"
|
|
|
|
|
2019-07-30 07:41:42 +08:00
|
|
|
# Add linker, if specified and valid
|
|
|
|
# The linker to use for building:
|
|
|
|
# can be LD (system default, default choice), GOLD, LLD, or BFD
|
2019-08-01 09:17:46 +08:00
|
|
|
if [ -n "${USE_LD}" ] && \
|
|
|
|
(([[ "${CC}" == *"gcc"* ]] && [ "${COMPILER_MAJVER}" -ge 9 ]) || \
|
|
|
|
([[ "${CXX}" == *"clang++"* ]] && [ "${COMPILER_MAJVER}" -ge 4 ]) )
|
|
|
|
then
|
|
|
|
if [ "${PLATFORM}" == "linux" ]; then
|
|
|
|
if [ "${USE_LD}" == "BFD" ]; then
|
|
|
|
OPTIONS+='-fuse-ld=bfd -Wl,--disable-new-dtags'
|
|
|
|
elif [ "${USE_LD}" == "GOLD" ]; then
|
|
|
|
OPTIONS+='-fuse-ld=gold -Wl,--disable-new-dtags'
|
|
|
|
elif [ "${USE_LD}" == "LLD" ]; then
|
|
|
|
OPTIONS+='-fuse-ld=lld -Wl,--disable-new-dtags'
|
|
|
|
elif [ "${USE_LD}" != "DEFAULT" ] && [ "${USE_LD}" != "LD" ]; then
|
|
|
|
echo 'USE_LD must be set to DEFAULT, LD, BFD, GOLD, or LLD!'
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-07-30 07:41:42 +08:00
|
|
|
fi
|
|
|
|
fi
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
case $1 in
|
|
|
|
Application | DynamicLibrary)
|
|
|
|
echo "Linking $3"
|
|
|
|
|
|
|
|
if [ "$1" = "DynamicLibrary" ]; then
|
2019-07-30 07:41:42 +08:00
|
|
|
OPTIONS+=" -shared"
|
|
|
|
if [ "$PLATFORM" = "linux" ]; then
|
|
|
|
OPTIONS+=" -Wl,-z,noexecstack -Wl,-soname,$( basename $3 )"
|
|
|
|
elif [ "$PLATFORM" = "osx" ]; then
|
|
|
|
OPTIONS+=" -Wl,-dylib_install_name -Wl,$( basename $3 )"
|
|
|
|
fi
|
2017-05-26 04:48:44 +08:00
|
|
|
fi
|
|
|
|
|
2019-02-28 07:39:47 +08:00
|
|
|
OPTIONS=$( eval echo "$OPTIONS $LDFLAGS \$$2_OBJECTS \$$2_LIBS \$$2_STATIC_LIBS_REAL \$$2_LDFLAGS -o $3" )
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2019-08-01 08:41:40 +08:00
|
|
|
if [[ "${OPTIONS}" == *"-static-libstdc++"* ]]; then
|
|
|
|
staticlibs=()
|
2019-08-03 01:04:36 +08:00
|
|
|
staticpaths=''
|
2019-08-01 08:41:40 +08:00
|
|
|
if [[ "${CC}" == *"gcc"* ]]; then
|
|
|
|
staticlibs+=('libstdc++.a')
|
|
|
|
elif [[ "${CXX}" == *"clang++"* ]]; then
|
|
|
|
staticlibs+=('libc++.a' 'libc++abi.a')
|
|
|
|
fi
|
|
|
|
for staticlib in "${staticlibs[@]}"; do
|
2019-08-03 01:04:36 +08:00
|
|
|
staticpaths+="$("${CC}" -print-file-name="${staticlib}") "
|
|
|
|
done
|
2019-08-01 08:41:40 +08:00
|
|
|
OPTIONS=$( echo $OPTIONS | sed -e s,-static-libstdc\+\+,, -e s,\$,\ "${staticpaths}"\ -lm, )
|
2017-05-26 04:48:44 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
case $PLATFORM in
|
|
|
|
osx)
|
2019-08-01 08:41:40 +08:00
|
|
|
if [[ "${OPTIONS}" == *"-static-libgcc"* ]]; then
|
2017-05-26 04:48:44 +08:00
|
|
|
$( $CC -### $OPTIONS 2>&1 | grep '^ ' | sed -e s,^\ ,, -e s,-lgcc[^\ ]*,,g -e s,\",,g -e s,\$,\ `$CC -print-file-name=libgcc_eh.a`, -e s,10.8.2,10.6, )
|
|
|
|
else
|
|
|
|
$CC $OPTIONS
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
$CC $OPTIONS
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ -z "$UNSTRIPPED" ]; then
|
|
|
|
if [ -z "${NOSTRIP}" ]; then echo "Stripping $3"; else echo "Not stripping $3"; fi
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
Application)
|
|
|
|
case $PLATFORM in
|
|
|
|
linux)
|
|
|
|
objcopy --only-keep-debug $3 $3.debug
|
|
|
|
if [ -z "${NOSTRIP}" ]; then strip --strip-debug --strip-unneeded $3; fi
|
|
|
|
objcopy --add-gnu-debuglink=$3.debug $3
|
|
|
|
./build/link-validate.sh $3 $4
|
|
|
|
;;
|
|
|
|
osx)
|
|
|
|
cp $3 $3.debug
|
|
|
|
if [ -z "${NOSTRIP}" ]; then strip $3; fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "I don't know how to strip a binary on $PLATFORM"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
DynamicLibrary)
|
|
|
|
cp $3 $3-debug
|
|
|
|
case $PLATFORM in
|
|
|
|
linux)
|
|
|
|
if [ -z "${NOSTRIP}" ]; then strip --strip-all $3; fi
|
|
|
|
;;
|
|
|
|
osx)
|
|
|
|
if [ -z "${NOSTRIP}" ]; then strip -S -x $3; fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "I don't know how to strip a library on $PLATFORM"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
StaticLibrary)
|
|
|
|
echo "Archiving $3"
|
|
|
|
rm -f $3
|
|
|
|
eval ar rcs $3 \$$2_OBJECTS
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "I don't know how to build a $1"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|