#!/usr/bin/env bash
#
# Build a static binary for the host OS/ARCH
#

set -eu -o pipefail

source ./scripts/build/.variables

mkdir -p "build/plugins-${GOOS}-${GOARCH}"
for p in cli-plugins/examples/* "$@" ; do
    [ -d "$p" ] || continue

    n=$(basename "$p")

    TARGET="build/plugins-${GOOS}-${GOARCH}/docker-${n}"

    echo "Building statically linked $TARGET"
    export CGO_ENABLED=0
    GO111MODULE=auto go build -o "${TARGET}" --ldflags "${GO_LDFLAGS}" "github.com/docker/cli/${p}"
done
