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