aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: cb8c687eaa391bf11ddde56051dad586d0b480c0 (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.py $(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. $(TARBALL): archive
  75. $(ZIPARCHIVE): archive
  76. testarchive: testtarball testziparchive
  77. rm -rf $(PKGDIR)
  78. testtarball: $(TARBALL)
  79. rm -rf $(PKGDIR); \
  80. tar xvzf $(TARBALL); \
  81. cd $(PKGDIR); \
  82. mkdir build && cd build && cmake .. && make && ctest -V
  83. testziparchive: $(ZIPARCHIVE)
  84. rm -rf $(PKGDIR); \
  85. unzip $(ZIPARCHIVE); \
  86. cd $(PKGDIR); \
  87. mkdir build && cd build && cmake .. && make && ctest -V
  88. leakcheck: $(PROG)
  89. cat leakcheck.md | valgrind --leak-check=full --dsymutil=yes --error-exitcode=1 $(PROG)
  90. fuzztest:
  91. { for i in `seq 1 10`; do \
  92. cat /dev/urandom | head -c $(FUZZCHARS) | iconv -f latin1 -t utf-8 | tee fuzz-$$i.txt | \
  93. /usr/bin/env time -p $(PROG) >/dev/null && rm fuzz-$$i.txt ; \
  94. done } 2>&1 | grep 'user\|abnormally'
  95. # for benchmarking
  96. $(BENCHFILE): progit/progit.md
  97. -rm $@; for x in `seq 1 20` ; do cat $< >> $@; done
  98. progit:
  99. git clone https://github.com/progit/progit.git
  100. progit/progit.md: progit
  101. cat progit/en/*/*.markdown > $@
  102. bench: $(BENCHFILE)
  103. { sudo renice 99 $$$$; \
  104. for x in `seq 1 $(NUMRUNS)` ; do \
  105. /usr/bin/env time -p ${PROG} $< >/dev/null ; \
  106. done \
  107. } 2>&1 | grep 'real' | awk '{print $$2}' | python3 'bench/stats.py'
  108. operf: $(PROG)
  109. operf $(PROG) <$(BENCHINP) >/dev/null
  110. distclean: clean
  111. -rm -f js/commonmark.js
  112. -rm -rf *.dSYM
  113. -rm -f README.html
  114. -rm -f spec.md fuzz.txt spec.html
  115. -rm -rf $(BENCHFILE) progit
  116. ### JavaScript ###
  117. js/commonmark.js: js/lib/index.js ${JSMODULES}
  118. browserify --standalone commonmark $< -o $@
  119. testjs: $(SPEC)
  120. node js/test.js
  121. jshint:
  122. jshint ${JSMODULES}
  123. benchjs:
  124. node js/bench.js ${BENCHINP}
  125. npm:
  126. cd js; npm publish
  127. dingus: js/commonmark.js
  128. echo "Starting dingus server at http://localhost:9000" && python -m SimpleHTTPServer 9000
  129. ### Spec ###
  130. spec.md: $(SPEC)
  131. perl spec2md.pl < $< > $@
  132. spec.html: spec.md template.html
  133. pandoc --no-highlight --number-sections --template template.html -s --toc -S $< | \
  134. perl -pe 's/a href="@([^"]*)"/a id="\1" href="#\1" class="definition"/g' | \
  135. perl -pe 's/␣/<span class="space"> <\/span>/g' \
  136. > $@
  137. spec.pdf: spec.md template.tex specfilter.hs
  138. pandoc -s $< --template template.tex \
  139. --filter ./specfilter.hs -o $@ --latex-engine=xelatex --toc \
  140. --number-sections -V documentclass=report -V tocdepth=2 \
  141. -V classoption=twosides
  142. ### Website ###
  143. update-site: spec.html js/commonmark.js
  144. make -C $(SITE) update
  145. upload-site: spec.html
  146. make -C $(SITE) upload