cmark

My personal build of CMark ✏️

Makefile (6077B)

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