aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 6f2af0cfcd6ac50d74937edf7981f136d5787a2c (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. INSTALL_PREFIX?=/usr/local
  22. .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
  23. all: cmake_build man/man3/cmark.3
  24. $(PROG): cmake_build
  25. cmake_build: $(BUILDDIR)
  26. @make -j2 -C $(BUILDDIR)
  27. @echo "Binaries can be found in $(BUILDDIR)/src"
  28. $(BUILDDIR): $(SRCDIR)/html_unescape.h $(SRCDIR)/case_fold_switch.inc
  29. @cmake --version > /dev/null || (echo "You need cmake to build this program: http://www.cmake.org/download/" && exit 1)
  30. mkdir -p $(BUILDDIR); \
  31. cd $(BUILDDIR); \
  32. cmake .. \
  33. -G "$(GENERATOR)" \
  34. -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
  35. -DCMAKE_INSTALL_PREFIX=$(INSTALL_PREFIX)
  36. install: $(BUILDDIR)
  37. make -C $(BUILDDIR) install
  38. debug:
  39. mkdir -p $(BUILDDIR); \
  40. cd $(BUILDDIR); \
  41. cmake .. -DCMAKE_BUILD_TYPE=Debug; \
  42. make
  43. mingw:
  44. mkdir -p $(MINGW_BUILDDIR); \
  45. cd $(MINGW_BUILDDIR); \
  46. cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchain-mingw32.cmake -DCMAKE_INSTALL_PREFIX=$(MINGW_INSTALLDIR) ;\
  47. make && make install
  48. man/man3/cmark.3: src/cmark.h | $(PROG)
  49. python3 man/make_man_page.py $< > $@ \
  50. archive:
  51. git archive --prefix=$(RELEASE)/ -o $(RELEASE).tar.gz HEAD
  52. git archive --prefix=$(RELEASE)/ -o $(RELEASE).zip HEAD
  53. clean:
  54. rm -rf $(BUILDDIR) $(MINGW_BUILDDIR) $(MINGW_INSTALLDIR) $(PKGDIR)
  55. # We include html_unescape.h in the repository, so this shouldn't
  56. # normally need to be generated.
  57. $(SRCDIR)/html_unescape.h: $(SRCDIR)/html_unescape.gperf
  58. gperf -L ANSI-C -I -t -N find_entity -H hash_entity -K entity -C -l \
  59. -F ',{0}' --null-strings -m5 -P -Q entity_pool $< > $@
  60. # We include case_fold_switch.inc in the repository, so this shouldn't
  61. # normally need to be generated.
  62. $(SRCDIR)/case_fold_switch.inc: $(DATADIR)/CaseFolding-3.2.0.txt
  63. perl tools/mkcasefold.pl < $< > $@
  64. # We include scanners.c in the repository, so this shouldn't
  65. # normally need to be generated.
  66. $(SRCDIR)/scanners.c: $(SRCDIR)/scanners.re
  67. re2c --case-insensitive -b -i --no-generation-date -o $@ $<
  68. test: $(SPEC) $(BUILDDIR)
  69. make -C $(BUILDDIR) test || (cat $(BUILDDIR)/Testing/Temporary/LastTest.log && exit 1)
  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/dist/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/dist/commonmark.js: js/lib/index.js ${JSMODULES}
  108. browserify --standalone commonmark $< -o $@
  109. # 'npm install -g uglify-js' for the uglifyjs tool:
  110. js/dist/commonmark.min.js: js/dist/commonmark.js
  111. uglifyjs $< --compress keep_fargs=true,pure_getters=true --preamble "/* commonmark $(VERSION) https://github.com/jgm/CommonMark @license BSD3 */" > $@
  112. testjs: $(SPEC)
  113. node js/test.js
  114. jshint:
  115. jshint ${JSMODULES}
  116. lint:
  117. eslint -c js/eslint.json ${JSMODULES} js/bin/commonmark js/test.js js/bench.js
  118. benchjs:
  119. sudo renice 99 $$$$; node js/bench.js ${BENCHINP}
  120. npm:
  121. cd js; npm publish
  122. dingus: js/dist/commonmark.js
  123. echo "Starting dingus server at http://localhost:9000/dingus.html" && python -m SimpleHTTPServer 9000
  124. ### Spec ###
  125. spec.md: $(SPEC)
  126. python3 tools/makespec.py markdown > $@
  127. spec.html: spec.txt tools/template.html ${PROG}
  128. python3 tools/makespec.py html > $@
  129. spec.pdf: spec.md tools/template.tex tools/specfilter.hs
  130. pandoc -s $< --template tools/template.tex \
  131. --filter tools/specfilter.hs -o $@ --latex-engine=xelatex --toc \
  132. --number-sections -V documentclass=report -V tocdepth=2 \
  133. -V classoption=twosides
  134. ### Website ###
  135. update-site: spec js/dist/commonmark.js
  136. make -C $(SITE) update
  137. upload-site: spec js/dist/commonmark.js
  138. make -C $(SITE) upload