# Copyright (c) 2007-2010, Andrew Deason
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.

XML = resume.xml
XSLDIR = xsl/
PDFLATEX = pdflatex -interaction=batchmode
LATEX = latex -interaction=batchmode
GZIP = gzip
DVIPS = dvips -z
XSLT = xsltproc
PARAMS = --stringparam lastmod "$(shell date --utc +"%e %B %Y %H:%M %Z")" --stringparam text.width 81

# If there is some way to get latex and dvips to not generate these, I'd
# like to hear it
TEX_TMP = resume.log resume.aux resume.out
DVIPS_TMP = head.tmp body.tmp

all: html xhtml pdf ps dvi txt rtf roff
html: resume.html
xhtml: resume.xhtml
pdf: resume.pdf
ps: resume.ps.gz
dvi: resume.dvi
txt: resume.txt
rtf: resume.rtf
roff: resume.roff

clean:
	rm -f resume.html resume.xhtml resume.pdf resume.ps.gz resume.ps resume.tex resume.txt resume.roff

resume.xml:
resume.pdf: resume.tex
	$(PDFLATEX) -output-directory . $<
	rm -f $(TEX_TMP)

resume.ps.gz: resume.dvi
	$(DVIPS) $<
	rm -f $(DVIPS_TMP)
	$(GZIP) -c resume.ps > resume.ps.gz.tmp
	rm -f resume.ps
	mv -f resume.ps.gz.tmp resume.ps.gz

resume.dvi: resume.tex
	$(LATEX) -output-directory . $<
	rm -f $(TEX_TMP)

# Double-colon prevents resume.xml and resume.pdf from also getting processed
# by this. Not sure if this is "proper" usage or not, but the GNU manual section
# on double-colons is a bit confusing.
resume.%:: resume.xml $(XSLDIR)/resume-%.xsl
	$(XSLT) -o resume.$*.tmp $(PARAMS) $(XSLDIR)/resume-$*.xsl resume.xml
	mv -f resume.$*.tmp resume.$*

.PHONY: all html xhtml pdf ps dvi txt rtf roff
