2021-03-03 02:03:02 -05:00
|
|
|
#!/usr/bin/env sh
|
2017-05-11 18:52:17 -04:00
|
|
|
set -eu
|
|
|
|
|
2021-11-17 11:18:15 -05:00
|
|
|
: "${CGO_ENABLED=}"
|
|
|
|
: "${GO_LINKMODE=static}"
|
|
|
|
: "${GO_BUILDMODE=}"
|
|
|
|
: "${GO_BUILDTAGS=}"
|
|
|
|
: "${GO_STRIP=}"
|
|
|
|
|
2021-03-03 02:03:02 -05:00
|
|
|
TARGET=${TARGET:-"build"}
|
|
|
|
|
2017-12-01 08:47:20 -05:00
|
|
|
PLATFORM=${PLATFORM:-}
|
2021-03-05 17:34:32 -05:00
|
|
|
VERSION=${VERSION:-$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags | sed 's/^v//' 2>/dev/null || echo "unknown-version" )}
|
2017-05-11 18:52:17 -04:00
|
|
|
GITCOMMIT=${GITCOMMIT:-$(git rev-parse --short HEAD 2> /dev/null || true)}
|
2020-11-29 10:07:46 -05:00
|
|
|
BUILDTIME=${BUILDTIME:-$(date -u --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" +"%Y-%m-%dT%H:%M:%SZ")}
|
2017-05-11 18:52:17 -04:00
|
|
|
|
2021-03-03 02:03:02 -05:00
|
|
|
GOOS="$(go env GOOS)"
|
|
|
|
GOARCH="$(go env GOARCH)"
|
2019-05-02 12:05:47 -04:00
|
|
|
if [ "${GOARCH}" = "arm" ]; then
|
2021-11-17 11:18:15 -05:00
|
|
|
GOARM="$(go env GOARM)"
|
2019-05-02 12:05:47 -04:00
|
|
|
fi
|
|
|
|
|
2021-03-03 02:03:02 -05:00
|
|
|
TARGET="$TARGET/docker-${GOOS}-${GOARCH}"
|
2019-05-02 12:05:47 -04:00
|
|
|
if [ "${GOARCH}" = "arm" ] && [ -n "${GOARM}" ]; then
|
2021-03-03 02:03:02 -05:00
|
|
|
TARGET="${TARGET}-v${GOARM}"
|
2019-05-02 12:05:47 -04:00
|
|
|
fi
|
|
|
|
if [ "${GOOS}" = "windows" ]; then
|
2021-11-17 11:18:15 -05:00
|
|
|
TARGET="${TARGET}.exe"
|
2019-05-02 12:05:47 -04:00
|
|
|
fi
|
|
|
|
export TARGET
|
|
|
|
|
2021-11-17 11:18:15 -05:00
|
|
|
if [ -z "$CGO_ENABLED" ]; then
|
|
|
|
case "$(go env GOOS)" in
|
|
|
|
linux)
|
|
|
|
case "$(go env GOARCH)" in
|
|
|
|
amd64|arm64|arm|s390x)
|
|
|
|
CGO_ENABLED=1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
CGO_ENABLED=0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
darwin|windows)
|
|
|
|
CGO_ENABLED=1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
CGO_ENABLED=0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
export CGO_ENABLED
|
|
|
|
|
|
|
|
if [ "$CGO_ENABLED" = "1" ] && [ "$(go env GOOS)" != "windows" ]; then
|
|
|
|
case "$(go env GOARCH)" in
|
|
|
|
mips*|ppc64)
|
|
|
|
# pie build mode is not supported on mips architectures
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
GO_BUILDMODE="-buildmode=pie"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
export GO_BUILDMODE
|
|
|
|
|
|
|
|
LDFLAGS="${LDFLAGS:-} -w"
|
|
|
|
LDFLAGS="$LDFLAGS -X \"github.com/docker/cli/cli/version.GitCommit=${GITCOMMIT}\""
|
|
|
|
LDFLAGS="$LDFLAGS -X \"github.com/docker/cli/cli/version.BuildTime=${BUILDTIME}\""
|
|
|
|
LDFLAGS="$LDFLAGS -X \"github.com/docker/cli/cli/version.Version=${VERSION}\""
|
|
|
|
if test -n "${PLATFORM}"; then
|
|
|
|
LDFLAGS="$LDFLAGS -X \"github.com/docker/cli/cli/version.PlatformName=${PLATFORM}\""
|
|
|
|
fi
|
|
|
|
if [ "$CGO_ENABLED" = "1" ] && [ "$GO_LINKMODE" = "static" ] && [ "$(go env GOOS)" = "linux" ]; then
|
|
|
|
LDFLAGS="$LDFLAGS -extldflags -static"
|
|
|
|
fi
|
|
|
|
if [ -n "$GO_STRIP" ]; then
|
|
|
|
LDFLAGS="$LDFLAGS -s"
|
|
|
|
fi
|
|
|
|
export LDFLAGS="$LDFLAGS" # https://github.com/koalaman/shellcheck/issues/2064
|
|
|
|
|
2017-05-11 18:52:17 -04:00
|
|
|
export SOURCE="github.com/docker/cli/cmd/docker"
|