-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
84 lines (63 loc) · 1.62 KB
/
Makefile
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
# Commands
STRIP := gstrip
# Flags
BUILD_FLAGS := --threads:on -d:release --opt:size \
--passC:-ffunction-sections --passC:-fdata-sections \
--passL:-Wl
TEST_BUILD_FLAGS := --debugger:native --passC:--coverage --passL:--coverage
# Dirs
PROJECT_ROOT:= $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
BIN_DIR := $(PROJECT_ROOT)bin
TESTS_DIR := $(PROJECT_ROOT)tests
COVERAGE_DIR:= coverage
# Files
MAIN_NIM := xx0.nim
MAIN_BIN := $(BIN_DIR)/xx0
MAIN_INFO := xx0.info
TEST_NIM := $(TESTS_DIR)/tests.nim
TEST_BIN := $(BIN_DIR)/tests
TEST_INFO := $(TESTS_DIR)/tests.info
# ----- Rules
# Default rule
.PHONY: default
default: run
# Binaries
$(BIN_DIR):
mkdir -p $@
$(MAIN_BIN): $(MAIN_NIM) $(BIN_DIR)
nim c $(BUILD_FLAGS) --out:$@ $<
$(STRIP) -S -x $@
$(TEST_BIN): $(TEST_NIM) $(BIN_DIR)
nim c $(TEST_BUILD_FLAGS) --out:$@ $<
# Coverage
$(TEST_INFO): $(TEST_BIN)
$(MAKE) clean-test-info
# reset counters
lcov --base-directory . --directory . --zerocounters -q
$(MAKE) run-test
# create coverage info
lcov --base-directory . --directory . -c -o $(TEST_INFO)
# remove Nim system libs from coverage
lcov --remove $(TEST_INFO) "*/nim/lib/*" -o $(TEST_INFO)
$(COVERAGE_DIR): $(TEST_INFO)
$(MAKE) clean-coverage
genhtml -o $(COVERAGE_DIR) $(TEST_INFO)
.PHONY: build
build: $(MAIN_BIN)
.PHONY: cov
cov: $(COVERAGE_DIR)
.PHONY: run
run: $(MAIN_BIN)
$(MAIN_BIN)
.PHONY: run-test
run-test: $(TEST_BIN)
$(TEST_BIN)
.PHONY: clean-test-info
clean-test-info:
rm -f $(TEST_INFO)
.PHONY: clean-coverage
clean-coverage:
rm -rf $(COVERAGE_DIR)
.PHONY: install-dev-deps
install-dev-deps:
nimble install sdl2 strfmt