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