make.bash 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. # Windows requires CGO due to sqlite. OpenSSL will likely eventually require CGO everywhere
  31. echo "CGO Enabled"
  32. export CGO_ENABLED=1
  33. echo "Building windows-i686..."
  34. CC=/usr/bin/i686-w64-mingw32-gcc gox -verbose -ldflags "$LDFLAGS" -osarch windows/386 -output bin/windows/${EXE_BASENAME}-i686
  35. # We are finding that UPXing the full Windows Psiphon client produces better results if psiphon-tunnel-core.exe is not already UPX'd.
  36. echo "..No UPX for this build"
  37. echo "Building windows-x86_64..."
  38. CC=/usr/bin/x86_64-w64-mingw32-gcc gox -verbose -ldflags "$LDFLAGS" -osarch windows/amd64 -output bin/windows/${EXE_BASENAME}-x86_64
  39. # We are finding that UPXing the full Windows Psiphon client produces better results if psiphon-tunnel-core.exe is not already UPX'd.
  40. echo "..No UPX for this build"
  41. echo "CGO Enabled unset (Preferred unless needed)"
  42. unset CGO_ENABLED
  43. echo "Building linux-i686..."
  44. CFLAGS=-m32 gox -verbose -ldflags "$LDFLAGS" -osarch linux/386 -output bin/linux/${EXE_BASENAME}-i686
  45. echo "..UPX packaging output"
  46. goupx --best bin/linux/${EXE_BASENAME}-i686
  47. echo "Building linux-x86_64..."
  48. gox -verbose -ldflags "$LDFLAGS" -osarch linux/amd64 -output bin/linux/${EXE_BASENAME}-x86_64
  49. echo "..UPX packaging output"
  50. goupx --best bin/linux/${EXE_BASENAME}-x86_64
  51. echo "Building darwin-x86_64..."
  52. gox -verbose -ldflags "$LDFLAGS" -osarch darwin/amd64 -output bin/darwin/${EXE_BASENAME}-x86_64
  53. # Darwin binaries don't seem to be UPXable when built this way
  54. echo "..No UPX for this build"
  55. echo "Done"