From b952e998adf55e46ce9129bc814830b9f4e3d73d Mon Sep 17 00:00:00 2001 From: Dainis Date: Wed, 5 Jul 2017 14:27:35 +0300 Subject: [PATCH] Added make target for prebuilding binary for mutliple targets --- .gitignore | 2 ++ Makefile | 29 ++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 5e56e040..53c8005f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /bin +/release +/build diff --git a/Makefile b/Makefile index 8824a293..1eaece5e 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,35 @@ SOURCEDIR=. SOURCES := $(shell find $(SOURCEDIR) -name '*.go') -BINARY=bin/terraform-provider-zabbix +BUILD_PATH=build +BINARY=terraform-provider-zabbix +BIN=bin +TARGETS=darwin linux windows +VERSION=0.0.2 +RELEASE_DIR=release +RELEASE=terraform-provider-zabbix_$(VERSION).tar.gz -VERSION=1.0.0 -BUILD_TIME=`date +%FT%T%z` +build=GOOS=$(1) GOARCH=$(2) go build -o ${BUILD_PATH}/$(BINARY)/$(1)_$(2)/${BINARY}`if [ "$(1)" = "windows" ]; then echo ".exe"; fi` main.go .DEFAULT_GOAL: $(BINARY) -$(BINARY): $(SOURCES) - go build ${LDFLAGS} -o ${BINARY} main.go +$(BIN)/$(BINARY): $(SOURCES) + go build -o $(BIN)/${BINARY} main.go + +$(TARGETS): $(SOURCES) + $(call build,$@,amd64,$(ext)) + $(call build,$@,386,$(ext)) + +release: $(TARGETS) + mkdir -p $(RELEASE_DIR) + tar -czvf $(RELEASE_DIR)/$(RELEASE) -C $(BUILD_PATH) $(BINARY) install: go install ./... clean: - if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi + @if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi + @if [ -d ${BUILD_PATH} ]; then rm -r ${BUILD_PATH} ; fi + @if [ -d ${RELEASE_DIR} ]; then rm -r $(RELEASE_DIR) ; fi -.PHONY: clean install \ No newline at end of file +.PHONY: clean install build release $(TARGETS) \ No newline at end of file