@@ -0,0 +1,214 @@
1+source $stdenv/setup
2+
3+
4+mkdir -p $out/bin
5+mkdir -p $out/nix-support
6+
7+
8+if test -z "$nativeLibc"; then
9+ dynamicLinker="$libc/lib/$dynamicLinker"
10+ echo $dynamicLinker > $out/nix-support/dynamic-linker
11+
12+ if test -e $libc/lib/32/ld-linux.so.2; then
13+ echo $libc/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32
14+ fi
15+
16+ # The "-B$libc/lib/" flag is a quick hack to force gcc to link
17+ # against the crt1.o from our own glibc, rather than the one in
18+ # /usr/lib. (This is only an issue when using an `impure'
19+ # compiler/linker, i.e., one that searches /usr/lib and so on.)
20+ #
21+ # Unfortunately, setting -B appears to override the default search
22+ # path. Thus, the gcc-specific "../includes-fixed" directory is
23+ # now longer searched and glibc's <limits.h> header fails to
24+ # compile, because it uses "#include_next <limits.h>" to find the
25+ # limits.h file in ../includes-fixed. To remedy the problem,
26+ # another -idirafter is necessary to add that directory again.
27+ echo "-B$libc/lib/ -idirafter $libc/include -idirafter $gcc/lib/gcc/*/*/include-fixed" > $out/nix-support/libc-cflags
28+
29+ echo "-L$libc/lib" > $out/nix-support/libc-ldflags
30+
31+ # The dynamic linker is passed in `ldflagsBefore' to allow
32+ # explicit overrides of the dynamic linker by callers to gcc/ld
33+ # (the *last* value counts, so ours should come first).
34+ echo "-dynamic-linker" $dynamicLinker > $out/nix-support/libc-ldflags-before
35+fi
36+
37+if test -n "$nativeTools"; then
38+ gccPath="$nativePrefix/bin"
39+ ldPath="$nativePrefix/bin"
40+else
41+ if test -e "$gcc/lib64"; then
42+ gccLDFlags="$gccLDFlags -L$gcc/lib64"
43+ fi
44+ gccLDFlags="$gccLDFlags -L$gcc/lib"
45+ if [ -n "$langVhdl" ]; then
46+ gccLDFlags="$gccLDFlags -L$zlib/lib"
47+ fi
48+ echo "$gccLDFlags" > $out/nix-support/gcc-ldflags
49+
50+ # GCC shows $gcc/lib in `gcc -print-search-dirs', but not
51+ # $gcc/lib64 (even though it does actually search there...)..
52+ # This confuses libtool. So add it to the compiler tool search
53+ # path explicitly.
54+ if test -e "$gcc/lib64"; then
55+ gccCFlags="$gccCFlags -B$gcc/lib64"
56+ fi
57+
58+ # Find the gcc libraries path (may work only without multilib)
59+ if [ -n "$langAda" ]; then
60+ basePath=`echo $gcc/lib/*/*/*`
61+ gccCFlags="$gccCFlags -B$basePath -I$basePath/adainclude"
62+
63+ gnatCFlags="-aI$basePath/adainclude -aO$basePath/adalib"
64+ echo "$gnatCFlags" > $out/nix-support/gnat-cflags
65+ fi
66+ echo "$gccCFlags" > $out/nix-support/gcc-cflags
67+
68+ gccPath="$gcc/bin"
69+ # On Illumos/Solaris we might prefer native ld
70+ if test -n "$nativePrefix"; then
71+ ldPath="$nativePrefix/bin"
72+ else
73+ ldPath="$binutils/bin"
74+ fi;
75+fi
76+
77+
78+doSubstitute() {
79+ local src=$1
80+ local dst=$2
81+ local ld="$ldPath/ld"
82+ if $ld -V 2>&1 |grep Solaris; then
83+ # Use Solaris specific linker wrapper
84+ ld="$out/bin/ld-solaris"
85+ fi
86+ # Can't use substitute() here, because replace may not have been
87+ # built yet (in the bootstrap).
88+ sed \
89+ -e "s^@out@^$out^g" \
90+ -e "s^@shell@^$shell^g" \
91+ -e "s^@gcc@^$gcc^g" \
92+ -e "s^@gccProg@^$gccProg^g" \
93+ -e "s^@gnatProg@^$gnatProg^g" \
94+ -e "s^@gnatlinkProg@^$gnatlinkProg^g" \
95+ -e "s^@binutils@^$binutils^g" \
96+ -e "s^@coreutils@^$coreutils^g" \
97+ -e "s^@libc@^$libc^g" \
98+ -e "s^@ld@^$ld^g" \
99+ < "$src" > "$dst"
100+}
101+
102+
103+# Make wrapper scripts around gcc, g++, and gfortran. Also make symlinks
104+# cc, c++, and f77.
105+mkGccWrapper() {
106+ local dst=$1
107+ local src=$2
108+
109+ if ! test -f "$src"; then
110+ echo "$src does not exist (skipping)"
111+ return 1
112+ fi
113+
114+ gccProg="$src"
115+ doSubstitute "$gccWrapper" "$dst"
116+ chmod +x "$dst"
117+}
118+
119+mkGnatWrapper() {
120+ local dst=$1
121+ local src=$2
122+
123+ if ! test -f "$src"; then
124+ echo "$src does not exist (skipping)"
125+ return 1
126+ fi
127+
128+ gnatProg="$src"
129+ doSubstitute "$gnatWrapper" "$dst"
130+ chmod +x "$dst"
131+}
132+
133+mkGnatLinkWrapper() {
134+ local dst=$1
135+ local src=$2
136+
137+ if ! test -f "$src"; then
138+ echo "$src does not exist (skipping)"
139+ return 1
140+ fi
141+
142+ gnatlinkProg="$src"
143+ doSubstitute "$gnatlinkWrapper" "$dst"
144+ chmod +x "$dst"
145+}
146+
147+if mkGccWrapper $out/bin/gcc $gccPath/gcc
148+then
149+ ln -sv gcc $out/bin/cc
150+fi
151+
152+if mkGccWrapper $out/bin/g++ $gccPath/g++
153+then
154+ ln -sv g++ $out/bin/c++
155+fi
156+
157+mkGccWrapper $out/bin/cpp $gccPath/cpp || true
158+
159+if mkGccWrapper $out/bin/gfortran $gccPath/gfortran
160+then
161+ ln -sv gfortran $out/bin/g77
162+ ln -sv gfortran $out/bin/f77
163+fi
164+
165+mkGccWrapper $out/bin/gcj $gccPath/gcj || true
166+
167+mkGccWrapper $out/bin/gccgo $gccPath/gccgo || true
168+
169+mkGccWrapper $out/bin/gnatgcc $gccPath/gnatgcc || true
170+mkGnatWrapper $out/bin/gnatmake $gccPath/gnatmake || true
171+mkGnatWrapper $out/bin/gnatbind $gccPath/gnatbind || true
172+mkGnatLinkWrapper $out/bin/gnatlink $gccPath/gnatlink || true
173+
174+if [ -f $gccPath/ghdl ]; then
175+ ln -sf $gccPath/ghdl $out/bin/ghdl
176+fi
177+
178+
179+# Create a symlink to as (the assembler). This is useful when a
180+# gcc-wrapper is installed in a user environment, as it ensures that
181+# the right assembler is called.
182+ln -s $ldPath/as $out/bin/as
183+
184+
185+# Make a wrapper around the linker.
186+doSubstitute "$ldWrapper" "$out/bin/ld"
187+chmod +x "$out/bin/ld"
188+
189+# Copy solaris ld wrapper if needed
190+if $ldPath/ld -V 2>&1 |grep Solaris; then
191+ # Use Solaris specific linker wrapper
192+ sed -e "s^@ld@^$ldPath/ld^g" < "$ldSolarisWrapper" > "$out/bin/ld-solaris"
193+ chmod +x "$out/bin/ld-solaris"
194+fi
195+
196+
197+# Emit a setup hook. Also store the path to the original GCC and
198+# Glibc.
199+test -n "$gcc" && echo $gcc > $out/nix-support/orig-gcc
200+test -n "$libc" && echo $libc > $out/nix-support/orig-libc
201+
202+doSubstitute "$addFlags" "$out/nix-support/add-flags.sh"
203+
204+doSubstitute "$setupHook" "$out/nix-support/setup-hook"
205+
206+cp -p $utils $out/nix-support/utils.sh
207+
208+
209+# Propagate the wrapped gcc so that if you install the wrapper, you get
210+# tools like gcov, the manpages, etc. as well (including for binutils
211+# and Glibc).
212+if test -z "$nativeTools"; then
213+ echo $gcc $binutils $libc > $out/nix-support/propagated-user-env-packages
214+fi