R = $(R_HOME)/bin/R

RNW0 = Introduction.Rnw SequencesAndRanges.Rnw ReadsAndAlignments.Rnw \
	RNASeq.Rnw ChIPSeq.Rnw Annotation.Rnw
RNW = $(RNW0:%=chpt/%)

# rules
%.R: %.Rnw
	@cd `dirname $<`; "$(R_HOME)/bin/R" CMD Stangle `basename $<`; cd ..

%.tex: %.Rnw
	@cd `dirname $<`; "$(R_HOME)/bin/R" CMD Sweave `basename $<`; cd ..

all: Bioconductor-tutorial.pdf
	mkdir -p ../inst/doc
	cp chpt/*R ../inst/doc/

myclean:
	@cd chpt; rm -f *png *tex *aux *bbl *blg *log *out *toc; cd ..
	@rm -f *png *tex *aux *bbl *blg *log *out *toc
	@rm -f chpt/Rplots.pdf

Bioconductor-tutorial.pdf: $(RNW:%.Rnw=%.tex) $(RNW:%.Rnw=%.R) Bioconductor.sty
	@"$(R_HOME)/bin/R" CMD Sweave Bioconductor-tutorial.Rnw
	@"$(R_HOME)/bin/R" CMD Stangle Bioconductor-tutorial.Rnw
	@"$(R_HOME)/bin/R" CMD texi2dvi --pdf Bioconductor-tutorial.tex
	@"$(R_HOME)/bin/R" CMD pdflatex Bioconductor-tutorial.tex

