aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: a0c1a62daacffa95392fca6f20ca806e00fdf968 (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 spec.html $(PKGDIR); \
  45. cp CMakeLists.txt $(PKGDIR); \
  46. perl -ne '$$p++ if /^### JavaScript/; print if (!$$p)' Makefile > $(PKGDIR)/Makefile; \
  47. cp man/man1/cmark.1 $(PKGDIR)/man/man1/; \
  48. cp README.md LICENSE spec.txt runtests.pl $(PKGDIR)/; \
  49. tar czf $(TARBALL) $(PKGDIR); \
  50. rm -rf $(PKGDIR)
  51. clean:
  52. rm -rf $(BUILDDIR) $(MINGW_BUILDDIR) $(MINGW_INSTALLDIR)
  53. $(PROG): all
  54. $(SRCDIR)/case_fold_switch.inc: $(DATADIR)/CaseFolding-3.2.0.txt
  55. perl mkcasefold.pl < $< > $@
  56. man/man1/cmark.1: man/cmark.1.md
  57. pandoc $< -o $@ -s -t man
  58. test: $(SPEC)
  59. perl runtests.pl $< $(PROG)
  60. testlib: $(SPEC)
  61. perl runtests.pl $< ./wrapper.py
  62. testtarball: $(TARBALL)
  63. rm -rf $(PKGDIR); \
  64. tar xvzf $(TARBALL); \
  65. cd $(PKGDIR); \
  66. make && make test; \
  67. cd .. ; \
  68. rm -rf $(PKGDIR)
  69. leakcheck: $(PROG)
  70. cat leakcheck.md | valgrind --leak-check=full --dsymutil=yes $(PROG)
  71. fuzztest:
  72. { for i in `seq 1 10`; do \
  73. cat /dev/urandom | head -c $(FUZZCHARS) | iconv -f latin1 -t utf-8 | tee fuzz-$$i.txt | \
  74. /usr/bin/env time -p $(PROG) >/dev/null && rm fuzz-$$i.txt ; \
  75. done } 2>&1 | grep 'user\|abnormally'
  76. bench:
  77. # First build with TIMER=1
  78. { for x in `seq 1 100` ; do \
  79. /usr/bin/env time -p ${PROG} progit.md >/dev/null ; \
  80. done \
  81. } 2>&1 | grep ${BENCHPATT} | \
  82. awk '{print $$3;}' | \
  83. Rscript -e 'summary (as.numeric (readLines ("stdin")))'
  84. operf: $(PROG)
  85. operf $(PROG) <$(BENCHINP) >/dev/null
  86. distclean: clean
  87. -rm -f js/commonmark.js
  88. -rm -rf *.dSYM
  89. -rm -f README.html
  90. -rm -f spec.md fuzz.txt spec.html
  91. ### JavaScript ###
  92. js/commonmark.js: js/lib/index.js ${JSMODULES}
  93. browserify --standalone commonmark $< -o $@
  94. testjs: $(SPEC)
  95. node js/test.js
  96. jshint:
  97. jshint ${JSMODULES}
  98. benchjs:
  99. node js/bench.js ${BENCHINP}
  100. npm:
  101. cd js; npm publish
  102. dingus: js/commonmark.js
  103. echo "Starting dingus server at http://localhost:9000" && python -m SimpleHTTPServer 9000
  104. ### Spec ###
  105. spec.md: $(SPEC)
  106. perl spec2md.pl < $< > $@
  107. spec.html: spec.md template.html
  108. pandoc --no-highlight --number-sections --template template.html -s --toc -S $< | \
  109. perl -pe 's/a href="@([^"]*)"/a id="\1" href="#\1" class="definition"/g' | \
  110. perl -pe 's/␣/<span class="space"> <\/span>/g' \
  111. > $@
  112. spec.pdf: spec.md template.tex specfilter.hs
  113. pandoc -s $< --template template.tex \
  114. --filter ./specfilter.hs -o $@ --latex-engine=xelatex --toc \
  115. --number-sections -V documentclass=report -V tocdepth=2 \
  116. -V classoption=twosides
  117. ### Website ###
  118. update-site: spec.html js/commonmark.js
  119. make -C $(SITE) update
  120. upload-site: spec.html
  121. make -C $(SITE) upload