# $Id: Makefile,v 1.14 2002/06/06 11:27:30 blackh Exp $

.SUFFIXES=.lyx .html .pdf .ps .rtf .tex .txt

LYXS=$(wildcard *.lyx)
BASES=$(LYXS:.lyx=)
HTMLS=$(LYXS:lyx=html)
PDFS=$(LYXS:lyx=pdf)
PSS=$(LYXS:lyx=ps)
RTFS=$(LYXS:lyx=rtf)
TEXS=$(LYXS:lyx=tex)
TXTS=$(LYXS:lyx=txt)
FILES=$(HTMLS) $(PDFS) $(PSS) $(RTFS) $(TEXS) $(TXTS)

PNGS=$(wildcard *.png)

all:   $(FILES) doc.inc

SSH=ssh
ifeq ($(USER),ross)
SSH=ssh -l rossta
endif

HTDOCS=/home/groups/g/gr/grapevine/htdocs/

tidy:
	@-rm -fR $(LYXS:lyx=aux)
	@-rm -fR $(LYXS:lyx=dvi)
	@-rm -fR $(LYXS:lyx=*log)
	@-rm -fR $(LYXS:lyx=tmp)
	@-rm -fR $(LYXS:lyx=toc)
	@-rm -fR $(LYXS:lyx=xhtml)
	@-rm -fR *.lyx~
	@-rm -fR .log
	@-rm -fR texput.log

publish: all tidy
	-RSYNC_RSH="$(SSH)" rsync -r --delete . ssh.sourceforge.net:$(HTDOCS)/doc
	-$(SSH) ssh.sourceforge.net chmod -R g+rw $(HTDOCS)

doc.inc: $(TEXS) $(PNGS)
	perl index.pl $(BASES) $(PNGS) >doc.inc

clean:	tidy
	@-rm -f doc.inc
	@-rm -fR $(FILES)
	@-rm -fR $(BASES)
	@-rm -fR $(LYXS:lyx=css)
	@-rmdir -p $(BASES) >/dev/null 2>/dev/null || true

%.tex: %.lyx
# don't seem to work, appearently ... too bad
#	-lyx -e ascii $<                                                    2>&1 | tee $(*F).lyx.ascii.log 
#	-lyx -e dvi   $<                                                    2>&1 | tee $(*F).lyx.dvi.log 
#	-lyx -e html  $<                                                    2>&1 | tee $(*F).lyx.html.log 
#	-lyx -e pdf   $<                                                    2>&1 | tee $(*F).lyx.pdf.log 
#	-lyx -e ps    $<                                                    2>&1 | tee $(*F).lyx.postscript.log 
	lyx -e latex $<                                                     2>&1 | tee $(*F).lyx.latex.log 
	perl fix_tex.pl <$(*F).tex | sed 's/\\raggedright //g' >$(*F).tmp
	mv -f $(*F).tmp $(*F).tex

%.html: %.tex
	-latex2html -no_auto_link -nonavigation -split 0 -info 0 $(*F).tex   2>&1 | tee $(*F).latex2html.log 
	-touch $(*F).html
	# convert html to xhtml
	#(cd $(*F) && -tidy -config ../.tidyrc $(*F).html >$(*F).xhtml 2>$(*F).tidy.log)
	#(cd $(*F) && mv -f $(*F).xhtml $(*F).html)

%.txt: %.html
	-lynx -nolist -dump file://`pwd`/$(*F)/$(*F).html >$(*F).txt         

%.ps: %.tex
	pslatex $(*F).tex                                                   2>&1 | tee $(*F).pslatex.log 
	dvips -o $(*F).ps $(*F).dvi                                         2>&1 | tee $(*F).dvips.log 

%.pdf: %.ps
	ps2pdf $(*F).ps                                                     2>&1 | tee $(*F).ps2pdf.log 
	
%.rtf: %.tex
	-latex2rtf -o $(*F).rtf $(*F).tex                                    2>&1 | tee $(*F).latex2rtf.log 

#eof
