-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathss-build2.sh
204 lines (185 loc) · 7.38 KB
/
ss-build2.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
#!/bin/sh
###############
# config area #
###############
export WORK_DIR=$PWD
export NDK=${WORK_DIR}/android
export SYSROOT="$NDK/sysroot"
export ANDROID_NDK_VERSION=r20b
ANDROID_PLATFORM=29
BUILD_HOST=aarch64-linux-android
BUILD_ARCH=arm64
LIBSODIUM_VER=1.0.18
LIBMBEDTLS_VER=2.6.0
PCRE_VER=8.41
SHADOWSOCKS_VER=v3.3.5
CARES_VER=1.12.0
prepare_ndk() {
if [ -f .ndk.installed ]; then
echo "NDK already installed, skip."
return 0
else
echo "Prepare ndk..."
wget https://dl.google.com/android/repository/android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip
unzip android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip
rm -rf android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip
mv android-ndk-${ANDROID_NDK_VERSION} ${NDK}
touch .ndk.installed
fi
}
case "$1" in
arm) BUILD_ARCH=arm; BUILD_HOST=arm-linux-androideabi;;
arm64) BUILD_ARCH=arm64; BUILD_HOST=aarch64-linux-android;;
x86) BUILD_ARCH=x86; BUILD_HOST=i686-linux-android;;
x86_64) BUILD_ARCH=x86_64; BUILD_HOST=x86_64-linux-android;;
init) prepare_ndk; exit 0;;
*) __errmsg "unknown arch $1, use default. Support arch: arm, arm64, x86, x86_64";;
esac
uname -a
###############
# init env #
###############
init_env() {
export BUILDTOOL_PATH=${WORK_DIR}/android-${BUILD_HOST}
export PATH=$PATH:${BUILDTOOL_PATH}/bin
export STAGING_DIR=${BUILDTOOL_PATH}
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${BUILDTOOL_PATH}/lib:${BUILDTOOL_PATH}/sysroot/usr/lib
export BUILD_INCLUDE_PATH=${BUILDTOOL_PATH}/sysroot/usr/include
if [ $BUILD_ARCH = "arm" ] || [ $BUILD_ARCH = "x86" ]; then
export CC="${BUILD_HOST}-gcc -m32"
export CXX="${BUILD_HOST}-g++ -m32"
export LD="${BUILD_HOST}-ld -m32"
else
export CC=${BUILD_HOST}-gcc
export CXX=${BUILD_HOST}-g++
export LD=${BUILD_HOST}-ld
fi
export AR=${BUILD_HOST}-ar
export RANLIB=${BUILD_HOST}-ranlib
}
init_buildfolder() {
mkdir build-${BUILD_ARCH}
cd build-${BUILD_ARCH}
mkdir insdir
}
#build ndk
build_ndk() {
${NDK}/build/tools/make-standalone-toolchain.sh --arch=${BUILD_ARCH} --platform=android-${ANDROID_PLATFORM} --install-dir=${BUILDTOOL_PATH}
}
build_deps() {
echo "Build mbedtls..."
wget https://tls.mbed.org/download/mbedtls-${LIBMBEDTLS_VER}-gpl.tgz -O mbedtls-${LIBMBEDTLS_VER}.tgz
tar -zxf mbedtls-${LIBMBEDTLS_VER}.tgz
cd mbedtls-${LIBMBEDTLS_VER}
ln -s ../insdir .
make install DESTDIR=$PWD/insdir/mbedtls LDFLAGS=-static
cd -
echo "Build libsodium..."
wget https://github.com/jedisct1/libsodium/releases/download/${LIBSODIUM_VER}/libsodium-${LIBSODIUM_VER}.tar.gz -O libsodium-${LIBSODIUM_VER}.tar.gz
tar -zxf libsodium-${LIBSODIUM_VER}.tar.gz
cd libsodium-${LIBSODIUM_VER}
ln -s ../insdir .
./configure --host=${BUILD_HOST} --prefix=$PWD/insdir/libsodium --disable-ssp --disable-shared
make && make install
cd -
echo "Build pcre..."
wget https://ftp.pcre.org/pub/pcre/pcre-${PCRE_VER}.tar.gz -O pcre-${PCRE_VER}.tar.gz
tar -zxf pcre-${PCRE_VER}.tar.gz
cd pcre-${PCRE_VER}
ln -s ../insdir .
./configure --host=${BUILD_HOST} --enable-pcre8 --enable-pcre16 --enable-pcre32 --disable-cpp --prefix=$PWD/insdir/pcre --disable-shared --enable-utf8 --enable-unicode-properties
make && make install
cd -
echo "Build libev..."
wget https://github.com/shadowsocks/libev/archive/master.zip -O libev.zip
unzip libev.zip
cd libev-master
ln -s ../insdir .
#./autogen.sh
./configure --host=${BUILD_HOST} --prefix=$PWD/insdir/libev --disable-shared
make && make install
cd -
echo "Build c-ares..."
wget https://c-ares.haxx.se/download/c-ares-${CARES_VER}.tar.gz -O c-ares-${CARES_VER}.tar.gz
tar -zxf c-ares-${CARES_VER}.tar.gz
cd c-ares-${CARES_VER}
ln -s ../insdir .
./configure --host=${BUILD_HOST} LDFLAGS=-static --prefix=$PWD/insdir/cares
make && make install
cd -
echo "Build simple obfs"
git clone https://github.com/shadowsocks/simple-obfs.git
cd simple-obfs
git submodule update --init --recursive
ln -s ../insdir .
./autogen.sh && ./configure --host=${BUILD_HOST} --prefix=$PWD/insdir/simple-obfs --disable-assert --disable-ssp --disable-system-shared-lib --enable-static --disable-documentation --with-pcre=$PWD/insdir/pcre --with-libev=$PWD/insdir/libev LDFLAGS="-Wl -Wno-implicit-function-declaration -Wno-error,-static -static-libgcc -L$PWD/insdir/cares/lib -L$PWD/insdir/libev/lib -L${SYSROOT}/usr/lib -U__ANDROID__ -llog" CFLAGS="-I$PWD/insdir/libev/include -I$PWD/insdir/cares/include -I${BUILD_INCLUDE_PATH} -U__ANDROID__ -Wno-implicit-function-declaration -Wno-error -Wno-deprecated-declarations -fno-strict-aliasing"
make && make install
cd -
echo "Build v2ray-plugin"
git clone https://github.com/shadowsocks/v2ray-plugin.git
cd v2ray-plugin
ln -s ../insdir .
if [ $BUILD_ARCH = "x86" ]; then
GOBUILD_ARCH="386"
elif [ $BUILD_ARCH = "x86_64" ]; then
GOBUILD_ARCH=amd64
elif [ $BUILD_ARCH = "arm" ]; then
GOBUILD_ARCH='arm GOARM=7'
elif [ $BUILD_ARCH = "arm64" ]; then
GOBUILD_ARCH=arm64
fi
env CGO_ENABLED=0 GOOS=linux GOARCH=${GOBUILD_ARCH} go build -v -ldflags "-X main.VERSION=master -s -w" -gcflags "" -o insdir/v2ray-plugin/v2ray-plugin
cd -
}
build_ss() {
echo "build ss"
git clone https://github.com/shadowsocks/shadowsocks-libev
cd shadowsocks-libev
git checkout -b origin/${SHADOWSOCKS_VER}
git submodule update --init --recursive
ln -s ../insdir .
./autogen.sh && ./configure --host=${BUILD_HOST} --prefix=$PWD/insdir/shadowsocks-libev --disable-assert --disable-ssp --disable-system-shared-lib --enable-static --disable-documentation --with-mbedtls=$PWD/insdir/mbedtls --with-pcre=$PWD/insdir/pcre --with-sodium=$PWD/insdir/libsodium --with-libev=$PWD/insdir/libev LDFLAGS="-Wl -Wno-implicit-function-declaration -Wno-error,-static -static-libgcc -L$PWD/insdir/cares/lib -L$PWD/insdir/libev/lib -L${SYSROOT}/usr/lib -U__ANDROID__ -llog" CFLAGS="-I$PWD/insdir/libev/include -I$PWD/insdir/cares/include -I${BUILD_INCLUDE_PATH} -U__ANDROID__ -Wno-implicit-function-declaration -Wno-error -Wno-deprecated-declarations -fno-strict-aliasing"
make && make install
cd -
mkdir ../shadowsocks-libev-${BUILD_ARCH}
cp insdir/shadowsocks-libev/bin/ss-* ../shadowsocks-libev-${BUILD_ARCH}
cp insdir/simple-obfs/bin/obfs* ../shadowsocks-libev-${BUILD_ARCH}
cp insdir/v2ray-plugin/v2ray-plug* ../shadowsocks-libev-${BUILD_ARCH}
cd ..
tar -zcvf shadowsocks-libev-${SHADOWSOCKS_VER}-${BUILD_ARCH}.tar.gz ./shadowsocks-libev-${BUILD_ARCH}/
rm -rf build-${BUILD_ARCH}
}
release_assets() {
USER=${GITHUB_USER}
REPO="ss-libev-build"
TAG=${SHADOWSOCKS_VER}
FILE_NAME=shadowsocks-libev-${SHADOWSOCKS_VER}-${BUILD_ARCH}.tar.gz
FILE_PATH=$PWD/shadowsocks-libev-${SHADOWSOCKS_VER}-${BUILD_ARCH}.tar.gz
chmod +x ./ok.sh
# Create a release if not exist:
./ok.sh create_release "$USER" "$REPO" "$TAG" _filter='.upload_url'
# Find a release by tag then upload a file:
./ok.sh list_releases "$USER" "$REPO" \
| awk -v "tag=$TAG" -F'\t' '$2 == tag { print $3 }' \
| xargs -I@ ./ok.sh release "$USER" "$REPO" @ _filter='.upload_url' \
| sed 's/{.*$/?name='"$FILE_NAME"'/' \
| xargs -I@ ./ok.sh upload_asset @ "$FILE_PATH"
}
########
# main #
########
init_env
init_buildfolder
#prepare ndk if not found
if [ ! -d ${NDK} ]; then
echo "NDK not found, download."
prepare_ndk
fi
#build if ndk not found
if [ ! -d ${BUILDTOOL_PATH} ]; then
echo "NDK found but not build, build it."
build_ndk
fi
build_deps
build_ss
release_assets