
TARFILE = ./deposit-$(shell date +'%Y-%m-%d').tar.gz

%.xml: %.cml
	# Protect HTML special chars in R code chunks
	Rscript -e 't <- readLines("$*.cml"); writeLines(gsub("str>", "strong>", gsub("<rcode([^>]*)>", "<rcode\\1><![CDATA[", gsub("</rcode>", "]]></rcode>", t))), "$*.xml")'

%.Rhtml : %.xml
	# Transform to .Rhtml
	xsltproc knitr.xsl $*.xml > $*.Rhtml

%.html : %.Rhtml
	# Use knitr to produce HTML
	Rscript -e 'library(knitr); knit("$<")'

docker:
	sudo docker run -v $(shell pwd):/home/work/ -w /home/work pmur002/dom-v0.4 make DOM-v0.4.html

web:
	make DOM-v0.4.xml
	make DOM-v0.4.Rhtml
	make docker
	cp DOM-v0.4.html ~/Web/Reports/DOM/v0.4/
	cp *.png ~/Web/Reports/DOM/v0.4/
	cp *.svg ~/Web/Reports/DOM/v0.4/
	cp *.html ~/Web/Reports/DOM/v0.4/
	cp DOM-v0.4.cml ~/Web/Reports/DOM/v0.4/
	cp DOM-v0.4.xml ~/Web/Reports/DOM/v0.4/
	cp DOM-v0.4.Rhtml ~/Web/Reports/DOM/v0.4/
	cp Makefile ~/Web/Reports/DOM/v0.4/
	cp knitr.xsl ~/Web/Reports/DOM/v0.4/
	cp common.xsl ~/Web/Reports/DOM/v0.4/
	cp Dockerfile ~/Web/Reports/DOM/v0.4/

zip:
	make DOM-v0.4.xml
	make DOM-v0.4.Rhtml
	make docker
	tar zcvf $(TARFILE) DOM-v0.4.html *.png *.svg *.html DOM-v0.4.cml DOM-v0.4.xml DOM-v0.4.Rhtml phantom-script.js Makefile knitr.xsl common.xsl Dockerfile README-deposit
