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