# Makefile to test if installed TeX  is working
# originally by Ken Moffat (ken at linuxfromscratch dot org)
# licensed under the MIT License: http://opensource.org/licenses/MIT
#
# This is intended to create PDF files on A4 paper.  Other paper
# sizes probably work, but might spill onto multiple pages (latex,
# lualatex) or oddly (encyclopedium)

# copy the latex file to a working directory
# and run it
#
# Dependencies:
# for latex
#	installed TeX Live or equivalent
#	- do not forget to ensure that the TeX binaries can be executed
#	(in BLFS we put them in /opt/texlive/${tex-YYYY}/${tex-ARCH}/bin)
#	gnu make
#	rm
#	Xorg
#	a PDF viewer so that you can view the results
# for lualatex, add
#	gnu sed
#	fontconfig
#	either DejaVuSerif.ttf or FreeSerif.otf installed below /usr/share/fonts
#	 or, perhaps, somewhere else acceptable to fontconfig.
#
# for picture the above deps are sufficient, but it must be run from an Xterm
# or equivalent.
#
# for encyclopedium, the same deps as for lualatex.
#
# Usage:
#	if you just run 'make', it will 'make latex' to create latex.pdf
#	which you can then review.
#
#	'make lualatex' will look for DejaVuSerif.ttf,
#	or failing that FreeSerif.otf, in either case creating font.name.
#	This is then use to control the creation of lualatex.tex from lualatex.in
#	and then lualatex is run to create lualatex.pdf for your review.
#
#	'make picture' uses asymptote to create picture.pdf
#
#	'make encyclopedium' - create encyclopedium.pdf to test xindy.
#
#	`make bibertest' - a test of biber which I found online,
#	it creates a single page with annotations.
#
#	'make clean' removes aux, log, and out files and also the
#	.pre andpicture-?.{asy,pdf} created while making picture,
#	and all the .b?? files from biber.
#
#	'make really-clean' invokes 'make clean' and also removes
#	font.name, lualatex.tex, and any pdf files


.PHONY : clean really-clean

all:	latex lualatex picture encyclopedium bibertest
	touch all

latex:
	pdflatex latex.tex

font.name:
	fc-list | grep -q DejaVuSerif.ttf && echo 'DejaVu Serif' >font.name ;\
	if [ $$? -ne 0 ]; then \
	 fc-list | grep -q FreeSerif.otf && echo 'FreeSerif' >font.name ; \
	fi

lualatex.tex: font.name
	cat lualatex.in | sed "s/FONT/$$(cat font.name)/" >lualatex.tex

lualatex: lualatex.tex
	lualatex lualatex.tex

picture:
	pdflatex picture.tex
	asy picture-*.asy
	pdflatex picture.tex

encyclopedium.tex: font.name
	cat encyclopedium.in | sed "s/FONT/$$(cat font.name)/g" >encyclopedium.tex

encyclopedium: encyclopedium.tex
	lualatex encyclopedium.tex
	makeglossaries encyclopedium
	lualatex -shell-escape encyclopedium.tex

bibertest:
	pdflatex bibertest
	biber bibertest
	pdflatex bibertest

clean:
	-rm -f *.{aux,b??,gl?,idx,log,out,pre,xdy} {encyclopedium,picture}-*.* font.name all

really-clean: clean
	-rm -f encyclopedium.tex lualatex.tex *.pdf

