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