2016-11-19 14:36:42 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-01-01 20:54:40 -05:00
|
|
|
set -e
|
|
|
|
|
2016-11-19 14:36:42 -05:00
|
|
|
# This script cross-compiles cuberite for the android platform. It uses
|
|
|
|
# the following enviroment variables
|
2020-05-10 12:18:28 -04:00
|
|
|
# CMAKE: Should be the path to a cmake executable of version 3.12.4+
|
2016-11-19 14:36:42 -05:00
|
|
|
# NDK: Should be the path to the android ndk root
|
|
|
|
# (optional) TYPE: either Release or Debug, sets the build type
|
|
|
|
# (optional) THREADS: The number of threads to use, default 4
|
|
|
|
|
|
|
|
function usage() {
|
|
|
|
echo "Usage: NDK=<path-to-ndk> CMAKE=<cmake-binary> $0 (clean|<ABI>)";
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
BASEDIR="$(realpath $(dirname $0))"
|
2020-01-01 20:54:40 -05:00
|
|
|
BUILDDIR="$BASEDIR/../android-build"
|
2016-11-19 14:36:42 -05:00
|
|
|
SELF="./$(basename $0)"
|
|
|
|
|
|
|
|
# Clean doesn't need CMAKE and NDK, so it's handled here
|
|
|
|
if [ "$1" == "clean" ]; then
|
2020-01-01 20:54:40 -05:00
|
|
|
rm -rf $BUILDDIR
|
2016-11-19 14:36:42 -05:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2020-01-01 20:54:40 -05:00
|
|
|
if [ -z "$CMAKE" -o -z "$NDK" ]; then
|
2016-11-19 14:36:42 -05:00
|
|
|
usage;
|
|
|
|
fi
|
|
|
|
|
|
|
|
# CMake wants absolute path
|
|
|
|
CMAKE="$(realpath $CMAKE)"
|
|
|
|
NDK="$(realpath $NDK)"
|
|
|
|
|
|
|
|
if [ -z "$TYPE" ]; then
|
|
|
|
TYPE="Release"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$THREADS" ]; then
|
|
|
|
THREADS="4"
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd $BASEDIR
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
|
|
|
|
armeabi-v7a)
|
2020-01-02 19:40:26 -05:00
|
|
|
APILEVEL=16
|
2016-11-19 14:36:42 -05:00
|
|
|
;;
|
|
|
|
|
|
|
|
arm64-v8a)
|
|
|
|
APILEVEL=21
|
|
|
|
;;
|
|
|
|
|
|
|
|
x86)
|
2020-01-02 19:40:26 -05:00
|
|
|
APILEVEL=16
|
2016-11-19 14:36:42 -05:00
|
|
|
;;
|
|
|
|
|
|
|
|
x86_64)
|
|
|
|
APILEVEL=21
|
|
|
|
;;
|
|
|
|
|
|
|
|
all)
|
2016-12-18 04:23:52 -05:00
|
|
|
echo "Packing server.zip ..."
|
2020-01-01 20:54:40 -05:00
|
|
|
rm -rf Server
|
2016-11-19 14:36:42 -05:00
|
|
|
mkdir -p Server
|
|
|
|
|
2020-01-01 20:54:40 -05:00
|
|
|
for arch in armeabi-v7a arm64-v8a x86 x86_64; do
|
2016-11-19 14:36:42 -05:00
|
|
|
echo "Doing ... $arch ..." && \
|
|
|
|
cd $BASEDIR && \
|
|
|
|
"$SELF" clean && \
|
|
|
|
"$SELF" "$arch" && \
|
2020-01-01 20:54:40 -05:00
|
|
|
cd $BUILDDIR/Server && \
|
|
|
|
zip $BASEDIR/Server/"$arch".zip Cuberite
|
2016-11-19 14:36:42 -05:00
|
|
|
done
|
|
|
|
|
2020-01-02 10:59:07 -05:00
|
|
|
echo "Packing server.zip ..."
|
|
|
|
cd $BUILDDIR/Server
|
|
|
|
zip -r $BASEDIR/Server/server.zip -@ -x Cuberite < Install/UnixExecutables.list
|
|
|
|
|
2016-12-18 04:23:52 -05:00
|
|
|
cd $BASEDIR/Server
|
2020-01-01 20:54:40 -05:00
|
|
|
for file in server.zip armeabi-v7a.zip arm64-v8a.zip x86.zip x86_64.zip; do
|
2016-12-18 04:23:52 -05:00
|
|
|
echo "Generating sha1 sum for ... $file ..." && \
|
|
|
|
sha1sum "$file" > "$file".sha1
|
|
|
|
done
|
|
|
|
|
2016-11-19 14:36:42 -05:00
|
|
|
echo "Done! The built zip files await you in the Server/ directory"
|
|
|
|
exit;
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
usage;
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2020-01-01 20:54:40 -05:00
|
|
|
mkdir -p $BUILDDIR
|
|
|
|
cd $BUILDDIR
|
|
|
|
"$CMAKE" $BASEDIR/../android -DCMAKE_TOOLCHAIN_FILE="$NDK/build/cmake/android.toolchain.cmake" \
|
|
|
|
-DANDROID_ABI="$1" \
|
|
|
|
-DANDROID_NATIVE_API_LEVEL="$APILEVEL" \
|
2020-08-04 18:37:21 -04:00
|
|
|
-DCMAKE_BUILD_TYPE="$TYPE" \
|
2020-08-04 18:24:35 -04:00
|
|
|
-DWHOLE_PROGRAM_OPTIMISATION=No
|
2020-01-01 20:54:40 -05:00
|
|
|
|
2016-11-19 14:36:42 -05:00
|
|
|
make -j "$THREADS"
|