build.sh 756 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #/bin/bash
  2. set -euo pipefail
  3. NAME=watchlogs
  4. function build() {
  5. local -r name=${1:-main}
  6. export GOOS=$2
  7. export GOARCH=$3
  8. local artifact=$name-$GOOS-$GOARCH
  9. if [ $GOOS == windows ]
  10. then artifact=$artifact.exe
  11. fi
  12. go build \
  13. -o $artifact \
  14. -buildmode pie \
  15. -ldflags "\
  16. -w -s \
  17. -X main.Version=$(git describe --tags | head -1) \
  18. -X main.Build=$(date -u -Iseconds)"
  19. shasum -a 256 ./$artifact > $artifact.sha256sum
  20. }
  21. function main() {
  22. local -r name=watchlogs
  23. local -r targets="linux amd64
  24. linux arm64
  25. darwin amd64
  26. darwin arm64
  27. windows amd64"
  28. local -a target
  29. while read line
  30. do
  31. read -a target <<< $line
  32. echo "Building ${target[@]}..." >&2
  33. build $NAME ${target[0]} ${target[1]}
  34. done < <(echo "$targets")
  35. }
  36. main $@