2 set -eu -o pipefail
+o posix
5 if (( "${NIX_DEBUG:-0}" >= 7 )); then
11 # That @-vars are substituted separately from bash evaluation makes
12 # shellcheck think this, and others like it, are useless conditionals.
13 # shellcheck disable=SC2157
14 if [[ -n "@coreutils_bin@" && -n "@gnugrep_bin@" ]]; then
15 PATH
="@coreutils_bin@/bin:@gnugrep_bin@/bin"
20 source @out@
/nix-support
/utils.bash
22 # Flirting with a layer violation here.
23 if [ -z "${NIX_BINTOOLS_WRAPPER_FLAGS_SET_@suffixSalt@:-}" ]; then
24 source @bintools@
/nix-support
/add-flags.sh
27 # Put this one second so libc ldflags take priority.
28 if [ -z "${NIX_CC_WRAPPER_FLAGS_SET_@suffixSalt@:-}" ]; then
29 source @out@
/nix-support
/add-flags.sh
32 if [ -z "${NIX_GNAT_WRAPPER_EXTRA_FLAGS_SET_@suffixSalt@:-}" ]; then
33 source @out@
/nix-support
/add-gnat-extra-flags.sh
36 # Parse command line options and set several variables.
37 # For instance, figure out if linker flags should be passed.
38 # GCC prints annoying warnings when they are not needed.
41 # shellcheck disable=SC2193
43 expandResponseParams
"$@"
46 while (( "$n" < "$nParams" )); do
48 p2
=${params[n+1]:-} # handle `p` being last one
49 if [ "$p" = -c ]; then
51 elif [ "$p" = -S ]; then
53 elif [ "$p" = -E ]; then
55 elif [ "$p" = -E ]; then
57 elif [ "$p" = -M ]; then
59 elif [ "$p" = -MM ]; then
61 elif [[ "$p" = -x && "$p2" = *-header ]]; then
63 elif [[ "$p" != -?
* ]]; then
64 # A dash alone signifies standard input; it is not a flag
70 # If we pass a flag like -Wl, then gcc will call the linker unless it
71 # can figure out that it has to do something else (e.g., because of a
72 # "-c" flag). So if no non-flag arguments are given, don't pass any
73 # linker flags. This catches cases like "gcc" (should just print
74 # "gcc: no input files") and "gcc -v" (should print the version).
75 if [ "$nonFlagArgs" = 0 ]; then
79 # Optionally filter out paths not refering to the store.
80 if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "$NIX_STORE" ]]; then
84 while (( "$n" < "$nParams" )); do
86 p2
=${params[n+1]:-} # handle `p` being last one
87 if [ "${p:0:3}" = -L/ ] && badPath
"${p:2}"; then
89 elif [ "$p" = -L ] && badPath
"$p2"; then
91 elif [ "${p:0:3}" = -I/ ] && badPath
"${p:2}"; then
93 elif [ "$p" = -I ] && badPath
"$p2"; then
95 elif [ "${p:0:4}" = -aI/ ] && badPath
"${p:3}"; then
97 elif [ "$p" = -aI ] && badPath
"$p2"; then
99 elif [ "${p:0:4}" = -aO/ ] && badPath
"${p:3}"; then
101 elif [ "$p" = -aO ] && badPath
"$p2"; then
103 elif [ "$p" = -isystem ] && badPath
"$p2"; then
110 # Old bash empty array hack
111 params
=(${rest+"${rest[@]}"})
115 # Clear march/mtune=native -- they bring impurity.
116 if [ "$NIX_ENFORCE_NO_NATIVE_@suffixSalt@" = 1 ]; then
118 # Old bash empty array hack
119 for p
in ${params+"${params[@]}"}; do
120 if [[ "$p" = -m*=native
]]; then
126 # Old bash empty array hack
127 params
=(${rest+"${rest[@]}"})
130 case "$(basename $0)x" in
133 extraAfter
=($NIX_GNATFLAGS_COMPILE_@suffixSalt@
)
136 extraBefore
=("--GCC=@out@/bin/gcc")
140 extraBefore
=($NIX_GNATFLAGS_COMPILE_@suffixSalt@
)
145 extraAfter
=("--GCC=@out@/bin/gcc")
149 extraAfter
=($NIX_GNATFLAGS_COMPILE_@suffixSalt@
)
152 extraBefore
=("--GNATBIND=@out@/bin/gnatbind" "--GNATLINK=@out@/bin/gnatlink")
153 extraAfter
=($NIX_GNATFLAGS_COMPILE_@suffixSalt@
-cargs $NIX_GNATMAKE_CARGS_@suffixSalt@
)
157 # As a very special hack, if the arguments are just `-v', then don't
158 # add anything. This is to prevent `gcc -v' (which normally prints
159 # out the version number and returns exit code 0) from printing out
160 # `No input files specified' and returning exit code 1.
161 if [ "$*" = -v ]; then
166 # Optionally print debug info.
167 if (( "${NIX_DEBUG:-0}" >= 1 )); then
168 # Old bash workaround, see ld-wrapper for explanation.
169 echo "extra flags before to @prog@:" >&2
170 printf " %q\n" ${extraBefore+"${extraBefore[@]}"} >&2
171 echo "original flags to @prog@:" >&2
172 printf " %q\n" ${params+"${params[@]}"} >&2
173 echo "extra flags after to @prog@:" >&2
174 printf " %q\n" ${extraAfter+"${extraAfter[@]}"} >&2
178 # Old bash workaround, see above.
180 ${extraBefore+"${extraBefore[@]}"} \
181 ${params+"${params[@]}"} \
182 ${extraAfter+"${extraAfter[@]}"}