aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 8714093d839af6cf1ec8caf6bf02ca28ca37b12f (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 tarball ziparchive testarchive testtarball testziparchive testlib bench
  18. all: $(BUILDDIR) $(SRCDIR)/html/html_unescape.h $(SRCDIR)/case_fold_switch.inc
  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 $(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) $(PKGDIR)
  57. $(PROG): all
  58. # We include html_unescape.h in the repository, so this shouldn't
  59. # normally need to be generated.
  60. $(SRCDIR)/html/html_unescape.h: $(SRCDIR)/html/html_unescape.gperf
  61. gperf -L ANSI-C -I -t -N find_entity -H hash_entity -K entity -C -l \
  62. --null-strings -m5 $< > $@
  63. # We include case_fold_switch.inc in the repository, so this shouldn't
  64. # normally need to be generated.
  65. $(SRCDIR)/case_fold_switch.inc: $(DATADIR)/CaseFolding-3.2.0.txt
  66. perl mkcasefold.pl < $< > $@
  67. man/man1/cmark.1: man/cmark.1.md
  68. pandoc $< -o $@ -s -t man
  69. test: $(SPEC)
  70. perl runtests.pl $< $(PROG)
  71. testlib: $(SPEC)
  72. perl runtests.pl $< ./wrapper.py
  73. $(TARBALL): archive
  74. $(ZIPARCHIVE): archive
  75. testarchive: testtarball testziparchive
  76. rm -rf $(PKGDIR)
  77. testtarball: $(TARBALL)
  78. rm -rf $(PKGDIR); \
  79. tar xvzf $(TARBALL); \
  80. cd $(PKGDIR); \
  81. mkdir build && cd build && cmake .. && make && ctest -V
  82. testziparchive: $(ZIPARCHIVE)
  83. rm -rf $(PKGDIR); \
  84. unzip $(ZIPARCHIVE); \
  85. cd $(PKGDIR); \
  86. mkdir build && cd build && cmake .. && make && ctest -V
  87. leakcheck: $(PROG)
  88. cat leakcheck.md | valgrind --leak-check=full --dsymutil=yes $(PROG)
  89. fuzztest:
  90. { for i in `seq 1 10`; do \
  91. cat /dev/urandom | head -c $(FUZZCHARS) | iconv -f latin1 -t utf-8 | tee fuzz-$$i.txt | \
  92. /usr/bin/env time -p $(PROG) >/dev/null && rm fuzz-$$i.txt ; \
  93. done } 2>&1 | grep 'user\|abnormally'
  94. bench:
  95. # First build with TIMER=1
  96. { for x in `seq 1 100` ; do \
  97. /usr/bin/env time -p ${PROG} progit.md >/dev/null ; \
  98. done \
  99. } 2>&1 | grep ${BENCHPATT} | \
  100. awk '{print $$3;}' | \
  101. Rscript -e 'summary (as.numeric (readLines ("stdin")))'
  102. operf: $(PROG)
  103. operf $(PROG) <$(BENCHINP) >/dev/null
  104. distclean: clean
  105. -rm -f js/commonmark.js
  106. -rm -rf *.dSYM
  107. -rm -f README.html
  108. -rm -f spec.md fuzz.txt spec.html
  109. ### JavaScript ###
  110. js/commonmark.js: js/lib/index.js ${JSMODULES}
  111. browserify --standalone commonmark $< -o $@
  112. testjs: $(SPEC)
  113. node js/test.js
  114. jshint:
  115. jshint ${JSMODULES}
  116. benchjs:
  117. node js/bench.js ${BENCHINP}
  118. npm:
  119. cd js; npm publish
  120. dingus: js/commonmark.js
  121. echo "Starting dingus server at http://localhost:9000" && python -m SimpleHTTPServer 9000
  122. ### Spec ###
  123. spec.md: $(SPEC)
  124. perl spec2md.pl < $< > $@
  125. spec.html: spec.md template.html
  126. pandoc --no-highlight --number-sections --template template.html -s --toc -S $< | \
  127. perl -pe 's/a href="@([^"]*)"/a id="\1" href="#\1" class="definition"/g' | \
  128. perl -pe 's/␣/<span class="space"> <\/span>/g' \
  129. > $@
  130. spec.pdf: spec.md template.tex specfilter.hs
  131. pandoc -s $< --template template.tex \
  132. --filter ./specfilter.hs -o $@ --latex-engine=xelatex --toc \
  133. --number-sections -V documentclass=report -V tocdepth=2 \
  134. -V classoption=twosides
  135. ### Website ###
  136. update-site: spec.html js/commonmark.js
  137. make -C $(SITE) update
  138. upload-site: spec.html
  139. make -C $(SITE) upload