123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- #!/bin/sh
- # Fedora
- # dnf install wget git make which patch findutils unzip
- # Ubuntu
- # apt install wget git build-essential unzip time python
- # ./android_do
- die() { echo "Error: $1"; exit 1; }
- need() { which "$1" >/dev/null 2>/dev/null || die "Missing $1"; }
- need which
- need wget
- need git
- need make
- need patch
- need find
- need unzip
- need ls
- need uname
- need pwd
- need mkdir
- need rm
- need time
- #change this to valid ndk path, otherwise it will be downloaded
- BUILD_PATH=$(pwd)/build_android
- NDK_VERSION="android-ndk-r21"
- case $(uname -s) in
- Darwin)
- TYPE=darwin
- ;;
- Linux)
- TYPE=linux
- ;;
- *)
- TYPE=
- ;;
- esac
- if test "x$CJDNS_NDK_PATH" != "x"; then
- false # we already have an ndk path...
- elif test "x$TYPE" = xdarwin; then
- CJDNS_NDK_PATH_HINT=`echo $HOME/Library/Android/sdk/ndk/* | tail -1`
- elif test "x$TYPE" = xlinux; then
- CJDNS_NDK_PATH_HINT=`echo $HOME/Android/Sdk/ndk/* | tail -1`
- fi
- if test "x$CJDNS_NDK_PATH" = "x"; then
- if test "x$CJDNS_NDK_PATH_HINT" != "x" && [ -d "$CJDNS_NDK_PATH_HINT" ]; then
- echo "Using NDK at path $CJDNS_NDK_PATH_HINT"
- CJDNS_NDK_PATH=$CJDNS_NDK_PATH_HINT
- elif [ -d "$BUILD_PATH/$NDK_VERSION/" ]; then
- CJDNS_NDK_PATH="$BUILD_PATH/$NDK_VERSION"
- echo "Using previously downloaded NDK $CJDNS_NDK_PATH"
- else
- echo "No NDK path known, NDK will be downloaded"
- fi
- elif [ -d "$CJDNS_NDK_PATH" ]; then
- echo "Using NDK at specified path $CJDNS_NDK_PATH"
- else
- die "NDK path $CJDNS_NDK_PATH is not a directory"
- fi
- cpu_arch="$(uname -m)"
- [ -z "$cpu_arch" ] && die "NO CPU ARCHITECTURE DETECTED"
- [ "$cpu_arch" = "i686" ] && cpu_arch="x86"
- android_log=android_build_$$.log
- enabled_log=${LOG}
- mkdir $BUILD_PATH 2>/dev/null
- if test "x$CJDNS_NDK_PATH" = "x"; then
- cd "$BUILD_PATH"
- filename="$NDK_VERSION-${TYPE}-${cpu_arch}.zip"
- echo "$filename"
- if ! [ -f "$filename" ]; then
- url="https://dl.google.com/android/repository/$NDK_VERSION-${TYPE}-${cpu_arch}.zip"
- wget "$url" || die "wget $url failed"
- fi
- if ! [ -d "$NDK_VERSION" ]; then
- unzip -q "$filename" || die "failed to unzip "
- fi
- CJDNS_NDK_PATH="$BUILD_PATH/$NDK_VERSION"
- [ -d "$CJDNS_NDK_PATH" ] || die "NDK zip file does not contain expected content"
- cd ..
- fi
- Seccomp_NO=1
- mkdir $(pwd)/build_android/out 2>/dev/null
- BUILD_0='
- APP_ABI=armv7a
- TOOLCHAIN_PREFIX=arm
- EABI=androideabi
- VERSION=16
- '
- BUILD_1='
- APP_ABI=aarch64
- VERSION=21
- '
- BUILD_2='
- APP_ABI=i686
- VERSION=16
- '
- BUILD_3='
- APP_ABI=x86_64
- VERSION=21
- '
- for i in `seq 0 100`; do
- BUILD=`eval echo "\\\$BUILD_$i"`
- if test "x$BUILD" = "x"; then
- continue
- fi
- export APP_ABI=
- export TOOLCHAIN_PREFIX=
- export EABI=
- export VERSION=
- export EABI=android
- export $BUILD
- if test "x$TOOLCHAIN_PREFIX" = "x"; then
- export TOOLCHAIN_PREFIX=$APP_ABI
- fi
- mkdir -p $(pwd)/build_android/out/${APP_ABI}/${VERSION}/
- rm -rf build_linux
- export SYSTEM=linux
- CROSS_PATH=$CJDNS_NDK_PATH/toolchains/llvm/prebuilt/${TYPE}-${cpu_arch}/bin
- export CC=${CROSS_PATH}/${APP_ABI}-linux-${EABI}${VERSION}-clang
- export CROSS=${CROSS_PATH}/${TOOLCHAIN_PREFIX}-linux-${EABI}
- export AR=${CROSS}-ar
- export LINK=${CROSS}-ld
- export RANLIB=${CROSS}-ranlib
- export CFLAGS=${CROSS_CFLAGS}
- export LDFLAGS=${CROSS_LDFLAGS}
- gcc_version=$(${CC} --version)
- echo Using $gcc_version
- echo Compiler CC: $CC
- echo Compiler LINK: $LINK
- echo Compiler CFLAGS: $CFLAGS
- echo Compiler LDFLAGS: $LDFLAGS
- time ./do
- cp cjdroute $(pwd)/build_android/out/${APP_ABI}/${VERSION}/ || ret=$?
- if [ "$ret" != "" ] && [ "$ret" != "0" ]; then
- printf "\e[1;31mCopying ${APP_ABI} binary failed, non zero status returned - $ret\e[0m\n"
- exit 1
- else
- printf "\e[1;32mCopied ${APP_ABI} successfully\e[0m\n\n"
- fi
- rm cjdroute 2>/dev/null
- done
- printf "\n\e[1;34mOutput:\e[0m\n"
- for i in `seq 0 100`; do
- BUILD=`eval echo "\\\$BUILD_$i"`
- if test "x$BUILD" = "x"; then
- continue
- fi
- export $BUILD
- printf "\e[1;34m $(pwd)/build_android/out/${APP_ABI}/${VERSION}/cjdroute\e[0m\n"
- done
- exit $ret
|