#! /bin/bash

cd "$(dirname "$BASH_SOURCE")"

binary_name="$(head -n 1 go.mod  | awk '{print $NF}' | sed 's/.*\///')"
git_commit="$((
   git rev-list -1 HEAD
   if git diff | grep . > /dev/null; then
      echo "-dirty"
   fi
) 2> /dev/null | tr -d '\n')"

GOFLAGS="" \
GO111MODULE="" \
CGO_ENABLED=0 \
go build \
   -o $GOPATH/bin/$binary_name \
   -a \
   -installsuffix cgo \
   -ldflags "-s -w -X main.GitCommit=$git_commit"
