forked from fopina/transmission-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·259 lines (209 loc) · 6.98 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/bin/bash
# original script taken from iTransmission project
# (https://github.com/ccp0101/iTransmission/blob/master/make_depend/build.sh)
. configuration
export TEMP_DIR="$PWD/temp"
export PATCH_DIR="$PWD/patches"
export BUILD_FILTER="ssl,curl,trans,libev"
function do_abort {
echo $1 >&2
exit 1
}
function do_loadenv {
export BUILD_DIR="$PWD/out/${ARCH}"
export BUILD_DIR_TRANS="$BUILD_DIR/transmission"
if [ ${ARCH} = "i386" ]
then
PLATFORM="iPhoneSimulator"
elif [ ${ARCH} = "armv7" ]
then
PLATFORM="iPhoneOS"
elif [ ${ARCH} = "armv6" ]
then
PLATFORM="iPhoneOS"
elif [ ${ARCH} = "system" ]
then
PLATFORM="none"
else
do_abort "invalid arch ${ARCH} specified"
fi
}
function do_export {
unset CFLAGS
if [[ ${ARCH} != "system" ]]; then
export DEVROOT="${DEVFOLDER}/Platforms/${PLATFORM}.platform/Developer"
export SDKROOT="${DEVFOLDER}/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}$SDK_VERSION.sdk"
export LD=${DEVROOT}/usr/bin/ld
export CPP="/usr/bin/cpp"
export CXX="${DEVROOT}/usr/bin/g++"
unset AR
unset AS
export NM=${DEVROOT}/usr/bin/nm
export CXXCPP="/usr/bin/cpp"
export RANLIB="${DEVROOT}/usr/bin/ranlib"
export CFLAGS="-arch ${ARCH} -isysroot ${SDKROOT}"
export LDFLAGS="-L${SDKROOT}/usr/lib -L${DEVROOT}/usr/lib -isysroot ${SDKROOT} -Wl,-syslibroot $SDKROOT"
export HAVE_CXX="yes"
fi
export CC="${DEVROOT}/usr/bin/gcc"
export CFLAGS="${CFLAGS} -I${BUILD_DIR}/include -I${BUILD_DIR_TRANS}/include -I${SDKROOT}/usr/include -pipe -no-cpp-precomp"
export CXXFLAGS="${CFLAGS}"
export LDFLAGS="-L${BUILD_DIR}/lib -L${BUILD_DIR_TRANS}/lib -pipe -no-cpp-precomp ${LDFLAGS}"
export COMMON_OPTIONS="--disable-shared --enable-static --disable-ipv6 --disable-manual "
if [ ${PLATFORM} = "iPhoneOS" ]
then
COMMON_OPTIONS="--host arm-apple-darwin ${COMMON_OPTIONS}"
elif [ ${PLATFORM} = "iPhoneSimulator" ]
then
COMMON_OPTIONS="--host i386-apple-darwin ${COMMON_OPTIONS}"
fi
export PKG_CONFIG_PATH="${SDKROOT}/usr/lib/pkgconfig:${BUILD_DIR}/lib/pkgconfig"
}
function do_openssl {
export PACKAGE_NAME="openssl-${OPENSSL_VERSION}"
pushd ${TEMP_DIR}
if [ ! -e "${PACKAGE_NAME}.tar.gz" ]
then
/usr/bin/curl -O -L "http://www.openssl.org/source/${PACKAGE_NAME}.tar.gz" || do_abort "$FUNCNAME: fetch failed "
fi
rm -rf "${PACKAGE_NAME}"
tar zxvf "${PACKAGE_NAME}.tar.gz" || do_abort "$FUNCNAME: unpack failed "
pushd ${PACKAGE_NAME}
do_export
./configure BSD-generic32 --openssldir=${BUILD_DIR} || do_abort "$FUNCNAME: configure failed "
# Patch for iOS, taken from https://github.com/st3fan/ios-openssl/blame/master/build.sh
perl -i -pe "s|static volatile sig_atomic_t intr_signal|static volatile int intr_signal|" ./crypto/ui/ui_openssl.c
perl -i -pe "s|^CC= gcc|CC= ${CC}|g" Makefile
perl -i -pe "s|^CFLAG= (.*)|CFLAG= ${CFLAGS} $1|g" Makefile
if [ ${PLATFORM} = "iPhoneSimulator" ]
then
pushd crypto/bn
rm -f bn_prime.h
perl bn_prime.pl >bn_prime.h
popd
fi
make -j ${PARALLEL_NUM} || do_abort "$FUNCNAME: make failed "
make install || do_abort "$FUNCNAME: install failed "
rm -rf ${BUILD_DIR}/share/man
popd
popd
}
function do_curl {
export PACKAGE_NAME="curl-${CURL_VERSION}"
pushd ${TEMP_DIR}
if [ ! -e "${PACKAGE_NAME}.tar.gz" ]
then
/usr/bin/curl -O -L "http://www.execve.net/curl/${PACKAGE_NAME}.tar.gz" || do_abort "$FUNCNAME: fetch failed "
fi
if [[ -z $DONT_OVERWRITE ]]; then
rm -rf "${PACKAGE_NAME}"
tar zxvf "${PACKAGE_NAME}.tar.gz" || do_abort "$FUNCNAME: unpack failed "
fi
pushd ${PACKAGE_NAME}
do_export
./configure --prefix="${BUILD_DIR}" ${COMMON_OPTIONS} --with-random=/dev/urandom --with-ssl --with-zlib LDFLAGS="${LDFLAGS}" || do_abort "$FUNCNAME: configure failed "
make -j ${PARALLEL_NUM} || do_abort "$FUNCNAME: make failed "
make install || do_abort "$FUNCNAME: install failed "
popd
popd
}
function do_libevent {
export PACKAGE_NAME="libevent-${LIBEVENT_VERSION}"
pushd ${TEMP_DIR}
if [ ! -e "${PACKAGE_NAME}.tar.gz" ]
then
/usr/bin/curl -O -L "https://github.com/downloads/libevent/libevent/${PACKAGE_NAME}.tar.gz" || do_abort "$FUNCNAME: fetch failed "
fi
if [[ -z $DONT_OVERWRITE ]]; then
rm -rf "${PACKAGE_NAME}"
tar zxvf "${PACKAGE_NAME}.tar.gz" || do_abort "$FUNCNAME: unpack failed "
fi
pushd ${PACKAGE_NAME}
# libevent patch to hardcode google public dns servers for iOS
# as there is no /etc/resolv.conf in iOS
# (TODO... it properly.. XD)
patch -N < ${PATCH_DIR}/libevent-nameservers.patch
do_export
if [[ ! -z $DONT_OVERWRITE ]]; then
make clean
fi
./configure --prefix="${BUILD_DIR}" ${COMMON_OPTIONS} || do_abort "$FUNCNAME: configure failed "
make -j ${PARALLEL_NUM} || do_abort "$FUNCNAME: make failed "
make install || do_abort "$FUNCNAME: install failed "
popd
popd
}
function do_transmission {
export PACKAGE_NAME="transmission-${TRANSMISSION_VERSION}"
pushd ${TEMP_DIR}
if [ ! -e "${PACKAGE_NAME}.tar.bz2" ]
then
/usr/bin/curl -O -L "http://download.transmissionbt.com/files/${PACKAGE_NAME}.tar.bz2" || do_abort "$FUNCNAME: fetch failed "
fi
if [[ -z $DONT_OVERWRITE ]]; then
rm -rf "${PACKAGE_NAME}"
tar jxvf "${PACKAGE_NAME}.tar.bz2" || do_abort "$FUNCNAME: unpack failed "
fi
pushd ${PACKAGE_NAME}
#apply whitelist patch (to allow LAN clients by default)
pushd libtransmission
patch -N < ${PATCH_DIR}/rpc_lan_whitelist.patch
popd
do_export
if [[ ! -z $DONT_OVERWRITE ]]; then
make clean
fi
./configure --prefix="${BUILD_DIR_TRANS}" ${COMMON_OPTIONS} --enable-largefile --enable-utp --disable-nls --enable-lightweight --enable-cli --enable-daemon --disable-mac --disable-gtk --with-kqueue --enable-debug --with-gtk=no || do_abort "$FUNCNAME: configure failed "
if [ ! -e "${SDKROOT}/usr/include/net/route.h" ]
then
mkdir -p ${BUILD_DIR_TRANS}/include/net
cp "${DEVFOLDER}/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${SDK_VERSION}.sdk/usr/include/net/route.h" "${BUILD_DIR_TRANS}/include/net/route.h"
fi
make -j ${PARALLEL_NUM} || do_abort "$FUNCNAME: make failed "
make install || do_abort "$FUNCNAME: install failed "
# Default installation doesn't copy library and header files
mkdir -p ${BUILD_DIR_TRANS}/include/libtransmission
mkdir -p ${BUILD_DIR_TRANS}/lib
find ./libtransmission -name "*.h" -exec cp "{}" ${BUILD_DIR_TRANS}/include/libtransmission \;
find . -name "*.a" -exec cp "{}" ${BUILD_DIR_TRANS}/lib \;
popd
popd
}
do_loadenv
while getopts ":o:a:ne" opt; do
case $opt in
a)
export ARCH="$OPTARG"
do_loadenv
;;
o)
export BUILD_FILTER="$OPTARG"
;;
n)
export DONT_OVERWRITE="YES"
;;
e)
export BUILD_FILTER=""
do_export
;;
\?)
do_abort "Invalid option: -$OPTARG"
;;
:)
do_abort "Option -$OPTARG requires an argument."
;;
esac
done
mkdir -p ${TEMP_DIR}
if [[ $BUILD_FILTER == *ssl* ]]; then
do_openssl
fi
if [[ $BUILD_FILTER == *curl* ]]; then
do_curl
fi
if [[ $BUILD_FILTER == *libev* ]]; then
do_libevent
fi
if [[ $BUILD_FILTER == *trans* ]]; then
do_transmission
fi