
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.3 make DOM-v0.3.html

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

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