# makefile to process documents using RefDB citations/bibliographies

# the following section contains variable settings generated by
# the refdbnd script. Feel free to change the bibliography style
# if you have to resubmit your paper! Change the other values with
# care

# the switch for processing a doctype document with refdb. Available are
# 'db31' (all DocBook SGML versions), 'db31x' (DocBook XML),
# 'db50x' (DocBook XML V5), 'teix' (TEI P4), and 'tei5x' (TEI P5)
doctypeswitch = <doctypeswitch>

# the root element of your document. This is usually one of 'set', 'book',
# or 'article' for all DocBook variants, and 'TEI.2' for TEI
pubtype = <pubtype>

# the base name of your document
basename = <basename>

# the extension of your document
extension = <extension>

# the bibliography style to be used
stylename = <style>

# the character encoding to be used
encoding = <encoding>

# the RefDB-generated CSS file
cssfile=${stylename:.=}.css

# the CSS file the (x)html output should link to
customcssfile=<cssfile>

# the stylesheet driver files for PDF and HTML output
ifeq ($(stylename),raw)
stylearg = -r
ifeq ($(doctypeswitch),db31)
htmlstylesheet = db
xhtmlstylesheet = db
printstylesheet = db
endif

ifeq ($(doctypeswitch),db31x)
htmlstylesheet = db
xhtmlstylesheet = db
printstylesheet = db
endif

ifeq ($(doctypeswitch),db50x)
htmlstylesheet = db5
xhtmlstylesheet = db5
printstylesheet = db5
endif

ifeq ($(doctypeswitch),teix)
htmlstylesheet = tei
xhtmlstylesheet = tei
printstylesheet = tei
endif

ifeq ($(doctypeswitch),tei5x)
htmlstylesheet = tei5
xhtmlstylesheet = tei5
printstylesheet = tei5
endif

else # not raw
stylearg = -S $(stylename)
htmlstylesheet = ${stylename:.=}<htmlstylesheet>
xhtmlstylesheet = ${stylename:.=}<xhtmlstylesheet>
printstylesheet = ${stylename:.=}<printstylesheet>
endif

# options to use customized RefDB driver files, if any
fodriveropt = <fodriveropt>
htmldriveropt = <htmldriveropt>
xhtmldriveropt = <xhtmldriveropt>

# the database that contains the references
database = <database>

# the script that does the actual document transformation to the output formats
transformscript = <transformscript>

# output is different if we use a DSSSL processor
ifeq ($(doctypeswitch),db31)
all: ps pdf rtf html-dsssl
else
all: pdf xhtml
endif

ifeq ($(doctypeswitch),db31)
dist: psdist pdfdist rtfdist html-dsssl-dist
else
dist: pdfdist rtfdist xhtmldist
endif

ifeq ($(doctypeswitch),db31)
rtfarg = ""
else
rtfarg = "-f jfor"
endif

# if no custom css file is specified, use the default css file
ifeq ($(customcssfile),$(cssfile))
customcssfile = $(cssfile)
cssarchive = $(cssfile)
else
cssarchive = $(cssfile) $(customcssfile)
endif

pdf: $(basename).pdf

ps: $(basename).ps

rtf: $(basename).rtf

html: $(basename).html

html-dsssl: $(pubtype)1.html

xhtml: $(basename).xhtml

bib: $(basename).bib.$(extension)

full: $(basename).$(extension)

pdfdist: $(basename).pdf
	tar -czf $(basename).pdf.tar.gz $(basename).pdf

psdist: $(basename).ps
	tar -czf $(basename).ps.tar.gz $(basename).ps

rtfdist: $(basename).rtf
	tar -czf $(basename).rtf.tar.gz $(basename).rtf

htmldist: $(basename).html
	tar -czf $(basename).html.tar.gz *.html $(cssarchive)

html-dsssl-dist: $(pubtype)1.html
	tar -czf $(basename).html.tar.gz *.html $(cssarchive)

xhtmldist: $(pubtype)1.xhtml
	tar -czf $(basename).xhtml.tar.gz *.xhtml $(cssarchive)
clean:
	rm -f $(basename).pdf
	rm -f $(basename).ps
	rm -f $(basename).dvi
	rm -f $(basename).rtf
	rm -f $(basename).aux*
	rm -f $(basename).log
	rm -f $(basename).out
	rm -f $(basename).tex
	rm -f $(basename).fo
	rm -f *.html
	rm -f *.xhtml
	rm -f *.err
	rm -f HTML.manifest
	rm -f $(basename).bib.$(extension)
	rm -f $(basename).id.xml
	rm -f $(printstylesheet)
	rm -f $(htmlstylesheet)
	rm -f $(xhtmlstylesheet)
	rm -f $(cssfile)
	rm -f $(basename)*.tar.gz

shortclean: clean
	rm -f $(basename).$(extension)

$(basename).pdf: $(basename).$(extension) $(basename).bib.$(extension)
	$(transformscript) -s $(printstylesheet) -t pdf $(basename).$(extension)

$(basename).ps: $(basename).$(extension) $(basename).bib.$(extension)
	$(transformscript) -s $(printstylesheet) -t ps $(basename).$(extension)

$(basename).rtf: $(basename).$(extension) $(basename).bib.$(extension)
	$(transformscript) -s $(printstylesheet) -t rtf $(rtfarg) $(basename).$(extension)

$(basename).html: $(basename).$(extension) $(basename).bib.$(extension)
	$(transformscript) -s $(htmlstylesheet) -t html $(basename).$(extension)

$(pubtype)1.html: $(basename).$(extension) $(basename).bib.$(extension)
	$(transformscript) -s $(htmlstylesheet) -t html $(basename).$(extension)

$(basename).xhtml: $(basename).$(extension) $(basename).bib.$(extension)
	$(transformscript) -s $(xhtmlstylesheet) -t xhtml $(basename).$(extension)

$(basename).$(extension): $(basename).short.$(extension)
	refdbxp -t $(doctypeswitch) < $(basename).short.$(extension) > $(basename).$(extension)

$(basename).bib.$(extension): $(basename).$(extension)
	runbib $(fodriveropt) $(htmldriveropt) $(xhtmldriveropt) -d $(database) -G $(customcssfile) $(stylearg) -t $(doctypeswitch) -E $(encoding) $(basename).$(extension)
