github.com/k8snetworkplumbingwg/sriov-network-operator@v1.2.1-0.20240408194816-2d2e5a45d453/hack/build-go.sh (about) 1 #!/usr/bin/env bash 2 3 set -eux 4 5 REPO=github.com/k8snetworkplumbingwg/sriov-network-operator 6 WHAT=${WHAT:-sriov-network-operator} 7 GOFLAGS=${GOFLAGS:-} 8 GLDFLAGS=${GLDFLAGS:-} 9 10 # eval $(go env | grep -e "GOHOSTOS" -e "GOHOSTARCH") 11 12 # : "${GOOS:=${GOHOSTOS}}" 13 # : "${GOARCH:=${GOHOSTARCH}}" 14 GOOS=$(go env GOOS) 15 GOARCH=$(go env GOARCH) 16 17 # Go to the root of the repo 18 cdup="$(git rev-parse --show-cdup)" && test -n "$cdup" && cd "$cdup" 19 20 if [ -z ${VERSION_OVERRIDE+a} ]; then 21 echo "Using version from git..." 22 VERSION_OVERRIDE=$(git describe --abbrev=8 --dirty --always) 23 fi 24 25 GLDFLAGS+="-X ${REPO}/pkg/version.Raw=${VERSION_OVERRIDE}" 26 27 # eval $(go env) 28 29 if [ -z ${BIN_PATH+a} ]; then 30 export BIN_PATH=build/_output/${GOOS}/${GOARCH} 31 fi 32 33 mkdir -p ${BIN_PATH} 34 35 CGO_ENABLED=${CGO_ENABLED:-0} 36 37 38 if [[ ${WHAT} == "manager" ]]; then 39 echo "Building ${WHAT} (${VERSION_OVERRIDE})" 40 CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} go build ${GOFLAGS} -ldflags "${GLDFLAGS} -s -w" -o ${BIN_PATH}/${WHAT} main.go 41 else 42 echo "Building ${REPO}/cmd/${WHAT} (${VERSION_OVERRIDE})" 43 CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} go build ${GOFLAGS} -ldflags "${GLDFLAGS} -s -w" -o ${BIN_PATH}/${WHAT} ${REPO}/cmd/${WHAT} 44 fi