ALL: all-redirect
SHELL = /bin/sh

srcdir = .

.SUFFIXES: .pdf .dvi .tex

# Set these to the location of the web and ftp locations for the documents
WEBDIR = /mcs/www/mpi/mpich2/docs
FTPDIR = /home/ftp/pub/mpi/mpich2


# The tests on files that use -s really need to also check for a valid
# link.  However, the -h test is not available in all shells,
# so we allow the ln to fail without exiting make (the -f option for
# ln is also non-standard, so we can't use that either)
.tex.dvi:
	@if [ ! -s ../mpiman.sty ] ; then \
	(cd .. && ln -s $(srcdir)/../mpiman.sty mpiman.sty) ; fi
	-latex $< 
	-bibtex $* 
	-latex $< 
	latex $< 

.dvi.pdf:
	dvipdfm $*

.dvi.ps:
	dvips $*

# Use latex2html to create the HTML version.  There are several 
# steps needed to workaround features of latex2html
# 1. latex2html needs the install.aux file, so we run a latex step if
#    necessary
# 2. latex2html is not compatible with VPATH builds (it runs in the
#    directory that contains the source file), so we copy the source
#    file.  If more source files are added, this step will need to 
#    be changed
install.tex: $(srcdir)/install.tex
	@if cmp -s install.tex $(srcdir)/install.tex ; then : ; else \
	cp $(srcdir)/install.tex install.tex ; fi

install.aux: $(srcdir)/install.tex
	latex $(srcdir)/install.tex
install/install.html: install.aux install.tex $(srcdir)/install.tex
	@if [ ! -s install.tex -a -s $(srcdir)/install.tex ] ; then \
	     cp $(srcdir)/install.tex . ; \
	elif cmp -s install.tex $(srcdir)/install.tex ; then : ; else \
	     cp $(srcdir)/install.tex . ; \
	fi
	latex2html install.tex

#
# Here are some thoughts on using tohtml
#	tohtml -debugfile -default -dosnl -gaudy \
#              -basedef $(srcdir)/../mpiman.def $(srcdir)/install.tex
#	tohtml -default -dosnl -gaudy -basedef $(srcdir)/../mpiman.def \
#	$(srcdir)/install.tex

all-redirect: install.pdf

mandoc:

htmldoc:

latexdoc: ALL

clean:
	-rm -f *.dvi *.log *.out *.aux *.toc *.bbl *.blg *.pdf *.ps

distclean: clean

install: install.pdf install/install.html
	@if [ -z "$(WEBDIR)" ] ; then echo "No WEBDIR set" ; exit 1 ; fi
	@if [ ! -d $(WEBDIR) ] ; then echo "Create $(WEBDIR) first" ; exit 1 ;fi
	@if [ -z "$(FTPDIR)" ] ; then echo "No FTPDIR set" ; exit 1 ; fi
	@if [ ! -d $(FTPDIR) ] ; then echo "Create $(FTPDIR) first" ; exit 1 ;fi
	cp install.pdf $(WEBDIR)/install.pdf
	cp -rp install $(WEBDIR)/install-new
	rm -rf $(WEBDIR)/install
	mv -f $(WEBDIR)/install-new $(WEBDIR)/install
	cp install.pdf $(FTPDIR)/install.pdf
	cp -rp install $(FTPDIR)/install-new
	rm -rf $(WEBDIR)/install
	mv -f $(FTPDIR)/install-new $(FTPDIR)/install
