-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
154 lines (125 loc) · 4.51 KB
/
Copy pathMakefile
File metadata and controls
154 lines (125 loc) · 4.51 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
SHELL := /bin/bash
PROJECT_NAME := dp
NIMBLE_FILE := devpilot.nimble
PROJECT_VERSION := $(shell sed -n 's/^[[:space:]]*version[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/p' $(NIMBLE_FILE) | head -1)
ifeq ($(PROJECT_VERSION),)
$(error Error: could not determine project version from $(NIMBLE_FILE))
endif
TOP_DIR := $(CURDIR)
NIM := nim
NIMBLE := nimble
NIMPRETTY := nimpretty
PREFIX ?= $(HOME)/.local
ARGS ?=
BUILD_FLAGS ?= -d:release
NIM_FILES := $(shell find src tests -name '*.nim' -type f | sort)
BOBABREW_SRC := $(shell if [ -n "$$NIMBLE_DIR" ] && [ -d "$$NIMBLE_DIR/pkgcache/githubcom_bresillabobabrew/src" ]; then printf '%s' "$$NIMBLE_DIR/pkgcache/githubcom_bresillabobabrew/src"; elif [ -n "$$NIMBLE_DIR" ] && [ -d "$$NIMBLE_DIR/pkgcache/githubcom_bresillabobabrew_0.1.0/src" ]; then printf '%s' "$$NIMBLE_DIR/pkgcache/githubcom_bresillabobabrew_0.1.0/src"; elif [ -d "$(TOP_DIR)/../bobabrew/src" ]; then printf '%s' "$(TOP_DIR)/../bobabrew/src"; fi)
NIM_FLAGS ?=
ifneq ($(BOBABREW_SRC),)
NIM_FLAGS += --path:$(BOBABREW_SRC)
endif
HAS_REL := $(shell command -v git-rel 2>/dev/null)
HAS_CLIFF := $(shell command -v git-cliff 2>/dev/null)
$(info ------------------------------------------)
$(info Project: $(PROJECT_NAME) v$(PROJECT_VERSION))
$(info ------------------------------------------)
.PHONY: build b compile c run r install uninstall test t test-all cover check vet fmt fmt-check tidy clean changelog verify release mdbook help h
build:
@$(NIM) c $(NIM_FLAGS) $(BUILD_FLAGS) --out:$(PROJECT_NAME) src/dp.nim
b: build
compile:
@$(MAKE) clean
@$(MAKE) build
c: compile
run: build
@./$(PROJECT_NAME) $(ARGS)
r: run
install: build
@install -d $(PREFIX)/bin
@install -m 0755 $(PROJECT_NAME) $(PREFIX)/bin/$(PROJECT_NAME)
@echo "installed -> $(PREFIX)/bin/$(PROJECT_NAME)"
uninstall:
@rm -f $(PREFIX)/bin/$(PROJECT_NAME)
@echo "removed -> $(PREFIX)/bin/$(PROJECT_NAME)"
test:
@$(NIMBLE) test -y
t: test
test-all:
@$(NIMBLE) test -y
@$(NIM) c $(NIM_FLAGS) -d:release --out:/tmp/devpilot-release-check src/dp.nim
@rm -f /tmp/devpilot-release-check
cover:
@echo "coverage is not configured for this Nim project yet; running tests instead"
@$(MAKE) test
check:
@$(NIM) check $(NIM_FLAGS) src/dp.nim
vet: check
fmt:
@$(NIMPRETTY) $(NIM_FILES)
fmt-check:
@set -e; \
needed=""; \
for f in $(NIM_FILES); do \
tmp="/tmp/devpilot-nimpretty-$$(basename "$$f").$$$$.nim"; \
cp "$$f" "$$tmp"; \
$(NIMPRETTY) "$$tmp" >/dev/null; \
if ! cmp -s "$$f" "$$tmp"; then needed="$$needed $$f"; fi; \
rm -f "$$tmp"; \
done; \
if [ -n "$$needed" ]; then echo "nimpretty needed on:$$needed"; exit 1; fi
tidy:
@$(NIMBLE) install -y --depsOnly
clean:
@rm -f $(PROJECT_NAME) coverage.out
@rm -rf bin nimcache
@find tests -maxdepth 1 -type f -name 'test_*' ! -name '*.nim' -delete
changelog:
@if [ -z "$(HAS_CLIFF)" ]; then \
echo "git-cliff is not installed. Please install it first."; \
exit 1; \
fi
@git cliff -o CHANGELOG.md
verify: fmt-check check test
release:
@if [ -z "$(HAS_REL)" ]; then \
echo "git-rel is not installed. Please install it first."; \
exit 1; \
fi
@if [ -z "$(TYPE)" ]; then \
echo "Release type not specified. Use 'make release TYPE=[patch|minor|major|M.m.p]'"; \
exit 1; \
fi
@git rel $(TYPE)
mdbook:
@mdbook build book --dest-dir ../docs
@git add -A && git commit -m "docs: building website/mdbook"
help:
@echo
@echo "Usage: make [target]"
@echo
@echo "Available targets:"
@echo " build Build the binary (./$(PROJECT_NAME))"
@echo " compile Clean and rebuild"
@echo " run Run locally (pass args with ARGS=...)"
@echo " install Install to \$$PREFIX/bin (default ~/.local/bin)"
@echo " uninstall Remove the installed binary"
@echo " test Run all tests"
@echo " test-all Run tests plus release compile check"
@echo " cover Run tests (coverage not configured yet)"
@echo " check Run Nim semantic checks"
@echo " vet Alias for check"
@echo " fmt Format Nim sources"
@echo " fmt-check Fail if Nim sources are unformatted"
@echo " tidy Install Nim dependencies"
@echo " clean Remove build artifacts"
@echo " changelog Regenerate CHANGELOG.md (git-cliff)"
@echo " verify Run the full local gate (fmt-check + check + test)"
@echo " release Release a new version (git-rel)"
@echo " mdbook Build the mdbook into ../docs"
@echo
@echo "Examples:"
@echo " make run ARGS='project list'"
@echo " make install PREFIX=/usr/local"
@echo " make release TYPE=minor"
@echo
h: help