2017-07-06 22:19:53 +01:00
|
|
|
# N.B. It may be a surprise that the derivation-specific variables are exported,
|
|
|
|
# since this is just sourced by the wrapped binaries---the end consumers. This
|
|
|
|
# is because one wrapper binary may invoke another (e.g. cc invoking ld). In
|
|
|
|
# that case, it is cheaper/better to not repeat this step and let the forked
|
|
|
|
# wrapped binary just inherit the work of the forker's wrapper script.
|
|
|
|
|
|
|
|
# Accumulate prefixes for taking in the right input parameters. See setup-hook
|
|
|
|
# for details.
|
|
|
|
declare -a role_prefixes=()
|
|
|
|
if [[ -n "${NIX_CC_WRAPPER_@infixSalt@_TARGET_BUILD:-}" ]]; then
|
|
|
|
role_prefixes+=(_BUILD)
|
|
|
|
fi
|
|
|
|
if [[ -n "${NIX_CC_WRAPPER_@infixSalt@_TARGET_TARGET:-}" ]]; then
|
|
|
|
role_prefixes+=(_TARGET)
|
|
|
|
fi
|
2017-08-08 09:14:54 +01:00
|
|
|
# use this as default if no role is inferred
|
|
|
|
if [[ -n "${NIX_CC_WRAPPER_@infixSalt@_TARGET_HOST:-}" || ${#role_prefixes[@]} -eq 0 ]]; then
|
|
|
|
role_prefixes+=('')
|
|
|
|
fi
|
2017-07-06 22:19:53 +01:00
|
|
|
|
|
|
|
# For each role we serve, we accumulate the input parameters into our own
|
|
|
|
# cc-wrapper-derivation-specific environment variables.
|
|
|
|
for pre in "${role_prefixes[@]}"; do
|
|
|
|
# We need to mangle names for hygiene, but also take parameters/overrides
|
|
|
|
# from the environment.
|
|
|
|
slurpUnsalted () {
|
|
|
|
case "$1" in
|
|
|
|
CC_WRAPPER_*)
|
|
|
|
local firstPre=NIX_CC_WRAPPER_
|
|
|
|
local varname="${1#CC_WRAPPER_}"
|
|
|
|
;;
|
|
|
|
LD_WRAPPER_*)
|
|
|
|
local firstPre=NIX_LD_WRAPPER_
|
|
|
|
local varname="${1#LD_WRAPPER_}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
local firstPre=NIX_
|
|
|
|
local varname="$1"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
local inputVar="${firstPre}${pre}${varname}"
|
|
|
|
local outputVar="${firstPre}@infixSalt@_${varname}"
|
|
|
|
local delimiter=''
|
|
|
|
if [[ -n "${!outputVar:-}" && -n "${!inputVar:-}" ]]; then
|
|
|
|
delimiter=' '
|
|
|
|
fi
|
|
|
|
# Easiest to just do this to deal with either the input or (old) output.
|
|
|
|
set +u
|
|
|
|
export ${outputVar}+="${delimiter}${!inputVar}"
|
|
|
|
set -u
|
|
|
|
}
|
|
|
|
|
|
|
|
slurpUnsalted CC_WRAPPER_START_HOOK
|
|
|
|
slurpUnsalted CC_WRAPPER_EXEC_HOOK
|
|
|
|
slurpUnsalted LD_WRAPPER_START_HOOK
|
|
|
|
slurpUnsalted LD_WRAPPER_EXEC_HOOK
|
|
|
|
|
|
|
|
slurpUnsalted CFLAGS_COMPILE
|
|
|
|
slurpUnsalted CFLAGS_LINK
|
|
|
|
slurpUnsalted CXXSTDLIB_COMPILE
|
|
|
|
slurpUnsalted CXXSTDLIB_LINK
|
|
|
|
slurpUnsalted GNATFLAGS_COMPILE
|
|
|
|
slurpUnsalted IGNORE_LD_THROUGH_GCC
|
|
|
|
slurpUnsalted LDFLAGS
|
|
|
|
slurpUnsalted LDFLAGS_BEFORE
|
|
|
|
slurpUnsalted LDFLAGS_AFTER
|
|
|
|
slurpUnsalted LDFLAGS_HARDEN
|
|
|
|
|
|
|
|
slurpUnsalted SET_BUILD_ID
|
|
|
|
slurpUnsalted DONT_SET_RPATH
|
|
|
|
slurpUnsalted ENFORCE_NO_NATIVE
|
|
|
|
done
|
|
|
|
unset -f slurpUnsalted
|
|
|
|
|
2016-02-05 10:59:18 +00:00
|
|
|
# `-B@out@/bin' forces cc to use ld-wrapper.sh when calling ld.
|
2017-06-26 05:43:06 +01:00
|
|
|
export NIX_@infixSalt@_CFLAGS_COMPILE="-B@out@/bin/ $NIX_@infixSalt@_CFLAGS_COMPILE"
|
2008-06-26 12:07:46 +01:00
|
|
|
|
2017-08-02 17:48:51 +01:00
|
|
|
# Export and assign separately in order that a failing $(..) will fail
|
|
|
|
# the script.
|
|
|
|
|
2014-10-10 13:25:23 +01:00
|
|
|
if [ -e @out@/nix-support/libc-cflags ]; then
|
2017-06-26 05:43:06 +01:00
|
|
|
export NIX_@infixSalt@_CFLAGS_COMPILE
|
|
|
|
NIX_@infixSalt@_CFLAGS_COMPILE="$(< @out@/nix-support/libc-cflags) $NIX_@infixSalt@_CFLAGS_COMPILE"
|
2008-06-26 12:07:46 +01:00
|
|
|
fi
|
|
|
|
|
2016-02-05 10:59:18 +00:00
|
|
|
if [ -e @out@/nix-support/cc-cflags ]; then
|
2017-06-26 05:43:06 +01:00
|
|
|
export NIX_@infixSalt@_CFLAGS_COMPILE
|
|
|
|
NIX_@infixSalt@_CFLAGS_COMPILE="$(< @out@/nix-support/cc-cflags) $NIX_@infixSalt@_CFLAGS_COMPILE"
|
2008-06-26 12:07:46 +01:00
|
|
|
fi
|
|
|
|
|
2014-10-10 13:25:23 +01:00
|
|
|
if [ -e @out@/nix-support/gnat-cflags ]; then
|
2017-06-26 05:43:06 +01:00
|
|
|
export NIX_@infixSalt@_GNATFLAGS_COMPILE
|
|
|
|
NIX_@infixSalt@_GNATFLAGS_COMPILE="$(< @out@/nix-support/gnat-cflags) $NIX_@infixSalt@_GNATFLAGS_COMPILE"
|
2010-01-16 21:32:44 +00:00
|
|
|
fi
|
|
|
|
|
2014-10-10 13:25:23 +01:00
|
|
|
if [ -e @out@/nix-support/libc-ldflags ]; then
|
2017-06-26 05:43:06 +01:00
|
|
|
export NIX_@infixSalt@_LDFLAGS
|
|
|
|
NIX_@infixSalt@_LDFLAGS+=" $(< @out@/nix-support/libc-ldflags)"
|
2009-02-01 21:26:28 +00:00
|
|
|
fi
|
|
|
|
|
2016-02-05 10:59:18 +00:00
|
|
|
if [ -e @out@/nix-support/cc-ldflags ]; then
|
2017-06-26 05:43:06 +01:00
|
|
|
export NIX_@infixSalt@_LDFLAGS
|
|
|
|
NIX_@infixSalt@_LDFLAGS+=" $(< @out@/nix-support/cc-ldflags)"
|
2008-06-26 12:07:46 +01:00
|
|
|
fi
|
|
|
|
|
2014-10-10 13:25:23 +01:00
|
|
|
if [ -e @out@/nix-support/libc-ldflags-before ]; then
|
2017-06-26 05:43:06 +01:00
|
|
|
export NIX_@infixSalt@_LDFLAGS_BEFORE
|
|
|
|
NIX_@infixSalt@_LDFLAGS_BEFORE="$(< @out@/nix-support/libc-ldflags-before) $NIX_@infixSalt@_LDFLAGS_BEFORE"
|
2008-06-26 12:07:46 +01:00
|
|
|
fi
|
|
|
|
|
2017-07-06 22:19:53 +01:00
|
|
|
# That way forked processes don't againt extend these environment variables
|
2017-06-26 05:43:06 +01:00
|
|
|
export NIX_CC_WRAPPER_@infixSalt@_FLAGS_SET=1
|