make.bash 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env bash
  2. set -e -u -x
  3. if [ ! -f make.bash ]; then
  4. echo "make.bash must be run from $GOPATH/src/github.com/Psiphon-Labs/psiphon-tunnel-core/MobileLibrary/Android"
  5. exit 1
  6. fi
  7. # $1, if specified, is go build tags
  8. if [ -z ${1+x} ]; then BUILD_TAGS=""; else BUILD_TAGS="$1"; fi
  9. # At this time, psiphon-tunnel-core doesn't support modules
  10. export GO111MODULE=off
  11. export GOCACHE=/tmp
  12. BUILDINFOFILE="psiphon-tunnel-core_buildinfo.txt"
  13. BUILDDATE=$(date --iso-8601=seconds)
  14. BUILDREPO="https://github.com/Psiphon-Labs/psiphon-tunnel-core.git"
  15. BUILDREV=$(git rev-parse --short HEAD)
  16. GOVERSION=$(go version | perl -ne '/go version (.*?) / && print $1')
  17. LDFLAGS="\
  18. -s \
  19. -w \
  20. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildDate=$BUILDDATE \
  21. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildRepo=$BUILDREPO \
  22. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildRev=$BUILDREV \
  23. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.goVersion=$GOVERSION \
  24. "
  25. echo -e "${BUILDDATE}\n${BUILDREPO}\n${BUILDREV}\n" > $BUILDINFOFILE
  26. echo "Variables for ldflags:"
  27. echo " Build date: ${BUILDDATE}"
  28. echo " Build repo: ${BUILDREPO}"
  29. echo " Build revision: ${BUILDREV}"
  30. echo " Go version: ${GOVERSION}"
  31. echo ""
  32. gomobile bind -v -x -target=android/arm,android/arm64,android/386,android/amd64 -tags="${BUILD_TAGS}" -ldflags="$LDFLAGS" github.com/Psiphon-Labs/psiphon-tunnel-core/MobileLibrary/psi
  33. if [ $? != 0 ]; then
  34. echo "..'gomobile bind' failed, exiting"
  35. exit $?
  36. fi
  37. mkdir -p build-tmp/psi
  38. unzip -o psi.aar -d build-tmp/psi
  39. yes | cp -f PsiphonTunnel/AndroidManifest.xml build-tmp/psi/AndroidManifest.xml
  40. mkdir -p build-tmp/psi/res/xml
  41. yes | cp -f PsiphonTunnel/ca_psiphon_psiphontunnel_backup_rules.xml build-tmp/psi/res/xml/ca_psiphon_psiphontunnel_backup_rules.xml
  42. javac -d build-tmp -bootclasspath $ANDROID_HOME/platforms/android-$ANDROID_PLATFORM_VERSION/android.jar -source 1.8 -target 1.8 -classpath build-tmp/psi/classes.jar PsiphonTunnel/PsiphonTunnel.java
  43. if [ $? != 0 ]; then
  44. echo "..'javac' compiling PsiphonTunnel failed, exiting"
  45. exit $?
  46. fi
  47. cd build-tmp
  48. jar uf psi/classes.jar ca/psiphon/*.class
  49. if [ $? != 0 ]; then
  50. echo "..'jar' failed to add classes, exiting"
  51. exit $?
  52. fi
  53. cd -
  54. cd build-tmp/psi
  55. echo -e "-keep class psi.** { *; }\n-keep class ca.psiphon.** { *; }\n" >> proguard.txt
  56. rm -f ../../ca.psiphon.aar
  57. zip -r ../../ca.psiphon.aar ./
  58. cd -
  59. rm -rf build-tmp
  60. echo "Done"