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