aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 1e6c076bad6525d03468f6d35f029c5094c91177 (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
  22. all: $(BUILDDIR) $(SRCDIR)/html/html_unescape.h $(SRCDIR)/case_fold_switch.inc
  23. @make -C $(BUILDDIR)
  24. check:
  25. @cmake --version > /dev/null || (echo "You need cmake to build this program: http://www.cmake.org/download/" && exit 1)
  26. $(BUILDDIR): check
  27. mkdir -p $(BUILDDIR); \
  28. cd $(BUILDDIR); \
  29. cmake .. -G "$(GENERATOR)" -DCMAKE_BUILD_TYPE=$(BUILD_TYPE)
  30. install: $(BUILDDIR) man/man1/cmark.1
  31. make -C $(BUILDDIR) install
  32. debug:
  33. mkdir -p $(BUILDDIR); \
  34. cd $(BUILDDIR); \
  35. cmake .. -DCMAKE_BUILD_TYPE=Debug; \
  36. make
  37. mingw:
  38. mkdir -p $(MINGW_BUILDDIR); \
  39. cd $(MINGW_BUILDDIR); \
  40. cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchain-mingw32.cmake -DCMAKE_INSTALL_PREFIX=$(MINGW_INSTALLDIR) ;\
  41. make && make install
  42. archive: spec.html $(BUILDDIR)
  43. @rm -rf $(PKGDIR); \
  44. mkdir -p $(PKGDIR)/man/man1; \
  45. mkdir -p $(PKGDIR)/$(SRCDIR)/html; \
  46. mkdir -p $(PKGDIR)/api_test; \
  47. srcfiles=`git ls-tree --full-tree -r HEAD --name-only $(SRCDIR) api_test`; \
  48. for f in $$srcfiles; do cp -a $$f $(PKGDIR)/$$f; done; \
  49. cp -a $(SRCDIR)/scanners.c $(PKGDIR)/$(SRCDIR)/; \
  50. cp -a spec.html $(PKGDIR); \
  51. cp CMakeLists.txt $(PKGDIR); \
  52. perl -ne '$$p++ if /^### JavaScript/; print if (!$$p)' Makefile > $(PKGDIR)/Makefile; \
  53. cp -a Makefile.nmake nmake.bat $(PKGDIR); \
  54. cp -a man/man1/cmark.1 $(PKGDIR)/man/man1/; \
  55. cp -a README.md LICENSE spec.txt spec_tests.py pathological_tests.py $(PKGDIR)/; \
  56. tar czf $(TARBALL) $(PKGDIR); \
  57. zip -q -r $(ZIPARCHIVE) $(PKGDIR); \
  58. rm -rf $(PKGDIR) ; \
  59. echo "Created $(TARBALL) and $(ZIPARCHIVE)."
  60. clean:
  61. rm -rf $(BUILDDIR) $(MINGW_BUILDDIR) $(MINGW_INSTALLDIR) $(TARBALL) $(ZIPARCHIVE) $(PKGDIR)
  62. $(PROG): all
  63. # We include html_unescape.h in the repository, so this shouldn't
  64. # normally need to be generated.
  65. $(SRCDIR)/html/html_unescape.h: $(SRCDIR)/html/html_unescape.gperf
  66. gperf -L ANSI-C -I -t -N find_entity -H hash_entity -K entity -C -l \
  67. --null-strings -m5 $< > $@
  68. # We include case_fold_switch.inc in the repository, so this shouldn't
  69. # normally need to be generated.
  70. $(SRCDIR)/case_fold_switch.inc: $(DATADIR)/CaseFolding-3.2.0.txt
  71. perl mkcasefold.pl < $< > $@
  72. man/man1/cmark.1: man/cmark.1.md
  73. pandoc $< -o $@ -s -t man
  74. test: $(SPEC) $(BUILDDIR)
  75. make -C $(BUILDDIR) test ARGS="-V"
  76. $(TARBALL): archive
  77. $(ZIPARCHIVE): archive
  78. testarchive: testtarball testziparchive
  79. rm -rf $(PKGDIR)
  80. testtarball: $(TARBALL)
  81. rm -rf $(PKGDIR); \
  82. tar xvzf $(TARBALL); \
  83. cd $(PKGDIR); \
  84. mkdir build && cd build && cmake .. && make && ctest -V
  85. testziparchive: $(ZIPARCHIVE)
  86. rm -rf $(PKGDIR); \
  87. unzip $(ZIPARCHIVE); \
  88. cd $(PKGDIR); \
  89. mkdir build && cd build && cmake .. && make && ctest -V
  90. $(ALLTESTS): spec.txt
  91. python spec_tests.py --spec $< --dump-tests | python -c 'import json; import sys; tests = json.loads(sys.stdin.read()); print "\n".join([test["markdown"] for test in tests]).encode("utf-8")' > $@
  92. leakcheck: $(ALLTESTS) $(PROG)
  93. cat $< | valgrind --leak-check=full --dsymutil=yes --error-exitcode=1 $(PROG) >/dev/null
  94. fuzztest:
  95. { for i in `seq 1 10`; do \
  96. cat /dev/urandom | head -c $(FUZZCHARS) | iconv -f latin1 -t utf-8 | tee fuzz-$$i.txt | \
  97. /usr/bin/env time -p $(PROG) >/dev/null && rm fuzz-$$i.txt ; \
  98. done } 2>&1 | grep 'user\|abnormally'
  99. # for benchmarking
  100. $(BENCHFILE): progit/progit.md
  101. -rm $@; for x in `seq 1 20` ; do cat $< >> $@; done
  102. progit:
  103. git clone https://github.com/progit/progit.git
  104. progit/progit.md: progit
  105. cat progit/en/*/*.markdown > $@
  106. bench: $(BENCHFILE)
  107. { sudo renice 99 $$$$; \
  108. for x in `seq 1 $(NUMRUNS)` ; do \
  109. /usr/bin/env time -p $(PROG) </dev/null >/dev/null ; \
  110. /usr/bin/env time -p $(PROG) <$< >/dev/null ; \
  111. done \
  112. } 2>&1 | grep 'real' | awk '{print $$2}' | python3 'bench/stats.py'
  113. operf: $(PROG)
  114. operf $(PROG) <$(BENCHINP) >/dev/null
  115. distclean: clean
  116. -rm -f js/commonmark.js
  117. -rm -rf *.dSYM
  118. -rm -f README.html
  119. -rm -f spec.md fuzz.txt spec.html
  120. -rm -rf $(BENCHFILE) $(ALLTESTS) progit
  121. ### JavaScript ###
  122. js/commonmark.js: js/lib/index.js ${JSMODULES}
  123. browserify --standalone commonmark $< -o $@
  124. testjs: $(SPEC)
  125. node js/test.js
  126. jshint:
  127. jshint ${JSMODULES}
  128. benchjs:
  129. node js/bench.js ${BENCHINP}
  130. npm:
  131. cd js; npm publish
  132. dingus: js/commonmark.js
  133. echo "Starting dingus server at http://localhost:9000" && python -m SimpleHTTPServer 9000
  134. ### Spec ###
  135. spec.md: $(SPEC)
  136. perl spec2md.pl < $< > $@
  137. spec.html: spec.md template.html
  138. pandoc --no-highlight --number-sections --template template.html -s --toc -S $< | \
  139. perl -pe 's/a href="@([^"]*)"/a id="\1" href="#\1" class="definition"/g' | \
  140. perl -pe 's/␣/<span class="space"> <\/span>/g' \
  141. > $@
  142. spec.pdf: spec.md template.tex specfilter.hs
  143. pandoc -s $< --template template.tex \
  144. --filter ./specfilter.hs -o $@ --latex-engine=xelatex --toc \
  145. --number-sections -V documentclass=report -V tocdepth=2 \
  146. -V classoption=twosides
  147. ### Website ###
  148. update-site: spec.html js/commonmark.js
  149. make -C $(SITE) update
  150. upload-site: spec.html
  151. make -C $(SITE) upload