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