SOURCES = $(shell ls *Rmd)
SOURCES_RNW = $(shell ls *Rnw)

%.html: %.Rmd
	@echo "KNITR_CACHE=TRUE Sweave $<"
	@BIOCONDUCTOR_ONLINE_VERSION_DIAGNOSIS=FALSE \
	KNITR_CACHE=TRUE "$(R_HOME)"/bin/R --vanilla CMD Sweave $<

%.R: %.Rmd
	@echo "KNITR_CACHE=FALSE Stangle $<"
	@KNITR_CACHE=FALSE && "$(R_HOME)"/bin/R --vanilla CMD Stangle $<

%.pdf: %.Rnw
	@echo "KNITR_CACHE=TRUE Sweave $<"
	@KNITR_CACHE=TRUE "$(R_HOME)"/bin/R --vanilla CMD Sweave --pdf $<

all: $(SOURCES:.Rmd=.html) $(SOURCES_RNW:.Rnw=.pdf)

clean:
	rm -rf Rplots* *html *R *.md *_cache/ *_files/ figure/ \
		*pdf *snm *tex *toc *vrb *aux *log *nav *out