
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("<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.2 make DOM-v0.2.html

web:
	cp DOM-v0.2.html ~/Web/Reports/DOM/v0.2/
	cp *.png ~/Web/Reports/DOM/v0.2/
	cp *.html ~/Web/Reports/DOM/v0.2/
	cp DOM-v0.2.cml ~/Web/Reports/DOM/v0.2/
	cp DOM-v0.2.xml ~/Web/Reports/DOM/v0.2/
	cp DOM-v0.2.Rhtml ~/Web/Reports/DOM/v0.2/
	cp phantom-script.js ~/Web/Reports/DOM/v0.2/
	cp Makefile ~/Web/Reports/DOM/v0.2/
	cp knitr.xsl ~/Web/Reports/DOM/v0.2/
	cp common.xsl ~/Web/Reports/DOM/v0.2/
	cp Dockerfile ~/Web/Reports/DOM/v0.2/

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