make.bash 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. Parameter is: '$1'"
  28. GOOS=windows go get -d -v ./...
  29. if [ -z $1 ] || [ "$1" == "32" ]; then
  30. unset PKG_CONFIG_PATH
  31. export PKG_CONFIG_PATH=$PKG_CONFIG_PATH_32
  32. echo "...Building windows-i686"
  33. echo "....PKG_CONFIG_PATH=$PKG_CONFIG_PATH"
  34. CGO_CFLAGS="-I $PKG_CONFIG_PATH/include/" \
  35. CGO_LDFLAGS="-L $PKG_CONFIG_PATH -L /usr/i686-w64-mingw32/lib/ -lssl -lcrypto -lwsock32 -lcrypt32 -lgdi32" \
  36. CC=/usr/bin/i686-w64-mingw32-gcc \
  37. gox -verbose -ldflags "$LDFLAGS" -osarch windows/386 -output bin/windows/${EXE_BASENAME}-i686
  38. ## We are finding that UPXing the full Windows Psiphon client produces better results if psiphon-tunnel-core.exe is not already UPX'd.
  39. echo "....No UPX for this build"
  40. fi
  41. if [ -z $1 ] || [ "$1" == "64" ]; then
  42. unset PKG_CONFIG_PATH
  43. export PKG_CONFIG_PATH=$PKG_CONFIG_PATH_64
  44. echo "...Building windows-x86_64"
  45. echo "....PKG_CONFIG_PATH=$PKG_CONFIG_PATH"
  46. CGO_CFLAGS="-I $PKG_CONFIG_PATH/include/" \
  47. CGO_LDFLAGS="-L $PKG_CONFIG_PATH -L /usr/x86_64-w64-mingw32/lib/ -lssl -lcrypto -lwsock32 -lcrypt32 -lgdi32" \
  48. CC=/usr/bin/x86_64-w64-mingw32-gcc \
  49. gox -verbose -ldflags "$LDFLAGS" -osarch windows/amd64 -output bin/windows/${EXE_BASENAME}-x86_64
  50. # We are finding that UPXing the full Windows Psiphon client produces better results if psiphon-tunnel-core.exe is not already UPX'd.
  51. echo "....No UPX for this build"
  52. fi
  53. }
  54. build_for_linux () {
  55. echo "Getting project dependencies (via go get) for Linux. Parameter is: '$1'"
  56. GOOS=linux go get -d -v ./...
  57. if [ -z $1 ] || [ "$1" == "32" ]; then
  58. echo "...Building linux-i686"
  59. CFLAGS=-m32 gox -verbose -ldflags "$LDFLAGS" -osarch linux/386 -output bin/linux/${EXE_BASENAME}-i686
  60. echo "....UPX packaging output"
  61. goupx --best bin/linux/${EXE_BASENAME}-i686
  62. fi
  63. if [ -z $1 ] || [ "$1" == "64" ]; then
  64. echo "...Building linux-x86_64"
  65. gox -verbose -ldflags "$LDFLAGS" -osarch linux/amd64 -output bin/linux/${EXE_BASENAME}-x86_64
  66. echo "....UPX packaging output"
  67. goupx --best bin/linux/${EXE_BASENAME}-x86_64
  68. fi
  69. }
  70. build_for_osx () {
  71. echo "Getting project dependencies (via go get) for OSX"
  72. GOOS=darwin go get -d -v ./...
  73. echo "Building darwin-x86_64..."
  74. echo "..Disabling CGO for this build"
  75. CGO_ENABLED=0 gox -verbose -ldflags "$LDFLAGS" -osarch darwin/amd64 -output bin/darwin/${EXE_BASENAME}-x86_64
  76. # Darwin binaries don't seem to be UPXable when built this way
  77. echo "..No UPX for this build"
  78. }
  79. TARGET=$1
  80. case $TARGET in
  81. windows)
  82. echo "..Building for Windows"
  83. build_for_windows $2
  84. ;;
  85. linux)
  86. echo "..Building for Linux"
  87. build_for_linux $2
  88. ;;
  89. osx)
  90. echo "..Building for OSX"
  91. build_for_osx
  92. ;;
  93. all)
  94. echo "..Building all"
  95. build_for_windows $2
  96. build_for_linux $2
  97. build_for_osx
  98. ;;
  99. *)
  100. echo "..No selection made, building all"
  101. build_for_windows $2
  102. build_for_linux $2
  103. build_for_osx
  104. ;;
  105. esac
  106. echo "Done"