-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.sh
executable file
·269 lines (216 loc) · 4.24 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
260
261
262
263
264
265
266
267
268
269
#!/bin/sh
#
# SQLite3 compile options
#
CFLAGS=" \
-DSQLITE_HAS_CODEC \
-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT \
-DSQLITE_ENABLE_COLUMN_METADATA \
-DSQLITE_ENABLE_STAT3 \
-DSQLITE_ENABLE_RTREE \
-DSQLITE_ENABLE_FTS3 \
-DSQLITE_ENABLE_FTS3_PARENTHESIS \
-DSQLITE_ENABLE_FTS4 \
-DSQLITE_SECURE_DELETE \
-DSQLITE_ENABLE_ICU \
-DSQLITE_SOUNDEX \
-DSQLITE_DEFAULT_FOREIGN_KEYS=1 \
-I. -I/usr/local/include"
LDFLAGS="-lcrypto -licuuc -licui18n -L/usr/local/lib"
# fix FreeBSD include
UNAME=$(uname)
if [ "x${UNAME}" = "xFreeBSD" ]; then
CFLAGS="${CFLAGS} -include /usr/include/sys/stat.h"
fi
#
# Get PHP source code (installed version)
#
PHP_CONFIG=$(which php-config)
if [ "x${PHP_CONFIG}" = "x" ]; then
echo "Error: php-config not found"
exit 1
fi
PHP_VER=$(${PHP_CONFIG} --version | cut -d '-' -f 1)
PHP_MAJOR_VER=${PHP_VER:0:1}
if [ "x${PHP_VER}" = "x" ]; then
echo "Error: unknown php version"
exit 1
fi
PHP_SRC="php-${PHP_VER}"
PHP_TGZ="${PHP_SRC}.tar.gz"
if [ ! -f "${PHP_TGZ}" ]; then
wget "http://museum.php.net/php${PHP_MAJOR_VER}/${PHP_TGZ}"
if [ $? -ne 0 ]; then
# newest version?
wget -O "${PHP_TGZ}" "http://ru2.php.net/get/${PHP_TGZ}/from/this/mirror"
if [ $? -ne 0 ]; then
exit $?
fi
fi
fi
if [ ! -d "${PHP_SRC}" ]; then
tar -xf "${PHP_TGZ}" -C ./
if [ $? -ne 0 ]; then
exit $?
fi
fi
#
# Get SQLCipher source code and make SQLite Amalgamation
#
SQLCIPHER_SRC="sqlcipher.git"
if [ ! -d "${SQLCIPHER_SRC}" ]; then
git clone "git://github.com/sqlcipher/sqlcipher.git" "${SQLCIPHER_SRC}"
if [ $? -ne 0 ]; then
exit $?
fi
fi
if [ ! -f "${SQLCIPHER_SRC}/sqlite3.c" ]; then
cd "${SQLCIPHER_SRC}"
make distclean
# subject to change (see http://www.sqlite.org/compile.html)
./configure \
--disable-shared \
--enable-tempstore=yes \
CFLAGS="${CFLAGS}" \
LDFLAGS="${LDFLAGS}"
if [ $? -ne 0 ]; then
exit $?
fi
make
if [ $? -ne 0 ]; then
exit $?
fi
cd ..
fi
#
# Clone pdo_sqlite sources for pdo_sqlcipher
#
BUILD_DIR="build"
if [ -d "${BUILD_DIR}" ]; then
rm -rf "${BUILD_DIR}"
if [ $? -ne 0 ]; then
exit $?
fi
fi
mkdir -p "${BUILD_DIR}"
if [ $? -ne 0 ]; then
exit $?
fi
PDO_SQLITE="${PHP_SRC}/ext/pdo_sqlite"
cp "${PDO_SQLITE}/"*.c "${PDO_SQLITE}"/*.h "${BUILD_DIR}/"
if [ $? -ne 0 ]; then
exit $?
fi
# magic :)
for FILE in "${BUILD_DIR}"/*
do
cat "${FILE}" | \
sed -e 's/sqlite/sqlcipher/g' | \
sed -e 's/SQLite/SQLCipher/g' | \
sed -e 's/PDO_SQLITE/PDO_SQLCIPHER/g' > \
"${FILE}.tmp"
if [ $? -ne 0 ]; then
exit $?
fi
NEW_FILE=$(echo ${FILE} | sed 's/sqlite/sqlcipher/')
mv "${FILE}.tmp" "${NEW_FILE}"
if [ $? -ne 0 ]; then
exit $?
fi
if [ "${NEW_FILE}" != "${FILE}" ]; then
rm -f "${FILE}"
if [ $? -ne 0 ]; then
exit $?
fi
fi
done
# magic for sqlite3 api sources
cp "${SQLCIPHER_SRC}/sqlite3.c" "${BUILD_DIR}/sqlcipher3.c"
if [ $? -ne 0 ]; then
exit $?
fi
cp "${SQLCIPHER_SRC}/sqlite3.h" "${BUILD_DIR}/sqlcipher3.h"
if [ $? -ne 0 ]; then
exit $?
fi
for FILE in "${BUILD_DIR}"/sqlcipher3.*
do
sed -ie 's/sqlite3/sqlcipher3/g' "${FILE}"
if [ $? -ne 0 ]; then
exit $?
fi
sed -rie 's/(".*)sqlcipher3(.*")/\1sqlite3\2/g' "${FILE}"
if [ $? -ne 0 ]; then
exit $?
fi
done
#
# Build pdo_sqlcipher
#
cp "config.m4" "${BUILD_DIR}/config.m4"
if [ $? -ne 0 ]; then
exit $?
fi
cd "${BUILD_DIR}"
phpize --clean
if [ $? -ne 0 ]; then
exit $?
fi
phpize
if [ $? -ne 0 ]; then
exit $?
fi
./configure \
CFLAGS="${CFLAGS}" \
LDFLAGS="${LDFLAGS}"
if [ $? -ne 0 ]; then
exit $?
fi
make
if [ $? -ne 0 ]; then
exit $?
fi
cd ..
#
# Copy binaries
#
RELEASE_DIR="release"
if [ -d "${RELEASE_DIR}" ]; then
rm -rf "${RELEASE_DIR}"
if [ $? -ne 0 ]; then
exit $?
fi
fi
mkdir -p "${RELEASE_DIR}"
if [ $? -ne 0 ]; then
exit $?
fi
# pdo_sqlite.so
cp "${BUILD_DIR}/modules/pdo_sqlcipher.so" "${RELEASE_DIR}/pdo_sqlcipher.so"
if [ $? -ne 0 ]; then
exit $?
fi
strip "${RELEASE_DIR}/pdo_sqlcipher.so"
if [ $? -ne 0 ]; then
exit $?
fi
chmod 0644 "${RELEASE_DIR}/pdo_sqlcipher.so"
if [ $? -ne 0 ]; then
exit $?
fi
# sqlcipher static binary
cp "${SQLCIPHER_SRC}/sqlcipher" "${RELEASE_DIR}/sqlcipher"
if [ $? -ne 0 ]; then
exit $?
fi
strip "${RELEASE_DIR}/sqlcipher"
if [ $? -ne 0 ]; then
exit $?
fi
#
# Clean
#
rm -rf ${PHP_SRC}
rm -rf ${SQLCIPHER_SRC}
rm -rf ${BUILD_DIR}
rm -f ${PHP_TGZ}