aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 1a79f1287247b9fc34b65cf4d593bba1ca513590 (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. FUZZCHARS?=2000000 # for fuzztest
  12. BENCHPATT?="processing lines" # for bench
  13. PROG?=$(BUILDDIR)/src/cmark
  14. BENCHINP?=README.md
  15. JSMODULES=$(wildcard js/lib/*.js)
  16. .PHONY: all spec leakcheck clean fuzztest dingus upload jshint test testjs benchjs update-site upload-site check npm debug mingw tarball bench
  17. all: $(BUILDDIR)
  18. @make -C $(BUILDDIR)
  19. check:
  20. @cmake --version > /dev/null || (echo "You need cmake to build this program: http://www.cmake.org/download/" && exit 1)
  21. $(BUILDDIR): check
  22. mkdir -p $(BUILDDIR); \
  23. cd $(BUILDDIR); \
  24. cmake .. -DCMAKE_BUILD_TYPE=$(BUILD_TYPE)
  25. install: $(BUILDDIR) man/man1/cmark.1
  26. make -C $(BUILDDIR) install
  27. debug:
  28. mkdir -p $(BUILDDIR); \
  29. cd $(BUILDDIR); \
  30. cmake .. -DCMAKE_BUILD_TYPE=Debug; \
  31. make
  32. mingw:
  33. mkdir -p $(MINGW_BUILDDIR); \
  34. cd $(MINGW_BUILDDIR); \
  35. cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchain-mingw32.cmake -DCMAKE_INSTALL_PREFIX=$(MINGW_INSTALLDIR) ;\
  36. make && make install
  37. tarball: spec.html $(SRCDIR)/scanners.c
  38. rm -rf $(PKGDIR); \
  39. mkdir -p $(PKGDIR)/man/man1; \
  40. mkdir -p $(PKGDIR)/$(SRCDIR)/html; \
  41. srcfiles=`git ls-tree --full-tree -r HEAD --name-only $(SRCDIR)`; \
  42. for f in $$srcfiles; do cp -a $$f $(PKGDIR)/$$f; done; \
  43. cp -a $(SRCDIR)/scanners.c $(PKGDIR)/$(SRCDIR)/; \
  44. cp -a $(BUILDDIR)/$(SRCDIR)/cmark_export.h $(PKGDIR)/$(SRCDIR)/; \
  45. cp spec.html $(PKGDIR); \
  46. cp CMakeLists.txt $(PKGDIR); \
  47. perl -ne '$$p++ if /^### JavaScript/; print if (!$$p)' Makefile > $(PKGDIR)/Makefile; \
  48. cp Makefile.nmake nmake.bat $(PKGDIR); \
  49. cp man/man1/cmark.1 $(PKGDIR)/man/man1/; \
  50. cp README.md LICENSE spec.txt runtests.pl $(PKGDIR)/; \
  51. tar czf $(TARBALL) $(PKGDIR); \
  52. rm -rf $(PKGDIR)
  53. clean:
  54. rm -rf $(BUILDDIR) $(MINGW_BUILDDIR) $(MINGW_INSTALLDIR)
  55. $(PROG): all
  56. $(SRCDIR)/case_fold_switch.inc: $(DATADIR)/CaseFolding-3.2.0.txt
  57. perl mkcasefold.pl < $< > $@
  58. man/man1/cmark.1: man/cmark.1.md
  59. pandoc $< -o $@ -s -t man
  60. test: $(SPEC)
  61. perl runtests.pl $< $(PROG)
  62. testlib: $(SPEC)
  63. perl runtests.pl $< ./wrapper.py
  64. testtarball: $(TARBALL)
  65. rm -rf $(PKGDIR); \
  66. tar xvzf $(TARBALL); \
  67. cd $(PKGDIR); \
  68. make && make test; \
  69. cd .. ; \
  70. rm -rf $(PKGDIR)
  71. leakcheck: $(PROG)
  72. cat leakcheck.md | valgrind --leak-check=full --dsymutil=yes $(PROG)
  73. fuzztest:
  74. { for i in `seq 1 10`; do \
  75. cat /dev/urandom | head -c $(FUZZCHARS) | iconv -f latin1 -t utf-8 | tee fuzz-$$i.txt | \
  76. /usr/bin/env time -p $(PROG) >/dev/null && rm fuzz-$$i.txt ; \
  77. done } 2>&1 | grep 'user\|abnormally'
  78. bench:
  79. # First build with TIMER=1
  80. { for x in `seq 1 100` ; do \
  81. /usr/bin/env time -p ${PROG} progit.md >/dev/null ; \
  82. done \
  83. } 2>&1 | grep ${BENCHPATT} | \
  84. awk '{print $$3;}' | \
  85. Rscript -e 'summary (as.numeric (readLines ("stdin")))'
  86. operf: $(PROG)
  87. operf $(PROG) <$(BENCHINP) >/dev/null
  88. distclean: clean
  89. -rm -f js/commonmark.js
  90. -rm -rf *.dSYM
  91. -rm -f README.html
  92. -rm -f spec.md fuzz.txt spec.html
  93. ### JavaScript ###
  94. js/commonmark.js: js/lib/index.js ${JSMODULES}
  95. browserify --standalone commonmark $< -o $@
  96. testjs: $(SPEC)
  97. node js/test.js
  98. jshint:
  99. jshint ${JSMODULES}
  100. benchjs:
  101. node js/bench.js ${BENCHINP}
  102. npm:
  103. cd js; npm publish
  104. dingus: js/commonmark.js
  105. echo "Starting dingus server at http://localhost:9000" && python -m SimpleHTTPServer 9000
  106. ### Spec ###
  107. spec.md: $(SPEC)
  108. perl spec2md.pl < $< > $@
  109. spec.html: spec.md template.html
  110. pandoc --no-highlight --number-sections --template template.html -s --toc -S $< | \
  111. perl -pe 's/a href="@([^"]*)"/a id="\1" href="#\1" class="definition"/g' | \
  112. perl -pe 's/␣/<span class="space"> <\/span>/g' \
  113. > $@
  114. spec.pdf: spec.md template.tex specfilter.hs
  115. pandoc -s $< --template template.tex \
  116. --filter ./specfilter.hs -o $@ --latex-engine=xelatex --toc \
  117. --number-sections -V documentclass=report -V tocdepth=2 \
  118. -V classoption=twosides
  119. ### Website ###
  120. update-site: spec.html js/commonmark.js
  121. make -C $(SITE) update
  122. upload-site: spec.html
  123. make -C $(SITE) upload