nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
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# path to version-specific libraries, like libstdc++.so
21LIBSTDCXX_SO_DIR=$(echo $out/lib/gcc/*/*)
22
23# Move version-specific libraries out to avoid library mix when we
24# upgrade gcc.
25# TODO(trofi): update bootstrap tarball script and tarballs to put them
26# into expected location directly.
27LD_LIBRARY_PATH=$out/lib $LD_BINARY $out/bin/mv $out/lib/libstdc++.* $LIBSTDCXX_SO_DIR/
28
29# On x86_64, ld-linux-x86-64.so.2 barfs on patchelf'ed programs. So
30# use a copy of patchelf.
31LD_LIBRARY_PATH=$out/lib $LD_BINARY $out/bin/cp $out/bin/patchelf .
32
33# Older versions of the bootstrap-files did not compile their
34# patchelf with -static-libgcc, so we have to be very careful not to
35# run patchelf on the same copy of libgcc_s that it links against.
36LD_LIBRARY_PATH=$out/lib $LD_BINARY $out/bin/cp $out/lib/libgcc_s.so.1 .
37LD_LIBRARY_PATH=.:$out/lib:$LIBSTDCXX_SO_DIR $LD_BINARY \
38 ./patchelf --set-rpath $out/lib --force-rpath $out/lib/libgcc_s.so.1
39
40for i in $out/bin/* $out/libexec/gcc/*/*/*; do
41 if [ -L "$i" ]; then continue; fi
42 if [ -z "${i##*/liblto*}" ]; then continue; fi
43 echo patching "$i"
44 LD_LIBRARY_PATH=$out/lib:$LIBSTDCXX_SO_DIR $LD_BINARY \
45 ./patchelf --set-interpreter $LD_BINARY --set-rpath $out/lib:$LIBSTDCXX_SO_DIR --force-rpath "$i"
46done
47
48for i in $out/lib/librt-*.so $out/lib/libpcre*; do
49 if [ -L "$i" ]; then continue; fi
50 echo patching "$i"
51 $out/bin/patchelf --set-rpath $out/lib --force-rpath "$i"
52done
53
54export PATH=$out/bin
55
56# Provide some additional symlinks.
57ln -s bash $out/bin/sh
58ln -s bzip2 $out/bin/bunzip2
59
60# Provide a gunzip script.
61cat > $out/bin/gunzip <<EOF
62#!$out/bin/sh
63exec $out/bin/gzip -d "\$@"
64EOF
65chmod +x $out/bin/gunzip
66
67# Provide fgrep/egrep.
68echo "#! $out/bin/sh" > $out/bin/egrep
69echo "exec $out/bin/grep -E \"\$@\"" >> $out/bin/egrep
70echo "#! $out/bin/sh" > $out/bin/fgrep
71echo "exec $out/bin/grep -F \"\$@\"" >> $out/bin/fgrep
72
73# Provide xz (actually only xz -d will work).
74echo "#! $out/bin/sh" > $out/bin/xz
75echo "exec $builder unxz \"\$@\"" >> $out/bin/xz
76
77chmod +x $out/bin/egrep $out/bin/fgrep $out/bin/xz