make.bash 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. prepare_build () {
  12. BUILDINFOFILE="psiphond_buildinfo.txt"
  13. BUILDDATE=$(date -Iseconds)
  14. BUILDREPO=$(git config --get remote.origin.url)
  15. BUILDREV=$(git rev-parse --short HEAD)
  16. GOVERSION=$(go version | perl -ne '/go version (.*?) / && print $1')
  17. # see DEPENDENCIES comment in MobileLibrary/Android/make.bash
  18. 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 "}")
  19. LDFLAGS="\
  20. -linkmode external -extldflags \"-static\" \
  21. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildDate=$BUILDDATE \
  22. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildRepo=$BUILDREPO \
  23. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.buildRev=$BUILDREV \
  24. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.goVersion=$GOVERSION \
  25. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/buildinfo.dependencies=$DEPENDENCIES \
  26. "
  27. echo -e "${BUILDDATE}\n${BUILDREPO}\n${BUILDREV}\n" > $BUILDINFOFILE
  28. echo "Variables for ldflags:"
  29. echo " Build date: ${BUILDDATE}"
  30. echo " Build repo: ${BUILDREPO}"
  31. echo " Build revision: ${BUILDREV}"
  32. echo " Go version: ${GOVERSION}"
  33. echo " Dependencies: ${DEPENDENCIES}"
  34. echo ""
  35. }
  36. build_for_linux () {
  37. prepare_build linux
  38. GOOS=linux GOARCH=amd64 go build -v -x -tags "${BUILD_TAGS}" -ldflags "$LDFLAGS" -o psiphond
  39. if [ $? != 0 ]; then
  40. echo "...'go build' failed, exiting"
  41. exit $?
  42. fi
  43. chmod 555 psiphond
  44. if [ "$1" == "generate" ]; then
  45. ./psiphond --ipaddress 0.0.0.0 --web 3000 --protocol SSH:3001 --protocol OSSH:3002 --logFilename /var/log/psiphond/psiphond.log generate
  46. chmod 666 psiphond.config
  47. chmod 666 psiphond-traffic-rules.config
  48. chmod 666 psiphond-osl.config
  49. chmod 666 psiphond-tactics.config
  50. chmod 666 server-entry.dat
  51. fi
  52. }
  53. build_for_linux generate
  54. echo "Done"