#!/bin/bash
set -e

if [ -z "$1" ]; then
    OS_PLATFORM_ARG=(-os="darwin linux windows")
else
    OS_PLATFORM_ARG=($1)
fi

if [ -z "$2" ]; then
    OS_ARCH_ARG=(-arch="386 amd64 arm")
else
    OS_ARCH_ARG=($2)
fi

# Build Docker image unless we opt out of it
if [[ -z "$SKIP_BUILD" ]]; then
    docker build -t docker-machine .
fi

# Get rid of existing binaries
rm -f docker-machine*
rm -rf Godeps/_workspace/pkg
docker run --rm -v `pwd`:/go/src/github.com/docker/machine docker-machine gox "${OS_PLATFORM_ARG[@]}" "${OS_ARCH_ARG[@]}" -output="docker-machine_{{.OS}}-{{.Arch}}" -ldflags="-w -X github.com/docker/machine/version.GITCOMMIT `git rev-parse --short HEAD`"
