### NB, this probably requires GNU make

# very simple-mined way of doing things -- runs latex 3 times whenever
# anything changes

# Definition of the main file.  We basically want to run LaTeX on the
# file $(MAIN) to produce $(ROOT).dvi.
ROOT = manual
MAIN = $(ROOT).tex
LATEX = latex#2e

# These are the files which are \include'd:
INCLUDES = installation.tex overview.tex running.tex \
  intro.tex porting.tex fft.tex ir.tex preface.tex \
  solflat.tex licence.tex proc-reduc.tex refine.tex support.tex formats.tex \
  proglist.tex frontmatter.tex molrep.tex resources.tex writing.tex

# Any other files which are \input:
INPUTS = diff-map.tex patterson.tex solflat-fig.tex startup.tex \
   blackboard.eps combination.eps wizard.eps refine1.eps

# These are all the bibliography files needed:
BIBFILES = ccp4-manual.bib

.SUFFIXES: .ps .dvi

.PHONY:	clean veryclean

%.ps: %.dvi
#	dvips -Plw -o $@ $<     # for master copy
	dvips -o $@ $<		# for distribution

# This is how to make the .ind file from the .idx one:
%.ind: %.idx
	if [ -s $< ]; then makeindex  $<; fi

%.prd: %.prx
	if [ -s $< ]; then makeindex -o $@ -s prg.ist  $<; fi


%.cpd: %.cpx
	if [ -s $< ]; then makeindex -o $@ -s prg.ist  $<; fi

default: $(ROOT).dvi

# Making the .bbl file.  The leading `-' is to avoid stopping when
# BibTeX gives a warning.
$(ROOT).bbl: $(BIBFILES) $(ROOT).aux
	-if test -f $(ROOT).aux;then bibtex $(ROOT); \
	else rm -f $(ROOT).bbl; exit 1;fi

$(ROOT).dvi: $(MAIN) $(INCLUDES)
	$(LATEX) $(MAIN) || rm $(ROOT).dvi
	$(MAKE) $(ROOT).bbl $(ROOT).prd $(ROOT).cpd
	$(LATEX) $(MAIN) || rm $(ROOT).dvi
	$(MAKE) $(ROOT).bbl $(ROOT).prd $(ROOT).cpd  $(ROOT).ind
	$(LATEX) $(MAIN) || rm $(ROOT).dvi

clean:
	$(RM) *.dvi *.log *.ilg *.blg manual.ps

veryclean:
	$(RM) *.dvi *.log *.aux *.ilg *.blg *.toc *.ind *~
