Skip to content
This repository has been archived by the owner on Apr 14, 2020. It is now read-only.

Commit

Permalink
Added make target for prebuilding binary for mutliple targets
Browse files Browse the repository at this point in the history
  • Loading branch information
dainis committed Jul 5, 2017
1 parent 7183b9e commit b952e99
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/bin
/release
/build
29 changes: 22 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
.PHONY: clean install build release $(TARGETS)

0 comments on commit b952e99

Please sign in to comment.