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