.PRECIOUS : %.tex

MASTER = boss

Rnwfiles := $(wildcard *.Rnw)
Rbases   := $(basename $(Rnwfiles))
Rfiles   := $(foreach base, $(Rbases), $(wildcard $(base).R))
Rpics    := $(foreach base, $(Rbases), $(wildcard $(base)-*.pdf))
Rtex     := $(foreach base, $(Rbases), \
               $(wildcard $(addprefix $(base), .tex)))
Rtexfiles  := $(foreach base, $(Rbases), \
               $(wildcard $(addprefix $(base), .log .aux .out)))
%.tex : %.Rnw
	Sweave.sh $<

%.R : %.Rnw
	Stangle.sh $<
	mv $@ /home/berwin/lang/R/Develop/work

%.pdf : %.tex
	pdflatex '\nonstopmode\input{$<}'
	rm -f Rplots*.ps

all : 	$(MASTER).pdf

$(MASTER).pdf : $(MASTER).tex $(Rtex)
	pdflatex '\nonstopmode\input{$<}'

clean :
ifneq ($(strip ${Rfiles}), )
	rm -rf ${Rfiles}
endif
ifneq ($(strip ${Rpics}), )
	rm -rf ${Rpics}
endif
ifneq ($(strip ${Rtexfiles}), )
	rm -rf ${Rtexfiles}
endif
	rm -rf *~

