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