#---*- Makefile -*-------------------------------------------------------
#$Author: saulius $
#$Date: 2019-09-01 16:53:22 +0300 (Sun, 01 Sep 2019) $
#$Revision: 220 $
#$URL: svn+ssh://saulius-grazulis.lt/home/saulius/svn-repositories/makefiles/biber/Makelocal-biber $
#------------------------------------------------------------------------
#*
# Generate bibliography lists for LaTeX using Biber.
#**
#*
# The behaviour of this Makefile is following:
#
# 1. 'make cleanAll' cleans all files that are produced by this
# Makefile.
#
# 2. in the clean directory, just typing 'make' builds the .dvi file
# with *correct* bibliographic references; it runs latex 3 times to
# fix the references and biber to produce the citation list for the
# article as appropriate.
#
# 3. Now, if you modify the source .tex file and say 'make', the latex
# will be run only once, which is much faster but can build some new
# references incorrectly. To run the full "3-latex procedure" again,
# either type 'make cleanAll; make' or touch the .bib file(s) and type
# make (or use make's -W option)
#**

# Define LATEX to be 'latex', 'pdflatex', or other *tex family
# typesetter.

LATEX ?= xelatex

# Where the generated files are stored. Must be consistent for
# (Xe)LaTeX, BibTeX and/or Biber. MUST end in a slash, or MAY be
# empty:

GENERATED_DIR ?= ./

BIBINPUTS ?= bibliography:texinputs
BSTINPUTS ?= bibliography:bibstyles:texinputs::

export BIBINPUTS BSTINPUTS

TEX_FILES ?= $(wildcard *.tex)

BBL_FILES ?= ${TEX_FILES:%.tex=${GENERATED_DIR}%.bbl}
BLG_FILES ?= ${TEX_FILES:%.tex=${GENERATED_DIR}%.blg}
BCF_FILES ?= ${TEX_FILES:%.tex=${GENERATED_DIR}%.bcf}
XML_FILES ?= ${TEX_FILES:%.tex=${GENERATED_DIR}%.run.xml}

.PRECIOUS: %.aux %.bbl

# Additional dependency for %.dvi (via LaTeX) and %.pdf (via XeLaTeX):

%.dvi: %.bbl

%.pdf: %.bbl

%.bbl:
	${LATEX} $(notdir $*)
	( cd ${GENERATED_DIR}; biber $(notdir $*) )
	${LATEX} $(notdir $*)
	date +"%% %F %T %Z" >> $@

.PHONY: biber

biber: ${BBL_FILES}

%.bbl: %.bcf
	biber $*

%.bcf: %.tex
	${LATEX} $*

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

.PHONY: distclean-bbl

distclean-bbl:
	rm -f ${BBL_FILES}
	rm -f ${BLG_FILES}
	rm -f ${BCF_FILES}
	rm -f ${XML_FILES}

.PHONY: distclean

cleanAll distclean: distclean-bbl
