lol
1#! @shell@ -e
2
3if [ -n "$NIX_GNAT_WRAPPER_START_HOOK" ]; then
4 source "$NIX_GNAT_WRAPPER_START_HOOK"
5fi
6
7if [ -z "$NIX_GNAT_WRAPPER_FLAGS_SET" ]; then
8 source @out@/nix-support/add-flags.sh
9fi
10
11source @out@/nix-support/utils.sh
12
13
14# Figure out if linker flags should be passed. GCC prints annoying
15# warnings when they are not needed.
16dontLink=0
17getVersion=0
18nonFlagArgs=0
19
20for i in "$@"; do
21 if [ "$i" = -c ]; then
22 dontLink=1
23 elif [ "$i" = -M ]; then
24 dontLink=1
25 elif [ "${i:0:1}" != - ]; then
26 nonFlagArgs=1
27 elif [ "$i" = -m32 ]; then
28 if [ -e @out@/nix-support/dynamic-linker-m32 ]; then
29 NIX_LDFLAGS="$NIX_LDFLAGS -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)"
30 fi
31 fi
32done
33
34# If we pass a flag like -Wl, then gcc will call the linker unless it
35# can figure out that it has to do something else (e.g., because of a
36# "-c" flag). So if no non-flag arguments are given, don't pass any
37# linker flags. This catches cases like "gcc" (should just print
38# "gcc: no input files") and "gcc -v" (should print the version).
39if [ "$nonFlagArgs" = 0 ]; then
40 dontLink=1
41fi
42
43
44# Optionally filter out paths not refering to the store.
45params=("$@")
46if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" ]; then
47 rest=()
48 n=0
49 while [ $n -lt ${#params[*]} ]; do
50 p=${params[n]}
51 p2=${params[$((n+1))]}
52 if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
53 skip $p
54 elif [ "${p:0:3}" = -I/ ] && badPath "${p:2}"; then
55 skip $p
56 elif [ "${p:0:4}" = -aI/ ] && badPath "${p:3}"; then
57 skip $p
58 elif [ "${p:0:4}" = -aO/ ] && badPath "${p:3}"; then
59 skip $p
60 else
61 rest=("${rest[@]}" "$p")
62 fi
63 n=$((n + 1))
64 done
65 params=("${rest[@]}")
66fi
67
68
69# Add the flags for the GNAT compiler proper.
70extraAfter=($NIX_GNATFLAGS_COMPILE)
71extraBefore=()
72
73if [ "`basename $0`x" = "gnatmakex" ]; then
74 extraBefore=("--GNATBIND=@out@/bin/gnatbind --GNATLINK=@out@/bin/gnatlink ")
75fi
76
77# Add the flags that should be passed to the linker (and prevent
78# `ld-wrapper' from adding NIX_LDFLAGS again).
79#for i in $NIX_LDFLAGS_BEFORE; do
80# extraBefore=(${extraBefore[@]} "-largs $i")
81#done
82
83# Optionally print debug info.
84if [ -n "$NIX_DEBUG" ]; then
85 echo "original flags to @prog@:" >&2
86 for i in "${params[@]}"; do
87 echo " $i" >&2
88 done
89 echo "extraBefore flags to @prog@:" >&2
90 for i in ${extraBefore[@]}; do
91 echo " $i" >&2
92 done
93 echo "extraAfter flags to @prog@:" >&2
94 for i in ${extraAfter[@]}; do
95 echo " $i" >&2
96 done
97fi
98
99if [ -n "$NIX_GNAT_WRAPPER_EXEC_HOOK" ]; then
100 source "$NIX_GNAT_WRAPPER_EXEC_HOOK"
101fi
102
103exec @prog@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]}