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