aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: b77ab9481c22e7ee99563ce7437aa4d5eda1aaaf (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. VERSION?=$(SPECVERSION)
  22. RELEASE?=CommonMark-$(VERSION)
  23. .PHONY: all spec leakcheck clean fuzztest dingus upload jshint test testjs benchjs update-site upload-site check npm debug mingw archive tarball ziparchive testtarball testziparchive testlib bench astyle
  24. all: $(PROG) man/man3/cmark.3
  25. @echo "Binaries can be found in $(BUILDDIR)/src"
  26. $(PROG): $(BUILDDIR)
  27. @make -j2 -C $(BUILDDIR)
  28. check:
  29. @cmake --version > /dev/null || (echo "You need cmake to build this program: http://www.cmake.org/download/" && exit 1)
  30. $(BUILDDIR): check $(SRCDIR)/html_unescape.h $(SRCDIR)/case_fold_switch.inc
  31. mkdir -p $(BUILDDIR); \
  32. cd $(BUILDDIR); \
  33. cmake .. -G "$(GENERATOR)" -DCMAKE_BUILD_TYPE=$(BUILD_TYPE)
  34. install: $(BUILDDIR)
  35. make -C $(BUILDDIR) install
  36. debug:
  37. mkdir -p $(BUILDDIR); \
  38. cd $(BUILDDIR); \
  39. cmake .. -DCMAKE_BUILD_TYPE=Debug; \
  40. make
  41. mingw:
  42. mkdir -p $(MINGW_BUILDDIR); \
  43. cd $(MINGW_BUILDDIR); \
  44. cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchain-mingw32.cmake -DCMAKE_INSTALL_PREFIX=$(MINGW_INSTALLDIR) ;\
  45. make && make install
  46. man/man3/cmark.3: src/cmark.h | $(PROG)
  47. python3 man/make_man_page.py $< > $@ \
  48. archive:
  49. git archive --prefix=$(RELEASE)/ -o $(RELEASE).tar.gz HEAD
  50. git archive --prefix=$(RELEASE)/ -o $(RELEASE).zip HEAD
  51. clean:
  52. rm -rf $(BUILDDIR) $(MINGW_BUILDDIR) $(MINGW_INSTALLDIR) $(TARBALL) $(ZIPARCHIVE) $(PKGDIR)
  53. # We include html_unescape.h in the repository, so this shouldn't
  54. # normally need to be generated.
  55. $(SRCDIR)/html_unescape.h: $(SRCDIR)/html_unescape.gperf
  56. gperf -L ANSI-C -I -t -N find_entity -H hash_entity -K entity -C -l \
  57. -F ',{0}' --null-strings -m5 -P -Q entity_pool $< > $@
  58. # We include case_fold_switch.inc in the repository, so this shouldn't
  59. # normally need to be generated.
  60. $(SRCDIR)/case_fold_switch.inc: $(DATADIR)/CaseFolding-3.2.0.txt
  61. perl mkcasefold.pl < $< > $@
  62. # We include scanners.c in the repository, so this shouldn't
  63. # normally need to be generated.
  64. $(SRCDIR)/scanners.c: $(SRCDIR)/scanners.re
  65. re2c --case-insensitive -b -i --no-generation-date -o $@ $<
  66. test: $(SPEC) $(BUILDDIR)
  67. make -C $(BUILDDIR) test || (cat $(BUILDDIR)/Testing/Temporary/LastTest.log && exit 1)
  68. $(TARBALL): archive
  69. $(ZIPARCHIVE): archive
  70. $(ALLTESTS): spec.txt
  71. python3 test/spec_tests.py --spec $< --dump-tests | python3 -c 'import json; import sys; tests = json.loads(sys.stdin.read()); print("\n".join([test["markdown"] for test in tests]))' > $@
  72. leakcheck: $(ALLTESTS)
  73. cat $< | valgrind --leak-check=full --dsymutil=yes --error-exitcode=1 $(PROG) >/dev/null
  74. cat $< | valgrind --leak-check=full --dsymutil=yes --error-exitcode=1 $(PROG) -t man >/dev/null
  75. cat $< | valgrind --leak-check=full --dsymutil=yes --error-exitcode=1 $(PROG) -t xml >/dev/null
  76. fuzztest:
  77. { for i in `seq 1 10`; do \
  78. cat /dev/urandom | head -c $(FUZZCHARS) | iconv -f latin1 -t utf-8 | tee fuzz-$$i.txt | \
  79. /usr/bin/env time -p $(PROG) >/dev/null && rm fuzz-$$i.txt ; \
  80. done } 2>&1 | grep 'user\|abnormally'
  81. progit:
  82. git clone https://github.com/progit/progit.git
  83. $(BENCHFILE): progit
  84. echo "" > $@
  85. for lang in ar az be ca cs de en eo es es-ni fa fi fr hi hu id it ja ko mk nl no-nb pl pt-br ro ru sr th tr uk vi zh zh-tw; do \
  86. cat progit/$$lang/*/*.markdown >> $@; \
  87. done
  88. bench: $(BENCHFILE)
  89. { sudo renice 99 $$$$; \
  90. for x in `seq 1 $(NUMRUNS)` ; do \
  91. /usr/bin/env time -p $(PROG) </dev/null >/dev/null ; \
  92. /usr/bin/env time -p $(PROG) $< >/dev/null ; \
  93. done \
  94. } 2>&1 | grep 'real' | awk '{print $$2}' | python3 'bench/stats.py'
  95. astyle:
  96. astyle --style=linux -t -p -r 'src/*.c' --exclude=scanners.c
  97. astyle --style=linux -t -p -r 'src/*.h' --exclude=html_unescape.h
  98. operf: $(PROG)
  99. operf $(PROG) <$(BENCHINP) >/dev/null
  100. distclean: clean
  101. -rm -f js/commonmark.js
  102. -rm -rf *.dSYM
  103. -rm -f README.html
  104. -rm -f spec.md fuzz.txt spec.html
  105. -rm -rf $(BENCHFILE) $(ALLTESTS) progit
  106. ### JavaScript ###
  107. js/commonmark.js: js/lib/index.js ${JSMODULES}
  108. browserify --standalone commonmark $< -o $@
  109. testjs: $(SPEC)
  110. node js/test.js
  111. jshint:
  112. jshint ${JSMODULES}
  113. lint:
  114. eslint -c eslint.json ${JSMODULES} js/bin/commonmark js/test.js js/bench.js
  115. benchjs:
  116. sudo renice 99 $$$$; node js/bench.js ${BENCHINP}
  117. npm:
  118. cd js; npm publish
  119. dingus: js/commonmark.js
  120. echo "Starting dingus server at http://localhost:9000/dingus.html" && python -m SimpleHTTPServer 9000
  121. ### Spec ###
  122. spec.md: $(SPEC)
  123. python3 makespec.py markdown > $@
  124. spec.html: spec.txt template.html ${PROG}
  125. python3 makespec.py html > $@
  126. spec.pdf: spec.md template.tex specfilter.hs
  127. pandoc -s $< --template template.tex \
  128. --filter ./specfilter.hs -o $@ --latex-engine=xelatex --toc \
  129. --number-sections -V documentclass=report -V tocdepth=2 \
  130. -V classoption=twosides
  131. ### Website ###
  132. update-site: spec js/commonmark.js
  133. make -C $(SITE) update
  134. upload-site: spec js/commonmark.js
  135. make -C $(SITE) upload