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