make.bash 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. BUILDINFOFILE="psiphon-tunnel-core_buildinfo.txt"
  12. BUILDDATE=$(date --iso-8601=seconds)
  13. BUILDREPO=$(git config --get remote.origin.url)
  14. BUILDREV=$(git rev-parse --short HEAD)
  15. GOVERSION=$(go version | perl -ne '/go version (.*?) / && print $1')
  16. LDFLAGS="\
  17. -s \
  18. -w \
  19. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildDate=$BUILDDATE \
  20. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildRepo=$BUILDREPO \
  21. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildRev=$BUILDREV \
  22. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.goVersion=$GOVERSION \
  23. "
  24. echo -e "${BUILDDATE}\n${BUILDREPO}\n${BUILDREV}\n" > $BUILDINFOFILE
  25. echo "Variables for ldflags:"
  26. echo " Build date: ${BUILDDATE}"
  27. echo " Build repo: ${BUILDREPO}"
  28. echo " Build revision: ${BUILDREV}"
  29. echo " Go version: ${GOVERSION}"
  30. echo ""
  31. 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
  32. if [ $? != 0 ]; then
  33. echo "..'gomobile bind' failed, exiting"
  34. exit $?
  35. fi
  36. mkdir -p build-tmp/psi
  37. unzip -o psi.aar -d build-tmp/psi
  38. yes | cp -f PsiphonTunnel/AndroidManifest.xml build-tmp/psi/AndroidManifest.xml
  39. yes | cp -f PsiphonTunnel/libs/armeabi-v7a/libtun2socks.so build-tmp/psi/jni/armeabi-v7a/libtun2socks.so
  40. yes | cp -f PsiphonTunnel/libs/arm64-v8a/libtun2socks.so build-tmp/psi/jni/arm64-v8a/libtun2socks.so
  41. yes | cp -f PsiphonTunnel/libs/x86/libtun2socks.so build-tmp/psi/jni/x86/libtun2socks.so
  42. yes | cp -f PsiphonTunnel/libs/x86_64/libtun2socks.so build-tmp/psi/jni/x86_64/libtun2socks.so
  43. mkdir -p build-tmp/psi/res/xml
  44. yes | cp -f PsiphonTunnel/ca_psiphon_psiphontunnel_backup_rules.xml build-tmp/psi/res/xml/ca_psiphon_psiphontunnel_backup_rules.xml
  45. 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
  46. if [ $? != 0 ]; then
  47. echo "..'javac' compiling PsiphonTunnel failed, exiting"
  48. exit $?
  49. fi
  50. cd build-tmp
  51. jar uf psi/classes.jar ca/psiphon/*.class
  52. if [ $? != 0 ]; then
  53. echo "..'jar' failed to add classes, exiting"
  54. exit $?
  55. fi
  56. cd -
  57. cd build-tmp/psi
  58. echo -e "-keep class psi.** { *; }\n-keep class ca.psiphon.** { *; }\n" >> proguard.txt
  59. rm -f ../../ca.psiphon.aar
  60. zip -r ../../ca.psiphon.aar ./
  61. cd -
  62. rm -rf build-tmp
  63. echo "Done"