#---*- Makefile -*-------------------------------------------------------
#$Author: saulius $
#$Date: 2020-06-04 09:55:15 +0000 (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:.::

LATEX ?= pdflatex

export TEXINPUTS BIBINPUTS BSTINPUTS

TEX_FILES = $(wildcard *.tex)

PDF_FILES = ${TEX_FILES:%.tex=%.pdf}
PS_FILES  = ${TEX_FILES:%.tex=%.ps}
RTF_FILES = ${TEX_FILES:%.tex=%.rtf}
WWW_FILES = ${TEX_FILES:%.tex=%.www}

PS_TARGETS  = $(wildcard ${PS_FILES:%=%*})
RTF_TARGETS = $(wildcard ${PDF_FILES:%=%*})

TEX_DEPENDS = ${TEX_FILES:%.tex=.%.d}

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

.PHONY: all
.PHONY: ps pdf rtf www html

all: pdf ${PS_TARGETS} ${RTF_TARGETS}

pdf:  ${PDF_FILES}
ps:   ${PS_FILES}
rtf:  ${RTF_FILES}
www:  ${WWW_FILES}
html: www

include ${TEX_DEPENDS}

.%.d: %.tex
	date +"# %F %T %Z" > $@
	mktexdepend $< | sed 's/\.dvi: /.pdf: /' >> $@

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

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

%.ps: %.pdf
	pdf2ps $< $@

%.www: %.tex
	([ -d $*.www ] && mv $*.www $*; true)
	latex2html $<
	mv $* $*.www

%.rtf: %.tex
	latex2rtf -o $@ $<

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

.PHONY: clean-pdflatex cleanMost-pdflatex cleanAll-pdflatex distclean-pdflatex
.PHONY: cleanps-pdflatex cleanpdf-pdflatex cleanrtf-pdflatex cleandvi-pdflatex

clean-pdflatex:
	rm -f *~
	rm -f ${TEX_DEPENDS}

cleanps-pdflatex:
	rm -f ${PS_FILES}

cleanpdf-pdflatex:
	rm -f ${PDF_FILES}

cleanrtf-pdflatex:
	rm -f ${RTF_FILES}

cleandvi-pdflatex:
	rm -f ${DVI_FILES}

cleanwww-pdflatex:
	rm -rf ${WWW_FILES}

cleanMost-pdflatex: clean-pdflatex
	rm -f *.log *.aux
	rm -f ${TEX_FILES:%.tex=%.bcf}
	rm -f ${TEX_FILES:%.tex=%.out}
	rm -f ${TEX_FILES:%.tex=%.run.xml}

cleanAll-pdflatex distclean-pdflatex: \
	clean-pdflatex cleanMost-pdflatex cleandvi-pdflatex cleanps-pdflatex \
	cleanpdf-pdflatex cleanrtf-pdflatex cleanMost-pdflatex

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

.PHONY: clean distclean cleanAll

clean: clean-pdflatex

cleanAll distclean: distclean-pdflatex
