2017-08-02 18:48:51 +02:00
|
|
|
#! @shell@
|
2017-10-16 23:31:44 +02:00
|
|
|
set -eu -o pipefail +o posix
|
2017-08-02 18:48:51 +02:00
|
|
|
shopt -s nullglob
|
|
|
|
|
2017-09-20 17:35:58 +02:00
|
|
|
if (( "${NIX_DEBUG:-0}" >= 7 )); then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
2017-08-03 21:34:23 +02: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 09:54:10 +01:00
|
|
|
path_backup="$PATH"
|
2017-08-02 18:48:51 +02:00
|
|
|
|
|
|
|
# phase separation makes this look useless
|
|
|
|
# shellcheck disable=SC2157
|
2016-02-01 14:42:33 +01:00
|
|
|
if [ -n "@coreutils_bin@" ]; then
|
2017-08-02 18:48:51 +02:00
|
|
|
PATH="@coreutils_bin@/bin"
|
2015-12-17 23:02:40 +01:00
|
|
|
fi
|
2010-01-17 00:09:27 +01:00
|
|
|
|
2017-08-03 21:34:23 +02:00
|
|
|
if [ -z "${NIX_@infixSalt@_GNAT_WRAPPER_FLAGS_SET:-}" ]; then
|
|
|
|
source @out@/nix-support/add-flags.sh
|
2010-01-17 00:09:27 +01:00
|
|
|
fi
|
|
|
|
|
2017-09-07 12:22:33 +02:00
|
|
|
source @out@/nix-support/utils.sh
|
|
|
|
|
2010-01-17 00:09:27 +01: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 14:25:23 +02:00
|
|
|
if [ "$i" = -c ]; then
|
2010-01-17 00:09:27 +01:00
|
|
|
dontLink=1
|
2014-10-10 14:25:23 +02:00
|
|
|
elif [ "$i" = -M ]; then
|
2010-01-17 00:09:27 +01:00
|
|
|
dontLink=1
|
2014-10-10 14:25:23 +02:00
|
|
|
elif [ "${i:0:1}" != - ]; then
|
2010-01-17 00:09:27 +01:00
|
|
|
nonFlagArgs=1
|
|
|
|
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 14:25:23 +02:00
|
|
|
if [ "$nonFlagArgs" = 0 ]; then
|
2010-01-17 00:09:27 +01:00
|
|
|
dontLink=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Optionally filter out paths not refering to the store.
|
|
|
|
params=("$@")
|
2017-08-03 21:34:23 +02:00
|
|
|
if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "$NIX_STORE" ]]; then
|
2010-01-17 00:09:27 +01:00
|
|
|
rest=()
|
2017-08-02 18:48:51 +02:00
|
|
|
for p in "${params[@]}"; do
|
2014-10-10 14:25:23 +02:00
|
|
|
if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
|
2017-08-02 18:48:51 +02:00
|
|
|
skip "${p:2}"
|
2014-10-10 14:25:23 +02:00
|
|
|
elif [ "${p:0:3}" = -I/ ] && badPath "${p:2}"; then
|
2017-08-02 18:48:51 +02:00
|
|
|
skip "${p:2}"
|
2014-10-10 14:25:23 +02:00
|
|
|
elif [ "${p:0:4}" = -aI/ ] && badPath "${p:3}"; then
|
2017-08-02 18:48:51 +02:00
|
|
|
skip "${p:2}"
|
2014-10-10 14:25:23 +02:00
|
|
|
elif [ "${p:0:4}" = -aO/ ] && badPath "${p:3}"; then
|
2017-08-02 18:48:51 +02:00
|
|
|
skip "${p:2}"
|
2010-01-17 00:09:27 +01:00
|
|
|
else
|
2016-03-24 19:12:48 +01:00
|
|
|
rest+=("$p")
|
2010-01-17 00:09:27 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
params=("${rest[@]}")
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2016-03-15 17:35:07 +01:00
|
|
|
# Clear march/mtune=native -- they bring impurity.
|
2017-06-26 06:43:06 +02:00
|
|
|
if [ "$NIX_@infixSalt@_ENFORCE_NO_NATIVE" = 1 ]; then
|
2016-03-15 17:35:07 +01:00
|
|
|
rest=()
|
2017-08-02 18:48:51 +02:00
|
|
|
for p in "${params[@]}"; do
|
|
|
|
if [[ "$p" = -m*=native ]]; then
|
|
|
|
skip "$p"
|
2016-03-15 17:35:07 +01:00
|
|
|
else
|
2017-08-02 18:48:51 +02:00
|
|
|
rest+=("$p")
|
2016-03-15 17:35:07 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
params=("${rest[@]}")
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2010-01-17 00:09:27 +01:00
|
|
|
# Add the flags for the GNAT compiler proper.
|
2017-06-26 06:43:06 +02:00
|
|
|
extraAfter=($NIX_@infixSalt@_GNATFLAGS_COMPILE)
|
2010-01-17 00:09:27 +01:00
|
|
|
extraBefore=()
|
|
|
|
|
2017-08-02 18:48:51 +02:00
|
|
|
if [ "$(basename "$0")x" = "gnatmakex" ]; then
|
|
|
|
extraBefore=("--GNATBIND=@out@/bin/gnatbind" "--GNATLINK=@out@/bin/gnatlink ")
|
2010-01-17 00:09:27 +01:00
|
|
|
fi
|
|
|
|
|
2017-08-02 18:48:51 +02:00
|
|
|
#if [ "$dontLink" != 1 ]; then
|
|
|
|
# # Add the flags that should be passed to the linker (and prevent
|
2017-06-26 06:43:06 +02:00
|
|
|
# # `ld-wrapper' from adding NIX_@infixSalt@_LDFLAGS again).
|
|
|
|
# for i in $NIX_@infixSalt@_LDFLAGS_BEFORE; do
|
2017-08-02 18:48:51 +02:00
|
|
|
# extraBefore+=("-largs" "$i")
|
|
|
|
# done
|
2017-06-26 06:43:06 +02:00
|
|
|
# for i in $NIX_@infixSalt@_LDFLAGS; do
|
2017-08-02 18:48:51 +02:00
|
|
|
# if [ "${i:0:3}" = -L/ ]; then
|
|
|
|
# extraAfter+=("$i")
|
|
|
|
# else
|
|
|
|
# extraAfter+=("-largs" "$i")
|
|
|
|
# fi
|
|
|
|
# done
|
2017-06-26 06:43:06 +02:00
|
|
|
# export NIX_@infixSalt@_LDFLAGS_SET=1
|
2017-08-02 18:48:51 +02:00
|
|
|
#fi
|
2010-01-17 00:09:27 +01:00
|
|
|
|
|
|
|
# Optionally print debug info.
|
2017-09-20 01:10:49 +02:00
|
|
|
if (( "${NIX_DEBUG:-0}" >= 1 )); then
|
2017-08-02 18:48:51 +02: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-17 00:09:27 +01:00
|
|
|
fi
|
|
|
|
|
2016-01-25 09:54:10 +01:00
|
|
|
PATH="$path_backup"
|
2017-08-02 18:48:51 +02:00
|
|
|
exec @prog@ "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"
|