aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: e1475d55c74227291bf81e128a31d0d70d1eed78 (plain)
  1. CFLAGS?=--O3 -Wall -Wextra -std=c99 -Isrc -Wno-missing-field-initializers -fPIC $(OPTFLAGS)
  2. LDFLAGS?=-g -O3 -Wall -Werror
  3. SRCDIR?=src
  4. DATADIR?=data
  5. BENCHINP?=README.md
  6. PROG?=./cmark
  7. JSMODULES=$(wildcard js/lib/*.js)
  8. PREFIX?=/usr/local
  9. SPEC=spec.txt
  10. SITE=_site
  11. SPECVERSION=$(shell grep version: $(SPEC) | sed -e 's/version: *//')
  12. VERSIONS=$(shell cd $(SITE); ls -d -1 0.* | sort -r -g)
  13. .PHONY: all spec leakcheck clean fuzztest dingus upload jshint test testjs benchjs update-site upload-site
  14. all: $(SRCDIR)/case_fold_switch.inc $(PROG) libcmark.so
  15. README.html: README.md template.html
  16. pandoc --template template.html -S -s -t html5 -o $@ $<
  17. spec: test spec.html
  18. spec.md: $(SPEC)
  19. perl spec2md.pl < $< > $@
  20. spec.html: spec.md template.html
  21. pandoc --no-highlight --number-sections --template template.html -s --toc -S $< > $@ # | perl -pe 's/␣/<span class="space"> <\/span>/g' > $@
  22. spec.pdf: spec.md template.tex specfilter.hs
  23. pandoc -s $< --template template.tex \
  24. --filter ./specfilter.hs -o $@ --latex-engine=xelatex --toc \
  25. --number-sections -V documentclass=report -V tocdepth=2 \
  26. -V classoption=twosides
  27. test: $(SPEC)
  28. perl runtests.pl $< $(PROG)
  29. js/commonmark.js: js/lib/index.js ${JSMODULES}
  30. browserify --standalone commonmark $< -o $@
  31. testjs: $(SPEC)
  32. node js/test.js
  33. jshint:
  34. jshint ${JSMODULES}
  35. benchjs:
  36. node js/bench.js ${BENCHINP}
  37. HTML_OBJ=$(SRCDIR)/html/html.o $(SRCDIR)/html/houdini_href_e.o $(SRCDIR)/html/houdini_html_e.o $(SRCDIR)/html/houdini_html_u.o
  38. CMARK_OBJ=$(SRCDIR)/inlines.o $(SRCDIR)/buffer.o $(SRCDIR)/blocks.o $(SRCDIR)/scanners.c $(SRCDIR)/print.o $(SRCDIR)/utf8.o $(SRCDIR)/references.o
  39. CMARK_HDR = $(SRCDIR)/cmark.h $(SRCDIR)/buffer.h $(SRCDIR)/references.h \
  40. $(SRCDIR)/chunk.h $(SRCDIR)/debug.h $(SRCDIR)/utf8.h \
  41. $(SRCDIR)/scanners.h $(SRCDIR)/inlines.h
  42. HTML_HDR = $(SRCDIR)/html/html_unescape.h $(SRCDIR)/html/houdini.h
  43. $(PROG): $(SRCDIR)/html/html_unescape.h $(SRCDIR)/case_fold_switch.inc $(HTML_OBJ) $(CMARK_OBJ) $(SRCDIR)/main.c
  44. $(CC) $(LDFLAGS) -o $@ $(HTML_OBJ) $(CMARK_OBJ) $(SRCDIR)/main.c
  45. $(SRCDIR)/scanners.c: $(SRCDIR)/scanners.re
  46. re2c --case-insensitive -bis $< > $@ || (rm $@ && false)
  47. $(SRCDIR)/case_fold_switch.inc: $(DATADIR)/CaseFolding-3.2.0.txt
  48. perl mkcasefold.pl < $< > $@
  49. $(SRCDIR)/html/html_unescape.h: $(SRCDIR)/html/html_unescape.gperf
  50. gperf -I -t -N find_entity -H hash_entity -K entity -C -l --null-strings -m5 $< > $@
  51. libcmark.so: $(HTML_OBJ) $(CMARK_OBJ)
  52. $(CC) $(LDFLAGS) -shared -o $@ $^
  53. install: libcmark.so $(cmark_HDR) $(HTML_HDR)
  54. install -d $(PREFIX)/lib $(PREFIX)/include/cmark/html
  55. install libcmark.so $(PREFIX)/lib/
  56. install $(cmark_HDR) $(PREFIX)/include/cmark/
  57. install $(HTML_HDR) $(PREFIX)/include/cmark/html/
  58. dingus: js/commonmark.js
  59. echo "Starting dingus server at http://localhost:9000" && python -m SimpleHTTPServer 9000
  60. leakcheck: $(PROG)
  61. cat leakcheck.md | valgrind --leak-check=full --dsymutil=yes $(PROG)
  62. operf: $(PROG)
  63. operf $(PROG) <$(BENCHINP) >/dev/null
  64. fuzztest:
  65. for i in `seq 1 10`; do \
  66. time cat /dev/urandom | head -c 100000 | iconv -f latin1 -t utf-8 | $(PROG) >/dev/null; done
  67. $(SITE)/spec.html: spec.txt
  68. (echo "% CommonMark Spec\n";\
  69. for vers in $(VERSIONS); do \
  70. if [ "$$vers" != "$(SPECVERSION)" ]; then \
  71. perl -p -i -e 's/<div id="watermark">.*?<\/div>/<div id="watermark" style="background-color:black">This is an older version of the spec. For the most recent version, see <a href="http:\/\/spec.commonmark.org">http:\/\/spec.commonmark.org<\/a>.<\/div>/' $(SITE)/$$vers/index.html ; \
  72. fi; \
  73. echo "- [Version $$vers](/$$vers/)" ; \
  74. done) | \
  75. pandoc --template template.html -S -s -t html5 -o $@
  76. $(SITE)/index.html: $(SITE)/spec.html
  77. cp $< $@
  78. $(SITE)/$(SPECVERSION)/index.html: spec.html
  79. mkdir -p $(SITE)/$(SPECVERSION)
  80. cp $< $@
  81. cd $(SITE); git add $(SPECVERSION)/index.html; git commit -a -m "Added version $(SPECVERSION) of spec"; cd ..
  82. $(SITE)/%: %
  83. cp $< $@
  84. update-site: $(SITE)/dingus.html $(SITE)/js/commonmark.js $(SITE)/index.html $(SITE)/$(SPECVERSION)/index.html $(SITE)/spec.html $(SITE)/js/LICENSE
  85. upload-site:
  86. cd $(SITE) ; git pull; git commit -a -m "Updated site for latest spec, js" ; git push; cd ..
  87. clean:
  88. -rm -f test $(SRCDIR)/*.o $(SRCDIR)/scanners.c $(SRCDIR)/html/*.o libcmark.so
  89. -rm js/commonmark.js
  90. -rm -rf *.dSYM
  91. -rm -f README.html
  92. -rm -f spec.md fuzz.txt spec.html