2017-08-28 19:56:08 +01:00
|
|
|
# Binutils Wrapper hygiene
|
|
|
|
#
|
|
|
|
# See comments in cc-wrapper's setup hook. This works exactly the same way.
|
|
|
|
|
2017-08-03 17:45:06 +01:00
|
|
|
set -u
|
|
|
|
|
2017-08-28 16:33:08 +01:00
|
|
|
# Skip setup hook if we're neither a build-time dep, nor, temporarily, doing a
|
|
|
|
# native compile.
|
|
|
|
#
|
|
|
|
# TODO(@Ericson2314): No native exception
|
|
|
|
[[ -z ${crossConfig-} ]] || (( "$hostOffset" < 0 )) || return 0
|
2017-08-03 17:45:06 +01:00
|
|
|
|
2017-08-28 19:56:08 +01:00
|
|
|
bintoolsWrapper_addLDVars () {
|
2017-08-03 17:45:06 +01:00
|
|
|
case $depHostOffset in
|
2017-08-28 19:56:08 +01:00
|
|
|
-1) local role='BUILD_' ;;
|
|
|
|
0) local role='' ;;
|
|
|
|
1) local role='TARGET_' ;;
|
2017-08-03 17:45:06 +01:00
|
|
|
*) echo "bintools-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2;
|
2017-08-28 19:56:08 +01:00
|
|
|
return 1 ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [[ -d "$1/lib64" && ! -L "$1/lib64" ]]; then
|
|
|
|
export NIX_${role}LDFLAGS+=" -L$1/lib64"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -d "$1/lib" ]]; then
|
|
|
|
export NIX_${role}LDFLAGS+=" -L$1/lib"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-08-03 17:45:06 +01:00
|
|
|
case $targetOffset in
|
|
|
|
-1)
|
|
|
|
export NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_BUILD=1
|
|
|
|
role_pre='BUILD_'
|
|
|
|
role_post='_FOR_BUILD'
|
|
|
|
;;
|
|
|
|
0)
|
|
|
|
export NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_HOST=1
|
|
|
|
role_pre=''
|
|
|
|
role_post=''
|
|
|
|
;;
|
|
|
|
1)
|
|
|
|
export NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_TARGET=1
|
|
|
|
role_pre='TARGET_'
|
|
|
|
role_post='_FOR_TARGET'
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "cc-wrapper: used as improper sort of dependency" >2;
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
2017-08-28 19:56:08 +01:00
|
|
|
|
2017-08-03 17:45:06 +01:00
|
|
|
addEnvHooks "$targetOffset" bintoolsWrapper_addLDVars
|
2017-08-28 19:56:08 +01:00
|
|
|
|
|
|
|
# shellcheck disable=SC2157
|
|
|
|
if [ -n "@bintools_bin@" ]; then
|
|
|
|
addToSearchPath _PATH @bintools_bin@/bin
|
|
|
|
fi
|
|
|
|
|
|
|
|
# shellcheck disable=SC2157
|
|
|
|
if [ -n "@libc_bin@" ]; then
|
|
|
|
addToSearchPath _PATH @libc_bin@/bin
|
|
|
|
fi
|
|
|
|
|
|
|
|
# shellcheck disable=SC2157
|
|
|
|
if [ -n "@coreutils_bin@" ]; then
|
|
|
|
addToSearchPath _PATH @coreutils_bin@/bin
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Export tool environment variables so various build systems use the right ones.
|
|
|
|
|
|
|
|
export NIX_${role_pre}BINTOOLS=@out@
|
|
|
|
|
|
|
|
for cmd in \
|
|
|
|
ar as ld nm objcopy objdump readelf ranlib strip strings size windres
|
|
|
|
do
|
|
|
|
if
|
|
|
|
PATH=$_PATH type -p "@targetPrefix@${cmd}" > /dev/null
|
|
|
|
then
|
|
|
|
upper_case="$(echo "$cmd" | tr "[:lower:]" "[:upper:]")"
|
|
|
|
export "${role_pre}${upper_case}=@targetPrefix@${cmd}";
|
|
|
|
export "${upper_case}${role_post}=@targetPrefix@${cmd}";
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2018-03-07 00:21:10 +00:00
|
|
|
# If unset, assume the default hardening flags.
|
|
|
|
: ${NIX_HARDENING_ENABLE="fortify stackprotector pic strictoverflow format relro bindnow"}
|
|
|
|
export NIX_HARDENING_ENABLE
|
|
|
|
|
2017-08-28 19:56:08 +01:00
|
|
|
# No local scope in sourced file
|
|
|
|
unset -v role_pre role_post cmd upper_case
|
2017-08-03 17:45:06 +01:00
|
|
|
set +u
|