#!/usr/bin/env sh # # Build a static binary for the host OS/ARCH # set -eu . ./scripts/build/.variables if [ "$CGO_ENABLED" = "1" ] && [ "$(go env GOOS)" != "windows" ] && [ "$GO_LINKMODE" != "static" ]; then # pkcs11 cannot be compiled statically if CGO is enabled (and glibc is used) # see https://github.com/docker/cli/blob/3897c3fa544f1239c2bc2c3af2adcebcb3650c4d/vendor/github.com/miekg/pkcs11/pkcs11.go#L75 # see https://github.com/docker/cli/pull/3490#issuecomment-1079711973 GO_BUILDTAGS="$GO_BUILDTAGS pkcs11" fi echo "Building $GO_LINKMODE $(basename "${TARGET}")" export GO111MODULE=auto if [ "$(go env GOOS)" = "windows" ]; then if [ ! -x "$(command -v goversioninfo)" ]; then >&2 echo "goversioninfo not found, skipping manifesting binary" else ./scripts/build/mkversioninfo (set -x ; go generate -v "${SOURCE}") fi fi (set -x ; go build -o "${TARGET}" -tags "${GO_BUILDTAGS}" -ldflags "${GO_LDFLAGS}" ${GO_BUILDMODE} "${SOURCE}") ln -sf "$(basename "${TARGET}")" "$(dirname "${TARGET}")/docker"