make.bash 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. prep_openssl () {
  27. if [ ! -f /tmp/openssl.tar.gz ]; then
  28. curl -L https://github.com/Psiphon-Labs/psiphon-tunnel-core/raw/master/openssl/openssl-$OPENSSL_VERSION.tar.gz -o /tmp/openssl.tar.gz
  29. fi
  30. if [ -d /tmp/openssl ]; then
  31. rm -rf /tmp/openssl
  32. fi
  33. mkdir -p /tmp/openssl
  34. tar -C /tmp/openssl -xzf /tmp/openssl.tar.gz
  35. }
  36. build_for_windows () {
  37. echo "...Getting project dependencies (via go get) for Windows. Parameter is: '$1'"
  38. GOOS=windows go get -d -v ./...
  39. if [ -z $1 ] || [ "$1" == "32" ]; then
  40. echo "...Building windows-i686"
  41. echo "....Preparing clean OpenSSL"
  42. prep_openssl
  43. cd $PKG_CONFIG_PATH && ./Configure --cross-compile-prefix=i686-w64-mingw32- mingw no-shared no-ssl2 no-ssl3 no-comp no-hw no-md2 no-md4 no-rc2 no-rc5 no-krb5 no-ripemd160 no-idea no-gost no-camellia no-seed no-3des no-heartbeats && make depend && make && cd $GOPATH/src/github.com/Psiphon-Labs/psiphon-tunnel-core/ConsoleClient || exit 1
  44. CGO_CFLAGS="-I $PKG_CONFIG_PATH/include/" CGO_LDFLAGS="-L $PKG_CONFIG_PATH -L /usr/i686-w64-mingw32/lib/ -lssl -lcrypto -lwsock32 -lcrypt32 -lgdi32" CC=/usr/bin/i686-w64-mingw32-gcc gox -verbose -ldflags "$LDFLAGS" -osarch windows/386 -output bin/windows/${EXE_BASENAME}-i686
  45. ## We are finding that UPXing the full Windows Psiphon client produces better results if psiphon-tunnel-core.exe is not already UPX'd.
  46. echo "....No UPX for this build"
  47. fi
  48. if [ -z $1 ] || [ "$1" == "64" ]; then
  49. echo "...Building windows-x86_64"
  50. echo "....Preparing clean OpenSSL"
  51. prep_openssl
  52. cd $PKG_CONFIG_PATH && ./Configure --cross-compile-prefix=x86_64-w64-mingw32- mingw64 no-shared no-ssl2 no-ssl3 no-comp no-hw no-md2 no-md4 no-rc2 no-rc5 no-krb5 no-ripemd160 no-idea no-gost no-camellia no-seed no-3des no-heartbeats && make depend && make && cd $GOPATH/src/github.com/Psiphon-Labs/psiphon-tunnel-core/ConsoleClient || exit 1
  53. CGO_CFLAGS="-I $PKG_CONFIG_PATH/include/" CGO_LDFLAGS="-L $PKG_CONFIG_PATH -L /usr/x86_64-w64-mingw32/lib/ -lssl -lcrypto -lwsock32 -lcrypt32 -lgdi32" CC=/usr/bin/x86_64-w64-mingw32-gcc gox -verbose -ldflags "$LDFLAGS" -osarch windows/amd64 -output bin/windows/${EXE_BASENAME}-x86_64
  54. # We are finding that UPXing the full Windows Psiphon client produces better results if psiphon-tunnel-core.exe is not already UPX'd.
  55. echo "....No UPX for this build"
  56. fi
  57. }
  58. build_for_linux () {
  59. echo "Getting project dependencies (via go get) for Linux. Parameter is: '$1'"
  60. GOOS=linux go get -d -v ./...
  61. if [ -z $1 ] || [ "$1" == "32" ]; then
  62. echo "...Building linux-i686"
  63. CFLAGS=-m32 gox -verbose -ldflags "$LDFLAGS" -osarch linux/386 -output bin/linux/${EXE_BASENAME}-i686
  64. echo "....UPX packaging output"
  65. goupx --best bin/linux/${EXE_BASENAME}-i686
  66. fi
  67. if [ -z $1 ] || [ "$1" == "64" ]; then
  68. echo "...Building linux-x86_64"
  69. gox -verbose -ldflags "$LDFLAGS" -osarch linux/amd64 -output bin/linux/${EXE_BASENAME}-x86_64
  70. echo "....UPX packaging output"
  71. goupx --best bin/linux/${EXE_BASENAME}-x86_64
  72. fi
  73. }
  74. build_for_osx () {
  75. echo "Getting project dependencies (via go get) for OSX"
  76. GOOS=darwin go get -d -v ./...
  77. echo "Building darwin-x86_64..."
  78. echo "..Disabling CGO for this build"
  79. CGO_ENABLED=0 gox -verbose -ldflags "$LDFLAGS" -osarch darwin/amd64 -output bin/darwin/${EXE_BASENAME}-x86_64
  80. # Darwin binaries don't seem to be UPXable when built this way
  81. echo "..No UPX for this build"
  82. }
  83. TARGET=$1
  84. case $TARGET in
  85. windows)
  86. echo "..Building for Windows"
  87. build_for_windows $2
  88. ;;
  89. linux)
  90. echo "..Building for Linux"
  91. build_for_linux $2
  92. ;;
  93. osx)
  94. echo "..Building for OSX"
  95. build_for_osx
  96. ;;
  97. all)
  98. echo "..Building all"
  99. build_for_windows $2
  100. build_for_linux $2
  101. build_for_osx
  102. ;;
  103. *)
  104. echo "..No selection made, building all"
  105. build_for_windows $2
  106. build_for_linux $2
  107. build_for_osx
  108. ;;
  109. esac
  110. echo "Done"