aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 617598c251c33b256c2c4b265b958ca420dae455 (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. srcfiles=`git ls-tree --full-tree -r HEAD --name-only $(SRCDIR)`; \
  45. for f in $$srcfiles; do cp -a $$f $(PKGDIR)/$$f; done; \
  46. cp -a $(SRCDIR)/scanners.c $(PKGDIR)/$(SRCDIR)/; \
  47. cp spec.html $(PKGDIR); \
  48. cp CMakeLists.txt $(PKGDIR); \
  49. perl -ne '$$p++ if /^### JavaScript/; print if (!$$p)' Makefile > $(PKGDIR)/Makefile; \
  50. cp Makefile.nmake nmake.bat $(PKGDIR); \
  51. cp man/man1/cmark.1 $(PKGDIR)/man/man1/; \
  52. cp README.md LICENSE spec.txt runtests.pl $(PKGDIR)/; \
  53. tar czf $(TARBALL) $(PKGDIR); \
  54. zip -q -r $(ZIPARCHIVE) $(PKGDIR); \
  55. rm -rf $(PKGDIR) ; \
  56. echo "Created $(TARBALL) and $(ZIPARCHIVE)."
  57. clean:
  58. rm -rf $(BUILDDIR) $(MINGW_BUILDDIR) $(MINGW_INSTALLDIR) $(TARBALL) $(ZIPARCHIVE) $(PKGDIR)
  59. $(PROG): all
  60. # We include html_unescape.h in the repository, so this shouldn't
  61. # normally need to be generated.
  62. $(SRCDIR)/html/html_unescape.h: $(SRCDIR)/html/html_unescape.gperf
  63. gperf -L ANSI-C -I -t -N find_entity -H hash_entity -K entity -C -l \
  64. --null-strings -m5 $< > $@
  65. # We include case_fold_switch.inc in the repository, so this shouldn't
  66. # normally need to be generated.
  67. $(SRCDIR)/case_fold_switch.inc: $(DATADIR)/CaseFolding-3.2.0.txt
  68. perl mkcasefold.pl < $< > $@
  69. man/man1/cmark.1: man/cmark.1.md
  70. pandoc $< -o $@ -s -t man
  71. test: $(SPEC)
  72. perl runtests.pl $< $(PROG)
  73. testlib: $(SPEC)
  74. perl runtests.pl $< ./wrapper.py
  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 $(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 ; \
  107. done \
  108. } 2>&1 | grep 'real' | awk '{print $$2}' | python3 'bench/stats.py'
  109. operf: $(PROG)
  110. operf $(PROG) <$(BENCHINP) >/dev/null
  111. distclean: clean
  112. -rm -f js/commonmark.js
  113. -rm -rf *.dSYM
  114. -rm -f README.html
  115. -rm -f spec.md fuzz.txt spec.html
  116. -rm -rf $(BENCHFILE) progit
  117. ### JavaScript ###
  118. js/commonmark.js: js/lib/index.js ${JSMODULES}
  119. browserify --standalone commonmark $< -o $@
  120. testjs: $(SPEC)
  121. node js/test.js
  122. jshint:
  123. jshint ${JSMODULES}
  124. benchjs:
  125. node js/bench.js ${BENCHINP}
  126. npm:
  127. cd js; npm publish
  128. dingus: js/commonmark.js
  129. echo "Starting dingus server at http://localhost:9000" && python -m SimpleHTTPServer 9000
  130. ### Spec ###
  131. spec.md: $(SPEC)
  132. perl spec2md.pl < $< > $@
  133. spec.html: spec.md template.html
  134. pandoc --no-highlight --number-sections --template template.html -s --toc -S $< | \
  135. perl -pe 's/a href="@([^"]*)"/a id="\1" href="#\1" class="definition"/g' | \
  136. perl -pe 's/␣/<span class="space"> <\/span>/g' \
  137. > $@
  138. spec.pdf: spec.md template.tex specfilter.hs
  139. pandoc -s $< --template template.tex \
  140. --filter ./specfilter.hs -o $@ --latex-engine=xelatex --toc \
  141. --number-sections -V documentclass=report -V tocdepth=2 \
  142. -V classoption=twosides
  143. ### Website ###
  144. update-site: spec.html js/commonmark.js
  145. make -C $(SITE) update
  146. upload-site: spec.html
  147. make -C $(SITE) upload