-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
100 lines (83 loc) · 1.71 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
99
100
NAME := tf
ifneq (,$(wildcard .env))
include .env
export
endif
AWK = awk
GO = go
GORELEASER = goreleaser
HEAD = head
INSTALL = install
PRINTF = printf
RM = rm
SORT = sort
ifeq ($(OS),Darwin)
SORT = gsort
else
SORT = sort
endif
ifeq ($(GOOS),windows)
EXE = .exe
else ifeq ($(shell $(GO) env GOOS),windows)
EXE = .exe
endif
BIN = $(NAME)$(EXE)
ifeq ($(OS),Windows_NT)
ifneq (,$(LOCALAPPDATA))
BINDIR = $(LOCALAPPDATA)\Microsoft\WindowsApps
else
BINDIR = C:\Windows\System32
endif
else
ifneq (,$(wildcard $(HOME)/.local/bin))
BINDIR = $(HOME)/.local/bin
else ifneq (,$(wildcard $(HOME)/bin))
BINDIR = $(HOME)/bin
else
BINDIR = /usr/local/bin
endif
endif
.PHONY: help
help:
@echo Targets:
@$(AWK) 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9._-]+:.*?## / {printf " %-20s %s\n", $$1, $$2}' $(MAKEFILE_LIST) | $(SORT)
.PHONY: build
build: ## Build app binary for single target
$(call print-target)
$(GORELEASER) build --clean --snapshot --single-target --output $(BIN)
$(BIN):
@$(MAKE) build
.PHONY: install
install: ## Build and install app binary
install: $(BIN)
$(call print-target)
$(INSTALL) $(BIN) $(BINDIR)
.PHONY: uninstall
uninstall: ## Uninstall app binary
uninstall:
$(RM) -f $(BINDIR)/$(BIN)
.PHONY: download
download: ## Download Go modules
$(call print-target)
$(GO) mod download
.PHONY: tidy
tidy: ## Tidy Go modules
$(call print-target)
$(GO) mod tidy
.PHONY: upgrade
upgrade: ## Upgrade Go modules
$(call print-target)
$(GO) get -u
.PHONY: clean
clean: ## Clean working directory
$(call print-target)
$(RM) -f $(BIN)
$(RM) -rf dist
.PHONY: test
test: ## Test app binary
test: $(BIN)
$(call print-target)
$(MAKE) -C tests test
define print-target
@$(PRINTF) "Executing target: \033[36m$@\033[0m\n"
endef