-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
88 lines (65 loc) · 3.18 KB
/
Makefile
File metadata and controls
88 lines (65 loc) · 3.18 KB
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
# Makefile
VERSION := $(shell \
tag=$$(git describe --tags --exact-match 2>/dev/null); \
if [ -n "$$tag" ]; then echo $$tag | sed 's/^v//'; \
else git rev-parse --short=7 HEAD; fi)
A2X = a2x
A2X_FLAGS = -a version=$(VERSION)
DOCS_DIR = docs
ZIPFUSE = zipfuse
ZIPFUSE_DIR = ./cmd/zipfuse
ZIPFUSE_ADOC = $(DOCS_DIR)/zipfuse.adoc
HELPER = mount.zipfuse
HELPER_DIR = ./cmd/mount.zipfuse
HELPER_ADOC = $(DOCS_DIR)/mount.zipfuse.adoc
.PHONY: all $(ZIPFUSE) $(HELPER) check clean debug docs docs-clean docs-man docs-pdf docs-text help info lint test test-coverage vendor
all: vendor $(ZIPFUSE) $(HELPER) ## Runs the entire build chain for the application
$(ZIPFUSE): ## Builds the application
CGO_ENABLED=0 GOFLAGS="-mod=vendor" go build -ldflags="-w -s -X main.Version=$(VERSION) -buildid=" -trimpath -o $(ZIPFUSE) $(ZIPFUSE_DIR)
$(HELPER): ## Builds the helper application
CGO_ENABLED=0 GOFLAGS="-mod=vendor" go build -ldflags="-w -s -X main.Version=$(VERSION) -buildid=" -trimpath -o $(HELPER) $(HELPER_DIR)
check: ## Runs all static analysis and tests on the application code
@$(MAKE) lint
@$(MAKE) test
clean: ## Returns the application build stage to its original state (deleting files)
@$(MAKE) docs-clean
@rm -vfr dist || true
@rm -vf $(ZIPFUSE) $(HELPER) || true
debug: ## Builds the application in debug mode (with symbols, race checks, ...)
CGO_ENABLED=1 GOFLAGS="-mod=vendor" go build -ldflags="-X main.Version=$(VERSION)-DBG" -trimpath -race -o $(ZIPFUSE) $(ZIPFUSE_DIR)
CGO_ENABLED=1 GOFLAGS="-mod=vendor" go build -ldflags="-X main.Version=$(VERSION)-DBG" -trimpath -race -o $(HELPER) $(HELPER_DIR)
@$(MAKE) info
docs: ## Builds all documentation (manpages, PDF, plain text)
@$(MAKE) docs-man
@$(MAKE) docs-pdf
@$(MAKE) docs-text
docs-clean: ## Removes generated documentation files
@rm -vf $(DOCS_DIR)/*.pdf $(DOCS_DIR)/*.text $(DOCS_DIR)/*.1 $(DOCS_DIR)/*.8 $(DOCS_DIR)/*.xml || true
docs-man: ## Builds manpage documentation
$(A2X) $(A2X_FLAGS) -f manpage $(ZIPFUSE_ADOC)
$(A2X) $(A2X_FLAGS) -f manpage $(HELPER_ADOC)
docs-pdf: ## Builds PDF documentation
$(A2X) $(A2X_FLAGS) -f pdf $(ZIPFUSE_ADOC)
$(A2X) $(A2X_FLAGS) -f pdf $(HELPER_ADOC)
docs-text: ## Builds plain text documentation
$(A2X) $(A2X_FLAGS) -f text $(ZIPFUSE_ADOC)
$(A2X) $(A2X_FLAGS) -f text $(HELPER_ADOC)
help: ## Shows all build related commands of the Makefile
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
info: ## Shows information about the application binaries that were built
@file $(ZIPFUSE) || true
@ldd $(ZIPFUSE) || true
@file $(HELPER) || true
@ldd $(HELPER) || true
lint: ## Runs the linter on the application code
@golangci-lint cache clean
@golangci-lint run
test: ## Runs all written tests for and on the application code
@go test -failfast -race -covermode=atomic ./...
test-coverage: ## Runs all coverage tests for and on the application code
@go test -failfast -race -covermode=atomic -coverpkg=./... -coverprofile=coverage.tmp ./... && \
grep -v "mock_" coverage.tmp > coverage.txt && \
rm coverage.tmp
vendor: ## Pulls the (remote) dependencies into the local vendor folder
@go mod tidy
@go mod vendor