aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 0da8449b155a0e958df0ebe69f76df437a264353 (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. TARBALL?=cmark-$(SPECVERSION).tar.gz
  12. ZIPARCHIVE?=cmark-$(SPECVERSION).zip
  13. FUZZCHARS?=2000000 # for fuzztest
  14. BENCHDIR=bench
  15. BENCHFILE=$(BENCHDIR)/benchinput.md
  16. ALLTESTS=alltests.md
  17. NUMRUNS?=10
  18. PROG?=$(BUILDDIR)/src/cmark
  19. BENCHINP?=README.md
  20. JSMODULES=$(wildcard js/lib/*.js)
  21. .PHONY: all spec leakcheck clean fuzztest dingus upload jshint test testjs benchjs update-site upload-site check npm debug mingw archive tarball ziparchive testarchive testtarball testziparchive testlib bench astyle
  22. all: $(PROG)
  23. @echo "Binaries can be found in $(BUILDDIR)/src"
  24. $(PROG): $(BUILDDIR)
  25. @make -C $(BUILDDIR)
  26. check:
  27. @cmake --version > /dev/null || (echo "You need cmake to build this program: http://www.cmake.org/download/" && exit 1)
  28. $(BUILDDIR): check $(SRCDIR)/html_unescape.h $(SRCDIR)/case_fold_switch.inc
  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. archive: spec.html $(BUILDDIR) man/man1/cmark.1 man/make_man_page.py
  45. @rm -rf $(PKGDIR); \
  46. mkdir -p $(PKGDIR)/$(SRCDIR); \
  47. mkdir -p $(PKGDIR)/api_test $(PKGDIR)/man/man1 $(PKGDIR)/man/man3 ; \
  48. mkdir -p $(PKGDIR)/test ; \
  49. srcfiles=`git ls-tree --full-tree -r HEAD --name-only $(SRCDIR) test api_test`; \
  50. for f in $$srcfiles; do cp -a $$f $(PKGDIR)/$$f; done; \
  51. cp -a $(SRCDIR)/scanners.c $(PKGDIR)/$(SRCDIR)/; \
  52. cp -a spec.html $(PKGDIR); \
  53. cp -a man/CMakeLists.txt $(PKGDIR)/man;\
  54. cp -a man/make_man_page.py $(PKGDIR)/man;\
  55. cp -a man/man1/cmark.1 $(PKGDIR)/man/man1;\
  56. cp CMakeLists.txt $(PKGDIR); \
  57. perl -ne '$$p++ if /^### JavaScript/; print if (!$$p)' Makefile > $(PKGDIR)/Makefile; \
  58. cp -a Makefile.nmake nmake.bat $(PKGDIR); \
  59. cp -a README.md LICENSE spec.txt $(PKGDIR)/; \
  60. tar czf $(TARBALL) $(PKGDIR); \
  61. zip -q -r $(ZIPARCHIVE) $(PKGDIR); \
  62. rm -rf $(PKGDIR) ; \
  63. echo "Created $(TARBALL) and $(ZIPARCHIVE)."
  64. clean:
  65. rm -rf $(BUILDDIR) $(MINGW_BUILDDIR) $(MINGW_INSTALLDIR) $(TARBALL) $(ZIPARCHIVE) $(PKGDIR)
  66. # We include html_unescape.h in the repository, so this shouldn't
  67. # normally need to be generated.
  68. $(SRCDIR)/html_unescape.h: $(SRCDIR)/html_unescape.gperf
  69. gperf -L ANSI-C -I -t -N find_entity -H hash_entity -K entity -C -l \
  70. -F ',0,{0}' --null-strings -m5 $< > $@
  71. # We include case_fold_switch.inc in the repository, so this shouldn't
  72. # normally need to be generated.
  73. $(SRCDIR)/case_fold_switch.inc: $(DATADIR)/CaseFolding-3.2.0.txt
  74. perl mkcasefold.pl < $< > $@
  75. # We include scanners.c in the repository, so this shouldn't
  76. # normally need to be generated.
  77. $(SRCDIR)/scanners.c: $(SRCDIR)/scanners.re
  78. re2c --case-insensitive -b -i --no-generation-date -o $@ $<
  79. test: $(SPEC) $(BUILDDIR)
  80. make -C $(BUILDDIR) test ARGS="-V"
  81. $(TARBALL): archive
  82. $(ZIPARCHIVE): archive
  83. testarchive: testtarball testziparchive
  84. rm -rf $(PKGDIR)
  85. testtarball: $(TARBALL)
  86. rm -rf $(PKGDIR); \
  87. tar xvzf $(TARBALL); \
  88. cd $(PKGDIR); \
  89. mkdir build && cd build && cmake .. && make && ctest -V
  90. testziparchive: $(ZIPARCHIVE)
  91. rm -rf $(PKGDIR); \
  92. unzip $(ZIPARCHIVE); \
  93. cd $(PKGDIR); \
  94. mkdir build && cd build && cmake .. && make && ctest -V
  95. $(ALLTESTS): spec.txt
  96. 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]).encode("utf-8"))' > $@
  97. leakcheck: $(ALLTESTS)
  98. cat $< | valgrind --leak-check=full --dsymutil=yes --error-exitcode=1 $(PROG) >/dev/null
  99. fuzztest:
  100. { for i in `seq 1 10`; do \
  101. cat /dev/urandom | head -c $(FUZZCHARS) | iconv -f latin1 -t utf-8 | tee fuzz-$$i.txt | \
  102. /usr/bin/env time -p $(PROG) >/dev/null && rm fuzz-$$i.txt ; \
  103. done } 2>&1 | grep 'user\|abnormally'
  104. # for benchmarking
  105. $(BENCHFILE): progit/progit.md
  106. -rm $@; for x in `seq 1 20` ; do cat $< >> $@; done
  107. progit:
  108. git clone https://github.com/progit/progit.git
  109. progit/progit.md: progit
  110. cat progit/en/*/*.markdown > $@
  111. bench: $(BENCHFILE)
  112. { sudo renice 99 $$$$; \
  113. for x in `seq 1 $(NUMRUNS)` ; do \
  114. /usr/bin/env time -p $(PROG) </dev/null >/dev/null ; \
  115. /usr/bin/env time -p $(PROG) <$< >/dev/null ; \
  116. done \
  117. } 2>&1 | grep 'real' | awk '{print $$2}' | python3 'bench/stats.py'
  118. astyle:
  119. astyle --style=linux -t -p -r 'src/*.c' --exclude=scanners.c
  120. astyle --style=linux -t -p -r 'src/*.h' --exclude=html_unescape.h
  121. operf: $(PROG)
  122. operf $(PROG) <$(BENCHINP) >/dev/null
  123. distclean: clean
  124. -rm -f js/commonmark.js
  125. -rm -rf *.dSYM
  126. -rm -f README.html
  127. -rm -f spec.md fuzz.txt spec.html
  128. -rm -rf $(BENCHFILE) $(ALLTESTS) progit
  129. ### JavaScript ###
  130. js/commonmark.js: js/lib/index.js ${JSMODULES}
  131. browserify --standalone commonmark $< -o $@
  132. testjs: $(SPEC)
  133. node js/test.js
  134. jshint:
  135. jshint ${JSMODULES}
  136. lint:
  137. eslint -c eslint.json ${JSMODULES} js/bin/commonmark js/test.js js/bench.js
  138. benchjs:
  139. sudo renice 99 $$$$; node js/bench.js ${BENCHINP}
  140. npm:
  141. cd js; npm publish
  142. dingus: js/commonmark.js
  143. echo "Starting dingus server at http://localhost:9000" && python -m SimpleHTTPServer 9000
  144. ### Spec ###
  145. spec.md: $(SPEC)
  146. python3 makespec.py markdown > $@
  147. spec.html: spec.txt template.html ${PROG}
  148. python3 makespec.py html > $@
  149. spec.pdf: spec.md template.tex specfilter.hs
  150. pandoc -s $< --template template.tex \
  151. --filter ./specfilter.hs -o $@ --latex-engine=xelatex --toc \
  152. --number-sections -V documentclass=report -V tocdepth=2 \
  153. -V classoption=twosides
  154. ### Website ###
  155. update-site: spec js/commonmark.js
  156. make -C $(SITE) update
  157. upload-site: spec js/commonmark.js
  158. make -C $(SITE) upload