2015-11-13 22:38:17 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2017-10-13 06:59:19 +00:00
|
|
|
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
TARGET_SDK=$(grep "targetSdkVersion" "${ROOT_DIR}/build.gradle" -m 1 | awk '{print $2}')
|
|
|
|
# Use seperate build dir so standalone ndk isn't deleted by `gradle clean`
|
|
|
|
BUILD_DIR="${ROOT_DIR}/gobuild"
|
|
|
|
export GOPATH="${ROOT_DIR}/go/"
|
2015-11-13 22:38:17 +00:00
|
|
|
|
2017-10-13 06:59:19 +00:00
|
|
|
cd "${ROOT_DIR}/go/src/github.com/syncthing/syncthing"
|
2015-11-13 22:38:17 +00:00
|
|
|
|
2017-06-07 01:35:45 +00:00
|
|
|
# Make sure all tags are available for git describe
|
|
|
|
# https://github.com/syncthing/syncthing-android/issues/872
|
|
|
|
git fetch --tags
|
|
|
|
|
2017-10-13 06:59:19 +00:00
|
|
|
for ANDROID_ARCH in arm x86 arm64; do
|
|
|
|
echo -e "Starting build for ${ANDROID_ARCH}\n"
|
|
|
|
case ${ANDROID_ARCH} in
|
|
|
|
arm)
|
|
|
|
GOARCH=arm
|
|
|
|
JNI_DIR="armeabi"
|
|
|
|
GCC="arm-linux-androideabi-gcc"
|
|
|
|
;;
|
|
|
|
arm64)
|
|
|
|
GOARCH=arm64
|
|
|
|
JNI_DIR="arm64-v8a"
|
|
|
|
GCC="aarch64-linux-android-gcc"
|
|
|
|
;;
|
|
|
|
x86)
|
|
|
|
GOARCH=386
|
|
|
|
JNI_DIR="x86"
|
|
|
|
GCC="i686-linux-android-gcc"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Invalid architecture"
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Build standalone NDK toolchain if it doesn't exist.
|
|
|
|
# https://developer.android.com/ndk/guides/standalone_toolchain.html
|
|
|
|
STANDALONE_NDK_DIR="${BUILD_DIR}/standalone-ndk/android-${TARGET_SDK}-${GOARCH}"
|
2015-11-13 22:38:17 +00:00
|
|
|
|
2017-10-13 06:59:19 +00:00
|
|
|
if [ ! -d "$STANDALONE_NDK_DIR" ]; then
|
|
|
|
echo -e "Building standalone NDK\n"
|
|
|
|
${ANDROID_NDK_HOME}/build/tools/make-standalone-toolchain.sh \
|
|
|
|
--platform=android-${TARGET_SDK} --arch=${ANDROID_ARCH} \
|
|
|
|
--install-dir=${STANDALONE_NDK_DIR}
|
|
|
|
fi
|
2015-11-13 22:38:17 +00:00
|
|
|
|
2017-10-13 06:59:19 +00:00
|
|
|
echo -e "Building Syncthing\n"
|
|
|
|
CGO_ENABLED=1 CC="${STANDALONE_NDK_DIR}/bin/${GCC}" \
|
|
|
|
go run build.go -goos android -goarch ${GOARCH} -pkgdir "${BUILD_DIR}/go-packages" -no-upgrade build
|
2015-11-13 22:38:17 +00:00
|
|
|
|
2017-10-13 06:59:19 +00:00
|
|
|
# Copy compiled binary to jniLibs folder
|
|
|
|
TARGET_DIR="$ROOT_DIR/src/main/jniLibs/$JNI_DIR"
|
|
|
|
mkdir -p ${TARGET_DIR}
|
|
|
|
mv syncthing ${TARGET_DIR}/libsyncthing.so
|
2015-11-13 22:38:17 +00:00
|
|
|
|
2017-10-13 06:59:19 +00:00
|
|
|
echo -e "Finished build for ${ANDROID_ARCH}\n"
|
2015-11-13 22:38:17 +00:00
|
|
|
|
2017-10-13 06:59:19 +00:00
|
|
|
done
|
2015-11-13 22:38:17 +00:00
|
|
|
|
2017-10-13 06:59:19 +00:00
|
|
|
echo -e "All builds finished"
|