make.bash 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env bash
  2. set -e -u -x
  3. BASE_DIR=$( cd "$(dirname "$0")" ; pwd -P )
  4. cd $BASE_DIR
  5. if [ ! -f make.bash ]; then
  6. echo "make.bash must be run from $GOPATH/src/github.com/Psiphon-Labs/psiphon-tunnel-core/Server"
  7. exit 1
  8. fi
  9. # $1, if specified, is go build tags
  10. if [ -z ${1+x} ]; then BUILD_TAGS=""; else BUILD_TAGS="$1"; fi
  11. # At this time, we don't support modules
  12. export GO111MODULE=off
  13. prepare_build () {
  14. BUILDINFOFILE="psiphond_buildinfo.txt"
  15. BUILDDATE=$(date -Iseconds)
  16. BUILDREPO=$(git config --get remote.origin.url)
  17. BUILDREV=$(git rev-parse --short HEAD)
  18. GOVERSION=$(go version | perl -ne '/go version (.*?) / && print $1')
  19. # see DEPENDENCIES comment in MobileLibrary/Android/make.bash
  20. DEPENDENCIES=$(echo -n "{" && GOOS=$1 go list -tags "${BUILD_TAGS}" -f '{{range $dep := .Deps}}{{printf "%s\n" $dep}}{{end}}' | GOOS=$1 xargs go list -tags "${BUILD_TAGS}" -f '{{if not .Standard}}{{.ImportPath}}{{end}}' | xargs -I pkg bash -c 'cd $GOPATH/src/$0 && if echo -n "$0" | grep -vEq "^github.com/Psiphon-Labs/psiphon-tunnel-core/" ; then echo -n "\"$0\":\"$(git rev-parse --short HEAD)\"," ; fi' pkg | sed 's/,$//' | tr -d '\n' && echo -n "}")
  21. LDFLAGS="\
  22. -linkmode external -extldflags \"-static\" \
  23. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildDate=$BUILDDATE \
  24. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildRepo=$BUILDREPO \
  25. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildRev=$BUILDREV \
  26. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.goVersion=$GOVERSION \
  27. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.dependencies=$DEPENDENCIES \
  28. "
  29. echo -e "${BUILDDATE}\n${BUILDREPO}\n${BUILDREV}\n" > $BUILDINFOFILE
  30. echo "Variables for ldflags:"
  31. echo " Build date: ${BUILDDATE}"
  32. echo " Build repo: ${BUILDREPO}"
  33. echo " Build revision: ${BUILDREV}"
  34. echo " Go version: ${GOVERSION}"
  35. echo " Dependencies: ${DEPENDENCIES}"
  36. echo ""
  37. }
  38. build_for_linux () {
  39. prepare_build linux
  40. GOOS=linux GOARCH=amd64 go build -v -x -tags "${BUILD_TAGS}" -ldflags "$LDFLAGS" -o psiphond
  41. if [ $? != 0 ]; then
  42. echo "...'go build' failed, exiting"
  43. exit $?
  44. fi
  45. chmod 555 psiphond
  46. if [ "$1" == "generate" ]; then
  47. ./psiphond --ipaddress 0.0.0.0 --web 3000 --protocol SSH:3001 --protocol OSSH:3002 --logFilename /var/log/psiphond/psiphond.log generate
  48. chmod 666 psiphond.config
  49. chmod 666 psiphond-traffic-rules.config
  50. chmod 666 psiphond-osl.config
  51. chmod 666 psiphond-tactics.config
  52. chmod 666 server-entry.dat
  53. fi
  54. }
  55. build_for_linux generate
  56. echo "Done"