#
# Copyright (C) 2017,2018,2019,2020,2021  John Gatewood Ham
#
# This file is for generating the book entitled
# "An Introduction to Programming with ECMA-55 Minimal BASIC"
#
# ecma55 is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation.
#
# ecma55 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ecma55.  If not, see <http://www.gnu.org/licenses/>.
#
.SUFFIXES:

LATEXOPTIONS=-interaction=nonstopmode -file-line-error

.PHONY:	all
all:	Learn_BASIC.pdf Learn_BASIC.ps

.NOTPARALLEL:	Learn_BASIC.pdf
Learn_BASIC.pdf:	Learn_BASIC.tex
	$(MAKE) clean
	-pdflatex $(LATEXOPTIONS) $<
	-pdflatex $(LATEXOPTIONS) $<
	-makeindex Learn_BASIC
	-pdflatex $(LATEXOPTIONS) $<
	-pdflatex $(LATEXOPTIONS) $<
	mv $@ $@.in
	qpdf --no-warn --warning-exit-0 --linearize $@.in $@ && rm -f $@.in
	chmod a=r $@

.NOTPARALLEL:	Learn_BASIC.ps
Learn_BASIC.ps:	Learn_BASIC.pdf
	pdftops -paper A4 -duplex -level3 $< $@

duplex:
	echo '<< /Duplex true >> setpagedevice' >duplex

.PHONY:	clean
clean:
	rm -f Learn_BASIC.aux Learn_BASIC.dvi Learn_BASIC.log Learn_BASIC.out \
	      Learn_BASIC.toc Learn_BASIC.lof Learn_BASIC.lot Learn_BASIC.idx \
	      Learn_BASIC.ilg Learn_BASIC.ind Learn_BASIC.xmpdata duplex pdfa.xmpi \
	      duplex.tex

.PHONY:	distclean
distclean:	clean
	rm -f Learn_BASIC.pdf Learn_BASIC.ps

.PHONY:	distcleaner
distcleaner:	distclean
	rm -f $(PREFLIGHT)
