SHELL=/bin/sh

FILE_BASE=$(TEX_BASE:.tex=)

BMP_FILES=$(XPM_FILES:.xpm=.bmp)
EPS_FILES=$(XPM_FILES:.xpm=.eps)
GIF_FILES=$(XPM_FILES:.xpm=.gif)

TEX2RTF=$(WXBASEDIR)/bin/$(OSTYPE)/tex2rtf

HTML_BUTTONS=back.gif forward.gif contents.gif up.gif

all:: doc

clean::
	@ for each in $(DIRS) . ; do \
	( cd $$each; \
	  rm -f *.bmp *.eps *.gif *.aux *.dvi *.log  \
	        *.ps  *.toc *~    *.idx *.hlp *.html \
	        *.rtf *.ref *.xlp *.con *.win *.fts  \
	        *.hpj *.HLP; \
	); done 

doc:: doc_ps doc_html doc_xlp doc_winhelp doc_rtf

#############################################

doc_ps:: $(FILE_BASE).ps

$(FILE_BASE).ps: $(FILE_BASE).dvi
	dvips $(FILE_BASE).dvi -o$@

#############################################

doc_dvi:: $(FILE_BASE).dvi

$(FILE_BASE).dvi: $(FILE_BASE).tex $(TEX_ADDITIONAL) $(EPS_FILES)
	latex $(FILE_BASE).tex
	latex $(FILE_BASE).tex

#############################################

doc_xlp:: $(FILE_BASE).xlp

$(FILE_BASE).xlp: $(FILE_BASE).tex $(TEX_ADDITIONAL)
	$(TEX2RTF) $(FILE_BASE).tex $(FILE_BASE).xlp -twice -xlp

#############################################

doc_html:: $(FILE_BASE)_contents.html $(FILE_BASE).html

$(FILE_BASE).html: 
	@ln -s $(FILE_BASE)_contents.html $@

$(FILE_BASE)_contents.html: $(FILE_BASE).tex $(TEX_ADDITIONAL) $(GIF_FILES) $(HTML_BUTTONS)
	$(TEX2RTF) $(FILE_BASE).tex $(FILE_BASE) -twice -html

#############################################

doc_rtf:: $(FILE_BASE).rtf

$(FILE_BASE).rtf: $(FILE_BASE).tex $(TEX_ADDITIONAL) $(BMP_FILES)
	$(TEX2RTF) $(FILE_BASE).tex $(FILE_BASE).rtf -twice -rtf

#############################################

doc_winhelp:: $(FILE_BASE).win

$(FILE_BASE).win: $(FILE_BASE).tex $(TEX_ADDITIONAL) $(BMP_FILES)
	../../../bin/$(OSTYPE)/tex2rtf $(FILE_BASE).tex $(FILE_BASE).win -twice -winhelp
	@echo final conversion still needs to be done by MSWin

#############################################

.SUFFIXES:
.SUFFIXES: .eps .xpm
.SUFFIXES: .bmp .xpm
.SUFFIXES: .gif .xpm

.xpm.eps :
	@$(RM) -f $@
	xpmtoppm $< | ppmtogif | giftopnm | pnmtops -rle -center -noturn -scale 0.5 - > $@

.xpm.bmp :
	@$(RM) -f $@
	xpmtoppm $< | ppmtobmp -windows - > $@

.xpm.gif :
	@$(RM) -f $@ 
	xpmtoppm $< | ppmtogif -interlace - > $@
