-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
64 lines (48 loc) · 1.41 KB
/
Makefile
File metadata and controls
64 lines (48 loc) · 1.41 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
.PHONY: fmt vet lint test check staticcheck vulncheck fix housekeeping build release install clean
# Versioning
VERSION ?= dev
GO_BUILD=go build
ifeq ($(OS),Windows_NT)
BIN_NAME=keymaster.exe
RELEASE_BIN=dist/keymaster.exe
else
BIN_NAME=keymaster
RELEASE_BIN=dist/keymaster
endif
fmt:
gofmt -s -w .
vet:
go vet ./...
lint:
which golangci-lint >/dev/null 2>&1 || echo "golangci-lint not installed; run 'go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest'"
golangci-lint run
test:
go test ./... -v -race
staticcheck:
staticcheck ./...
vulncheck:
govulncheck ./...
fix:
go fix ./...
housekeeping: fmt fix vet staticcheck vulncheck test
@echo "Housekeeping complete."
check: fmt vet lint test
# Build (debug/dev)
build:
$(GO_BUILD) -o $(BIN_NAME) .
# Release (stripped, versioned)
release:
@mkdir -p dist
$(GO_BUILD) -ldflags "-s -w -X 'main.version=$(VERSION)'" -o $(RELEASE_BIN) .
# Install to $GOBIN, $GOPATH/bin, or /usr/local/bin
install: build
@if [ -n "$$GOBIN" ]; then \
cp $(BIN_NAME) "$$GOBIN/$(BIN_NAME)" && echo "Installed to $$GOBIN/$(BIN_NAME)"; \
elif [ -n "$$GOPATH" ]; then \
cp $(BIN_NAME) "$$GOPATH/bin/$(BIN_NAME)" && echo "Installed to $$GOPATH/bin/$(BIN_NAME)"; \
else \
cp $(BIN_NAME) /usr/local/bin/$(BIN_NAME) 2>/dev/null && echo "Installed to /usr/local/bin/$(BIN_NAME)" || echo "Copy to /usr/local/bin failed (try sudo)"; \
fi
clean:
rm -f $(BIN_NAME)
rm -rf dist