2004-03-30 14:46:52 +02:00
|
|
|
#! @shell@ -e
|
2004-03-08 17:02:46 +01:00
|
|
|
|
|
|
|
if test -n "$NIX_GCC_WRAPPER_START_HOOK"; then
|
2005-12-05 15:11:09 +01:00
|
|
|
source "$NIX_GCC_WRAPPER_START_HOOK"
|
2004-03-08 17:02:46 +01:00
|
|
|
fi
|
|
|
|
|
2006-10-24 20:26:23 +02:00
|
|
|
if test -z "$NIX_GCC_WRAPPER_FLAGS_SET"; then
|
|
|
|
source @out@/nix-support/add-flags.sh
|
2004-03-08 17:02:46 +01:00
|
|
|
fi
|
|
|
|
|
2006-10-24 20:26:23 +02:00
|
|
|
source @out@/nix-support/utils.sh
|
2004-03-12 12:12:18 +01:00
|
|
|
|
2004-03-08 19:29:08 +01:00
|
|
|
|
2004-03-08 17:02:46 +01:00
|
|
|
# Figure out if linker flags should be passed. GCC prints annoying
|
|
|
|
# warnings when they are not needed.
|
|
|
|
dontLink=0
|
2007-05-24 17:35:14 +02:00
|
|
|
getVersion=0
|
|
|
|
nonFlagArgs=0
|
|
|
|
|
|
|
|
for i in "$@"; do
|
|
|
|
if test "$i" = "-c"; then
|
|
|
|
dontLink=1
|
|
|
|
elif test "$i" = "-S"; then
|
|
|
|
dontLink=1
|
|
|
|
elif test "$i" = "-E"; then
|
|
|
|
dontLink=1
|
|
|
|
elif test "$i" = "-E"; then
|
|
|
|
dontLink=1
|
|
|
|
elif test "$i" = "-M"; then
|
|
|
|
dontLink=1
|
|
|
|
elif test "$i" = "-MM"; then
|
|
|
|
dontLink=1
|
|
|
|
elif test "${i:0:1}" != "-"; then
|
|
|
|
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).
|
|
|
|
if test "$nonFlagArgs" = "0"; then
|
2004-03-08 17:02:46 +01:00
|
|
|
dontLink=1
|
|
|
|
fi
|
|
|
|
|
2004-03-08 19:29:08 +01:00
|
|
|
|
|
|
|
# Optionally filter out paths not refering to the store.
|
|
|
|
params=("$@")
|
2004-03-12 12:12:18 +01:00
|
|
|
if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE"; then
|
2004-03-08 19:29:08 +01:00
|
|
|
rest=()
|
|
|
|
n=0
|
|
|
|
while test $n -lt ${#params[*]}; do
|
|
|
|
p=${params[n]}
|
|
|
|
p2=${params[$((n+1))]}
|
2004-03-11 18:26:14 +01:00
|
|
|
if test "${p:0:3}" = "-L/" && badPath "${p:2}"; then
|
2004-03-08 19:29:08 +01:00
|
|
|
skip $p
|
2004-03-11 18:26:14 +01:00
|
|
|
elif test "$p" = "-L" && badPath "$p2"; then
|
2004-03-08 19:29:08 +01:00
|
|
|
n=$((n + 1)); skip $p2
|
2004-03-11 18:26:14 +01:00
|
|
|
elif test "${p:0:3}" = "-I/" && badPath "${p:2}"; then
|
2004-03-08 19:29:08 +01:00
|
|
|
skip $p
|
2004-03-11 18:26:14 +01:00
|
|
|
elif test "$p" = "-I" && badPath "$p2"; then
|
2004-03-08 19:29:08 +01:00
|
|
|
n=$((n + 1)); skip $p2
|
2004-03-11 18:26:14 +01:00
|
|
|
elif test "$p" = "-isystem" && badPath "$p2"; then
|
2004-03-08 19:29:08 +01:00
|
|
|
n=$((n + 1)); skip $p2
|
|
|
|
else
|
|
|
|
rest=("${rest[@]}" "$p")
|
|
|
|
fi
|
|
|
|
n=$((n + 1))
|
|
|
|
done
|
|
|
|
params=("${rest[@]}")
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2004-03-08 17:02:46 +01:00
|
|
|
# Add the flags for the C compiler proper.
|
2004-11-22 17:36:27 +01:00
|
|
|
extraAfter=($NIX_CFLAGS_COMPILE)
|
|
|
|
extraBefore=()
|
2004-03-08 17:02:46 +01:00
|
|
|
|
|
|
|
if test "$dontLink" != "1"; then
|
|
|
|
|
|
|
|
# Add the flags that should only be passed to the compiler when
|
|
|
|
# linking.
|
2004-11-22 17:36:27 +01:00
|
|
|
extraAfter=(${extraAfter[@]} $NIX_CFLAGS_LINK)
|
2004-03-08 17:02:46 +01:00
|
|
|
|
|
|
|
# Add the flags that should be passed to the linker (and prevent
|
|
|
|
# `ld-wrapper' from adding NIX_LDFLAGS again).
|
2004-11-22 17:36:27 +01:00
|
|
|
for i in $NIX_LDFLAGS_BEFORE; do
|
|
|
|
extraBefore=(${extraBefore[@]} "-Wl,$i")
|
|
|
|
done
|
2004-03-08 17:02:46 +01:00
|
|
|
for i in $NIX_LDFLAGS; do
|
2005-06-17 11:23:15 +02:00
|
|
|
if test "${i:0:3}" = "-L/"; then
|
|
|
|
extraAfter=(${extraAfter[@]} "$i")
|
|
|
|
else
|
|
|
|
extraAfter=(${extraAfter[@]} "-Wl,$i")
|
|
|
|
fi
|
2004-03-08 17:02:46 +01:00
|
|
|
done
|
|
|
|
export NIX_LDFLAGS_SET=1
|
|
|
|
|
|
|
|
if test "$NIX_STRIP_DEBUG" = "1"; then
|
|
|
|
# Add executable-stripping flags.
|
2004-11-22 17:36:27 +01:00
|
|
|
extraAfter=(${extraAfter[@]} $NIX_CFLAGS_STRIP)
|
2004-03-08 17:02:46 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2005-12-15 14:37:36 +01:00
|
|
|
# As a very special hack, if the arguments are just `-v', then don't
|
|
|
|
# add anything. This is to prevent `gcc -v' (which normally prints
|
|
|
|
# out the version number and returns exit code 0) from printing out
|
|
|
|
# `No input files specified' and returning exit code 1.
|
|
|
|
if test "$*" = "-v"; then
|
|
|
|
extraAfter=()
|
|
|
|
extraBefore=()
|
|
|
|
fi
|
|
|
|
|
2004-03-08 17:02:46 +01:00
|
|
|
# Optionally print debug info.
|
|
|
|
if test "$NIX_DEBUG" = "1"; then
|
2005-02-22 15:32:56 +01:00
|
|
|
echo "original flags to @gccProg@:" >&2
|
2004-03-08 19:29:08 +01:00
|
|
|
for i in "${params[@]}"; do
|
2004-03-08 17:02:46 +01:00
|
|
|
echo " $i" >&2
|
|
|
|
done
|
2005-02-22 15:32:56 +01:00
|
|
|
echo "extraBefore flags to @gccProg@:" >&2
|
2004-11-22 17:36:27 +01:00
|
|
|
for i in ${extraBefore[@]}; do
|
|
|
|
echo " $i" >&2
|
|
|
|
done
|
2005-02-22 15:32:56 +01:00
|
|
|
echo "extraAfter flags to @gccProg@:" >&2
|
2004-11-22 17:36:27 +01:00
|
|
|
for i in ${extraAfter[@]}; do
|
2004-03-08 17:02:46 +01:00
|
|
|
echo " $i" >&2
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test -n "$NIX_GCC_WRAPPER_EXEC_HOOK"; then
|
2005-12-05 15:11:09 +01:00
|
|
|
source "$NIX_GCC_WRAPPER_EXEC_HOOK"
|
2004-03-08 17:02:46 +01:00
|
|
|
fi
|
|
|
|
|
2005-07-12 16:02:36 +02:00
|
|
|
|
2005-07-13 10:45:57 +02:00
|
|
|
# Call the real `gcc'. Filter out warnings from stderr about unused
|
|
|
|
# `-B' flags, since they confuse some programs. Deep bash magic to
|
|
|
|
# apply grep to stderr (by swapping stdin/stderr twice).
|
2005-07-13 11:07:54 +02:00
|
|
|
if test -z "$NIX_GCC_NEEDS_GREP"; then
|
|
|
|
@gccProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]}
|
|
|
|
else
|
|
|
|
(@gccProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]} 3>&2 2>&1 1>&3- \
|
|
|
|
| (grep -v 'file path prefix' || true); exit ${PIPESTATUS[0]}) 3>&2 2>&1 1>&3-
|
|
|
|
exit $?
|
|
|
|
fi
|