#!/bin/bash
set -e -x

source $(dirname $0)/version

cd $(dirname $0)/..

mkdir -p bin
if [ "$(uname)" = "Linux" ]; then
    OTHER_LINKFLAGS="-extldflags -static -s"
fi
LINKFLAGS="-X github.com/rancher/system-agent/pkg/version.Version=$VERSION"
LINKFLAGS="-X github.com/rancher/system-agent/pkg/version.GitCommit=$COMMIT $LINKFLAGS"
CGO_ENABLED=0 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/rancher-system-agent
if [ "$CROSS" = "true" ] && [ "$ARCH" = "amd64" ]; then
    GOOS=darwin go build -ldflags "$LINKFLAGS" -o bin/rancher-system-agent-darwin
    GOOS=windows go build -ldflags "$LINKFLAGS" -o bin/rancher-system-agent-windows
fi
