2
0

linux.sh 910 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/bash
  2. read -p "file_name: " file_name
  3. to="${1:-all}"
  4. build() {
  5. local os=$1
  6. local arch=$2
  7. local ext=$3
  8. echo "$os $arch"
  9. export GOOS=$os
  10. export GOARCH=$arch
  11. export CGO_ENABLED=0
  12. export GOFLAGS="-trimpath"
  13. if [[ "$os" != "darwin" ]]; then
  14. go build -o "bin/$file_name.$arch$ext" "$file_name.go"
  15. else
  16. go build -o "bin/$file_name.mac.$arch$ext" "$file_name.go"
  17. fi
  18. }
  19. if [[ "$to" == "linux_amd64" || "$to" == "all" ]]; then
  20. build "linux" "amd64" ".bin"
  21. fi
  22. if [[ "$to" == "linux_arm64" || "$to" == "all" ]]; then
  23. build "linux" "arm64" ".bin"
  24. fi
  25. if [[ "$to" == "windows_amd64" || "$to" == "all" ]]; then
  26. build "windows" "amd64" ".exe"
  27. fi
  28. if [[ "$to" == "windows_arm64" || "$to" == "all" ]]; then
  29. build "windows" "arm64" ".exe"
  30. fi
  31. if [[ "$to" == "mac_arm64" || "$to" == "all" ]]; then
  32. build "darwin" "arm64" ".bin"
  33. fi