This repository has been archived by the owner on Jul 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
90 lines (65 loc) · 2.3 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
VERSION ?= $(shell git describe --tags --abbrev=0 | sed 's/^v//')
build: vendor clean test all ## Test and build binaries for local architecture
first: tools
.PHONY: clean
clean: ## Remove build products from bin/ and release/
rm -rf bin
rm -rf release
.PHONY: tools
tools: ## Download and install all dev/code tools
@echo "==> Installing dev tools"
go get -u honnef.co/go/tools/cmd/staticcheck
vendor: ## Install dependencies
go mod vendor
.PHONY: deps
deps: ## Update dependencies to latest version
go mod verify
.PHONY: test
test: ## Ensure that code matches best practices
go test --cover ./...
staticcheck ./...
go vet
.PHONY: help
help: ## Display this help message
@echo "GNU make(1) targets:"
@grep -E '^[a-zA-Z_.-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
.PHONY: docker_test
docker_test: ## run a test build in docker
docker/test.bash
.PHONY: docker_release
docker_release: ## Build all release binaries and checksums in docker
docker/release.bash
################################
# Dynamic Fanciness #
# aka Why GNU make Is Required #
################################
PLATFORMS := darwin-amd64 linux-amd64 solaris-amd64 freebsd-amd64 openbsd-amd64 linux-arm
BINARIES := kosh
RELEASE_BINARIES := kosh
BINS := $(foreach bin,$(BINARIES),bin/$(bin))
RELEASES := $(foreach bin,$(RELEASE_BINARIES),release/$(bin))
GIT_REV := $(shell git describe --always --abbrev --dirty --long)
LD_FLAGS := -ldflags="-X main.Version=$(VERSION) -X main.GitRev=$(GIT_REV)"
BUILD := CGO_ENABLED=0 go build $(LD_FLAGS)
####
all: $(BINS) ## Build all binaries
.PHONY: release
release: vendor test $(RELEASES) ## Build release binaries with checksums
bin/%:
@mkdir -p bin
@echo "> Building bin/$(subst bin/,,$@)"
@$(BUILD) -o bin/$(subst bin/,,$@) *.go
os = $(firstword $(subst -, ,$1))
arch = $(lastword $(subst -, ,$1))
define release_me
$(eval BIN:=$(subst release/,,$@))
$(eval GOOS:=$(call os, $(platform)))
$(eval GOARCH:=$(call arch, $(platform)))
$(eval RPATH:=release/$(BIN)-$(GOOS)-$(GOARCH))
@echo "> Building $(RPATH)"
@GOOS=$(GOOS) GOARCH=$(GOARCH) $(BUILD) -o $(RPATH) *.go
shasum -a 256 $(RPATH) > $(RPATH).sha256
endef
release/%:
@mkdir -p release
$(foreach platform,$(PLATFORMS),$(call release_me))