From 04fa50458099b1e1c21d3c5323c8877045154c4d Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Wed, 22 Mar 2023 23:11:37 +0100 Subject: [PATCH] Update build script --- app/src/make.sh | 157 ++++++++++++++++++++---------------------------- gradlew | 0 2 files changed, 64 insertions(+), 93 deletions(-) mode change 100644 => 100755 app/src/make.sh mode change 100644 => 100755 gradlew diff --git a/app/src/make.sh b/app/src/make.sh old mode 100644 new mode 100755 index a415b1c..6025a43 --- a/app/src/make.sh +++ b/app/src/make.sh @@ -1,69 +1,50 @@ #!/usr/bin/env bash +set -e + function getHostTag() { - # Copyright (C) 2010 The Android Open Source Project - # Modified by Andy Wang (cbeuw.andy@gmail.com) - # - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Detect host operating system and architecture - # The 64-bit / 32-bit distinction gets tricky on Linux and Darwin because - # uname -m returns the kernel's bit size, and it's possible to run with - # a 64-bit kernel and a 32-bit userland. - # - HOST_OS=$(uname -s) - case $HOST_OS in - Darwin) HOST_OS=darwin ;; - Linux) HOST_OS=linux ;; - FreeBsd) HOST_OS=freebsd ;; - CYGWIN* | *_NT-*) HOST_OS=windows ;; - *) - echo "ERROR: Unknown host operating system: $HOST_OS" - exit 1 - ;; - esac - echo "HOST_OS=$HOST_OS" - - HOST_ARCH=$(uname -m) - case $HOST_ARCH in - i?86) HOST_ARCH=x86 ;; - x86_64 | amd64) HOST_ARCH=x86_64 ;; - *) - echo "ERROR: Unknown host CPU architecture: $HOST_ARCH" - exit 1 - ;; - esac - echo "HOST_ARCH=$HOST_ARCH" - - # Detect 32-bit userland on 64-bit kernels - HOST_TAG="$HOST_OS-$HOST_ARCH" - case $HOST_TAG in - linux-x86_64 | darwin-x86_64) - # we look for x86_64 or x86-64 in the output of 'file' for our shell - # the -L flag is used to dereference symlinks, just in case. - file -L "$SHELL" | grep -q "x86[_-]64" - if [ $? != 0 ]; then - HOST_ARCH=x86 - HOST_TAG=$HOST_OS-x86 - echo "HOST_ARCH=$HOST_ARCH (32-bit userland detected)" - fi - ;; - esac - # Check that we have 64-bit binaries on 64-bit system, otherwise fallback - # on 32-bit ones. This gives us more freedom in packaging the NDK. - if [ $HOST_ARCH = x86_64 -a ! -d $ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$HOST_TAG ]; then - HOST_TAG=$HOST_OS-x86 - if [ $HOST_TAG = windows-x86 ]; then - HOST_TAG=windows - fi - echo "HOST_TAG=$HOST_TAG (no 64-bit prebuilt binaries detected)" - else - echo "HOST_TAG=$HOST_TAG" - fi + # Copyright (C) 2022 The Android Open Source Project + # + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + # + # From NDK/build/tools/ndk_bin_common.sh + + HOST_OS=$(uname -s) + case $HOST_OS in + Darwin) HOST_OS=darwin;; + Linux) HOST_OS=linux;; + FreeBsd) HOST_OS=freebsd;; + CYGWIN*|*_NT-*) HOST_OS=cygwin;; + *) echo "ERROR: Unknown host operating system: $HOST_OS" + exit 1 + esac + + HOST_ARCH=$(uname -m) + case $HOST_ARCH in + arm64) HOST_ARCH=arm64;; + i?86) HOST_ARCH=x86;; + x86_64|amd64) HOST_ARCH=x86_64;; + *) echo "ERROR: Unknown host CPU architecture: $HOST_ARCH" + exit 1 + esac + + HOST_TAG=$HOST_OS-$HOST_ARCH + + if [ $HOST_TAG = darwin-arm64 ]; then + # The NDK ships universal arm64+x86_64 binaries in the darwin-x86_64 + # directory. + HOST_TAG=darwin-x86_64 + fi } #Copyright (C) 2017 by Max Lv @@ -72,12 +53,8 @@ function getHostTag() { #This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. #You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/. -function try() { - "$@" || exit -1 -} - pushd ../.. -"${ANDROID_NDK_HOME:=$(./gradlew -q printNDKPath)}" +ANDROID_NDK_HOME="${ANDROID_NDK_HOME:-$(./gradlew -q printNDKPath)}" CK_RELEASE_TAG=v"$(./gradlew -q printVersionName)" popd @@ -88,50 +65,44 @@ done getHostTag MIN_API=21 -ANDROID_PREBUILT_TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$HOST_TAG +ANDROID_PREBUILT_TOOLCHAIN="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$HOST_TAG" -ANDROID_ARM_CC=$ANDROID_PREBUILT_TOOLCHAIN/bin/armv7a-linux-androideabi${MIN_API}-clang +ANDROID_ARM_CC="$ANDROID_PREBUILT_TOOLCHAIN/bin/armv7a-linux-androideabi${MIN_API}-clang" -ANDROID_ARM64_CC=$ANDROID_PREBUILT_TOOLCHAIN/bin/aarch64-linux-android21-clang -ANDROID_ARM64_STRIP=$ANDROID_PREBUILT_TOOLCHAIN/bin/aarch64-linux-android-strip +ANDROID_ARM64_CC="$ANDROID_PREBUILT_TOOLCHAIN/bin/aarch64-linux-android21-clang" -ANDROID_X86_CC=$ANDROID_PREBUILT_TOOLCHAIN/bin/i686-linux-android${MIN_API}-clang -ANDROID_X86_STRIP=$ANDROID_PREBUILT_TOOLCHAIN/bin/i686-linux-android-strip +ANDROID_X86_CC="$ANDROID_PREBUILT_TOOLCHAIN/bin/i686-linux-android${MIN_API}-clang" -ANDROID_X86_64_CC=$ANDROID_PREBUILT_TOOLCHAIN/bin/x86_64-linux-android${MIN_API}-clang -ANDROID_X86_64_STRIP=$ANDROID_PREBUILT_TOOLCHAIN/bin/x86_64-linux-android-strip +ANDROID_X86_64_CC="$ANDROID_PREBUILT_TOOLCHAIN/bin/x86_64-linux-android${MIN_API}-clang" SRC_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -DEPS=$(pwd)/.deps -try mkdir -p $DEPS $SRC_DIR/main/jniLibs/armeabi-v7a $SRC_DIR/main/jniLibs/x86 $SRC_DIR/main/jniLibs/arm64-v8a $SRC_DIR/main/jniLibs/x86_64 +DEPS="$(pwd)/.deps" +mkdir -p "$DEPS" "$SRC_DIR/main/jniLibs/armeabi-v7a" "$SRC_DIR/main/jniLibs/x86" "$SRC_DIR/main/jniLibs/arm64-v8a" "$SRC_DIR/main/jniLibs/x86_64" -try cd $DEPS +cd "$DEPS" echo "Getting Cloak source code" rm -rf Cloak -try git clone https://github.com/cbeuw/Cloak +git clone https://github.com/cbeuw/Cloak cd Cloak -try git checkout tags/$CK_RELEASE_TAG -try go get ./... +git checkout tags/$CK_RELEASE_TAG +go get ./... cd cmd/ck-client echo "Cross compiling ckclient for arm" -try env CGO_ENABLED=1 CC="$ANDROID_ARM_CC" GOOS=android GOARCH=arm GOARM=7 go build -ldflags="-s -w" -try mv ck-client $SRC_DIR/main/jniLibs/armeabi-v7a/libck-client.so +env CGO_ENABLED=1 CC="$ANDROID_ARM_CC" GOOS=android GOARCH=arm GOARM=7 go build -ldflags="-s -w" +mv ck-client "$SRC_DIR/main/jniLibs/armeabi-v7a/libck-client.so" echo "Cross compiling ckclient for arm64" -try env CGO_ENABLED=1 CC="$ANDROID_ARM64_CC" GOOS=android GOARCH=arm64 go build -ldflags="-s -w" -try "$ANDROID_ARM64_STRIP" ck-client -try mv ck-client $SRC_DIR/main/jniLibs/arm64-v8a/libck-client.so +env CGO_ENABLED=1 CC="$ANDROID_ARM64_CC" GOOS=android GOARCH=arm64 go build -ldflags="-s -w" +mv ck-client "$SRC_DIR/main/jniLibs/arm64-v8a/libck-client.so" echo "Cross compiling ckclient for x86" -try env CGO_ENABLED=1 CC="$ANDROID_X86_CC" GOOS=android GOARCH=386 go build -ldflags="-s -w" -try "$ANDROID_X86_STRIP" ck-client -try mv ck-client $SRC_DIR/main/jniLibs/x86/libck-client.so +env CGO_ENABLED=1 CC="$ANDROID_X86_CC" GOOS=android GOARCH=386 go build -ldflags="-s -w" +mv ck-client "$SRC_DIR/main/jniLibs/x86/libck-client.so" echo "Cross compiling ckclient for x86_64" -try env CGO_ENABLED=1 CC="$ANDROID_X86_64_CC" GOOS=android GOARCH=amd64 go build -ldflags="-s -w" -try "$ANDROID_X86_64_STRIP" ck-client -try mv ck-client $SRC_DIR/main/jniLibs/x86_64/libck-client.so +env CGO_ENABLED=1 CC="$ANDROID_X86_64_CC" GOOS=android GOARCH=amd64 go build -ldflags="-s -w" +mv ck-client "$SRC_DIR/main/jniLibs/x86_64/libck-client.so" echo "Success" diff --git a/gradlew b/gradlew old mode 100644 new mode 100755