# %auto-ignore
LATEX  = latex
BIBTEX = bibtex
DVIPS  = dvips
SHELL  = /bin/sh

MAINFILE=  paper.tex

TEXFILES =  ws-procs9x6.cls  rotating_pr.sty
AXISFILES=  BK.ax
FIGFILES =  
PSFILES  = 
#########################################################################
# special rules if any

#########################################################################
#									#
#                 NO USER SERVICEABLE PARTS BELOW !!!                   #
# 									#
#########################################################################


# List of all the sources
SOURCES= Makefile ${MAINFILE} ${TEXFILES} ${AXISFILES} ${FIGFILES} ${PSFILES}

# List of all postscript figures to be included.
PSINCLUSIONS= ${AXISFILES:.ax=.ps} ${FIGFILES:.fig=.ps} ${PSFILES}

# what is to be made by default
all: ${MAINFILE:.tex=.ps}

# re-dvips if any of these change
${MAINFILE:.tex=.ps}: ${MAINFILE:.tex=.dvi} ${PSINCLUSIONS}

# re-latex if any of these change
${MAINFILE:.tex=.dvi}: ${MAIN} ${TEXFILES} ${PSINCLUSIONS}

${MAINFILE:.tex=.bbl}: ${MAIN} ${TEXFILES} ${PSINCLUSIONS}
# Never try to `make' any of the sources
${SOURCES}:;

# The rest of them do not have any `extra' dependencies, i.e. a.x depends 
# obviously depends on a.y if a.x is to be created from a.y.

.PHONY: clean realclean
# clean removes ~ aux log and tmp files
clean:
	rm -f *~ *.aux *.log *.tmp
# real clean removes everything but sources and final products
realclean: clean
	rm -f ${AXISFILES:.ax=.ps} ${FIGFILES:.fig=.ps}

########################################################################
# General rules of how to build something from something else.
.SUFFIXES: .ps .dvi .tex .ax .xy .fig

# If .fig exists that is how to create ps.
%.ps: %.fig
	fig2dev -L ps $< > $@

# If .ax or .xy exist, that is the source of the .ps file
%.ps: %.ax
	xyplot $< | epsplot > $@.tmp
	sed -e "s/%%BoundingBox: (atend)/`psbbox $@.tmp | head -1`/p" \
            -e '/%%BoundingBox/d' $@.tmp > $@ 
	rm -f $@.tmp
%.ps: %.xy
	xyplot $< | epsplot > $@.tmp
	sed -e "s/%%BoundingBox: (atend)/`psbbox $@.tmp | head -1`/p" \
            -e '/%%BoundingBox/d' $@.tmp > $@ 
	rm -f $@.tmp

# else look for a dvi file.
%.ps: %.dvi
	$(DVIPS)  $< -o
%.dvi: %.tex
	$(LATEX) $< && $(LATEX) $< && $(LATEX) $<
	-while [ `grep '^Rerun ' $*.log` ]; do $(LATEX) $< ; done

# Save paper
%.ps2: %.ps
	pstops -w21cm -h29.7cm '2:0L@.65(1w,0)+1L@.65(1w,.45h)' $< | sed -e '1a\
	%%Orientation: Landscape' > $@

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

submission: ${SOURCES} ${PSINCLUSIONS} 
	rm -f submission.uu
	(echo "."; \
	 echo "${SOURCES} ${PSINCLUSIONS}" ; \
	 echo "submission") | uufiles -gz -9

