-
Notifications
You must be signed in to change notification settings - Fork 162
/
build.sh
executable file
·136 lines (111 loc) · 2.64 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env bash
export LC_ALL=C
pushd "${0%/*}" &>/dev/null
export CC=clang
export CXX=clang++
set -e
function verbose_cmd
{
echo "$@"
eval "$@"
}
function extract()
{
echo "extracting $(basename $1) ..."
local tarflags="xf"
case $1 in
*.tar.xz)
xz -dc $1 | tar $tarflags -
;;
*.tar.gz)
gunzip -dc $1 | tar $tarflags -
;;
*.tar.bz2)
bzip2 -dc $1 | tar $tarflags -
;;
*)
echo "unhandled archive type"
exit 1
;;
esac
}
if [ $# -lt 2 ]; then
echo "usage: $0 iPhoneOS.sdk.tar* <target cpu>" 1>&2
echo "i.e. $0 /path/to/iPhoneOS.sdk.tar.xz armv7" 1>&2
exit 1
fi
TRIPLE="arm-apple-darwin11"
TARGETDIR="$PWD/target"
SDKDIR="$TARGETDIR/SDK"
if [ -d $TARGETDIR ]; then
echo "cleaning up ..."
rm -rf $TARGETDIR
fi
mkdir -p $TARGETDIR
mkdir -p $TARGETDIR/bin
mkdir -p $SDKDIR
echo ""
echo "*** extracting SDK ***"
echo ""
pushd $SDKDIR &>/dev/null
SDK_VERSION=$(echo $1 | grep -P -o "[0-9].[0-9]+" | head -1)
if [ -z "$SDK_VERSION" ]; then
echo "iPhoneOS Version must be in the SDK filename!" 1>&2
exit 1
fi
extract $1
SYSLIB=$(find $SDKDIR -name "libSystem.dylib" | head -n1)
if [ -z "$SYSLIB" ]; then
echo "SDK should contain libSystem.dylib" 1>&2
exit 1
fi
SYSROOT="$(dirname $SYSLIB)/../.."
set +e
mv $SYSROOT/* $SDKDIR 2>/dev/null
set -e
popd &>/dev/null
echo ""
echo "*** building wrapper ***"
echo ""
echo "int main(){return 0;}" | $CC -xc -O2 -o $TARGETDIR/bin/dsymutil -
verbose_cmd $CC -O2 -Wall -Wextra -pedantic wrapper.c \
-DTARGET_CPU=\"\\\"$2\\\"\" \
-DOS_VER_MIN=\"\\\"$SDK_VERSION\\\"\" \
-o $TARGETDIR/bin/$TRIPLE-clang
pushd $TARGETDIR/bin &>/dev/null
verbose_cmd ln -sf $TRIPLE-clang $TRIPLE-clang++
popd &>/dev/null
echo ""
echo "*** building ldid ***"
echo ""
rm -rf tmp
mkdir -p tmp
pushd tmp &>/dev/null
git clone git://git.saurik.com/ldid.git
pushd ldid &>/dev/null
git clone git://git.saurik.com/minimal.git
cp ../../LDID.Makefile Makefile
make INSTALLPREFIX=$TARGETDIR -j4 install
popd &>/dev/null
popd &>/dev/null
echo ""
echo "*** building cctools / ld64 ***"
echo ""
pushd ../../cctools &>/dev/null
git clean -fdx . &>/dev/null || true
./autogen.sh
./configure --target=$TRIPLE --prefix=$TARGETDIR
make -j4 && make install
popd &>/dev/null
echo ""
echo "*** checking toolchain ***"
echo ""
export PATH=$TARGETDIR/bin:$PATH
echo "int main(){return 0;}" | $TRIPLE-clang -xc -O2 -o test - 1>/dev/null || exit 1
rm test
echo "OK"
echo ""
echo "*** all done ***"
echo ""
echo "do not forget to add $TARGETDIR/bin to your PATH variable"
echo ""