forked from inercia/kubetnl
/
Makefile
98 lines (73 loc) · 3.39 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
89
90
91
92
93
94
95
96
97
98
PLATFORMS := linux/amd64 windows/amd64 darwin/amd64
VERSION = $(shell git describe HEAD --tags --abbrev=0)
GIT_COMMIT = $(shell git rev-parse HEAD)
LD_FLAGS = -ldflags="-X 'github.com/pschmitt/kubetnl/pkg/version.gitCommit=$(GIT_COMMIT)'"
MAIN = ./main.go
SRCS = $(shell find . -name '*.go' ! -path './tests/*')
ALL_SRCS = $(shell find . -name '*.go')
SHS = $(shell find . -name '*.sh')
GO ?= go
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
GOEXE ?= kubetnl
GOFLAGS ?=
SHFMT_ARGS = -s -ln bash
############################################################################################
.DEFAULT_GOAL:=help
.PHONY: help
help: ## Show this help screen
@echo 'Usage: make <OPTIONS> ... <TARGETS>'
@echo ''
@echo 'Available targets are:'
@echo ''
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
#########################################
##@ Build
#########################################
bin/kubetnl-$(VERSION)_windows-amd64/kubetnl.exe: GOARCH=amd64
bin/kubetnl-$(VERSION)_windows-amd64/kubetnl.exe: GOOS=windows
bin/kubetnl-$(VERSION)_windows-amd64/kubetnl.exe: GOEXE=kubetnl.exe
bin/kubetnl-$(VERSION)_linux-amd64/kubetnl: GOARCH=amd64
bin/kubetnl-$(VERSION)_linux-amd64/kubetnl: GOOS=linux
bin/kubetnl-$(VERSION)_darwin-amd64/kubetnl: GOARCH=amd64
bin/kubetnl-$(VERSION)_darwin-amd64/kubetnl: GOOS=darwin
bin/kubetnl-$(VERSION)_darwin-arm64/kubetnl: GOARCH=arm64
bin/kubetnl-$(VERSION)_darwin-arm64/kubetnl: GOOS=darwin
bin/%: $(SRCS)
@echo ">>> Building $(GOEXE) executable (OS='$(GOOS)', ARCH='$(GOARCH)')"
go build ${LD_FLAGS} -o 'bin/kubetnl-$(VERSION)_$(GOOS)-$(GOARCH)/$(GOEXE)' ${MAIN}
exe: bin/kubetnl-$(VERSION)_$(GOOS)-$(GOARCH)/$(GOEXE) ## Build the default executable
windows-amd64: bin/kubetnl-$(VERSION)_windows-amd64/kubetnl.exe
linux-amd64: bin/kubetnl-$(VERSION)_linux-amd64/kubetnl
darwin-amd64: bin/kubetnl-$(VERSION)_darwin-amd64/kubetnl
darwin-arm64: bin/kubetnl-$(VERSION)_darwin-arm64/kubetnl
clean: ## Clean all the artifacts
rm -rf bin
version:
echo ${VERSION}
#########################################
##@ Release
#########################################
release: clean windows-amd64 linux-amd64 darwin-amd64 darwin-arm64 ## Create release executables
zip -r bin/kubetnl-$(VERSION)_windows-amd64.zip bin/kubetnl-$(VERSION)_windows-amd64
zip -r bin/kubetnl-$(VERSION)_linux-amd64.zip bin/kubetnl-$(VERSION)_linux-amd64
zip -r bin/kubetnl-$(VERSION)_darwin-amd64.zip bin/kubetnl-$(VERSION)_darwin-amd64
zip -r bin/kubetnl-$(VERSION)_darwin-arm64.zip bin/kubetnl-$(VERSION)_darwin-arm64
#########################################
##@ Code fomatting
#########################################
format-go: ## Format the Go source code
@echo ">>> Formatting the Go source code..."
GOFLAGS="$(GOFLAGS)" $(GO) fmt `$(GO) list ./...`
format-sh: ## Format the Shell source code
@echo ">>> Formatting the Shell source code..."
echo "$(SHS)" | xargs shfmt $(SHFMT_ARGS) -w
format-all: format-go format-sh
format: format-all ## Format all the code
fmt: format
#########################################
##@ Tests
#########################################
PHONY: tests
tests: $(ALL_SRCS) ## Run all the tests
go test ./tests -test.v