## We don't know what you expect, but it is really -*- makefile -*-
## Copyright (C) 2005,2008 DMTCS
## Author: Jens Gustedt < Jens Gustedt [AT] dmtcs org>
##
############ REQUIRED TOOLS #######################
##
## You may simply overwrite these on the make commandline
## with arguments like LATEX=lytex
##
LATEX = latex
PDFLATEX = pdflatex
DVIPS = dvips
PS2PDF = ps2pdf
PDF2PS = pdftops
TAR = tar --create --dereference --gzip --verbose
GZIP = gzip -9
MV = mv -f
CP = cp -f
RM = rm -f
DIFF = diff -awq
MKDIR = mkdir -p
TOUCH = touch
PERL = /usr/bin/perl -w -s
##
## There should be nothing to change beyond this point.
##
############ TARGETS ##############################
## The meta information about the volume.
## Edit them accordingly.
META = paperlist.txt volume-info.tex
## The directories of the individual papers
DIRS = ${shell cat paperlist.txt}
## plus the target directories
ALLDIRS = ${DIRS} pdfpapers pspapers ps.gzpapers
## The latex sources
TEXS = ${foreach dir,${DIRS},${dir}/${dir}.tex}
## The files that come with this distribution
DISTR =	${META}\
	firstPaper secPaper thirdPap lastOne\
	dmtcs.cls dmtcs-front.sty header.tex\
	Makefile\
	gen_prevs.pl\
	buildPlain.pl html-TeX.pl\
	README.txt\
	frontpage-sample.tex\
	dmtcs.eps dmtcs.pdf
DDISTR = ${foreach file,${DISTR},sample-conference/${file}}
## The files that are proceduce to forward the
## page information from one paper to another
HEADERS = ${foreach dir,${DIRS},${dir}/header.tex}
## Tells each directory where its predecessor is found.
PREVS = ${foreach dir,${DIRS},${dir}/previous.tex}
## Intermediate files
## The links to the class file.
CLSS = ${foreach dir,${DIRS},${dir}/dmtcs.cls}
PDFS = ${foreach dir,${DIRS},${dir}/${dir}.pdf}
PSS = ${foreach dir,${DIRS},${dir}/${dir}.ps}
AUXS = ${foreach dir,${DIRS},${dir}/${dir}.aux}
DVIS = ${foreach dir,${DIRS},${dir}/${dir}.dvi}
LOGS = ${foreach dir,${DIRS},${dir}/${dir}.log}
########### CLASSIFICATION OF THE TARGETS #######
.SECONDARY : ${PREVS} ${HEADERS}
.INTERMEDIATE : ${AUXS} ${DVIS} ${LOGS} ${CLSS} ${DIRS} .touch
.PHONY : clean distclean
############ RULES ###############################

prevs : ${PREVS}

headers : ${HEADERS}

gentoc.tex Makefile-inc : ${META} gen_prevs.pl
	${PERL} ./gen_prevs.pl < paperlist.txt

${PREVS}: %/previous.tex : ${META} gen_prevs.pl
	${PERL} ./gen_prevs.pl -target=${@D} < paperlist.txt

${HEADERS}: %/header.tex : ${META}
	(cd ${@D} && ${LATEX} ${@D})

${CLSS}: %/dmtcs.cls : dmtcs.cls
	ln -s ../dmtcs.cls $@

${PSS}: %.ps : %.tex
	(cd ${@D};						      \
	    ( [ -r nops ]					      \
			&& ( ${PDFLATEX} "\nonstopmode\input{${@D}}"; \
			     ${PDFLATEX} "\nonstopmode\input{${@D}}"; \
			     ${PDFLATEX} "\nonstopmode\input{${@D}}"; \
			     ${PDF2PS} ${@D}.pdf;		      \
                             true )				      \
			)					      \
		|| ( ${LATEX} "\nonstopmode\input{${@D}}";	      \
                     ${LATEX} "\nonstopmode\input{${@D}}";	      \
		     ${LATEX} "\nonstopmode\input{${@D}}";	      \
                     ${DVIPS} ${@D} -o ${@D}.ps ) )

${PDFS}: %.pdf : %.tex %.ps
	( cd ${@D} && ( [ -r nopdf ] 				 \
			&& ( ${PS2PDF} ${@D}.ps; true ) )	 \
		|| ( ${PDFLATEX} "\nonstopmode\input{${@D}}";	 \
		     ${PDFLATEX} "\nonstopmode\input{${@D}}";	 \
		     ${PDFLATEX} "\nonstopmode\input{${@D}}" ) )

ps.gzpapers/%.ps.gz : pspapers/%.ps
	${CP} $< tmp.ps && ${GZIP} tmp.ps && ${MV} tmp.ps.gz $@

${ALLDIRS} : paperlist.txt
	-${MKDIR} ${ALLDIRS}

%.tgz :
	-${MAKE} clean
	${TAR} --file=$@ ${ALLDIRS}

dirs : ${ALLDIRS}

clss : ${CLSS}

previous : ${PREVS}

psgz : ps

pdf : ps ${PDFS}

ps : ${ALLDIRS} ${PSS}

all : ${ALLDIRS} psgz ps pdf .touch

distclean : clean tgzclean
	${RM} ${HEADERS} ${PREVS} gentoc.tex Makefile-inc
	${RM} -r pdfpapers pspapers ps.gzpapers

clean :
	${RM} ${AUXS} ${DVIS} ${LOGS} ${CLSS}

../dmtcs-proc-kit.tgz : ${DISTR}
	-${MAKE} clean
	(cd ..; ${TAR} --file=${@F} '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.cvsignore' '--exclude=.gitignore' ${DDISTR})

distri : ../dmtcs-proc-kit.tgz

include Makefile-inc

