make.bash 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. # -checklinkname=0 is a required workaround for an PSIPHON_ENABLE_INPROXY dependency:
  18. # https://github.com/wlynxg/anet/tree/5501d401a269290292909e6cc75f105571f97cfa?tab=readme-ov-file#how-to-build-with-go-1230-or-later
  19. #
  20. # TODO: conditional on PSIPHON_ENABLE_INPROXY build tag?
  21. LDFLAGS="\
  22. -checklinkname=0 \
  23. -s \
  24. -w \
  25. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildDate=$BUILDDATE \
  26. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildRepo=$BUILDREPO \
  27. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildRev=$BUILDREV \
  28. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.goVersion=$GOVERSION \
  29. "
  30. echo -e "${BUILDDATE}\n${BUILDREPO}\n${BUILDREV}\n" > $BUILDINFOFILE
  31. echo "Variables for ldflags:"
  32. echo " Build date: ${BUILDDATE}"
  33. echo " Build repo: ${BUILDREPO}"
  34. echo " Build revision: ${BUILDREV}"
  35. echo " Go version: ${GOVERSION}"
  36. echo ""
  37. 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
  38. if [ $? != 0 ]; then
  39. echo "..'gomobile bind' failed, exiting"
  40. exit $?
  41. fi
  42. mkdir -p build-tmp/psi
  43. unzip -o psi.aar -d build-tmp/psi
  44. yes | cp -f PsiphonTunnel/AndroidManifest.xml build-tmp/psi/AndroidManifest.xml
  45. mkdir -p build-tmp/psi/res/xml
  46. yes | cp -f PsiphonTunnel/ca_psiphon_psiphontunnel_backup_rules.xml build-tmp/psi/res/xml/ca_psiphon_psiphontunnel_backup_rules.xml
  47. 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
  48. if [ $? != 0 ]; then
  49. echo "..'javac' compiling PsiphonTunnel failed, exiting"
  50. exit $?
  51. fi
  52. cd build-tmp
  53. jar uf psi/classes.jar ca/psiphon/*.class
  54. if [ $? != 0 ]; then
  55. echo "..'jar' failed to add classes, exiting"
  56. exit $?
  57. fi
  58. cd -
  59. cd build-tmp/psi
  60. echo -e "-keep class psi.** { *; }\n-keep class ca.psiphon.** { *; }\n" >> proguard.txt
  61. rm -f ../../ca.psiphon.aar
  62. zip -r ../../ca.psiphon.aar ./
  63. cd -
  64. rm -rf build-tmp
  65. echo "Done"