···44# that case, it is cheaper/better to not repeat this step and let the forked
55# wrapped binary just inherit the work of the forker's wrapper script.
6677-# Accumulate prefixes for taking in the right input parameters. See setup-hook
77+var_templates=(
88+ NIX_CC_WRAPPER+START_HOOK
99+ NIX_CC_WRAPPER+EXEC_HOOK
1010+ NIX_LD_WRAPPER+START_HOOK
1111+ NIX_LD_WRAPPER+EXEC_HOOK
1212+1313+ NIX+CFLAGS_COMPILE
1414+ NIX+CFLAGS_LINK
1515+ NIX+CXXSTDLIB_COMPILE
1616+ NIX+CXXSTDLIB_LINK
1717+ NIX+GNATFLAGS_COMPILE
1818+ NIX+IGNORE_LD_THROUGH_GCC
1919+ NIX+LDFLAGS
2020+ NIX+LDFLAGS_BEFORE
2121+ NIX+LDFLAGS_AFTER
2222+ NIX+LDFLAGS_HARDEN
2323+2424+ NIX+SET_BUILD_ID
2525+ NIX+DONT_SET_RPATH
2626+ NIX+ENFORCE_NO_NATIVE
2727+)
2828+2929+# Accumulate infixes for taking in the right input parameters. See setup-hook
830# for details.
99-declare -a role_prefixes=()
1010-if [[ -n "${NIX_CC_WRAPPER_@infixSalt@_TARGET_BUILD:-}" ]]; then
1111- role_prefixes+=(_BUILD)
3131+declare -a role_infixes=()
3232+if [ "${NIX_CC_WRAPPER_@infixSalt@_TARGET_BUILD:-}" ]; then
3333+ role_infixes+=(_BUILD_)
1234fi
1313-if [[ -n "${NIX_CC_WRAPPER_@infixSalt@_TARGET_HOST:-}" ]]; then
1414- role_prefixes+=('')
3535+if [ "${NIX_CC_WRAPPER_@infixSalt@_TARGET_HOST:-}" ]; then
3636+ role_infixes+=(_)
1537fi
1616-if [[ -n "${NIX_CC_WRAPPER_@infixSalt@_TARGET_TARGET:-}" ]]; then
1717- role_prefixes+=(_TARGET)
3838+if [ "${NIX_CC_WRAPPER_@infixSalt@_TARGET_TARGET:-}" ]; then
3939+ role_infixes+=(_TARGET_)
1840fi
19412020-# For each role we serve, we accumulate the input parameters into our own
2121-# cc-wrapper-derivation-specific environment variables.
2222-for pre in "${role_prefixes[@]}"; do
2323- # We need to mangle names for hygiene, but also take parameters/overrides
2424- # from the environment.
2525- slurpUnsalted () {
2626- case "$1" in
2727- CC_WRAPPER_*)
2828- local firstPre=NIX_CC_WRAPPER_
2929- local varname="${1#CC_WRAPPER_}"
3030- ;;
3131- LD_WRAPPER_*)
3232- local firstPre=NIX_LD_WRAPPER_
3333- local varname="${1#LD_WRAPPER_}"
3434- ;;
3535- *)
3636- local firstPre=NIX_
3737- local varname="$1"
3838- ;;
3939- esac
4040- local inputVar="${firstPre}${pre}${varname}"
4141- local outputVar="${firstPre}@infixSalt@_${varname}"
4242- local delimiter=''
4343- if [[ -n "${!outputVar:-}" && -n "${!inputVar:-}" ]]; then
4444- delimiter=' '
4242+# We need to mangle names for hygiene, but also take parameters/overrides
4343+# from the environment.
4444+for var in "${var_templates[@]}"; do
4545+ outputVar="${var/+/_@infixSalt@_}"
4646+ export ${outputVar}+=''
4747+ # For each role we serve, we accumulate the input parameters into our own
4848+ # cc-wrapper-derivation-specific environment variables.
4949+ for infix in "${role_infixes[@]}"; do
5050+ inputVar="${var/+/${infix}}"
5151+ if [ -v "$inputVar" ]; then
5252+ export ${outputVar}+="${!outputVar:+ }${!inputVar}"
4553 fi
4646- # Easiest to just do this to deal with either the input or (old) output.
4747- set +u
4848- export ${outputVar}+="${delimiter}${!inputVar}"
4949- set -u
5050- }
5151-5252- slurpUnsalted CC_WRAPPER_START_HOOK
5353- slurpUnsalted CC_WRAPPER_EXEC_HOOK
5454- slurpUnsalted LD_WRAPPER_START_HOOK
5555- slurpUnsalted LD_WRAPPER_EXEC_HOOK
5656-5757- slurpUnsalted CFLAGS_COMPILE
5858- slurpUnsalted CFLAGS_LINK
5959- slurpUnsalted CXXSTDLIB_COMPILE
6060- slurpUnsalted CXXSTDLIB_LINK
6161- slurpUnsalted GNATFLAGS_COMPILE
6262- slurpUnsalted IGNORE_LD_THROUGH_GCC
6363- slurpUnsalted LDFLAGS
6464- slurpUnsalted LDFLAGS_BEFORE
6565- slurpUnsalted LDFLAGS_AFTER
6666- slurpUnsalted LDFLAGS_HARDEN
6767-6868- slurpUnsalted SET_BUILD_ID
6969- slurpUnsalted DONT_SET_RPATH
7070- slurpUnsalted ENFORCE_NO_NATIVE
5454+ done
7155done
7272-unset -f slurpUnsalted
73567457# `-B@out@/bin' forces cc to use ld-wrapper.sh when calling ld.
7575-export NIX_@infixSalt@_CFLAGS_COMPILE="-B@out@/bin/ $NIX_@infixSalt@_CFLAGS_COMPILE"
5858+NIX_@infixSalt@_CFLAGS_COMPILE="-B@out@/bin/ $NIX_@infixSalt@_CFLAGS_COMPILE"
76597760# Export and assign separately in order that a failing $(..) will fail
7861# the script.
79628063if [ -e @out@/nix-support/libc-cflags ]; then
8181- export NIX_@infixSalt@_CFLAGS_COMPILE
8264 NIX_@infixSalt@_CFLAGS_COMPILE="$(< @out@/nix-support/libc-cflags) $NIX_@infixSalt@_CFLAGS_COMPILE"
8365fi
84668567if [ -e @out@/nix-support/cc-cflags ]; then
8686- export NIX_@infixSalt@_CFLAGS_COMPILE
8768 NIX_@infixSalt@_CFLAGS_COMPILE="$(< @out@/nix-support/cc-cflags) $NIX_@infixSalt@_CFLAGS_COMPILE"
8869fi
89709071if [ -e @out@/nix-support/gnat-cflags ]; then
9191- export NIX_@infixSalt@_GNATFLAGS_COMPILE
9272 NIX_@infixSalt@_GNATFLAGS_COMPILE="$(< @out@/nix-support/gnat-cflags) $NIX_@infixSalt@_GNATFLAGS_COMPILE"
9373fi
94749575if [ -e @out@/nix-support/libc-ldflags ]; then
9696- export NIX_@infixSalt@_LDFLAGS
9776 NIX_@infixSalt@_LDFLAGS+=" $(< @out@/nix-support/libc-ldflags)"
9877fi
997810079if [ -e @out@/nix-support/cc-ldflags ]; then
101101- export NIX_@infixSalt@_LDFLAGS
10280 NIX_@infixSalt@_LDFLAGS+=" $(< @out@/nix-support/cc-ldflags)"
10381fi
1048210583if [ -e @out@/nix-support/libc-ldflags-before ]; then
106106- export NIX_@infixSalt@_LDFLAGS_BEFORE
10784 NIX_@infixSalt@_LDFLAGS_BEFORE="$(< @out@/nix-support/libc-ldflags-before) $NIX_@infixSalt@_LDFLAGS_BEFORE"
10885fi
10986110110-# That way forked processes don't againt extend these environment variables
8787+# That way forked processes will not extend these environment variables again.
11188export NIX_CC_WRAPPER_@infixSalt@_FLAGS_SET=1