Skip to content

Commit 6541912

Browse files
committed
add release to Makefile
1 parent 3466413 commit 6541912

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

.goosarch

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
darwin/amd64
2+
linux/amd64

Makefile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ BUILD_DIR := $(shell pwd)/build
44
TARGET := ${BUILD_DIR}/${NAME}
55
LDFLAGS ?=
66

7+
# List the GOOS and GOARCH to build
8+
GOOSARCHES = $(shell cat .goosarch)
9+
710
.PHONY: help
811
help:
912
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@@ -33,4 +36,16 @@ test: ## Runs the go tests.
3336

3437
.PHONY: vet
3538
vet: ## Verifies `go vet` passes.
36-
@go vet $(shell go list ./... | grep -v vendor) | tee /dev/stderr
39+
@go vet $(shell go list ./... | grep -v vendor) | tee /dev/stderr
40+
41+
define buildrelease
42+
GOOS=$(1) GOARCH=$(2) go build \
43+
-ldflags "$(LDFLAGS)" \
44+
-o $(BUILD_DIR)/$(NAME)-$(1)-$(2);
45+
md5sum $(BUILD_DIR)/$(NAME)-$(1)-$(2) > $(BUILD_DIR)/$(NAME)-$(1)-$(2).md5;
46+
sha256sum $(BUILD_DIR)/$(NAME)-$(1)-$(2) > $(BUILD_DIR)/$(NAME)-$(1)-$(2).sha256;
47+
endef
48+
49+
.PHONY: release
50+
release: ## Builds the cross-compiled binaries, naming them in such a way for release (eg. binary-GOOS-GOARCH).
51+
@$(foreach GOOSARCH,$(GOOSARCHES), $(call buildrelease,$(subst /,,$(dir $(GOOSARCH))),$(notdir $(GOOSARCH))))

0 commit comments

Comments
 (0)