make.bash 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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=$(git config --get remote.origin.url)
  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. yes | cp -f PsiphonTunnel/libs/armeabi-v7a/libtun2socks.so build-tmp/psi/jni/armeabi-v7a/libtun2socks.so
  41. yes | cp -f PsiphonTunnel/libs/arm64-v8a/libtun2socks.so build-tmp/psi/jni/arm64-v8a/libtun2socks.so
  42. yes | cp -f PsiphonTunnel/libs/x86/libtun2socks.so build-tmp/psi/jni/x86/libtun2socks.so
  43. yes | cp -f PsiphonTunnel/libs/x86_64/libtun2socks.so build-tmp/psi/jni/x86_64/libtun2socks.so
  44. mkdir -p build-tmp/psi/res/xml
  45. yes | cp -f PsiphonTunnel/ca_psiphon_psiphontunnel_backup_rules.xml build-tmp/psi/res/xml/ca_psiphon_psiphontunnel_backup_rules.xml
  46. 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
  47. if [ $? != 0 ]; then
  48. echo "..'javac' compiling PsiphonTunnel failed, exiting"
  49. exit $?
  50. fi
  51. cd build-tmp
  52. jar uf psi/classes.jar ca/psiphon/*.class
  53. if [ $? != 0 ]; then
  54. echo "..'jar' failed to add classes, exiting"
  55. exit $?
  56. fi
  57. cd -
  58. cd build-tmp/psi
  59. echo -e "-keep class psi.** { *; }\n-keep class ca.psiphon.** { *; }\n" >> proguard.txt
  60. rm -f ../../ca.psiphon.aar
  61. zip -r ../../ca.psiphon.aar ./
  62. cd -
  63. rm -rf build-tmp
  64. echo "Done"