2017-08-02 17:48:51 +01:00
|
|
|
#! @shell@
|
2017-08-03 20:34:23 +01:00
|
|
|
set -eu -o pipefail
|
2017-08-02 17:48:51 +01:00
|
|
|
shopt -s nullglob
|
|
|
|
|
2017-09-20 16:35:58 +01:00
|
|
|
if (( "${NIX_DEBUG:-0}" >= 7 )); then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
2017-08-03 20:34:23 +01:00
|
|
|
# N.B. Gnat is not used during bootstrapping, so we don't need to
|
|
|
|
# worry about the old bash empty array `set -u` workarounds.
|
|
|
|
|
2016-01-25 08:54:10 +00:00
|
|
|
path_backup="$PATH"
|
2017-08-02 17:48:51 +01:00
|
|
|
|
|
|
|
# phase separation makes this look useless
|
|
|
|
# shellcheck disable=SC2157
|
2016-02-01 13:42:33 +00:00
|
|
|
if [ -n "@coreutils_bin@" ]; then
|
2017-08-02 17:48:51 +01:00
|
|
|
PATH="@coreutils_bin@/bin"
|
2015-12-17 22:02:40 +00:00
|
|
|
fi
|
2010-01-16 23:09:27 +00:00
|
|
|
|
2017-08-03 20:34:23 +01:00
|
|
|
if [ -z "${NIX_@infixSalt@_GNAT_WRAPPER_FLAGS_SET:-}" ]; then
|
|
|
|
source @out@/nix-support/add-flags.sh
|
2010-01-16 23:09:27 +00:00
|
|
|
fi
|
|
|
|
|
2017-09-07 11:22:33 +01:00
|
|
|
source @out@/nix-support/utils.sh
|
|
|
|
|
2010-01-16 23:09:27 +00:00
|
|
|
|
|
|
|
# Figure out if linker flags should be passed. GCC prints annoying
|
|
|
|
# warnings when they are not needed.
|
|
|
|
dontLink=0
|
|
|
|
nonFlagArgs=0
|
|
|
|
|
|
|
|
for i in "$@"; do
|
2014-10-10 13:25:23 +01:00
|
|
|
if [ "$i" = -c ]; then
|
2010-01-16 23:09:27 +00:00
|
|
|
dontLink=1
|
2014-10-10 13:25:23 +01:00
|
|
|
elif [ "$i" = -M ]; then
|
2010-01-16 23:09:27 +00:00
|
|
|
dontLink=1
|
2014-10-10 13:25:23 +01:00
|
|
|
elif [ "${i:0:1}" != - ]; then
|
2010-01-16 23:09:27 +00:00
|
|
|
nonFlagArgs=1
|
2014-10-10 13:25:23 +01:00
|
|
|
elif [ "$i" = -m32 ]; then
|
|
|
|
if [ -e @out@/nix-support/dynamic-linker-m32 ]; then
|
2017-06-26 05:43:06 +01:00
|
|
|
NIX_@infixSalt@_LDFLAGS+=" -dynamic-linker $(< @out@/nix-support/dynamic-linker-m32)"
|
2010-01-16 23:09:27 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# If we pass a flag like -Wl, then gcc will call the linker unless it
|
|
|
|
# can figure out that it has to do something else (e.g., because of a
|
|
|
|
# "-c" flag). So if no non-flag arguments are given, don't pass any
|
|
|
|
# linker flags. This catches cases like "gcc" (should just print
|
|
|
|
# "gcc: no input files") and "gcc -v" (should print the version).
|
2014-10-10 13:25:23 +01:00
|
|
|
if [ "$nonFlagArgs" = 0 ]; then
|
2010-01-16 23:09:27 +00:00
|
|
|
dontLink=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Optionally filter out paths not refering to the store.
|
|
|
|
params=("$@")
|
2017-08-03 20:34:23 +01:00
|
|
|
if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "$NIX_STORE" ]]; then
|
2010-01-16 23:09:27 +00:00
|
|
|
rest=()
|
2017-08-02 17:48:51 +01:00
|
|
|
for p in "${params[@]}"; do
|
2014-10-10 13:25:23 +01:00
|
|
|
if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
|
2017-08-02 17:48:51 +01:00
|
|
|
skip "${p:2}"
|
2014-10-10 13:25:23 +01:00
|
|
|
elif [ "${p:0:3}" = -I/ ] && badPath "${p:2}"; then
|
2017-08-02 17:48:51 +01:00
|
|
|
skip "${p:2}"
|
2014-10-10 13:25:23 +01:00
|
|
|
elif [ "${p:0:4}" = -aI/ ] && badPath "${p:3}"; then
|
2017-08-02 17:48:51 +01:00
|
|
|
skip "${p:2}"
|
2014-10-10 13:25:23 +01:00
|
|
|
elif [ "${p:0:4}" = -aO/ ] && badPath "${p:3}"; then
|
2017-08-02 17:48:51 +01:00
|
|
|
skip "${p:2}"
|
2010-01-16 23:09:27 +00:00
|
|
|
else
|
2016-03-24 18:12:48 +00:00
|
|
|
rest+=("$p")
|
2010-01-16 23:09:27 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
params=("${rest[@]}")
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2016-03-15 16:35:07 +00:00
|
|
|
# Clear march/mtune=native -- they bring impurity.
|
2017-06-26 05:43:06 +01:00
|
|
|
if [ "$NIX_@infixSalt@_ENFORCE_NO_NATIVE" = 1 ]; then
|
2016-03-15 16:35:07 +00:00
|
|
|
rest=()
|
2017-08-02 17:48:51 +01:00
|
|
|
for p in "${params[@]}"; do
|
|
|
|
if [[ "$p" = -m*=native ]]; then
|
|
|
|
skip "$p"
|
2016-03-15 16:35:07 +00:00
|
|
|
else
|
2017-08-02 17:48:51 +01:00
|
|
|
rest+=("$p")
|
2016-03-15 16:35:07 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
params=("${rest[@]}")
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2010-01-16 23:09:27 +00:00
|
|
|
# Add the flags for the GNAT compiler proper.
|
2017-06-26 05:43:06 +01:00
|
|
|
extraAfter=($NIX_@infixSalt@_GNATFLAGS_COMPILE)
|
2010-01-16 23:09:27 +00:00
|
|
|
extraBefore=()
|
|
|
|
|
2017-08-02 17:48:51 +01:00
|
|
|
if [ "$(basename "$0")x" = "gnatmakex" ]; then
|
|
|
|
extraBefore=("--GNATBIND=@out@/bin/gnatbind" "--GNATLINK=@out@/bin/gnatlink ")
|
2010-01-16 23:09:27 +00:00
|
|
|
fi
|
|
|
|
|
2017-08-02 17:48:51 +01:00
|
|
|
#if [ "$dontLink" != 1 ]; then
|
|
|
|
# # Add the flags that should be passed to the linker (and prevent
|
2017-06-26 05:43:06 +01:00
|
|
|
# # `ld-wrapper' from adding NIX_@infixSalt@_LDFLAGS again).
|
|
|
|
# for i in $NIX_@infixSalt@_LDFLAGS_BEFORE; do
|
2017-08-02 17:48:51 +01:00
|
|
|
# extraBefore+=("-largs" "$i")
|
|
|
|
# done
|
2017-06-26 05:43:06 +01:00
|
|
|
# for i in $NIX_@infixSalt@_LDFLAGS; do
|
2017-08-02 17:48:51 +01:00
|
|
|
# if [ "${i:0:3}" = -L/ ]; then
|
|
|
|
# extraAfter+=("$i")
|
|
|
|
# else
|
|
|
|
# extraAfter+=("-largs" "$i")
|
|
|
|
# fi
|
|
|
|
# done
|
2017-06-26 05:43:06 +01:00
|
|
|
# export NIX_@infixSalt@_LDFLAGS_SET=1
|
2017-08-02 17:48:51 +01:00
|
|
|
#fi
|
2010-01-16 23:09:27 +00:00
|
|
|
|
|
|
|
# Optionally print debug info.
|
2017-09-20 00:10:49 +01:00
|
|
|
if (( "${NIX_DEBUG:-0}" >= 1 )); then
|
2017-08-02 17:48:51 +01:00
|
|
|
echo "extra flags before to @prog@:" >&2
|
|
|
|
printf " %q\n" "${extraBefore[@]}" >&2
|
|
|
|
echo "original flags to @prog@:" >&2
|
|
|
|
printf " %q\n" "${params[@]}" >&2
|
|
|
|
echo "extra flags after to @prog@:" >&2
|
|
|
|
printf " %q\n" "${extraAfter[@]}" >&2
|
2010-01-16 23:09:27 +00:00
|
|
|
fi
|
|
|
|
|
2016-01-25 08:54:10 +00:00
|
|
|
PATH="$path_backup"
|
2017-08-02 17:48:51 +01:00
|
|
|
exec @prog@ "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"
|