.binary 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env bash
  2. set -e
  3. # a helper to provide ".exe" when it's appropriate
  4. binary_extension() {
  5. if [ "$(go env GOOS)" = 'windows' ]; then
  6. echo -n '.exe'
  7. fi
  8. }
  9. GO_PACKAGE='github.com/docker/docker/cmd/dockerd'
  10. BINARY_SHORT_NAME='dockerd'
  11. BINARY_NAME="$BINARY_SHORT_NAME-$VERSION"
  12. BINARY_EXTENSION="$(binary_extension)"
  13. BINARY_FULLNAME="$BINARY_NAME$BINARY_EXTENSION"
  14. source "${MAKEDIR}/.go-autogen"
  15. hash_files() {
  16. while [ $# -gt 0 ]; do
  17. f="$1"
  18. shift
  19. dir="$(dirname "$f")"
  20. base="$(basename "$f")"
  21. for hashAlgo in md5 sha256; do
  22. if command -v "${hashAlgo}sum" &> /dev/null; then
  23. (
  24. # subshell and cd so that we get output files like:
  25. # $HASH docker-$VERSION
  26. # instead of:
  27. # $HASH /go/src/github.com/.../$VERSION/binary/docker-$VERSION
  28. cd "$dir"
  29. "${hashAlgo}sum" "$base" > "$base.$hashAlgo"
  30. )
  31. fi
  32. done
  33. done
  34. }
  35. (
  36. export GOGC=${DOCKER_BUILD_GOGC:-1000}
  37. if [ "$(go env GOOS)/$(go env GOARCH)" != "$(go env GOHOSTOS)/$(go env GOHOSTARCH)" ]; then
  38. # must be cross-compiling!
  39. case "$(go env GOOS)/$(go env GOARCH)" in
  40. windows/amd64)
  41. export CC=x86_64-w64-mingw32-gcc
  42. export CGO_ENABLED=1
  43. ;;
  44. esac
  45. fi
  46. echo "Building: $DEST/$BINARY_FULLNAME"
  47. go build \
  48. -o "$DEST/$BINARY_FULLNAME" \
  49. "${BUILDFLAGS[@]}" \
  50. -ldflags "
  51. $LDFLAGS
  52. $LDFLAGS_STATIC_DOCKER
  53. $DOCKER_LDFLAGS
  54. " \
  55. $GO_PACKAGE
  56. )
  57. echo "Created binary: $DEST/$BINARY_FULLNAME"
  58. ln -sf "$BINARY_FULLNAME" "$DEST/$BINARY_SHORT_NAME$BINARY_EXTENSION"
  59. hash_files "$DEST/$BINARY_FULLNAME"