aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 363772cf4384d233a1e2b051da251240a5368df1 (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. cd js && 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. index.md: _site/$(SPECVERSION)/index.html
  66. echo "" > $@
  67. for vers in $(shell cd _site; ls -d -t 0.*) ; do \
  68. echo "- [Version $$vers](/$$vers/)" >> $@ ; done
  69. _site/index.html: index.md
  70. pandoc --template template.html -S -s -t html5 -o $@ $<
  71. _site/$(SPECVERSION)/index.html: spec.html
  72. mkdir -p _site/$(SPECVERSION)
  73. cp $< $@
  74. cd _site; git add $(SPECVERSION)/index.html; git commit -a -m "Added version $(SPECVERSION) of spec"; cd ..
  75. update-site: spec.html js/commonmark.js _site/index.html _site/$(SPECVERSION)/index.html
  76. cp js/index.html _site/js/
  77. cp js/commonmark.js _site/js/
  78. cp js/LICENSE _site/js/
  79. (cd _site ; git pull ; git commit -a -m "Updated site for latest spec, js" ; git push; cd ..)
  80. clean:
  81. -rm -f test $(SRCDIR)/*.o $(SRCDIR)/scanners.c $(SRCDIR)/html/*.o libcmark.so index.md
  82. -rm js/commonmark.js
  83. -rm -rf *.dSYM
  84. -rm -f README.html
  85. -rm -f spec.md fuzz.txt spec.html