make.bash 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env bash
  2. set -e
  3. #set -exv # verbose output for testing
  4. if [ ! -f make.bash ]; then
  5. echo 'make.bash must be run from $GOPATH/src/github.com/Psiphon-Labs/psiphon-tunnel-core/AndroidLibrary'
  6. exit 1
  7. fi
  8. # Make sure we have our dependencies
  9. echo -e "go-getting dependencies...\n"
  10. go get -d -v ./...
  11. # Force an update of the go-mobile package, since it's being improved rapidly
  12. # NOTE: for some reason this either doesn't complete or stalls for a very long time.
  13. #echo -e "Updating go-mobile...\n"
  14. #go get -u -d -v golang.org/x/mobile/...
  15. LIB_BASENAME="libgojni"
  16. BUILDINFOFILE="${LIB_BASENAME}_buildinfo.txt"
  17. BUILDDATE=$(date --iso-8601=seconds)
  18. BUILDREPO=$(git config --get remote.origin.url)
  19. BUILDREV=$(git rev-parse HEAD)
  20. LDFLAGS="\
  21. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon.buildDate $BUILDDATE \
  22. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon.buildRepo $BUILDREPO \
  23. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon.buildRev $BUILDREV \
  24. "
  25. echo -e "${BUILDDATE}\n${BUILDREPO}\n${BUILDREV}\n" > $BUILDINFOFILE
  26. echo -e "LDFLAGS=$LDFLAGS\n"
  27. echo -e "Building library...\n"
  28. CGO_ENABLED=1 GOOS=android GOARCH=arm GOARM=7 \
  29. go build -a -v -ldflags="-shared $LDFLAGS" -o ${LIB_BASENAME}.so ./libpsi
  30. mkdir -p libs/armeabi-v7a
  31. mv -f ${LIB_BASENAME}.so libs/armeabi-v7a/${LIB_BASENAME}.so
  32. echo -e "Library can be found at: libs/armeabi-v7a/${LIB_BASENAME}.so\n"