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