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