aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: d4d43cfc19f6423ea76bcb346807e887c2ddb5c0 (plain)
  1. SRCDIR?=src
  2. DATADIR?=data
  3. BUILDDIR?=build
  4. GENERATOR?=Unix Makefiles
  5. MINGW_BUILDDIR?=build-mingw
  6. MINGW_INSTALLDIR?=windows
  7. SPEC=spec.txt
  8. SITE=_site
  9. SPECVERSION=$(shell perl -ne 'print $$1 if /^version: *([0-9.]+)/' $(SPEC))
  10. PKGDIR?=cmark-$(SPECVERSION)
  11. TARBALL?=cmark-$(SPECVERSION).tar.gz
  12. ZIPARCHIVE?=cmark-$(SPECVERSION).zip
  13. FUZZCHARS?=2000000 # for fuzztest
  14. BENCHDIR=bench
  15. BENCHFILE=$(BENCHDIR)/benchinput.md
  16. ALLTESTS=alltests.md
  17. NUMRUNS?=10
  18. PROG?=$(BUILDDIR)/src/cmark
  19. BENCHINP?=README.md
  20. JSMODULES=$(wildcard js/lib/*.js)
  21. .PHONY: all spec leakcheck clean fuzztest dingus upload jshint test testjs benchjs update-site upload-site check npm debug mingw archive tarball ziparchive testarchive testtarball testziparchive testlib bench astyle
  22. all: $(PROG)
  23. @echo "Binaries can be found in $(BUILDDIR)/src"
  24. $(PROG): $(BUILDDIR)
  25. @make -C $(BUILDDIR)
  26. check:
  27. @cmake --version > /dev/null || (echo "You need cmake to build this program: http://www.cmake.org/download/" && exit 1)
  28. $(BUILDDIR): check $(SRCDIR)/html_unescape.h $(SRCDIR)/case_fold_switch.inc man/man3/cmark.3
  29. mkdir -p $(BUILDDIR); \
  30. cd $(BUILDDIR); \
  31. cmake .. -G "$(GENERATOR)" -DCMAKE_BUILD_TYPE=$(BUILD_TYPE)
  32. install: $(BUILDDIR)
  33. make -C $(BUILDDIR) install
  34. debug:
  35. mkdir -p $(BUILDDIR); \
  36. cd $(BUILDDIR); \
  37. cmake .. -DCMAKE_BUILD_TYPE=Debug; \
  38. make
  39. mingw:
  40. mkdir -p $(MINGW_BUILDDIR); \
  41. cd $(MINGW_BUILDDIR); \
  42. cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchain-mingw32.cmake -DCMAKE_INSTALL_PREFIX=$(MINGW_INSTALLDIR) ;\
  43. make && make install
  44. man/man3/cmark.3: src/cmark.h
  45. mkdir -p man/man3 && \
  46. python3 man/make_man_page.py $< > $@
  47. archive: spec.html man/man1/cmark.1 man/man3/cmark.3
  48. @rm -rf $(PKGDIR); \
  49. mkdir -p $(PKGDIR)/$(SRCDIR) \
  50. $(PKGDIR)/api_test $(PKGDIR)/man/man1 $(PKGDIR)/man/man3 \
  51. $(PKGDIR)/test $(PKGDIR)/data ; \
  52. srcfiles=`git ls-tree --full-tree -r HEAD --name-only $(SRCDIR) test api_test`; \
  53. for f in $$srcfiles; \
  54. do cp -a $$f $(PKGDIR)/$$f; \
  55. done; \
  56. cp -a $(SRCDIR)/scanners.c $(PKGDIR)/$(SRCDIR)/; \
  57. cp -a man/CMakeLists.txt man/make_man_page.py $(PKGDIR)/man;\
  58. cp -a man/man1/cmark.1 $(PKGDIR)/man/man1;\
  59. cp -a man/man3/cmark.3 $(PKGDIR)/man/man3;\
  60. cp -a data/CaseFolding-3.2.0.txt $(PKGDIR)/data/;\
  61. cp CMakeLists.txt $(PKGDIR); \
  62. perl -ne '$$p++ if /^### JavaScript/; print if (!$$p)' Makefile > $(PKGDIR)/Makefile; \
  63. cp -a Makefile.nmake nmake.bat $(PKGDIR); \
  64. cp -a README.md COPYING spec.txt spec.html $(PKGDIR)/; \
  65. tar czf $(TARBALL) $(PKGDIR); \
  66. zip -q -r $(ZIPARCHIVE) $(PKGDIR); \
  67. rm -rf $(PKGDIR) ; \
  68. echo "Created $(TARBALL) and $(ZIPARCHIVE)."
  69. clean:
  70. rm -rf $(BUILDDIR) $(MINGW_BUILDDIR) $(MINGW_INSTALLDIR) $(TARBALL) $(ZIPARCHIVE) $(PKGDIR)
  71. # We include html_unescape.h in the repository, so this shouldn't
  72. # normally need to be generated.
  73. $(SRCDIR)/html_unescape.h: $(SRCDIR)/html_unescape.gperf
  74. gperf -L ANSI-C -I -t -N find_entity -H hash_entity -K entity -C -l \
  75. -F ',0,{0}' --null-strings -m5 $< > $@
  76. # We include case_fold_switch.inc in the repository, so this shouldn't
  77. # normally need to be generated.
  78. $(SRCDIR)/case_fold_switch.inc: $(DATADIR)/CaseFolding-3.2.0.txt
  79. perl mkcasefold.pl < $< > $@
  80. # We include scanners.c in the repository, so this shouldn't
  81. # normally need to be generated.
  82. $(SRCDIR)/scanners.c: $(SRCDIR)/scanners.re
  83. re2c --case-insensitive -b -i --no-generation-date -o $@ $<
  84. test: $(SPEC) $(BUILDDIR)
  85. make -C $(BUILDDIR) test || (cat $(BUILDDIR)/Testing/Temporary/LastTest.log && exit 1)
  86. $(TARBALL): archive
  87. $(ZIPARCHIVE): archive
  88. testarchive: testtarball testziparchive
  89. rm -rf $(PKGDIR)
  90. testtarball: $(TARBALL)
  91. rm -rf $(PKGDIR); \
  92. tar xvzf $(TARBALL); \
  93. cd $(PKGDIR); \
  94. mkdir build && cd build && cmake .. && make && ctest -V
  95. testziparchive: $(ZIPARCHIVE)
  96. rm -rf $(PKGDIR); \
  97. unzip $(ZIPARCHIVE); \
  98. cd $(PKGDIR); \
  99. mkdir build && cd build && cmake .. && make && ctest -V
  100. $(ALLTESTS): spec.txt
  101. 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]))' > $@
  102. leakcheck: $(ALLTESTS)
  103. cat $< | valgrind --leak-check=full --dsymutil=yes --error-exitcode=1 $(PROG) >/dev/null
  104. cat $< | valgrind --leak-check=full --dsymutil=yes --error-exitcode=1 $(PROG) -t man >/dev/null
  105. cat $< | valgrind --leak-check=full --dsymutil=yes --error-exitcode=1 $(PROG) -t xml >/dev/null
  106. fuzztest:
  107. { for i in `seq 1 10`; do \
  108. cat /dev/urandom | head -c $(FUZZCHARS) | iconv -f latin1 -t utf-8 | tee fuzz-$$i.txt | \
  109. /usr/bin/env time -p $(PROG) >/dev/null && rm fuzz-$$i.txt ; \
  110. done } 2>&1 | grep 'user\|abnormally'
  111. # for benchmarking
  112. $(BENCHFILE): progit/progit.md
  113. -rm $@; for x in `seq 1 20` ; do cat $< >> $@; done
  114. progit:
  115. git clone https://github.com/progit/progit.git
  116. progit/progit.md: progit
  117. cat progit/en/*/*.markdown > $@
  118. bench: $(BENCHFILE)
  119. { sudo renice 99 $$$$; \
  120. for x in `seq 1 $(NUMRUNS)` ; do \
  121. /usr/bin/env time -p $(PROG) </dev/null >/dev/null ; \
  122. /usr/bin/env time -p $(PROG) <$< >/dev/null ; \
  123. done \
  124. } 2>&1 | grep 'real' | awk '{print $$2}' | python3 'bench/stats.py'
  125. astyle:
  126. astyle --style=linux -t -p -r 'src/*.c' --exclude=scanners.c
  127. astyle --style=linux -t -p -r 'src/*.h' --exclude=html_unescape.h
  128. operf: $(PROG)
  129. operf $(PROG) <$(BENCHINP) >/dev/null
  130. distclean: clean
  131. -rm -f js/commonmark.js
  132. -rm -rf *.dSYM
  133. -rm -f README.html
  134. -rm -f spec.md fuzz.txt spec.html
  135. -rm -rf $(BENCHFILE) $(ALLTESTS) progit
  136. ### JavaScript ###
  137. js/commonmark.js: js/lib/index.js ${JSMODULES}
  138. browserify --standalone commonmark $< -o $@
  139. testjs: $(SPEC)
  140. node js/test.js
  141. jshint:
  142. jshint ${JSMODULES}
  143. lint:
  144. eslint -c eslint.json ${JSMODULES} js/bin/commonmark js/test.js js/bench.js
  145. benchjs:
  146. sudo renice 99 $$$$; node js/bench.js ${BENCHINP}
  147. npm:
  148. cd js; npm publish
  149. dingus: js/commonmark.js
  150. echo "Starting dingus server at http://localhost:9000/dingus.html" && python -m SimpleHTTPServer 9000
  151. ### Spec ###
  152. spec.md: $(SPEC)
  153. python3 makespec.py markdown > $@
  154. spec.html: spec.txt template.html ${PROG}
  155. python3 makespec.py html > $@
  156. spec.pdf: spec.md template.tex specfilter.hs
  157. pandoc -s $< --template template.tex \
  158. --filter ./specfilter.hs -o $@ --latex-engine=xelatex --toc \
  159. --number-sections -V documentclass=report -V tocdepth=2 \
  160. -V classoption=twosides
  161. ### Website ###
  162. update-site: spec js/commonmark.js
  163. make -C $(SITE) update
  164. upload-site: spec js/commonmark.js
  165. make -C $(SITE) upload