aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 6fcc956925cdbc722f20f66d86f252d5e5c0b11e (plain)
  1. SRCDIR?=src
  2. DATADIR?=data
  3. BUILDDIR?=build
  4. GENERATOR?=Unix Makefiles
  5. MINGW_BUILDDIR?=build-mingw
  6. MINGW_INSTALLDIR?=windows
  7. SPEC=spec.txt
  8. SITE=_site
  9. SPECVERSION=$(shell perl -ne 'print $$1 if /^version: *([0-9.]+)/' $(SPEC))
  10. PKGDIR?=cmark-$(SPECVERSION)
  11. TARBALL?=cmark-$(SPECVERSION).tar.gz
  12. ZIPARCHIVE?=cmark-$(SPECVERSION).zip
  13. FUZZCHARS?=2000000 # for fuzztest
  14. BENCHDIR=bench
  15. BENCHFILE=$(BENCHDIR)/benchinput.md
  16. ALLTESTS=alltests.md
  17. NUMRUNS?=10
  18. PROG?=$(BUILDDIR)/src/cmark
  19. BENCHINP?=README.md
  20. JSMODULES=$(wildcard js/lib/*.js)
  21. .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 apidoc
  22. all: $(BUILDDIR)
  23. @make -C $(BUILDDIR)
  24. check:
  25. @cmake --version > /dev/null || (echo "You need cmake to build this program: http://www.cmake.org/download/" && exit 1)
  26. $(BUILDDIR): check $(SRCDIR)/html/html_unescape.h $(SRCDIR)/case_fold_switch.inc man/man1/cmark.1 man/man3/cmark.3
  27. mkdir -p $(BUILDDIR); \
  28. cd $(BUILDDIR); \
  29. cmake .. -G "$(GENERATOR)" -DCMAKE_BUILD_TYPE=$(BUILD_TYPE)
  30. install: $(BUILDDIR)
  31. make -C $(BUILDDIR) install
  32. debug:
  33. mkdir -p $(BUILDDIR); \
  34. cd $(BUILDDIR); \
  35. cmake .. -DCMAKE_BUILD_TYPE=Debug; \
  36. make
  37. mingw:
  38. mkdir -p $(MINGW_BUILDDIR); \
  39. cd $(MINGW_BUILDDIR); \
  40. cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchain-mingw32.cmake -DCMAKE_INSTALL_PREFIX=$(MINGW_INSTALLDIR) ;\
  41. make && make install
  42. archive: spec.html $(BUILDDIR)
  43. @rm -rf $(PKGDIR); \
  44. mkdir -p $(PKGDIR)/$(SRCDIR)/html; \
  45. mkdir -p $(PKGDIR)/api_test; \
  46. srcfiles=`git ls-tree --full-tree -r HEAD --name-only $(SRCDIR) api_test`; \
  47. for f in $$srcfiles; do cp -a $$f $(PKGDIR)/$$f; done; \
  48. cp -a $(SRCDIR)/scanners.c $(PKGDIR)/$(SRCDIR)/; \
  49. cp -a spec.html $(PKGDIR); \
  50. cp CMakeLists.txt $(PKGDIR); \
  51. perl -ne '$$p++ if /^### JavaScript/; print if (!$$p)' Makefile > $(PKGDIR)/Makefile; \
  52. cp -a Makefile.nmake nmake.bat $(PKGDIR); \
  53. cp -r man $(PKGDIR)/; \
  54. cp -r test $(PKGDIR)/; \
  55. cp -a README.md LICENSE spec.txt $(PKGDIR)/; \
  56. tar czf $(TARBALL) $(PKGDIR); \
  57. zip -q -r $(ZIPARCHIVE) $(PKGDIR); \
  58. rm -rf $(PKGDIR) ; \
  59. echo "Created $(TARBALL) and $(ZIPARCHIVE)."
  60. clean:
  61. rm -rf $(BUILDDIR) $(MINGW_BUILDDIR) $(MINGW_INSTALLDIR) $(TARBALL) $(ZIPARCHIVE) $(PKGDIR)
  62. $(PROG): all
  63. man/man1/cmark.1: man/cmark.1.md
  64. mkdir -p man/man1 && pandoc -t man -s $< -o $@
  65. man/man3/cmark.3: man/cmark.3.md
  66. mkdir -p man/man3 && pandoc -t man -s $< -o $@
  67. man/cmark.3.md: src/cmark.h
  68. python man/make_man_page.py $< > $@
  69. # We include html_unescape.h in the repository, so this shouldn't
  70. # normally need to be generated.
  71. $(SRCDIR)/html/html_unescape.h: $(SRCDIR)/html/html_unescape.gperf
  72. gperf -L ANSI-C -I -t -N find_entity -H hash_entity -K entity -C -l \
  73. --null-strings -m5 $< > $@
  74. # We include case_fold_switch.inc in the repository, so this shouldn't
  75. # normally need to be generated.
  76. $(SRCDIR)/case_fold_switch.inc: $(DATADIR)/CaseFolding-3.2.0.txt
  77. perl mkcasefold.pl < $< > $@
  78. test: $(SPEC) $(BUILDDIR)
  79. make -C $(BUILDDIR) test ARGS="-V"
  80. $(TARBALL): archive
  81. $(ZIPARCHIVE): archive
  82. testarchive: testtarball testziparchive
  83. rm -rf $(PKGDIR)
  84. testtarball: $(TARBALL)
  85. rm -rf $(PKGDIR); \
  86. tar xvzf $(TARBALL); \
  87. cd $(PKGDIR); \
  88. mkdir build && cd build && cmake .. && make && ctest -V
  89. testziparchive: $(ZIPARCHIVE)
  90. rm -rf $(PKGDIR); \
  91. unzip $(ZIPARCHIVE); \
  92. cd $(PKGDIR); \
  93. mkdir build && cd build && cmake .. && make && ctest -V
  94. $(ALLTESTS): spec.txt
  95. python test/spec_tests.py --spec $< --dump-tests | python -c 'import json; import sys; tests = json.loads(sys.stdin.read()); print "\n".join([test["markdown"] for test in tests]).encode("utf-8")' > $@
  96. leakcheck: $(ALLTESTS) $(PROG)
  97. cat $< | valgrind --leak-check=full --dsymutil=yes --error-exitcode=1 $(PROG) >/dev/null
  98. fuzztest:
  99. { for i in `seq 1 10`; do \
  100. cat /dev/urandom | head -c $(FUZZCHARS) | iconv -f latin1 -t utf-8 | tee fuzz-$$i.txt | \
  101. /usr/bin/env time -p $(PROG) >/dev/null && rm fuzz-$$i.txt ; \
  102. done } 2>&1 | grep 'user\|abnormally'
  103. # for benchmarking
  104. $(BENCHFILE): progit/progit.md
  105. -rm $@; for x in `seq 1 20` ; do cat $< >> $@; done
  106. progit:
  107. git clone https://github.com/progit/progit.git
  108. progit/progit.md: progit
  109. cat progit/en/*/*.markdown > $@
  110. bench: $(BENCHFILE)
  111. { sudo renice 99 $$$$; \
  112. for x in `seq 1 $(NUMRUNS)` ; do \
  113. /usr/bin/env time -p $(PROG) </dev/null >/dev/null ; \
  114. /usr/bin/env time -p $(PROG) <$< >/dev/null ; \
  115. done \
  116. } 2>&1 | grep 'real' | awk '{print $$2}' | python3 'bench/stats.py'
  117. operf: $(PROG)
  118. operf $(PROG) <$(BENCHINP) >/dev/null
  119. distclean: clean
  120. -rm -f js/commonmark.js
  121. -rm -rf *.dSYM
  122. -rm -f README.html
  123. -rm -f spec.md fuzz.txt spec.html
  124. -rm -rf $(BENCHFILE) $(ALLTESTS) progit
  125. ### JavaScript ###
  126. js/commonmark.js: js/lib/index.js ${JSMODULES}
  127. browserify --standalone commonmark $< -o $@
  128. testjs: $(SPEC)
  129. node js/test.js
  130. jshint:
  131. jshint ${JSMODULES}
  132. benchjs:
  133. node js/bench.js ${BENCHINP}
  134. npm:
  135. cd js; npm publish
  136. dingus: js/commonmark.js
  137. echo "Starting dingus server at http://localhost:9000" && python -m SimpleHTTPServer 9000
  138. ### Spec ###
  139. spec.md: $(SPEC)
  140. perl spec2md.pl < $< > $@
  141. spec.html: spec.md template.html
  142. pandoc --no-highlight --number-sections --template template.html -s --toc -S $< | \
  143. perl -pe 's/a href="@([^"]*)"/a id="\1" href="#\1" class="definition"/g' | \
  144. perl -pe 's/␣/<span class="space"> <\/span>/g' \
  145. > $@
  146. spec.pdf: spec.md template.tex specfilter.hs
  147. pandoc -s $< --template template.tex \
  148. --filter ./specfilter.hs -o $@ --latex-engine=xelatex --toc \
  149. --number-sections -V documentclass=report -V tocdepth=2 \
  150. -V classoption=twosides
  151. ### Website ###
  152. update-site: spec.html js/commonmark.js
  153. make -C $(SITE) update
  154. upload-site: spec.html
  155. make -C $(SITE) upload