-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMakefile
More file actions
95 lines (79 loc) · 2.36 KB
/
Copy pathMakefile
File metadata and controls
95 lines (79 loc) · 2.36 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
89
90
91
92
93
94
95
BINARY := flow
CMD := ./cmd/flow
VERSION := v$(shell cat VERSION 2>/dev/null || echo "0.3.1")
LDFLAGS := -ldflags "-s -w -X main.version=$(VERSION)"
GOFLAGS :=
# Cross-platform detection
ifeq ($(OS),Windows_NT)
BINARY := flow.exe
MKDIR := mkdir
RMDIR := -rmdir /s /q
SEP := \\
else
MKDIR := mkdir -p
RMDIR := -rm -rf
SEP := /
endif
BUILDDIR := bin
.PHONY: all build install run test vet lint tidy clean demo help
all: build
$(BUILDDIR):
$(MKDIR) $(BUILDDIR)
## build: compile the binary into ./bin/flow
build: $(BUILDDIR)
go build $(GOFLAGS) $(LDFLAGS) -o $(BUILDDIR)$(SEP)$(BINARY) $(CMD)
## install: build and install to $GOBIN (or $GOPATH/bin)
install:
go install $(GOFLAGS) $(LDFLAGS) $(CMD)
@BIN="$$(go env GOBIN)"; \
if [ -z "$$BIN" ]; then BIN="$$(go env GOPATH)/bin"; fi; \
echo "installed: $$BIN/$(BINARY)"; \
"$$BIN/$(BINARY)" --version; \
case ":$$PATH:" in \
*"$$BIN"*) ;; \
*) echo "WARNING: $$BIN is not on your PATH, so '$(BINARY)' will not be found."; \
echo " Add this to ~/.bashrc or ~/.zshrc, then restart your shell:"; \
echo " export PATH=\"\$$PATH:$$BIN\""; ;; \
esac; \
FOUND="$$(command -v $(BINARY) 2>/dev/null || true)"; \
if [ -n "$$FOUND" ] && [ "$$FOUND" != "$$BIN/$(BINARY)" ]; then \
echo "WARNING: '$$FOUND' shadows the new binary (shell picks the first match on PATH)."; \
echo " Remove it or put $$BIN earlier on PATH to use the new build."; \
fi
## run: build and run
run: build
$(BUILDDIR)$(SEP)$(BINARY)
## test: run the test suite
test:
go test ./...
## vet: run go vet
vet:
go vet ./...
## lint: run golangci-lint (must be installed separately)
lint:
golangci-lint run ./...
## tidy: tidy and vendor dependencies
tidy:
go mod tidy
## clean: remove build artifacts
clean:
$(RMDIR) $(BUILDDIR)
## demo: generate assets/demo.gif with VHS
demo: build
vhs demo.tape
@if command -v gifsicle >/dev/null 2>&1; then \
echo "optimizing with gifsicle..."; \
gifsicle -O3 --colors 256 --lossy=80 -o assets/demo.gif assets/demo.gif; \
ls -lh assets/demo.gif; \
else \
echo "install gifsicle for further optimization: brew install gifsicle"; \
fi
## check: format, vet, lint, and test
check:
go fmt ./...
go vet ./...
golangci-lint run ./...
go test ./...
## help: print this message
help:
@sed -n 's/^## //p' $(MAKEFILE_LIST) 2>/dev/null || findstr /B "##" Makefile