#---*- Makefile -*-------------------------------------------------------
#$Author: saulius $
#$Date: 2020-06-04 12:55:15 +0300 (Thu, 04 Jun 2020) $
#$Revision: 243 $
#$URL: svn+ssh://saulius-grazulis.lt/home/saulius/svn-repositories/makefiles/pdflatex/Makelocal-pdflatex $
#------------------------------------------------------------------------

TEXINPUTS ?= ./texinputs:./text-parts:./bibliography::
BIBINPUTS ?= ./bibliography:./texinputs.::
BSTINPUTS ?= ./texinputs:.::

TEX_FILES ?= $(wildcard *.tex)
TEX_PARTS ?= $(wildcard text-parts/*.tex)
PDF_FILES ?= $(TEX_FILES:%.tex=%.pdf)

BIBLIOGRAPHY ?= $(shell perl -ne 'print $$1 . ".bib" if /\\bibliography\{(.*?)\}/' ${TEX_FILES})

# Executables to run:
LATEX  ?= pdflatex
BIBTEX ?= bibtex

.PHONY: all spell aspell clean distclean cleanAll
.PHONY: display latex bibtex

.PRECIOUS: %.bbl

all: ${PDF_FILES}

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

%.pdf: %.tex %.bbl ${TEX_PARTS}
	${LATEX} $<

%.pdf: %.tex ${TEX_PARTS}
	${LATEX} $<

%.bbl: ${BIBLIOGRAPHY}
	${LATEX} $*
	${BIBTEX} $*
	${LATEX} $*

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

.PHONY: clean-pdflatex distclean-pdflatex

clean-pdflatex:
	rm -f ${PDF_FILES}

distclean-pdflatex: clean-pdflatex
	rm -f ${TEX_FILES:%.tex=%.log}
	rm -f *.bbl
	rm -f *.blg
	rm -f *.aux
	rm -f *.toc
	rm -f *.out

clean: clean-pdflatex

distclean: distclean-pdflatex
