-
Notifications
You must be signed in to change notification settings - Fork 26
/
Makefile
161 lines (135 loc) · 5.69 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
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
155
156
157
158
159
160
161
# Include variables set by configure, only if file exists so that
# independent make targets still work:
ifneq ($(wildcard config.mk),)
include config.mk
endif
CXXFLAGS += -std=c++17 -lstdc++fs -DVERSION="\"$(VERSION)\""
COVERAGE_CXXFLAGS = $(CXXFLAGS) -fprofile-arcs -ftest-coverage
TARGETS = checktestdata
CHKOBJS = $(addsuffix $(OBJEXT),libchecktestdata parse lex parsetype)
OBJECTS = $(CHKOBJS)
PARSER_GEN = lex.cc scannerbase.h parse.cc parserbase.h
# Check for QUIET environment variable:
ifneq ($(QUIET),)
QUIET=1
MAKEFLAGS += --no-print-directory --quiet
endif
# Function to parse version number from bisonc++/flexc++ --version and
# add it as a define in generated code. This is used in the header
# files to conditionally include declarations that conflict between
# different versions.
INSERT_VERSION = \
sed -i "/^\/\/ Generated by /a \\\\n\#define $(1) \
`echo $(2) | sed 's/^.* V//;s/\\.//g;s/^0*//'`LL" $@
build: $(TARGETS) $(SUBST_FILES)
# These are build during dist stage, and this is independent of
# whether checktestdata is enabled after configure.
ifeq ($(PARSERGEN_ENABLED),yes)
$(PARSER_GEN): | config.mk
scannerbase.h: checktestdata.l scanner.h scanner.ih
flexc++ $<
$(call INSERT_VERSION,FLEXCPP_VERSION,$(shell flexc++ --version))
lex.cc: scannerbase.h
@# generated at the same time as scannerbase.h, nothing more to do here
@# (but we still need this dummy recipe)
parserbase.h: checktestdata.y parser.h parser.ih parsetype.hpp
bisonc++ $<
$(call INSERT_VERSION,BISONCPP_VERSION,$(shell bisonc++ --version))
parse.cc: parserbase.h
@# generated at the same time as parserbase.h, nothing more to do here
@# (but we still need this dummy recipe)
endif
checkcmd = ./checktestdata $$opts $$prog $$data
checksucc = $(checkcmd) >/dev/null 2>&1 || \
{ echo "Running '$(checkcmd)'$${try:+ attempt $$try} did not succeed..." ; exit 1; }
checkfail = $(checkcmd) >/dev/null 2>&1 && \
{ echo "Running '$(checkcmd)'$${try:+ attempt $$try} did not fail..." ; exit 1; }
checkgeneratesucc = $(checksucc) && \
{ cmp -s $$data $$expected_data || { echo "RESULT $$?" ; echo "Running '$(checkcmd)' did not generated expected output..." ; exit 1; } }
checkgeneratefail = $(checksucc) && \
{ cmp -s $$data $$expected_data && { echo "Running '$(checkcmd)' did not fail..." ; exit 1; } }
config.mk: config.mk.in
$(error run ./bootstrap and/or configure to create config.mk)
libchecktestdata.o: config.mk
libchecktestdata.o: $(PARSER_GEN)
libchecktestdata.o: %.o: %.cc %.hpp databuffer.hpp bigint.hpp parser.h
checktestdata: CPPFLAGS += $(BOOST_CPPFLAGS)
checktestdata: LDFLAGS += $(BOOST_LDFLAGS) $(STATIC_LINK_START) $(LIBGMPXX) $(STATIC_LINK_END)
checktestdata: LDFLAGS := $(filter-out -pie,$(LDFLAGS))
checktestdata: checktestdata.cc $(CHKOBJS)
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
check: checktestdata
@for prog in tests/test_*_prog.in ; do \
base=$${prog%_prog.*} ; \
for data in $${base}_data.in* ; do $(checksucc) ; done ; \
for data in $${base}_data.err* ; do $(checkfail) ; done ; \
data=$${base}_data.in ; \
for prog in $${base}_prog.err* ; do $(checkfail) ; done ; \
done || true
# Some additional tests with --whitespace-ok option enabled:
@opts=-w ; \
for prog in tests/testws_*_prog.in ; do \
base=$${prog%_prog.*} ; \
for data in $${base}_data.in* ; do $(checksucc) ; done ; \
for data in $${base}_data.err* ; do $(checkfail) ; done ; \
done || true
# A single hardcoded test for the --preset option:
@opts='-g -p n=10,pi=0.31415E1,foo="\"bar\""' ; \
prog=tests/testpreset_prog.in ; $(checksucc) ; \
prog=tests/testpreset_prog.err ; $(checkfail) ; \
true
@opts='-g -p n=10,pi=0.31415E1,foo="\"bar' ; \
prog=tests/testpreset_prog.in ; $(checkfail) ; \
true
# Another test for debugging to improve code coverage:
@opts=-d ; prog=tests/test_01_prog.in ; data=tests/test_01_data.in ; $(checksucc) ; true
# Test if generating testdata works and complies with the script:
@TMP=`mktemp --tmpdir dj_gendata.XXXXXX` || exit 1 ; data=$$TMP ; \
for prog in tests/test_*_prog.in ; do \
grep 'IGNORE GENERATE TESTING' $$prog >/dev/null && continue ; \
for try in `seq 10` ; do opts=-g ; $(checksucc) ; opts='' ; $(checksucc) ; done ; \
done ; \
rm -f $$TMP
# A single hardcoded test for the --seed option:
@opts='-g -s 31415' ; \
TMP=`mktemp --tmpdir dj_gendata.XXXXXX` || exit 1 ; \
data=$$TMP ; \
prog=tests/testgenerate_prog.in ; \
expected_data=tests/testgenerate_data.in ; $(checkgeneratesucc) ; \
expected_data=tests/testgenerate_data.err ; $(checkgeneratefail) ; \
opts='-g -s 0' ; \
expected_data=tests/testgenerate_data.in ; $(checkgeneratefail) ; \
true
@rm -f $$TMP
coverage:
$(MAKE) clean
$(MAKE) CXXFLAGS='$(COVERAGE_CXXFLAGS)'
$(MAKE) check
gcov checktestdata.cc libchecktestdata.cc libchecktestdata.hpp databuffer.hpp
coverage-clean:
rm -f *.gcda *.gcno *.gcov coverage*.html
# Requires gcovr >= 3.2
coverage-report: coverage
gcovr -g -r . --html --html-details -o coverage.html
# Rules to configure and build for a Coverity scan. This assumes we're
# running from the Git repository.
coverity-conf:
git checkout $(subst 1,-q,$(QUIET)) release
./bootstrap $(subst 1,-q,$(QUIET))
coverity-build: config.mk dist
$(MAKE) build
@VERSION=`grep '^VERSION =' config.mk | sed 's/^VERSION = *//'` \
echo "VERSION=$$VERSION" > cov-submit-data-version.sh
dist: $(PARSER_GEN)
clean:
-rm -f $(TARGETS) $(OBJECTS)
# Remove Coverity scan data:
-rm -rf cov-int coverity-scan.tar.xz cov-submit-data-version.sh
distclean: clean coverage-clean
-rm -f $(PARSER_GEN)
maintainer-clean: distclean
-rm -rf autom4te.cache
-rm -f config.mk config.status configure
.PHONY: build dist check clean distclean maintainer-clean \
coverage coverage-clean coverage-report \
coverity-conf coverity-build