-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
83 lines (67 loc) · 1.74 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
.SUFFIXES:
.SECONDARY:
BUILD := build
CXXFLAGS ?= -pedantic \
-Wall -Wextra -Wshadow -Werror \
-std=c++11 -Iinclude
ifdef NDEBUG
CXXFLAGS += -D NDEBUG
BUILD := $(BUILD)/ndebug
else
BUILD := $(BUILD)/debug
endif
ifdef USE_PEGTL
CXXFLAGS += -IPEGTL/include -D USE_PEGTL
BUILD := $(BUILD)/use_pegtl
else
BUILD := $(BUILD)/no_pegtl
endif
HEADER := $(shell find include -name '*.hpp')
SRC_EXAMPLE := $(shell find example -name '*.cpp')
DEP_EXAMPLE := $(SRC_EXAMPLE:%.cpp=$(BUILD)/%.d)
BIN_EXAMPLE := $(SRC_EXAMPLE:%.cpp=$(BUILD)/%)
SRC_TEST := $(shell find test -name '*.cpp')
DEP_TEST := $(SRC_TEST:%.cpp=$(BUILD)/%.d)
BIN_TEST := $(SRC_TEST:%.cpp=$(BUILD)/%)
# default
all: .build_test .build_example
.PHONY: all
# help
help:
@echo "goals:"
@echo " all (default): build tests and examples"
@echo " test : run tests"
@echo " clean : clean everything"
@echo " help : show help"
@echo ""
@echo "optional variables:"
@echo " USE_PEGTL : build with PEGTL library"
@echo " NDEBUG : build in none Debug mode"
@echo ""
@echo "for example, build and run test with PEGTL :"
@echo " $ make USE_PEGTL=1 test"
@echo ""
# clean build dir
clean:
@rm -rf build/
# build test
.build_test: $(BIN_TEST)
# build example
.build_example: $(BIN_EXAMPLE)
# run test
test: .build_test
@echo "Run tests..."
@set -e; for T in $(BIN_TEST) ; do echo $$T ; $$T > $$T.log ; tail -1 $$T.log ; done
# compile cpp
$(BUILD)/%: %.cpp $(BUILD)/%.d
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $< -o $@
# generates include-dependency on the fly
$(BUILD)/%.d: %.cpp
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -MM -MQ $@ $< -o $@
# include generated include-dependency if necessary
ifeq ($(filter clean help,$(MAKECMDGOALS)),)
-include $(DEP_EXAMPLE)
-include $(DEP_TEST)
endif