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