make.bash 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. if [ ! -d bin ]; then
  24. mkdir bin
  25. fi
  26. build_for_windows () {
  27. echo "...Getting project dependencies (via go get) for Windows"
  28. GOOS=windows go get -d -v ./...
  29. echo "...Building windows-i686"
  30. CC=/usr/bin/i686-w64-mingw32-gcc gox -verbose -ldflags "$LDFLAGS" -osarch windows/386 -output bin/windows/${EXE_BASENAME}-i686
  31. # We are finding that UPXing the full Windows Psiphon client produces better results if psiphon-tunnel-core.exe is not already UPX'd.
  32. echo "....No UPX for this build"
  33. echo "...Building windows-x86_64"
  34. CC=/usr/bin/x86_64-w64-mingw32-gcc gox -verbose -ldflags "$LDFLAGS" -osarch windows/amd64 -output bin/windows/${EXE_BASENAME}-x86_64
  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. }
  38. build_for_linux () {
  39. echo "Getting project dependencies (via go get) for Linux"
  40. GOOS=linux go get -d -v ./...
  41. echo "...Building linux-i686"
  42. CFLAGS=-m32 gox -verbose -ldflags "$LDFLAGS" -osarch linux/386 -output bin/linux/${EXE_BASENAME}-i686
  43. echo "....UPX packaging output"
  44. goupx --best bin/linux/${EXE_BASENAME}-i686
  45. echo "...Building linux-x86_64"
  46. gox -verbose -ldflags "$LDFLAGS" -osarch linux/amd64 -output bin/linux/${EXE_BASENAME}-x86_64
  47. echo "....UPX packaging output"
  48. goupx --best bin/linux/${EXE_BASENAME}-x86_64
  49. }
  50. build_for_osx () {
  51. echo "Getting project dependencies (via go get) for OSX"
  52. GOOS=darwin go get -d -v ./...
  53. echo "Building darwin-x86_64..."
  54. CGO_ENABLED=0 gox -verbose -ldflags "$LDFLAGS" -osarch darwin/amd64 -output bin/darwin/${EXE_BASENAME}-x86_64
  55. # Darwin binaries don't seem to be UPXable when built this way
  56. echo "..No UPX for this build"
  57. }
  58. TARGET=$1
  59. case $TARGET in
  60. windows)
  61. echo "..Building for Windows"
  62. build_for_windows
  63. ;;
  64. linux)
  65. echo "..Building for Linux"
  66. build_for_linux
  67. ;;
  68. osx)
  69. echo "..Building for OSX"
  70. build_for_osx
  71. ;;
  72. all)
  73. echo "..Building all"
  74. build_for_windows
  75. build_for_linux
  76. build_for_osx
  77. ;;
  78. *)
  79. echo "..No selection made, building all"
  80. build_for_windows
  81. build_for_linux
  82. build_for_osx
  83. ;;
  84. esac
  85. echo "Done"