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