You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.4 KiB

  1. #!/usr/bin/env bash
  2. package=$1
  3. package_split=(${package//\// })
  4. package_name=${package_split[-1]}
  5. CURDIR=`/bin/pwd`
  6. BASEDIR=$(dirname $0)
  7. ABSPATH=$(readlink -f $0)
  8. ABSDIR=$(dirname $ABSPATH)
  9. PLATFORMS="darwin/amd64" # amd64 only as of go1.5
  10. PLATFORMS="$PLATFORMS windows/amd64 windows/386" # arm compilation not available for Windows
  11. PLATFORMS="$PLATFORMS linux/amd64 linux/386"
  12. #PLATFORMS="$PLATFORMS linux/ppc64le" is it common enough ??
  13. #PLATFORMS="$PLATFORMS linux/mips64le" # experimental in go1.6 is it common enough ??
  14. PLATFORMS="$PLATFORMS freebsd/amd64 freebsd/386"
  15. PLATFORMS="$PLATFORMS netbsd/amd64" # amd64 only as of go1.6
  16. PLATFORMS="$PLATFORMS openbsd/amd64" # amd64 only as of go1.6
  17. PLATFORMS="$PLATFORMS dragonfly/amd64" # amd64 only as of go1.5
  18. #PLATFORMS="$PLATFORMS plan9/amd64 plan9/386" # as of go1.4, is it common enough ??
  19. PLATFORMS="$PLATFORMS solaris/amd64" # as of go1.3
  20. PLATFORMS_ARM="linux freebsd netbsd"
  21. type setopt >/dev/null 2>&1
  22. SCRIPT_NAME=`basename "$0"`
  23. FAILURES=""
  24. CURRENT_DIRECTORY=${PWD##*/}
  25. OUTPUT="$package_name" # if no src file given, use current dir name
  26. for PLATFORM in $PLATFORMS; do
  27. GOOS=${PLATFORM%/*}
  28. GOARCH=${PLATFORM#*/}
  29. OUTPUT_DIR="${ABSDIR}/build/dero_${GOOS}_${GOARCH}"
  30. BIN_FILENAME="${OUTPUT}-${GOOS}-${GOARCH}"
  31. echo mkdir -p $OUTPUT_DIR
  32. if [[ "${GOOS}" == "windows" ]]; then BIN_FILENAME="${BIN_FILENAME}.exe"; fi
  33. CMD="GOOS=${GOOS} GOARCH=${GOARCH} go build -o $OUTPUT_DIR/${BIN_FILENAME} $package"
  34. echo "${CMD}"
  35. eval $CMD || FAILURES="${FAILURES} ${PLATFORM}"
  36. done
  37. # ARM64 builds only for linux
  38. if [[ $PLATFORMS_ARM == *"linux"* ]]; then
  39. GOOS="linux"
  40. GOARCH="arm64"
  41. OUTPUT_DIR="${ABSDIR}/build/dero_${GOOS}_${GOARCH}"
  42. CMD="GOOS=linux GOARCH=arm64 go build -o $OUTPUT_DIR/${OUTPUT}-linux-arm64 $package"
  43. echo "${CMD}"
  44. eval $CMD || FAILURES="${FAILURES} ${PLATFORM}"
  45. fi
  46. for GOOS in $PLATFORMS_ARM; do
  47. GOARCH="arm"
  48. # build for each ARM version
  49. for GOARM in 7 6 5; do
  50. OUTPUT_DIR="${ABSDIR}/build/dero_${GOOS}_${GOARCH}${GOARM}"
  51. BIN_FILENAME="${OUTPUT}-${GOOS}-${GOARCH}${GOARM}"
  52. CMD="GOARM=${GOARM} GOOS=${GOOS} GOARCH=${GOARCH} go build -o $OUTPUT_DIR/${BIN_FILENAME} $package"
  53. echo "${CMD}"
  54. eval "${CMD}" || FAILURES="${FAILURES} ${GOOS}/${GOARCH}${GOARM}"
  55. done
  56. done
  57. # eval errors
  58. if [[ "${FAILURES}" != "" ]]; then
  59. echo ""
  60. echo "${SCRIPT_NAME} failed on: ${FAILURES}"
  61. exit 1
  62. fi