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