
#
# CONFIGURATION:
# Set language here.
# If your LANG environment variable ends on ``.UTF-8'' or ``.utf8''
# you have to use the same suffix here.
#
ifndef LANG
LANG=en_US.UTF-8
endif

#
# CONFIGURATION:
# How to run the htmlbook program?
#
ifndef HTMLBOOK
HTMLBOOK=htmlbook
endif

#
# CONFIGURATION:
# Resolution when converting from vector to bitmaps.
# Higher values create larger images.
#
ifndef FIGPNGRES
FIGPNGRES=96
endif

#
# If one of the *.prj, *.hbt or *.txt files was modified,
# we have to rebuild all.
#
TEXTFILES := $(wildcard *.txt)
HBTFILES  := $(wildcard *.hbt)
PRJFILES  := $(wildcard *.prj)

#
# All *.fig images, *.gp plots and *.tex files (formulas) are
# converted to *.png, *.pdf and *.svg.
#
IMAGES := \
	$(patsubst %.fig,%.png,$(wildcard *.fig)) \
	$(patsubst %.fig,%.pdf,$(wildcard *.fig)) \
	$(patsubst %.fig,%.svg,$(wildcard *.fig)) \
	$(patsubst %.gp,%.png,$(wildcard *.gp)) \
	$(patsubst %.gp,%.pdf,$(wildcard *.gp)) \
	$(patsubst %.gp,%.svg,$(wildcard *.gp)) \
	$(patsubst %.tex,%.png,$(wildcard *.tex)) \
	$(patsubst %.tex,%.pdf,$(wildcard *.tex)) \
	$(patsubst %.tex,%.svg,$(wildcard *.tex))

#
# Suffixes for graphics files
#
.SUFFIXES:	.png .svg .pdf .tex .fig .gp

#
# Graphics conversion rules
#
.tex.pdf:
	gxhconvert -o=pdf $<

.fig.pdf:
	gxhconvert -o=pdf $<

.gp.pdf:
	gxhconvert -o=pdf $<

.pdf.svg:
	gxhconvert -o=svg $<

#
# CONFIGURATION:
# If you do not need transparency, remove the -a option from the
# gxhconvert command below.
#
.svg.png:
	gxhconvert -o=png -r=$(FIGPNGRES) -a $<
	optipng -q -i1 -zc1-9 -zm1-9 -zs0-3 -f0-5 $@

#
# Names of icon files
#
ICONS=	toc.png prev.png next.png index.png

#
#	The first target is the default target.
#
install:	$(TEXTFILES) $(HBTFILES) $(PRJFILES) $(IMAGES)
	-[ ! -f htmlbook.sh ] || rm -f htmlbook.sh
	LANG=$(LANG) $(HTMLBOOK) index.prj
	chmod 755 htmlbook.sh
	./htmlbook.sh

webinstall:	$(TEXTFILES) $(HBTFILES) $(PRJFILES) $(IMAGES) $(ICONS)
	-[ ! -f htmlbook.sh ] || rm -f htmlbook.sh
	LANG=$(LANG) $(HTMLBOOK) -o web index.prj
	chmod 755 htmlbook.sh
	./htmlbook.sh

chminstall:	$(TEXTFILES) $(HBTFILES) $(PRJFILES) $(IMAGES)
	-[ ! -f htmlbook.sh ] || rm -f htmlbook.sh
	LANG=$(LANG) $(HTMLBOOK) -o chm index.prj
	chmod 755 htmlbook.sh
	./htmlbook.sh

#
# Icons
#

toc.png:	toc.fig
	gxhconvert -o=png -r=36 -a toc.fig
	optipng -q -i1 -zc1-9 -zm1-9 -zs0-3 -f0-5 $@

prev.png:	prev.fig
	gxhconvert -o=png -r=36 -a prev.fig
	optipng -q -i1 -zc1-9 -zm1-9 -zs0-3 -f0-5 $@

next.png:	next.fig
	gxhconvert -o=png -r=36 -a next.fig
	optipng -q -i1 -zc1-9 -zm1-9 -zs0-3 -f0-5 $@

index.png:	index.fig
	gxhconvert -o=png -r=36 -a index.fig
	optipng -q -i1 -zc1-9 -zm1-9 -zs0-3 -f0-5 $@


