aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 7d7e78c2f6fe1ed4686a25b333b419389d5668d7 (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. NUMRUNS?=10
  17. PROG?=$(BUILDDIR)/src/cmark
  18. BENCHINP?=README.md
  19. JSMODULES=$(wildcard js/lib/*.js)
  20. .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
  21. all: $(BUILDDIR) $(SRCDIR)/html/html_unescape.h $(SRCDIR)/case_fold_switch.inc
  22. @make -C $(BUILDDIR)
  23. check:
  24. @cmake --version > /dev/null || (echo "You need cmake to build this program: http://www.cmake.org/download/" && exit 1)
  25. $(BUILDDIR): check
  26. mkdir -p $(BUILDDIR); \
  27. cd $(BUILDDIR); \
  28. cmake .. -G "$(GENERATOR)" -DCMAKE_BUILD_TYPE=$(BUILD_TYPE)
  29. install: $(BUILDDIR) man/man1/cmark.1
  30. make -C $(BUILDDIR) install
  31. debug:
  32. mkdir -p $(BUILDDIR); \
  33. cd $(BUILDDIR); \
  34. cmake .. -DCMAKE_BUILD_TYPE=Debug; \
  35. make
  36. mingw:
  37. mkdir -p $(MINGW_BUILDDIR); \
  38. cd $(MINGW_BUILDDIR); \
  39. cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchain-mingw32.cmake -DCMAKE_INSTALL_PREFIX=$(MINGW_INSTALLDIR) ;\
  40. make && make install
  41. archive: spec.html $(BUILDDIR)
  42. @rm -rf $(PKGDIR); \
  43. mkdir -p $(PKGDIR)/man/man1; \
  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 -a man/man1/cmark.1 $(PKGDIR)/man/man1/; \
  54. cp -a README.md LICENSE spec.txt runtests.py $(PKGDIR)/; \
  55. tar czf $(TARBALL) $(PKGDIR); \
  56. zip -q -r $(ZIPARCHIVE) $(PKGDIR); \
  57. rm -rf $(PKGDIR) ; \
  58. echo "Created $(TARBALL) and $(ZIPARCHIVE)."
  59. clean:
  60. rm -rf $(BUILDDIR) $(MINGW_BUILDDIR) $(MINGW_INSTALLDIR) $(TARBALL) $(ZIPARCHIVE) $(PKGDIR)
  61. $(PROG): all
  62. # We include html_unescape.h in the repository, so this shouldn't
  63. # normally need to be generated.
  64. $(SRCDIR)/html/html_unescape.h: $(SRCDIR)/html/html_unescape.gperf
  65. gperf -L ANSI-C -I -t -N find_entity -H hash_entity -K entity -C -l \
  66. --null-strings -m5 $< > $@
  67. # We include case_fold_switch.inc in the repository, so this shouldn't
  68. # normally need to be generated.
  69. $(SRCDIR)/case_fold_switch.inc: $(DATADIR)/CaseFolding-3.2.0.txt
  70. perl mkcasefold.pl < $< > $@
  71. man/man1/cmark.1: man/cmark.1.md
  72. pandoc $< -o $@ -s -t man
  73. test: $(SPEC) $(BUILDDIR)
  74. make -C $(BUILDDIR) test ARGS="-V"
  75. $(TARBALL): archive
  76. $(ZIPARCHIVE): archive
  77. testarchive: testtarball testziparchive
  78. rm -rf $(PKGDIR)
  79. testtarball: $(TARBALL)
  80. rm -rf $(PKGDIR); \
  81. tar xvzf $(TARBALL); \
  82. cd $(PKGDIR); \
  83. mkdir build && cd build && cmake .. && make && ctest -V
  84. testziparchive: $(ZIPARCHIVE)
  85. rm -rf $(PKGDIR); \
  86. unzip $(ZIPARCHIVE); \
  87. cd $(PKGDIR); \
  88. mkdir build && cd build && cmake .. && make && ctest -V
  89. leakcheck: $(PROG)
  90. cat leakcheck.md | valgrind --leak-check=full --dsymutil=yes --error-exitcode=1 $(PROG)
  91. fuzztest:
  92. { for i in `seq 1 10`; do \
  93. cat /dev/urandom | head -c $(FUZZCHARS) | iconv -f latin1 -t utf-8 | tee fuzz-$$i.txt | \
  94. /usr/bin/env time -p $(PROG) >/dev/null && rm fuzz-$$i.txt ; \
  95. done } 2>&1 | grep 'user\|abnormally'
  96. # for benchmarking
  97. $(BENCHFILE): progit/progit.md
  98. -rm $@; for x in `seq 1 20` ; do cat $< >> $@; done
  99. progit:
  100. git clone https://github.com/progit/progit.git
  101. progit/progit.md: progit
  102. cat progit/en/*/*.markdown > $@
  103. bench: $(BENCHFILE)
  104. { sudo renice 99 $$$$; \
  105. for x in `seq 1 $(NUMRUNS)` ; do \
  106. /usr/bin/env time -p ${PROG} </dev/null >/dev/null ; \
  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