-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile_binaries.sh
executable file
·60 lines (50 loc) · 1.88 KB
/
compile_binaries.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
#!/bin/bash
# Bash script for compiling tinyDTLS binaries for Linux, Windows, and Android.
#
# Requires android-ndk for compiling the Android binaries and MinGW for the
# Windows binaries.
set -euo pipefail
# Path variables
TINYDTLS_DIRECTORY=$PWD/third_party/tinydtls
BINARIES_DIRECTORY=$PWD/native/lib
# Download tinydtls submodule
git submodule update --init --recursive
# Initialize tinydtls compilation
cd "$TINYDTLS_DIRECTORY"
./autogen.sh
# Compile Linux binary
make -k clean
./configure --host=x86_64-pc-linux-gnu
make
mv libtinydtls.so "$BINARIES_DIRECTORY"/linux_x64/libtinydtls.so
# Compile Windows binary (using MinGW)
make clean
CC=x86_64-w64-mingw32-gcc-posix ./configure --host=x86_64-w64-mingw32
make
mv libtinydtls.so "$BINARIES_DIRECTORY"/windows_x64/libtinydtls.dll
# Compile Android binaries
ANDROID_DIRECTORY=$PWD/android/src/main/jniLibs
NDK=$HOME/Android/Sdk/ndk/24.0.8215888 # Insert your NDK directory here
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
export API=21
# Configure and build.
export AR=$TOOLCHAIN/bin/llvm-ar
export LD=$TOOLCHAIN/bin/ld
export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
export STRIP=$TOOLCHAIN/bin/llvm-strip
# Android architectures and target triples that are used as compile targets
# See https://developer.android.com/ndk/guides/other_build_systems#autoconf
declare -a ANDROID_ARCHITECTURES=("arm64-v8a" "armeabi-v7a" "x86" "x86_64")
declare -a ANDROID_TRIPLES=("aarch64-linux-android" "armv7a-linux-androideabi" "i686-linux-android" "x86_64-linux-android")
# Compile Android binaries
for (( i=0; i<${#ANDROID_ARCHITECTURES[*]}; ++i));
do
make clean
export TARGET="${ANDROID_TRIPLES[$i]}"
export CC=$TOOLCHAIN/bin/$TARGET$API-clang
export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
export AS=$CC
CC=$CC ./configure --host "$TARGET"
make
mv libtinydtls.so "${ANDROID_DIRECTORY}/${ANDROID_ARCHITECTURES[$i]}"/libtinydtls.so
done