-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-tdlib.sh
executable file
·85 lines (72 loc) · 3.07 KB
/
build-tdlib.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
#!/usr/bin/env bash
source ./check-environment.sh || exit 1
if [ "$ANDROID_STL" != "c++_static" ] && [ "$ANDROID_STL" != "c++_shared" ] ; then
echo 'Error: ANDROID_STL must be either "c++_static" or "c++_shared".'
exit 1
fi
ANDROID_NDK_ROOT="$ANDROID_SDK_ROOT/ndk/$ANDROID_NDK_VERSION"
PATH=$ANDROID_SDK_ROOT/cmake/$CMAKE_VERSION/bin:$PATH
cd $(dirname $0)
echo "Generating TDLib source files..."
mkdir -p build-native || exit 1
cd build-native
cmake $TD_ROOT || exit 1
cmake --build . --target prepare_cross_compiling || exit 1
cd ..
echo "Building TDLib..."
for ABI in arm64-v8a armeabi-v7a x86_64 x86 ; do
mkdir -p build-$ABI install-$ABI || exit 1
cd build-$ABI
cmake \
-DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake" \
-DCMAKE_FIND_ROOT_PATH="$OPENSSL_INSTALL_DIR/$ABI" \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_CXX_FLAGS_RELWITHDEBINFO=" -flto=thin -Oz" \
-DCMAKE_SHARED_LINKER_FLAGS="-Wl,--gc-sections,--icf=safe" \
-GNinja \
-DANDROID_ABI=$ABI \
-DANDROID_STL=$ANDROID_STL \
-DANDROID_PLATFORM=android-$ANDROID_MIN_SDK \
-DCMAKE_INSTALL_PREFIX=../install-$ABI \
"$TD_ROOT" || exit 1
ninja install || exit 1
cd ..
mkdir -p tdlib/libs/$ABI/ || exit 1
cp -p install-$ABI/lib/libtdjson.so tdlib/libs/$ABI/ || exit 1
cp $OPENSSL_INSTALL_DIR/$ABI/lib/*.so tdlib/libs/$ABI/
"$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$HOST_ARCH/bin/llvm-strip" tdlib/libs/$ABI/*.so
if [[ "$ANDROID_STL" == "c++_shared" ]] ; then
if [[ "$ABI" == "arm64-v8a" ]] ; then
FULL_ABI="aarch64-linux-android"
elif [[ "$ABI" == "armeabi-v7a" ]] ; then
FULL_ABI="arm-linux-androideabi"
elif [[ "$ABI" == "x86_64" ]] ; then
FULL_ABI="x86_64-linux-android"
elif [[ "$ABI" == "x86" ]] ; then
FULL_ABI="i686-linux-android"
fi
cp "$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$HOST_ARCH/sysroot/usr/lib/$FULL_ABI/libc++_shared.so" tdlib/libs/$ABI/ || exit 1
"$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$HOST_ARCH/bin/llvm-strip" tdlib/libs/$ABI/libc++_shared.so || exit 1
fi
done
echo "Generating README.md..."
COMMIT_ID="$(cd $TD_ROOT && git rev-parse --short HEAD)"
TD_VERSION=$(grep 'TDLib VERSION' $TD_ROOT/CMakeLists.txt | cut -d ' ' -f 3)
REMOTE_URL="$(cd $TD_ROOT && git remote get-url $(git remote))"
REMOTE_NAME="$(sed -E 's#https*://[A-Za-z0-9.]*\/##' <<< "$REMOTE_URL")"
DATE="$(LC_ALL=C date "+%b %d %Y %H:%M %Z")"
echo "### TDLib build information
| | |
|:----------------|----------------------------------------------------------:|" > tdlib/README.md
echo \
"| **Build date** | $(printf '%-57s' "$DATE") |
| **Version** | $(printf '%-57s' "$TD_VERSION") |
| **Commit** | $(printf '%-57s' "$COMMIT_ID") |
| **Repository** | $(printf '%-57s' "[$REMOTE_NAME]($REMOTE_URL)") |" >> tdlib/README.md
echo "Compressing..."
rm -f tdlib.zip || exit 1
mkdir -p tdlib/scheme
cp -f $TD_ROOT/td/generate/scheme/td_api.tl tdlib/scheme/td_api.tl
zip -r tdlib.zip tdlib || exit 1
mv tdlib.zip tdlib || exit 1
echo "Done."