2
0

build.sh 837 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/bash
  2. PROJECT="$1"
  3. if [[ -z "$PROJECT" ]]; then
  4. echo "usage: $0 <package-name>"
  5. exit 1
  6. fi
  7. VERSION="$2"
  8. if [[ -z "$VERSION" ]]; then
  9. echo "usage: $0 <version-name>"
  10. exit 1
  11. fi
  12. GOLDFLAGS="$3"
  13. if [[ -z "$GOLDFLAGS" ]]; then
  14. GOLDFLAGS='-w -s -extldflags "-static"'
  15. fi
  16. PLATFORMS=("darwin/amd64")
  17. for platform in "${PLATFORMS[@]}"
  18. do
  19. platform_split=(${platform//\// })
  20. GOOS=${platform_split[0]}
  21. GOARCH=${platform_split[1]}
  22. output_name='cli-'$VERSION'-'$GOOS'-'$GOARCH
  23. echo "== Building $output_name"
  24. echo "== FLAGS: $GOLDFLAGS"
  25. CGO_ENABLED=1 GOOS=$GOOS GOARCH=$GOARCH go build -a -ldflags="$GOLDFLAGS" -gcflags=all="-l -B" -installsuffix cgo -o bin/$output_name $PROJECT/app
  26. if [ $? -ne 0 ]; then
  27. echo 'An error has occurred! Aborting the script execution...'
  28. exit 1
  29. fi
  30. done
  31. echo "== DONE"