aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 92b6482b2602150c89863a6c2f19559abe47d433 (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: $(PROG) man/man1/cmark.1 man/man3/cmark.3
  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/man3/cmark.3
  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/man1/cmark.1 $(PKGDIR)/man/man1;\
  55. cp -a man/man3/cmark.3 $(PKGDIR)/man/man3;\
  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. man/man3/cmark.3: src/cmark.h $(PROG)
  67. python man/make_man_page.py $< > $@
  68. man/man1/cmark.1.html: man/man1/cmark.1
  69. groff -mman -Thtml > $@
  70. man/man3/cmark.3.html: man/man3/cmark.3
  71. groff -mman -Thtml > $@
  72. # We include html_unescape.h in the repository, so this shouldn't
  73. # normally need to be generated.
  74. $(SRCDIR)/html_unescape.h: $(SRCDIR)/html_unescape.gperf
  75. gperf -L ANSI-C -I -t -N find_entity -H hash_entity -K entity -C -l \
  76. -F ',0,{0}' --null-strings -m5 $< > $@
  77. # We include case_fold_switch.inc in the repository, so this shouldn't
  78. # normally need to be generated.
  79. $(SRCDIR)/case_fold_switch.inc: $(DATADIR)/CaseFolding-3.2.0.txt
  80. perl mkcasefold.pl < $< > $@
  81. test: $(SPEC) $(BUILDDIR)
  82. make -C $(BUILDDIR) test ARGS="-V"
  83. $(TARBALL): archive
  84. $(ZIPARCHIVE): archive
  85. testarchive: testtarball testziparchive
  86. rm -rf $(PKGDIR)
  87. testtarball: $(TARBALL)
  88. rm -rf $(PKGDIR); \
  89. tar xvzf $(TARBALL); \
  90. cd $(PKGDIR); \
  91. mkdir build && cd build && cmake .. && make && ctest -V
  92. testziparchive: $(ZIPARCHIVE)
  93. rm -rf $(PKGDIR); \
  94. unzip $(ZIPARCHIVE); \
  95. cd $(PKGDIR); \
  96. mkdir build && cd build && cmake .. && make && ctest -V
  97. $(ALLTESTS): spec.txt
  98. 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")' > $@
  99. leakcheck: $(ALLTESTS)
  100. cat $< | valgrind --leak-check=full --dsymutil=yes --error-exitcode=1 $(PROG) >/dev/null
  101. fuzztest:
  102. { for i in `seq 1 10`; do \
  103. cat /dev/urandom | head -c $(FUZZCHARS) | iconv -f latin1 -t utf-8 | tee fuzz-$$i.txt | \
  104. /usr/bin/env time -p $(PROG) >/dev/null && rm fuzz-$$i.txt ; \
  105. done } 2>&1 | grep 'user\|abnormally'
  106. # for benchmarking
  107. $(BENCHFILE): progit/progit.md
  108. -rm $@; for x in `seq 1 20` ; do cat $< >> $@; done
  109. progit:
  110. git clone https://github.com/progit/progit.git
  111. progit/progit.md: progit
  112. cat progit/en/*/*.markdown > $@
  113. bench: $(BENCHFILE)
  114. { sudo renice 99 $$$$; \
  115. for x in `seq 1 $(NUMRUNS)` ; do \
  116. /usr/bin/env time -p $(PROG) </dev/null >/dev/null ; \
  117. /usr/bin/env time -p $(PROG) <$< >/dev/null ; \
  118. done \
  119. } 2>&1 | grep 'real' | awk '{print $$2}' | python3 'bench/stats.py'
  120. operf: $(PROG)
  121. operf $(PROG) <$(BENCHINP) >/dev/null
  122. distclean: clean
  123. -rm -f js/commonmark.js
  124. -rm -rf *.dSYM
  125. -rm -f README.html
  126. -rm -f spec.md fuzz.txt spec.html
  127. -rm -rf $(BENCHFILE) $(ALLTESTS) progit
  128. ### JavaScript ###
  129. js/commonmark.js: js/lib/index.js ${JSMODULES}
  130. browserify --standalone commonmark $< -o $@
  131. testjs: $(SPEC)
  132. node js/test.js
  133. jshint:
  134. jshint ${JSMODULES}
  135. lint:
  136. eslint -c eslint.json ${JSMODULES} js/bin/commonmark js/test.js js/bench.js
  137. benchjs:
  138. sudo renice 99 $$$$; node js/bench.js ${BENCHINP}
  139. npm:
  140. cd js; npm publish
  141. dingus: js/commonmark.js
  142. echo "Starting dingus server at http://localhost:9000" && python -m SimpleHTTPServer 9000
  143. ### Spec ###
  144. spec.md: $(SPEC)
  145. perl spec2md.pl < $< > $@
  146. spec.html: spec.md template.html
  147. pandoc --no-highlight --number-sections --template template.html -s --toc -S $< | \
  148. perl -pe 's/a href="@([^"]*)"/a id="\1" href="#\1" class="definition"/g' | \
  149. perl -pe 's/␣/<span class="space"> <\/span>/g' \
  150. > $@
  151. spec.pdf: spec.md template.tex specfilter.hs
  152. pandoc -s $< --template template.tex \
  153. --filter ./specfilter.hs -o $@ --latex-engine=xelatex --toc \
  154. --number-sections -V documentclass=report -V tocdepth=2 \
  155. -V classoption=twosides
  156. ### Website ###
  157. update-site: spec.html js/commonmark.js
  158. make -C $(SITE) update
  159. upload-site: spec.html
  160. make -C $(SITE) upload