-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
93 lines (70 loc) · 2.26 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
85
86
87
88
89
90
91
92
93
# CC=clang
CXX=clang++
RM=rm -f
WARNINGS=-Wall -Wextra -Wpedantic
DEBUG=-g -O1
override CXXFLAGS += $(WARNINGS) $(DEBUG) -std=c++2a -I./src/ -I./includes/
override LDFLAGS += $(DEBUG)
LDLIBS=
ifdef FUZZ
override CXXFLAGS += -g -O1 -fsanitize=fuzzer,address -fprofile-instr-generate -fcoverage-mapping
override LDFLAGS += -fsanitize=fuzzer,address
endif
ifdef COVERAGE
override CXXFLAGS += -g -fprofile-instr-generate -fcoverage-mapping
endif
ifdef RELEASE
override CXXFLAGS += -O3
endif
ifdef TRACE
override CXXFLAGS += -DTRACE
endif
SRCS_LIB:=$(filter-out src/main.cpp,$(shell find src -type f -name '*.cpp'))
OBJS_LIB:=$(patsubst %.cpp,%.o,$(SRCS_LIB))
SRCS_APP:=src/main.cpp
OBJS_APP:=$(patsubst %.cpp,%.o,$(SRCS_APP))
SRCS_TEST:=$(shell find test -type f -name '*.cpp')
OBJS_TEST:=$(pathsubst %cpp,%.o,$(SRCS_TEST))
SRCS_ALL:=$(SRCS_LIB) $(SRCS_APP) $(SRCS_TEST)
OBJS_ALL:=$(OBJS_LIB) $(OBJS_APP) $(OBJS_TEST)
# default target
all: jsonquery
# LIBRARY
lib.a: $(OBJS_LIB)
ar crvs $@ $^
# EXECUTABLE
jsonquery: src/main.o lib.a
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
# TESTS
check: jsonquery_test
./jsonquery_test
# main test suite
jsonquery_test: test/main.o lib.a
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
# fuzzer test
jsonquery_fuzz: test/test_fuzzer.cpp lib.a
@test $(FUZZ) || { echo -e "Fuzzing only works with clang and with FUZZ=1 when compiling ALL targets (you should run \"make clean\" if you previously built without fuzzing)! But with FUZZ=1 you can't make the other binaries.\n" && exit 1; }
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
# Generate a .depend file that contains all the header dependencies
# in Makefile format so we can include it below
#
# NOTE: The strange loop is needed to fix the rules generated by $(CXX) -MM
# because that outputs a rule for "main.o" given the file "src/main.cpp" and
# "test/main.cpp" which is wrong
.depend: $(SRCS_ALL)
$(RM) ./.depend
for f in $^; do \
echo -n $$(dirname $$f)/ >> ./.depend; \
$(CXX) $(CXXFLAGS) -MM $$f >> ./.depend; \
done
# CLEAN tasks
clean:
$(RM) $(OBJS_ALL) lib.a
distclean: clean
$(RM) *~ .depend
cleanall: distclean
$(RM) jsonquery jsonquery_test jsonquery_fuzz
.PHONY: clean distclean cleanall all check
include .depend