make.bash 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env bash
  2. set -e
  3. if [ ! -f make.bash ]; then
  4. echo "make.bash must be run from $GOPATH/src/github.com/Psiphon-Labs/psiphon-tunnel-core/ConsoleClient"
  5. exit 1
  6. fi
  7. EXE_BASENAME="psiphon-tunnel-core"
  8. BUILDINFOFILE="${EXE_BASENAME}_buildinfo.txt"
  9. BUILDDATE=$(date --iso-8601=seconds)
  10. BUILDREPO=$(git config --get remote.origin.url)
  11. BUILDREV=$(git rev-parse --short HEAD)
  12. LDFLAGS="\
  13. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon.buildDate $BUILDDATE \
  14. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon.buildRepo $BUILDREPO \
  15. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon.buildRev $BUILDREV \
  16. "
  17. echo -e "${BUILDDATE}\n${BUILDREPO}\n${BUILDREV}\n" > $BUILDINFOFILE
  18. echo "Variables for ldflags:"
  19. echo " Build date: ${BUILDDATE}"
  20. echo " Build repo: ${BUILDREPO}"
  21. echo " Build revision: ${BUILDREV}"
  22. echo ""
  23. echo "Getting project dependencies (via go get)"
  24. GOOS=linux go get -d -v ./...
  25. GOOS=windows go get -d -v ./...
  26. GOOS=darwin go get -d -v ./...
  27. if [ ! -d bin ]; then
  28. mkdir bin
  29. fi
  30. echo "Building windows-i686..."
  31. CC=/usr/bin/i686-w64-mingw32-gcc gox -verbose -ldflags "$LDFLAGS" -osarch windows/386 -output bin/windows/${EXE_BASENAME}-i686
  32. # We are finding that UPXing the full Windows Psiphon client produces better results if psiphon-tunnel-core.exe is not already UPX'd.
  33. echo "..No UPX for this build"
  34. echo "Building windows-x86_64..."
  35. CC=/usr/bin/x86_64-w64-mingw32-gcc gox -verbose -ldflags "$LDFLAGS" -osarch windows/amd64 -output bin/windows/${EXE_BASENAME}-x86_64
  36. # We are finding that UPXing the full Windows Psiphon client produces better results if psiphon-tunnel-core.exe is not already UPX'd.
  37. echo "..No UPX for this build"
  38. echo "Building linux-i686..."
  39. CFLAGS=-m32 gox -verbose -ldflags "$LDFLAGS" -osarch linux/386 -output bin/linux/${EXE_BASENAME}-i686
  40. echo "..UPX packaging output"
  41. goupx --best bin/linux/${EXE_BASENAME}-i686
  42. echo "Building linux-x86_64..."
  43. gox -verbose -ldflags "$LDFLAGS" -osarch linux/amd64 -output bin/linux/${EXE_BASENAME}-x86_64
  44. echo "..UPX packaging output"
  45. goupx --best bin/linux/${EXE_BASENAME}-x86_64
  46. echo "Building darwin-x86_64..."
  47. CGO_ENABLED=0 gox -verbose -ldflags "$LDFLAGS" -osarch darwin/amd64 -output bin/darwin/${EXE_BASENAME}-x86_64
  48. # Darwin binaries don't seem to be UPXable when built this way
  49. echo "..No UPX for this build"
  50. echo "Done"