Debian Codegraph @

Makefile

raw
1 SRCDIR=src
2 EXTDIR=extensions
3 DATADIR=data
4 BUILDDIR?=build
5 GENERATOR?=Unix Makefiles
6 MINGW_BUILDDIR?=build-mingw
7 MINGW_INSTALLDIR?=windows
8 SPEC=test/spec.txt
9 EXTENSIONS_SPEC=test/extensions.txt
10 SITE=_site
11 SPECVERSION=$(shell perl -ne 'print $$1 if /^version: *([0-9.]+)/' $(SPEC))
12 FUZZCHARS?=2000000 # for fuzztest
13 BENCHDIR=bench
14 BENCHSAMPLES=$(wildcard $(BENCHDIR)/samples/*.md)
15 BENCHFILE=$(BENCHDIR)/benchinput.md
16 ALLTESTS=alltests.md
17 NUMRUNS?=20
18 CMARK=$(BUILDDIR)/src/cmark-gfm
19 CMARK_FUZZ=$(BUILDDIR)/src/cmark-fuzz
20 PROG?=$(CMARK)
21 VERSION?=$(SPECVERSION)
22 RELEASE?=CommonMark-$(VERSION)
23 INSTALL_PREFIX?=/usr/local
24 CLANG_CHECK?=clang-check
25 CLANG_FORMAT=clang-format -style llvm -sort-includes=0 -i
26 AFL_PATH?=/usr/local/bin
27
28 .PHONY: all cmake_build leakcheck clean fuzztest test debug ubsan asan mingw archive newbench bench format update-spec afl clang-check docker libFuzzer
29
30 all: cmake_build man/man3/cmark-gfm.3
31
32 $(CMARK): cmake_build
33
34 cmake_build: $(BUILDDIR)
35 @$(MAKE) -j2 -C $(BUILDDIR)
36 @echo "Binaries can be found in $(BUILDDIR)/src"
37
38 $(BUILDDIR):
39 @cmake --version > /dev/null || (echo "You need cmake to build this program: http://www.cmake.org/download/" && exit 1)
40 mkdir -p $(BUILDDIR); \
41 cd $(BUILDDIR); \
42 cmake .. \
43 -G "$(GENERATOR)" \
44 -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
45 -DCMAKE_INSTALL_PREFIX=$(INSTALL_PREFIX) \
46 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
47
48 install: $(BUILDDIR)
49 $(MAKE) -C $(BUILDDIR) install
50
51 debug:
52 mkdir -p $(BUILDDIR); \
53 cd $(BUILDDIR); \
54 cmake .. -DCMAKE_BUILD_TYPE=Debug; \
55 $(MAKE)
56
57 ubsan:
58 mkdir -p $(BUILDDIR); \
59 cd $(BUILDDIR); \
60 cmake .. -DCMAKE_BUILD_TYPE=Ubsan; \
61 $(MAKE)
62
63 asan:
64 mkdir -p $(BUILDDIR); \
65 cd $(BUILDDIR); \
66 cmake .. -DCMAKE_BUILD_TYPE=Asan; \
67 $(MAKE)
68
69 prof:
70 mkdir -p $(BUILDDIR); \
71 cd $(BUILDDIR); \
72 cmake .. -DCMAKE_BUILD_TYPE=Profile; \
73 $(MAKE)
74
75 afl:
76 @[ -n "$(AFL_PATH)" ] || { echo '$$AFL_PATH not set'; false; }
77 mkdir -p $(BUILDDIR)
78 cd $(BUILDDIR) && cmake .. -DCMARK_TESTS=0 -DCMAKE_C_COMPILER=$(AFL_PATH)/afl-clang
79 $(MAKE)
80 $(AFL_PATH)/afl-fuzz \
81 -i test/afl_test_cases \
82 -o test/afl_results \
83 -x test/fuzzing_dictionary \
84 $(AFL_OPTIONS) \
85 -t 100 \
86 $(CMARK) -e table -e strikethrough -e autolink -e tagfilter $(CMARK_OPTS)
87
88 libFuzzer:
89 @[ -n "$(LIB_FUZZER_PATH)" ] || { echo '$$LIB_FUZZER_PATH not set'; false; }
90 mkdir -p $(BUILDDIR)
91 cd $(BUILDDIR) && cmake -DCMAKE_BUILD_TYPE=Asan -DCMARK_LIB_FUZZER=ON -DCMAKE_LIB_FUZZER_PATH=$(LIB_FUZZER_PATH) ..
92 $(MAKE) -j2 -C $(BUILDDIR) cmark-fuzz
93 test/run-cmark-fuzz $(CMARK_FUZZ)
94
95 clang-check: all
96 ${CLANG_CHECK} -p build -analyze src/*.c
97
98 mingw:
99 mkdir -p $(MINGW_BUILDDIR); \
100 cd $(MINGW_BUILDDIR); \
101 cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchain-mingw32.cmake -DCMAKE_INSTALL_PREFIX=$(MINGW_INSTALLDIR) ;\
102 $(MAKE) && $(MAKE) install
103
104 man/man3/cmark-gfm.3: src/cmark-gfm.h | $(CMARK)
105 python man/make_man_page.py $< > $@ \
106
107 archive:
108 git archive --prefix=$(RELEASE)/ -o $(RELEASE).tar.gz HEAD
109 git archive --prefix=$(RELEASE)/ -o $(RELEASE).zip HEAD
110
111 clean:
112 rm -rf $(BUILDDIR) $(MINGW_BUILDDIR) $(MINGW_INSTALLDIR)
113
114 # We include case_fold_switch.inc in the repository, so this shouldn't
115 # normally need to be generated.
116 $(SRCDIR)/case_fold_switch.inc: $(DATADIR)/CaseFolding.txt
117 perl tools/mkcasefold.pl < $< > $@
118
119 # We include scanners.c in the repository, so this shouldn't
120 # normally need to be generated.
121 $(SRCDIR)/scanners.c: $(SRCDIR)/scanners.re
122 @case "$$(re2c -v)" in \
123 *\ 0.13.*|*\ 0.14|*\ 0.14.1) \
124 echo "re2c >= 0.14.2 is required"; \
125 false; \
126 ;; \
127 esac
128 re2c -W -Werror --case-insensitive -b -i --no-generation-date -8 \
129 --encoding-policy substitute -o $@ $<
130 $(CLANG_FORMAT) $@
131
132 # We include scanners.c in the repository, so this shouldn't
133 # normally need to be generated.
134 $(EXTDIR)/ext_scanners.c: $(EXTDIR)/ext_scanners.re
135 @case "$$(re2c -v)" in \
136 *\ 0.13.*|*\ 0.14|*\ 0.14.1) \
137 echo "re2c >= 0.14.2 is required"; \
138 false; \
139 ;; \
140 esac
141 re2c --case-insensitive -b -i --no-generation-date -8 \
142 --encoding-policy substitute -o $@ $<
143 clang-format -style llvm -i $@
144
145 # We include entities.inc in the repository, so normally this
146 # doesn't need to be regenerated:
147 $(SRCDIR)/entities.inc: tools/make_entities_inc.py
148 python3 $< > $@
149
150 update-spec:
151 curl 'https://raw.githubusercontent.com/jgm/CommonMark/master/spec.txt'\
152 > $(SPEC)
153
154 test: $(SPEC) cmake_build
155 $(MAKE) -C $(BUILDDIR) test || (cat $(BUILDDIR)/Testing/Temporary/LastTest.log && exit 1)
156
157 $(ALLTESTS): $(SPEC) $(EXTENSIONS_SPEC)
158 ( \
159 python3 test/spec_tests.py --spec $(SPEC) --dump-tests | \
160 python3 -c 'import json; import sys; tests = json.loads(sys.stdin.read()); u8s = open(1, "w", encoding="utf-8", closefd=False); print("\n".join([test["markdown"] for test in tests]), file=u8s)'; \
161 python3 test/spec_tests.py --spec $(EXTENSIONS_SPEC) --dump-tests | \
162 python3 -c 'import json; import sys; tests = json.loads(sys.stdin.read()); u8s = open(1, "w", encoding="utf-8", closefd=False); print("\n".join([test["markdown"] for test in tests]), file=u8s)'; \
163 ) > $@
164
165 leakcheck: $(ALLTESTS)
166 for format in html man xml latex commonmark; do \
167 for opts in "" "--smart"; do \
168 echo "cmark-gfm -t $$format -e table -e strikethrough -e autolink -e tagfilter $$opts" ; \
169 valgrind -q --leak-check=full --dsymutil=yes --suppressions=suppressions --error-exitcode=1 $(PROG) -t $$format -e table -e strikethrough -e autolink -e tagfilter $$opts $(ALLTESTS) >/dev/null || exit 1;\
170 done; \
171 done;
172
173 fuzztest:
174 { for i in `seq 1 10`; do \
175 cat /dev/urandom | head -c $(FUZZCHARS) | iconv -f latin1 -t utf-8 | tee fuzz-$$i.txt | \
176 /usr/bin/env time -p $(PROG) >/dev/null && rm fuzz-$$i.txt ; \
177 done } 2>&1 | grep 'user\|abnormally'
178
179 progit:
180 git clone https://github.com/progit/progit.git
181
182 $(BENCHFILE): progit
183 echo "" > $@
184 for lang in ar az be ca cs de en eo es es-ni fa fi fr hi hu id it ja ko mk nl no-nb pl pt-br ro ru sr th tr uk vi zh zh-tw; do \
185 for i in `seq 1 10`; do \
186 cat progit/$$lang/*/*.markdown >> $@; \
187 done; \
188 done
189
190 # for more accurate results, run with
191 # sudo renice -10 $$; make bench
192 bench: $(BENCHFILE)
193 { for x in `seq 1 $(NUMRUNS)` ; do \
194 /usr/bin/env time -p $(PROG) </dev/null >/dev/null ; \
195 /usr/bin/env time -p $(PROG) $< >/dev/null ; \
196 done \
197 } 2>&1 | grep 'real' | awk '{print $$2}' | python3 'bench/stats.py'
198
199 newbench:
200 for f in $(BENCHSAMPLES) ; do \
201 printf "%26s " `basename $$f` ; \
202 { for x in `seq 1 $(NUMRUNS)` ; do \
203 /usr/bin/env time -p $(PROG) </dev/null >/dev/null ; \
204 for x in `seq 1 200` ; do cat $$f ; done | \
205 /usr/bin/env time -p $(PROG) > /dev/null; \
206 done \
207 } 2>&1 | grep 'real' | awk '{print $$2}' | \
208 python3 'bench/stats.py'; done
209
210 format:
211 $(CLANG_FORMAT) src/*.c src/*.h api_test/*.c api_test/*.h
212
213 format-extensions:
214 clang-format -style llvm -i extensions/*.c extensions/*.h
215
216 operf: $(CMARK)
217 operf $< < $(BENCHFILE) > /dev/null
218
219 distclean: clean
220 -rm -rf *.dSYM
221 -rm -f README.html
222 -rm -rf $(BENCHFILE) $(ALLTESTS) progit
223
224 docker:
225 docker build -t cmark-gfm $(CURDIR)/tools
226 docker run --privileged -t -i -v $(CURDIR):/src/cmark-gfm -w /src/cmark-gfm cmark-gfm /bin/bash