aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 47ff11150c7c88fc9caa86d665338d00085ce2a0 (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. VERSION?=$(SPECVERSION)
  20. RELEASE?=CommonMark-$(VERSION)
  21. INSTALL_PREFIX?=/usr/local
  22. .PHONY: all cmake_build spec leakcheck clean fuzztest dingus upload test update-site upload-site debug mingw archive bench astyle
  23. all: cmake_build man/man3/cmark.3
  24. $(CMARK): cmake_build
  25. cmake_build: $(BUILDDIR)
  26. @make -j2 -C $(BUILDDIR)
  27. @echo "Binaries can be found in $(BUILDDIR)/src"
  28. $(BUILDDIR):
  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 | $(CMARK)
  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) cmake_build
  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: $(CMARK)
  99. operf $< < $(BENCHINP) > /dev/null
  100. distclean: clean
  101. -rm -rf *.dSYM
  102. -rm -f README.html
  103. -rm -f spec.md fuzz.txt spec.html
  104. -rm -rf $(BENCHFILE) $(ALLTESTS) progit
  105. ### Spec ###
  106. spec.md: $(SPEC)
  107. python3 tools/makespec.py markdown > $@
  108. spec.html: spec.txt tools/template.html ${CMARK}
  109. python3 tools/makespec.py html > $@
  110. spec.pdf: spec.md tools/template.tex tools/specfilter.hs
  111. pandoc -s $< --template tools/template.tex \
  112. --filter tools/specfilter.hs -o $@ --latex-engine=xelatex --toc \
  113. --number-sections -V documentclass=report -V tocdepth=2 \
  114. -V classoption=twosides
  115. ### Website ###
  116. update-site: spec
  117. make -C $(SITE) update
  118. upload-site: spec
  119. make -C $(SITE) upload