diff --git a/Makefile b/Makefile index a3e377221..4d52f72ed 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,10 @@ GO_PKGS ?= $(shell glide nv) build: @scripts/build-go.sh +.PHONY: build-cross +build-cross: + @BUILD_CROSS=1 scripts/build-go.sh + .PHONY: all all: build diff --git a/scripts/build-go.sh b/scripts/build-go.sh index a824cdcbd..b15b1bcd7 100755 --- a/scripts/build-go.sh +++ b/scripts/build-go.sh @@ -9,14 +9,6 @@ readonly DIR="${GOPATH}/src/${REPO}" source "${DIR}/scripts/common.sh" -if [[ -z "${VERSION:-}" ]]; then - VERSION=$(version_from_git) -fi - -LDFLAGS="-s -X ${REPO}/pkg/version.DeploymentManagerVersion=${VERSION}" - -echo "Build version: ${VERSION}" - build_binaries "$@" exit 0 diff --git a/scripts/common.sh b/scripts/common.sh index 861e88400..f1c819213 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -10,6 +10,18 @@ error_exit() { exit 1 } +assign_version() { + if [[ -z "${VERSION:-}" ]]; then + VERSION=$(version_from_git) + fi +} + +assign_ldflags() { + if [[ -z "${LDFLAGS:-}" ]]; then + LDFLAGS="-s -X ${REPO}/pkg/version.DeploymentManagerVersion=${VERSION}" + fi +} + version_from_git() { local git_tag=$(git describe --tags --abbrev=0 2>/dev/null) local git_commit=$(git rev-parse --short HEAD) @@ -29,13 +41,19 @@ build_binary_cross() { build_binaries() { local -a targets=($@) + #TODO: accept specific os/arch + local build_cross="${BUILD_CROSS:-}" if [[ ${#targets[@]} -eq 0 ]]; then targets=("${ALL_TARGETS[@]}") fi for t in "${targets[@]}"; do - build_binary "$t" + if [[ -n "$build_cross" ]]; then + build_binary_cross "$t" + else + build_binary "$t" + fi done }