1# Unpack the bootstrap tools tarball.
2echo Unpacking the bootstrap tools...
3$builder mkdir $out
4< $tarball $builder unxz | $builder tar x -C $out
5
6# Set the ELF interpreter / RPATH in the bootstrap binaries.
7echo Patching the bootstrap tools...
8
9if test -f $out/lib/ld.so.?; then
10 # MIPS case
11 LD_BINARY=$out/lib/ld.so.?
12elif test -f $out/lib/ld64.so.?; then
13 # ppc64(le)
14 LD_BINARY=$out/lib/ld64.so.?
15else
16 # i686, x86_64 and armv5tel
17 LD_BINARY=$out/lib/ld-*so.?
18fi
19
20# On x86_64, ld-linux-x86-64.so.2 barfs on patchelf'ed programs. So
21# use a copy of patchelf.
22LD_LIBRARY_PATH=$out/lib $LD_BINARY $out/bin/cp $out/bin/patchelf .
23
24for i in $out/bin/* $out/libexec/gcc/*/*/*; do
25 if [ -L "$i" ]; then continue; fi
26 if [ -z "${i##*/liblto*}" ]; then continue; fi
27 echo patching "$i"
28 LD_LIBRARY_PATH=$out/lib $LD_BINARY \
29 ./patchelf --set-interpreter $LD_BINARY --set-rpath $out/lib --force-rpath "$i"
30done
31
32for i in $out/lib/librt-*.so $out/lib/libpcre*; do
33 if [ -L "$i" ]; then continue; fi
34 echo patching "$i"
35 $out/bin/patchelf --set-rpath $out/lib --force-rpath "$i"
36done
37
38# Fix the libc linker script.
39export PATH=$out/bin
40cat $out/lib/libc.so | sed "s|/nix/store/e*-[^/]*/|$out/|g" > $out/lib/libc.so.tmp
41mv $out/lib/libc.so.tmp $out/lib/libc.so
42cat $out/lib/libpthread.so | sed "s|/nix/store/e*-[^/]*/|$out/|g" > $out/lib/libpthread.so.tmp
43mv $out/lib/libpthread.so.tmp $out/lib/libpthread.so
44
45# Provide some additional symlinks.
46ln -s bash $out/bin/sh
47ln -s bzip2 $out/bin/bunzip2
48
49# Provide a gunzip script.
50cat > $out/bin/gunzip <<EOF
51#!$out/bin/sh
52exec $out/bin/gzip -d "\$@"
53EOF
54chmod +x $out/bin/gunzip
55
56# Provide fgrep/egrep.
57echo "#! $out/bin/sh" > $out/bin/egrep
58echo "exec $out/bin/grep -E \"\$@\"" >> $out/bin/egrep
59echo "#! $out/bin/sh" > $out/bin/fgrep
60echo "exec $out/bin/grep -F \"\$@\"" >> $out/bin/fgrep
61
62# Provide xz (actually only xz -d will work).
63echo "#! $out/bin/sh" > $out/bin/xz
64echo "exec $builder unxz \"\$@\"" >> $out/bin/xz
65
66chmod +x $out/bin/egrep $out/bin/fgrep $out/bin/xz