
#  type:
#
#  `make'               to create a PDF version of the manual in this dir
#                         (needs a working LaTeX package)
#  `make publish'       to copy it to the ^/doc dir
#  `make distclean'     to also clean all temporary files
#  `make realclean'     to clean everything but sources


# ----------------------------------------------------------------------
#  project-dependent variables (user defined)
# ----------------------------------------------------------------------

GOALS = \
orac-manual.pdf

TMP_FILES = 

# ----------------------------------------------------------------------

FILES_TIDY = *.aux *.log *.bbl *.blg *.bm *.brf *.cb *.ind *.idx *.ilg *.inx *.dvi *.toc *.out $(TMP_FILES)
FILES_CLEAN = $(GOALS)

# ----------------------------------------------------------------------
#  definition of commands to make targets (system defined)
# ----------------------------------------------------------------------

LATEX = latex
BIBTEX = bibtex
# use TeX4ht package; invoking it through `mk4ht' has files listed in ./.mk4ht cleaned
LATEX2HTML=mk4ht htlatex
###LATEX2HTML = latex2html
PS2PDF = ps2pdf
DVIPS = dvips 

LYX2TEX = lyx -e latex 
## LYX2TEX = lyx -e latex -f main  # use this in LyX 1.6.7
L2H_ONEFILE_OPTS = 
##L2H_ONEFILE_OPTS = -split 0 -nonavigation -noinfo -noaddress  -nosubdir -short_extn -no_auto_link 

# Does not catch lines like "(natbib)                Rerun to get citations correct."
#RERUN = "(There were undefined references|Rerun to get (cross-references|the bars) right)"
RERUN = "(There were undefined references|Rerun to get)"
#RERUN = "Rerun to"
RERUNBIB = "No file.*\.bbl|Citation.*undefined"

COPY = if test -r $*.toc; then cp $*.toc $*.toc.bak; fi
RM = /bin/rm -f

# ----------------------------------------------------------------------
#  pattern rules
# ----------------------------------------------------------------------

%.dvi:          %.tex
	$(COPY);$(LATEX) $<
	egrep -c $(RERUNBIB) $*.log && ($(BIBTEX) $*;$(COPY);$(LATEX) $<) ; true
	egrep $(RERUN) $*.log && ($(COPY);$(LATEX) $<) ; true
	egrep $(RERUN) $*.log && ($(COPY);$(LATEX) $<) ; true
	if cmp -s $*.toc $*.toc.bak; then true ;else $(LATEX) $< ; fi
# make index
	if [ -f $*.idx ]; then echo "=== Making index ==="; makeindex $*; $(LATEX) $< ; fi
	$(RM) $*.toc.bak
# Display relevant warnings
	egrep -i "(Reference|Citation).*undefined" $*.log ; true

%.ps:           %.dvi
	$(DVIPS) $< -o $@

%.pdf:          %.ps
	$(PS2PDF) $<

# .html will be made from .tex 
%.html : %.tex
	$(LATEX2HTML) $(L2H_ONEFILE_OPTS) $<



# ----------------------------------------------------------------------
#  general targets
# ----------------------------------------------------------------------

all:            $(GOALS)

# ----------------------------------------------------------------------------------
#  publish files on local and remote server
# ----------------------------------------------------------------------------------

PUBLISH = $(GOALS)
# directory where final copies will be published
PUB_DIR = ../..
PUBLISHED = $(patsubst %, $(PUB_DIR)/%, $(PUBLISH))


publish: $(PUBLISHED)

$(PUBLISHED): 	src=$(filter %$(notdir $@), $? )
$(PUBLISHED): 	tgt=$(PUB_DIR)/$(notdir $(filter %$(notdir $@), $? ))
$(PUBLISHED): $(PUBLISH)

# Multiple target with multiple prereqs!
# This rule applies for _any_ target if _any one_ of the prereqs is newer.

# Definitions of $(src), $(tgt):
#
# We must select the ONE name in the prerequiste list that matches the
# filename of the target, without the directory part, e.g.
#     split1/Corsi.html <- /u/lx01/signo/public_html/www-cdl/T/Corsi.html 
# This is done by the filter function. 

# Also: only those prerequisites that are newer than the target ($?) 
# are considered for the match. And, the command is executed (first
# argument to the if function) only if this one name is not the null
# string

# strip any leading/trailing/multiple spaces first
	$(if $(strip $(src)), \
         diff -q $(src) $(tgt) || ( rm -r $(tgt); cp -R $(src) $(tgt) ) , )


# ----------------------------------------------------------------------
#  service targets
# ----------------------------------------------------------------------

tidy:
	rm -f $(FILES_TIDY)

clean: tidy
	rm -f $(FILES_CLEAN) 

clean_pub:
	-rm -rf $(PUBLISHED)

realclean: clean clean_pub

distclean: publish clean

type_all_src:
	@ echo $(TEX_FILES) $(orac-manual.PSFIG) $(orac-manual.BIB)


# ----------------------------------------------------------------------
#  dependencies of text files on (compiled) figures and bibliography
# ----------------------------------------------------------------------

TEX_FILES = \
analys.tex \
chapter_atomistic-simulations-an-introduction.tex \
chapter_compiling-and-running-orac.tex \
chapter_input-to-orac.tex \
chapter_metadynamics-Simulation-history-dependent-algorithms-in-non-boltzmann-sampling.tex \
chapter_MTS-algorithms-for-large-size-flexible-systems-with-strong-electrostatic-interactions.tex \
chapter_MTS-algorithms-for-NPT-ensemble.tex \
chapter_replica-exchange-method.tex \
chapter_serial-generalized-ensemble-simulations.tex \
chapter_steered-molecular-dynamics.tex \
chapter_symplectic-and-reversible-integrators.tex \
inout.tex \
integrat.tex \
meta.tex \
orac-manual.tex \
paramete.tex \
potentia.tex \
properti.tex \
rem.tex \
run.tex \
setup.tex \
sge.tex \
simulati.tex \
solute.tex \
solvent.tex \
tpgprm.tex \


# PS/EPS figure files in 'orac-manual.tex':
orac-manual.PSFIG 	= \
alpha.eps \
cpu.eps \
gaussian.eps \
int-alpha.eps \
int-kc.eps \
kc.eps \
lagr.eps \
lucy2.eps \
sf.eps \
smd2.eps \
smd.eps \
spct.eps \
tors.eps \
traiettoriarepliche2.eps \
triple.eps \
vacf.eps \
vacf_tors.eps\
Figures*/* 


# bibliography
orac-manual.BIB = orac-manual.bib


# dependencies on figure files:
# don't set a .dvi or .ps file as the target, 
#    otherwise it will not be considered "intermediate"
orac-manual.pdf 		: $(TEX_FILES) $(orac-manual.PSFIG) $(orac-manual.BIB)


