#
# Generic makefile for use with docbook
#
# v2.0 - gtaylor@picante.com

# The basename of your sgml file
# 
NAME=mumble

# List of figures.  Currently, this handles png-format raster graphics
# only.  The extentions to handle vector graphics are straightforward,
# but I haven't had to put one in yet.  I'll probably work from fig
# files.
#
FIGURES=snapshot-nose.png

INSTALLDIR=/home/gtaylor/lporg_html/howto
MISCDEP=ldp.dsl

# tadokoro@ask.or.jp   Japanese?


# default target for `make', a combination of ps, html, txt, or dvi
#
all: html pdf ps txt

install: all
	(cd $(NAME) ; (tar cf - . | (cd $(INSTALLDIR) ; tar xvf -)))
	cp $(NAME).txt $(NAME).pdf $(NAME).ps $(INSTALLDIR)

##################################################
#
# Targets:
#
# ps, txt, html, dvi, and ascii all do what they ought
# clean removes all output of above, including log files.
#
##################################################
#
# You shouldn't need to change anything below here
#
##################################################
#
# shortcut targets
#
html: $(NAME)/index.html

pdf: $(NAME).pdf

ps: $(NAME).ps

ascii: txt

txt: $(NAME).txt

clean: 
	rm -rf $(NAME).ps *.html $(NAME).txt *~ *.log *.dvi $(NAME)/ \
		$(NAME).aux $(NAME).tex $(NAME).toc  \
		one.html $(NAME).junk DBTOHTML_OUTPUT* \
		*.pdf *.gif *.eps \
		index.sgml HTML.index

$(NAME).ps: $(NAME).aux $(patsubst %.png,%.eps,$(FIGURES))
	jadetex $(NAME).tex
	jadetex $(NAME).tex
	dvips -D 600 $(NAME).dvi -o

$(NAME).pdf: $(NAME).aux $(patsubst %.png,%.pdf,$(FIGURES))
	pdfjadetex $(NAME).tex
	pdfjadetex $(NAME).tex

$(NAME).aux: $(NAME).tex 
	pdfjadetex $(NAME).tex

$(NAME).tex: $(NAME).sgml $(MISCDEP) index.sgml 
	jade -Vtex-backend -i output.print \
			-t tex -d ./ldp.dsl#print -o $(NAME).tex $(NAME).sgml

one.html: $(NAME).sgml  $(MISCDEP) 
	jade \
	  -d ./ldp.dsl#html \
          -t sgml -ihtml -c /etc/sgml.catalog \
	  -V nochunks > one.html < $(NAME).sgml

index.sgml: HTML.index
	./collateindex.pl -g -i document-index \
					-t Index -o index.sgml HTML.index

HTML.index: $(NAME).sgml
	db2html -d ../ldp.dsl $(NAME).sgml  || echo Ignore index.sgml error...
	mv $(NAME)/HTML.index .

$(NAME).txt: one.html
	w3m -S -cols 78 -dump one.html > $(NAME).txt

$(NAME)/index.html: index.sgml $(NAME).sgml $(MISCDEP) $(patsubst %.png,%.gif,$(FIGURES))
	db2html -d ../ldp.dsl $(NAME).sgml
	cp *.gif $(NAME)/



# Various automagical graphics converstion rules

%.pdf: %.eps
	epstopdf $< --outfile=$@

%.eps: %.png
	convert $< EPS2:$@

%.gif: %.png
	convert $< GIF:$@
