-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
118 lines (95 loc) · 3.71 KB
/
Copy pathMakefile
File metadata and controls
118 lines (95 loc) · 3.71 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
DIST_DIR = dist
DEB_STAGING = .deb-staging
C_FILES = $(shell find * -name \*.c)
GO_FILES = $(shell find * -name \*.go)
SHELL_FILES = $(shell grep -rIl '^\#!.*sh' *)
SRC_DIRS = ./cmd/... ./src/...
CMDS = $(notdir $(wildcard ./cmd/*))
COVERAGE_FILE = cover.out
GOTEST_FLAGS = # Anything extra you'd like to pass to `go test`, e.g. `-v`
.PHONY: all
all: $(CMDS) test
.PHONY: cmds
cmds: $(CMDS)
# samoyed, ll2utm, etc. etc.
.PHONY: $(CMDS)
.SECONDEXPANSION:
$(CMDS): $(addprefix $(DIST_DIR)/,$$@)
$(DIST_DIR)/%: $(DIST_DIR) $(C_FILES) $(GO_FILES) ./cmd/%
go build -o $(DIST_DIR)/ -ldflags "-X 'github.com/doismellburning/samoyed/src.SAMOYED_VERSION=$(SAMOYED_VERSION)'" ./cmd/$*/...
$(DIST_DIR):
mkdir -p $(DIST_DIR)
.PHONY: deb
deb: cmds
test -n "$(SAMOYED_VERSION)" || (echo "ERROR: SAMOYED_VERSION is not set" >&2; exit 1)
rm -rf $(DEB_STAGING)
mkdir -p $(DEB_STAGING)/DEBIAN $(DEB_STAGING)/usr/bin $(DEB_STAGING)/usr/share/man/man1
strip $(DIST_DIR)/*
cp $(DIST_DIR)/samoyed-* $(DEB_STAGING)/usr/bin/
cp man/*.1 $(DEB_STAGING)/usr/share/man/man1/
grep -v '^#' packaging/debian/control.in \
| sed -e 's/@@VERSION@@/$(SAMOYED_VERSION)/g' \
-e "s/@@ARCH@@/$$(dpkg --print-architecture)/g" \
> $(DEB_STAGING)/DEBIAN/control
dpkg-deb --build --root-owner-group $(DEB_STAGING) samoyed-binary_$(SAMOYED_VERSION)_$$(dpkg --print-architecture).deb
rm -rf $(DEB_STAGING)
.PHONY: test
test: gotest test-scripts
.PHONY: gotest
gotest:
go test $(GOTEST_FLAGS) -cover -coverpkg=./cmd/...,./src/... -coverprofile $(COVERAGE_FILE) $(SRC_DIRS) # TODO Construct coverpkg from $SRC_DIRS
# TODO Better output name, non-PHONY target, docs, etc.
.PHONY: gotest-bin
gotest-bin:
go test -c -gcflags "-N -l" ./src
.PHONY: test-scripts
test-scripts: $(CMDS)
./test-scripts/runall
.PHONY: coveragereport
coveragereport:
go tool cover -func=$(COVERAGE_FILE)
.PHONY: perfilecoverage
perfilecoverage:
$(MAKE) coveragereport | awk -F'\t' '/^github/ { split($$1, a, ":"); file = a[1]; sub(".*samoyed/", "", file); pct = $$NF; sub(/%/, "", pct); totals[file] += pct; counts[file]++ } END { for (f in totals) { printf "%.1f%%\t%s\n", totals[f]/counts[f], f } }' | sort -k2
.PHONY: check
check: vet lint shellcheck reuse
go mod tidy -diff
.PHONY: reuse
reuse:
reuse lint
.PHONY: shellcheck
shellcheck:
shellcheck --external-sources --exclude SC1091 $(SHELL_FILES)
.PHONY: vet
vet:
go vet $(SRC_DIRS)
./bin/golangci-lint:
# This is not pleasant but it's also the/a recommended way of installation and means that we're explicitly pinning version
# https://golangci-lint.run/welcome/install/#binaries
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v2.11.4
.PHONY: lint
lint: ./bin/golangci-lint
./bin/golangci-lint run $(SRC_DIRS)
.PHONY: fix
fix: ./bin/golangci-lint
./bin/golangci-lint run --fix $(SRC_DIRS) || true # golangci-lint will still run other non-fix linters, and fail if it didn't fix everything - I just want best-effort
go mod tidy
.PHONY: stats
stats:
@echo "Code Stats"
@echo "=========="
@echo ""
@echo -n "C (src): "
@find src -name \*.c -exec wc -l {} + | tail -n 1 | sed -e "s/^ *//"
@echo -n "H (src): "
@find src -name \*.h -exec wc -l {} + | tail -n 1 | sed -e "s/^ *//"
@echo -n "C (external): "
@find external -name \*.c -exec wc -l {} + | tail -n 1 | sed -e "s/^ *//"
@echo -n "H (external): "
@find external -name \*.h -exec wc -l {} + | tail -n 1 | sed -e "s/^ *//"
@echo -n "Go: "
@find * -name \*.go -exec wc -l {} + | tail -n 1 | sed -e "s/^ *//"
@echo -n "CMake: "
@find * -name CMakeLists.txt -exec wc -l {} + | tail -n 1 | sed -e "s/^ *//"
tags: $(C_FILES) $(GO_FILES)
ctags --recurse --languages=C,Go --c-kinds=+p --fields=+iaS --extras=+q cmd/ src/