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