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