aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: baa68594d5eafd9a18d612ed324fc72e0d723e3c (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 cmake_build spec leakcheck clean fuzztest dingus upload jshint test testjs benchjs update-site upload-site npm debug mingw archive tarball ziparchive testtarball testziparchive testlib bench astyle
  22. all: cmake_build man/man3/cmark.3
  23. $(PROG): cmake_build
  24. cmake_build: $(BUILDDIR)
  25. @make -j2 -C $(BUILDDIR)
  26. @echo "Binaries can be found in $(BUILDDIR)/src"
  27. $(BUILDDIR): $(SRCDIR)/html_unescape.h $(SRCDIR)/case_fold_switch.inc
  28. @cmake --version > /dev/null || (echo "You need cmake to build this program: http://www.cmake.org/download/" && exit 1)
  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/dist/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/dist/commonmark.js: js/lib/index.js ${JSMODULES}
  104. browserify --standalone commonmark $< -o $@
  105. # 'npm install -g uglify-js' for the uglifyjs tool:
  106. js/dist/commonmark.min.js: js/dist/commonmark.js
  107. uglifyjs $< --compress keep_fargs=true,pure_getters=true --preamble "/* commonmark $(VERSION) https://github.com/jgm/CommonMark @license BSD3 */" > $@
  108. testjs: $(SPEC)
  109. node js/test.js
  110. jshint:
  111. jshint ${JSMODULES}
  112. lint:
  113. eslint -c js/eslint.json ${JSMODULES} js/bin/commonmark js/test.js js/bench.js
  114. benchjs:
  115. sudo renice 99 $$$$; node js/bench.js ${BENCHINP}
  116. npm:
  117. cd js; npm publish
  118. dingus: js/dist/commonmark.js
  119. echo "Starting dingus server at http://localhost:9000/dingus.html" && python -m SimpleHTTPServer 9000
  120. ### Spec ###
  121. spec.md: $(SPEC)
  122. python3 tools/makespec.py markdown > $@
  123. spec.html: spec.txt tools/template.html ${PROG}
  124. python3 tools/makespec.py html > $@
  125. spec.pdf: spec.md tools/template.tex tools/specfilter.hs
  126. pandoc -s $< --template tools/template.tex \
  127. --filter tools/specfilter.hs -o $@ --latex-engine=xelatex --toc \
  128. --number-sections -V documentclass=report -V tocdepth=2 \
  129. -V classoption=twosides
  130. ### Website ###
  131. update-site: spec js/dist/commonmark.js
  132. make -C $(SITE) update
  133. upload-site: spec js/dist/commonmark.js
  134. make -C $(SITE) upload