build.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #!/usr/bin/env bash
  2. export COPYFILE_DISABLE=true
  3. export GO386=387 # Don't use SSE on 32 bit builds
  4. distFiles=(README.md LICENSE) # apart from the binary itself
  5. version=$(git describe --always --dirty)
  6. date=$(git show -s --format=%ct)
  7. user=$(whoami)
  8. host=$(hostname)
  9. host=${host%%.*}
  10. ldflags="-w -X main.Version $version -X main.BuildStamp $date -X main.BuildUser $user -X main.BuildHost $host"
  11. check() {
  12. if ! command -v godep >/dev/null ; then
  13. echo "Error: no godep. Try \"$0 setup\"."
  14. exit 1
  15. fi
  16. }
  17. build() {
  18. check
  19. go vet ./...
  20. godep go build $* -ldflags "$ldflags" ./cmd/syncthing
  21. }
  22. assets() {
  23. check
  24. godep go run cmd/assets/assets.go gui > auto/gui.files.go
  25. }
  26. test() {
  27. check
  28. godep go test -cpu=1,2,4 ./...
  29. }
  30. sign() {
  31. if git describe --exact-match 2>/dev/null >/dev/null ; then
  32. # HEAD is a tag
  33. id=BCE524C7
  34. if gpg --list-keys "$id" >/dev/null 2>&1 ; then
  35. gpg -ab -u "$id" "$1"
  36. fi
  37. fi
  38. }
  39. tarDist() {
  40. name="$1"
  41. rm -rf "$name"
  42. mkdir -p "$name"
  43. cp syncthing "${distFiles[@]}" "$name"
  44. sign "$name/syncthing"
  45. tar zcvf "$name.tar.gz" "$name"
  46. rm -rf "$name"
  47. }
  48. zipDist() {
  49. name="$1"
  50. rm -rf "$name"
  51. mkdir -p "$name"
  52. cp syncthing.exe "${distFiles[@]}" "$name"
  53. sign "$name/syncthing.exe"
  54. zip -r "$name.zip" "$name"
  55. rm -rf "$name"
  56. }
  57. deps() {
  58. check
  59. godep save ./cmd/syncthing ./cmd/assets ./discover/cmd/discosrv
  60. }
  61. setup() {
  62. echo Installing godep...
  63. go get -u github.com/tools/godep
  64. echo Installing go vet...
  65. go get -u code.google.com/p/go.tools/cmd/vet
  66. }
  67. case "$1" in
  68. "")
  69. shift
  70. build $*
  71. ;;
  72. race)
  73. build -race
  74. ;;
  75. guidev)
  76. echo "Syncthing is already built for GUI developments. Try:"
  77. echo " STGUIASSETS=~/someDir/gui syncthing"
  78. ;;
  79. test)
  80. test
  81. ;;
  82. tar)
  83. rm -f *.tar.gz *.zip
  84. test || exit 1
  85. assets
  86. build
  87. eval $(go env)
  88. name="syncthing-$GOOS-$GOARCH-$version"
  89. tarDist "$name"
  90. ;;
  91. all)
  92. rm -f *.tar.gz *.zip
  93. test || exit 1
  94. assets
  95. godep go build ./discover/cmd/discosrv
  96. godep go build ./cmd/stpidx
  97. godep go build ./cmd/stcli
  98. for os in darwin-amd64 linux-386 linux-amd64 freebsd-amd64 windows-amd64 windows-386 ; do
  99. export GOOS=${os%-*}
  100. export GOARCH=${os#*-}
  101. build
  102. name="syncthing-$os-$version"
  103. case $GOOS in
  104. windows)
  105. zipDist "$name"
  106. rm -f syncthing.exe
  107. ;;
  108. *)
  109. tarDist "$name"
  110. rm -f syncthing
  111. ;;
  112. esac
  113. done
  114. export GOOS=linux
  115. export GOARCH=arm
  116. origldflags="$ldflags"
  117. export GOARM=7
  118. ldflags="$origldflags -X main.GoArchExtra v7"
  119. build
  120. tarDist "syncthing-linux-armv7-$version"
  121. export GOARM=6
  122. ldflags="$origldflags -X main.GoArchExtra v6"
  123. build
  124. tarDist "syncthing-linux-armv6-$version"
  125. export GOARM=5
  126. ldflags="$origldflags -X main.GoArchExtra v5"
  127. build
  128. tarDist "syncthing-linux-armv5-$version"
  129. ;;
  130. upload)
  131. tag=$(git describe)
  132. shopt -s nullglob
  133. for f in *.tar.gz *.zip *.asc ; do
  134. relup calmh/syncthing "$tag" "$f"
  135. done
  136. ;;
  137. deps)
  138. deps
  139. ;;
  140. assets)
  141. assets
  142. ;;
  143. setup)
  144. setup
  145. ;;
  146. *)
  147. echo "Unknown build parameter $1"
  148. ;;
  149. esac