-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
74 lines (60 loc) · 1.81 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
DEST=build
FLAGS=-Wall -Wextra -std=c++11 -Ilib/Catch2/single_include
TEST_DIR=tests
TEST_FLAGS=--durations yes
# Paths to all test files
TEST_SRCS=$(shell find $(TEST_DIR) -name '*.cpp')
EXAMPLE_DIR=examples
EXAMPLE_FLAGS=
# Paths to all example files
EXAMPLE_SRCS=$(shell find $(EXAMPLE_DIR) -name '*.cpp')
EXAMPLE_BINS=$(patsubst $(EXAMPLE_DIR)/%.cpp,$(DEST)/%,$(EXAMPLE_SRCS))
# Combine all cpp files into a single variable
ALL_SRCS=$(TEST_SRCS) $(EXAMPLE_SRCS) listtools-ng.h
$(DEST)/test_bin: $(TEST_SRCS)
@mkdir -p $(DEST)
@echo "---------------"
@echo "Compiling tests"
@echo "---------------"
$(CXX) $(FLAGS) -o $@ $^
$(DEST)/%: $(EXAMPLE_DIR)/%.cpp
@mkdir -p $(DEST)
@echo "------------------"
@echo "Compiling examples"
@echo "------------------"
$(CXX) $(FLAGS) -o $@ $^
test: $(DEST)/test_bin
@echo "-------------"
@echo "Running tests"
@echo "-------------"
$(DEST)/test_bin $(TEST_FLAGS)
examples: $(EXAMPLE_BINS)
@echo "----------------"
@echo "Running examples"
@echo "----------------"
@$(foreach bin,$(EXAMPLE_BINS),echo "Running \"$(patsubst $(DEST)/%,%,$(bin))\""; $(bin) $(EXAMPLE_FLAGS); echo "---";)
docs:
@echo "--------------"
@echo "Compiling docs"
@echo "--------------"
doxygen Doxyfile
check-format:
@echo "-------------------"
@echo "Checking formatting"
@echo "-------------------"
@for f in $(ALL_SRCS); do \
echo "clang-format $$f" ; \
clang-format -output-replacements-xml "$$f" | grep -c "<replacement " >/dev/null ; \
if [ $$? -ne 1 ]; then \
echo "Error: Filen '$$f' har ikke riktig formattering" ; \
exit 1 ; \
fi \
done
format:
@echo "----------------------"
@echo "Formatting sourcefiles"
@echo "----------------------"
clang-format -i $(EXAMPLE_SRCS) $(TEST_SRCS) listtools-ng.h
clean:
rm -rf $(DEST)
.PHONY: test clean docs examples format check-format