-
Notifications
You must be signed in to change notification settings - Fork 4
/
build-on-linux-android.sh
executable file
·191 lines (164 loc) · 5.52 KB
/
build-on-linux-android.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
#!/usr/bin/env bash
set -e
# WARN(pyoung): This is Experiment build script which produce library files but It doesn't work.
# ref: https://search.maven.org/artifact/net.zetetic/android-database-sqlcipher
# [variable]
VERSION=v4.5.6
ROOT=$(pwd)
DIR_SOURCE=${ROOT}/sqlcipher
DIR_OUTPUT=${ROOT}/output
MINIMUM_ANDROID_SDK_VERSION=21
MINIMUM_ANDROID_64_BIT_SDK_VERSION=21
# [src] openssl
OEPNSSL_VERSION=openssl-3.2.1
git clone -b ${OEPNSSL_VERSION} --depth 1 https://github.com/openssl/openssl && cd openssl
OPENSSL_CONFIGURE_OPTIONS="-fPIC -fstack-protector-all no-idea no-camellia \
no-seed no-bf no-cast no-rc2 no-rc4 no-rc5 no-md2 \
no-md4 no-ecdh no-sock no-ssl3 \
no-dsa no-dh no-ec no-ecdsa no-tls1 \
no-rfc3779 no-whirlpool no-srp \
no-mdc2 no-ecdh no-engine \
no-srtp \
"
TOOLCHAIN_SYSTEM=linux-x86_64
for ARCH in armv7-a # arm64 x86 x86_64
do
case "${ARCH}" in
armv7-a)
CONFIGURE_ARCH="android-arm -march=armv7-a"
ANDROID_API_VERSION=${MINIMUM_ANDROID_SDK_VERSION}
OFFSET_BITS=32
;;
arm64)
CONFIGURE_ARCH=android-arm64
ANDROID_API_VERSION=${MINIMUM_ANDROID_64_BIT_SDK_VERSION}
OFFSET_BITS=64
;;
x86)
CONFIGURE_ARCH=android-x86
ANDROID_API_VERSION=${MINIMUM_ANDROID_SDK_VERSION}
OFFSET_BITS=32
;;
x86_64)
CONFIGURE_ARCH=android64-x86_64
ANDROID_API_VERSION=${MINIMUM_ANDROID_64_BIT_SDK_VERSION}
OFFSET_BITS=64
;;
*)
exit 1
esac
git checkout -f
git clean -Xdf
ANDROID_NDK_ROOT=${ANDROID_NDK_HOME}
TOOLCHAIN=${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/${TOOLCHAIN_SYSTEM}
TOOLCHAIN_BIN_PATH=${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/${TOOLCHAIN_SYSTEM}/bin
PATH=${TOOLCHAIN_BIN_PATH}:${PATH} ./Configure ${CONFIGURE_ARCH} \
-D__ANDROID_API__=${ANDROID_API_VERSION} \
-D_FILE_OFFSET_BITS=${OFFSET_BITS} \
${OPENSSL_CONFIGURE_OPTIONS}
make clean
PATH=${TOOLCHAIN_BIN_PATH}:${PATH} make
CC=$TOOLCHAIN/bin/$TARGET$API-clang \
AR=$TOOLCHAIN/bin/llvm-ar \
RANLIB=$TOOLCHAIN/bin/llvm-ranlib
mkdir -p ${DIR_OUTPUT}/${ARCH}/
mv libcrypto.a ${DIR_OUTPUT}/${ARCH}/
cp -R include ${DIR_OUTPUT}/${ARCH}/
done
cd ..
# sqlcipher ===================================
echo "=========================================================="
otherSqlcipherCFlags="-DLOG_NDEBUG -fstack-protector-all"
sqlcipherCFlags="-DSQLITE_HAS_CODEC \
-DSQLITE_SOUNDEX \
-DHAVE_USLEEP=1 \
-DSQLITE_MAX_VARIABLE_NUMBER=99999 \
-DSQLITE_TEMP_STORE=3 \
-DSQLITE_THREADSAFE=1 \
-DSQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576 \
-DNDEBUG=1 \
-DSQLITE_ENABLE_MEMORY_MANAGEMENT=1 \
-DSQLITE_ENABLE_LOAD_EXTENSION \
-DSQLITE_ENABLE_COLUMN_METADATA \
-DSQLITE_ENABLE_UNLOCK_NOTIFY \
-DSQLITE_ENABLE_RTREE \
-DSQLITE_ENABLE_STAT3 \
-DSQLITE_ENABLE_STAT4 \
-DSQLITE_ENABLE_JSON1 \
-DSQLITE_ENABLE_FTS3_PARENTHESIS \
-DSQLITE_ENABLE_FTS4 \
-DSQLITE_ENABLE_FTS5 \
-DSQLCIPHER_CRYPTO_OPENSSL \
-DSQLITE_ENABLE_DBSTAT_VTAB \
"
#ARCH=arm
#ARCH=arm64
#ARCH=x86
#ARCH=x86_64
ANDROID_NDK_SYSROOT=${ANDROID_NDK_TOOLCHAIN}/sysroot
# [src] sqlcipher
git clone -b ${VERSION} --depth 1 https://github.com/sqlcipher/sqlcipher.git && cd $DIR_SOURCE
for ARCH in armv7-a # arm64 x86 x86_64
do
case "${ARCH}" in
armv7-a)
HOST=armv7a-linux-androideabi
API=${MINIMUM_ANDROID_SDK_VERSION}
;;
arm64)
HOST=aarch64-linux-android
API=${MINIMUM_ANDROID_64_BIT_SDK_VERSION}
;;
x86)
HOST=i686-linux-android
API=${MINIMUM_ANDROID_SDK_VERSION}
;;
x86_64)
HOST=x86_64-linux-android
API=${MINIMUM_ANDROID_64_BIT_SDK_VERSION}
;;
*)
exit 1
esac
git checkout -f
git clean -Xdf
export AR=${ANDROID_NDK_TOOLCHAIN}/bin/llvm-ar
export CC=${ANDROID_NDK_TOOLCHAIN}/bin/${HOST}${API}-clang
export AS=$CC
export CXX=${ANDROID_NDK_TOOLCHAIN}/bin/${HOST}${API}-clang++
export LD=${ANDROID_NDK_TOOLCHAIN}/bin/ld
export RANLIB=${ANDROID_NDK_TOOLCHAIN}/bin/llvm-ranlib
export STRIP=${ANDROID_NDK_TOOLCHAIN}/bin/llvm-strip
# configure
SQLCHIPER_CONFIGURE_OPTIONS=" \
--with-pic \
--disable-tcl \
--enable-shared=yes \
--enable-static=no \
--disable-readline \
--enable-tempstore=yes \
--enable-threadsafe=yes \
--with-crypto-lib=none \
--host ${HOST} \
"
CFLAGS="--sysroot=${ANDROID_NDK_SYSROOT} \
${sqlcipherCFlags} \
${otherSqlcipherCFlags} \
-I${DIR_OUTPUT}/${ARCH}/include \
"
LDFLAGS=" \
${DIR_OUTPUT}/${ARCH}/libcrypto.a \
-lm \
"
sed -i 's/for ac_option in --version -v -V -qversion; do/for ac_option in --version -v; do/' configure
./configure ${SQLCHIPER_CONFIGURE_OPTIONS} CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}"
# compile
# ref: https://github.com/sfackler/rust-openssl/issues/2154#issuecomment-1910717183
sed -E -i '' -e '/[.]hidden.*OPENSSL_armcap_P/d' -e '/[.]extern.*OPENSSL_armcap_P/ {p; s/extern/hidden/; }' crypto/*arm*pl crypto/*/asm/*arm*pl
make clean
make sqlite3.c
${CC} ${CFLAGS} ${DIR_OUTPUT}/${ARCH}/libcrypto.a -shared -fPIC -lm sqlite3.c -o libsqlcipher.so
mv libsqlcipher.so ${DIR_OUTPUT}/${ARCH}/
done
## zip -r lib.zip libsodium/.libs/*
#ls -al ${DIR_OUTPUT}