# Language
LANG=en_US.UTF-8

# Where is the htmlbook program
ifndef HTMLBOOK
HTMLBOOK=htmlbook
endif

# Resolution when converting from FIG to bitmaps
ifndef FIGPNGRES
FIGPNGRES=96
endif

TEXTFILES := $(wildcard *.txt)
HBTFILES  := $(wildcard *.hbt)
PRJFILES  := $(wildcard *.prj)

FIGIMAGES := \
	$(patsubst %.fig,%.png,$(wildcard *.fig)) \
	$(patsubst %.fig,%.pdf,$(wildcard *.fig)) \
	$(patsubst %.fig,%.svg,$(wildcard *.fig))

%.svg:	%.fig
	gxhconvert -o=svg $<

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

%.png:	%.fig
	gxhconvert -o=png -r=$(FIGPNGRES) -a $<
	optipng -q -i1 -zc1-9 -zm1-9 -zs0-3 -f0-5 $@

ICONS=	toc.png prev.png next.png index.png favicon.ico

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

webinstall:	$(TEXTFILES) $(HBTFILES) $(PRJFILES) $(FIGIMAGES) $(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) $(FIGIMAGES) $(ICONS)
	-[ ! -f htmlbook.sh ] || rm -f htmlbook.sh
	LANG=$(LANG) $(HTMLBOOK) -o chm index.prj
	chmod 755 htmlbook.sh
	./htmlbook.sh

icons:	toc.png prev.png next.png index.png

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 $@



clean:
	-rm $(FIGIMAGES)

favicon.ico:
	ln ../../../dkicon.ico favicon.ico

