lol
1set -e
2
3# Unpack the bootstrap tools tarball.
4echo Unpacking the bootstrap tools...
5$mkdir $out
6$bzip2 -d < $tarball | (cd $out && $cpio -i)
7
8# Set the ELF interpreter / RPATH in the bootstrap binaries.
9echo Patching the tools...
10
11export PATH=$out/bin
12
13for i in $out/bin/*; do
14 if ! test -L $i; then
15 echo patching $i
16 install_name_tool -add_rpath $out/lib $i || true
17 fi
18done
19
20install_name_tool \
21 -id $out/lib/system/libsystem_c.dylib \
22 $out/lib/system/libsystem_c.dylib
23
24install_name_tool \
25 -id $out/lib/system/libsystem_kernel.dylib \
26 $out/lib/system/libsystem_kernel.dylib
27
28# TODO: this logic basically duplicates similar logic in the Libsystem expression. Deduplicate them!
29libs=$(cat $reexportedLibrariesFile | grep -v '^#')
30
31for i in $libs; do
32 if [ "$i" != "/usr/lib/system/libsystem_kernel.dylib" ] && [ "$i" != "/usr/lib/system/libsystem_c.dylib" ]; then
33 args="$args -reexport_library $i"
34 fi
35done
36
37ld -macosx_version_min 10.7 \
38 -arch x86_64 \
39 -dylib \
40 -o $out/lib/libSystem.B.dylib \
41 -compatibility_version 1.0 \
42 -current_version 1226.10.1 \
43 -reexport_library $out/lib/system/libsystem_c.dylib \
44 -reexport_library $out/lib/system/libsystem_kernel.dylib \
45 $args
46
47ln -s libSystem.B.dylib $out/lib/libSystem.dylib
48
49for name in c dbm dl info m mx poll proc pthread rpcsvc util gcc_s.10.4 gcc_s.10.5; do
50 ln -s libSystem.dylib $out/lib/lib$name.dylib
51done
52
53ln -s libresolv.9.dylib $out/lib/libresolv.dylib
54
55for i in $out/lib/*.dylib $out/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation; do
56 if test ! -L "$i" -a "$i" != "$out/lib/libSystem*.dylib"; then
57 echo "Patching $i"
58
59 id=$(otool -D "$i" | tail -n 1)
60 install_name_tool -id "$(dirname $i)/$(basename $id)" $i
61
62 libs=$(otool -L "$i" | tail -n +2 | grep -v libSystem | cat)
63 if [ -n "$libs" ]; then
64 install_name_tool -add_rpath $out/lib $i
65 fi
66 fi
67done
68
69ln -s bash $out/bin/sh
70ln -s bzip2 $out/bin/bunzip2
71
72# Provide a gunzip script.
73cat > $out/bin/gunzip <<EOF
74#!$out/bin/sh
75exec $out/bin/gzip -d "\$@"
76EOF
77chmod +x $out/bin/gunzip
78
79# Provide fgrep/egrep.
80echo "#! $out/bin/sh" > $out/bin/egrep
81echo "exec $out/bin/grep -E \"\$@\"" >> $out/bin/egrep
82echo "#! $out/bin/sh" > $out/bin/fgrep
83echo "exec $out/bin/grep -F \"\$@\"" >> $out/bin/fgrep
84
85cat >$out/bin/dsymutil << EOF
86#!$out/bin/sh
87EOF
88
89chmod +x $out/bin/egrep $out/bin/fgrep $out/bin/dsymutil