.bashbrew-arch-to-goenv.sh 929 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/sh
  2. set -euo pipefail
  3. # usage: (from within another script)
  4. # eval "$(./.bashbrew-arch-to-goenv.sh)"
  5. # since we need those new environment variables in our other script
  6. bashbrewArch="$1"; shift # "amd64", "arm32v5", "windows-amd64", etc.
  7. os="${bashbrewArch%%-*}"
  8. [ "$os" != "$bashbrewArch" ] || os='linux'
  9. printf 'export GOOS="%s"\n' "$os"
  10. arch="${bashbrewArch#${os}-}"
  11. case "$arch" in
  12. arm32v*)
  13. printf 'export GOARCH="%s"\n' 'arm'
  14. printf 'export GOARM="%s"\n' "${arch#arm32v}"
  15. ;;
  16. arm64v*)
  17. printf 'export GOARCH="%s"\n' 'arm64'
  18. # no GOARM for arm64 (yet?) -- https://github.com/golang/go/blob/1e72bf62183ea21b9affffd4450d44d994393899/src/cmd/internal/objabi/util.go#L40
  19. #printf 'export GOARM="%s"\n' "${arch#arm64v}"
  20. printf 'unset GOARM\n'
  21. ;;
  22. i386)
  23. printf 'export GOARCH="%s"\n' '386'
  24. printf 'unset GOARM\n'
  25. ;;
  26. *)
  27. printf 'export GOARCH="%s"\n' "$arch"
  28. printf 'unset GOARM\n'
  29. ;;
  30. esac