MAX_TEX_RECURSION=4

XML_DECL=$(srcdir)/../stylesheets/xml.dcl
JADE_INCLUDE=-D $(builddir)/../common/

HTML_SS=$(srcdir)/../stylesheets/website.dsl
PRINT_SS=@DOCBOOK_DSL@

ENTITIES=$(srcdir)/../common/entities.xml
FDL=$(srcdir)/../common/fdl.xml

## Source files

faq_xml_source = cygwin-x-faq.xml
extra_faq_xml_source = biblio.xml \
	config.xml \
	contrib.xml \
	errors.xml \
	general.xml \
	glossary.xml \
	licptc.xml \
	install.xml \
	usage.xml \
	remote.xml \
	i18n.xml \
	trouble.xml \
	porting.xml \
	upgrade.xml

## Files generated by HTML build

extra_faq_html = \
	biblio.html \
	gfdl.html \
	glossary.html

## Files generated by other builds

if BUILD_HARDCOPY
extra_faq_ps = cygwin-x-faq.ps
extra_faq_ps_gz = cygwin-x-faq.ps.gz
extra_faq_pdf = cygwin-x-faq.pdf
extra_faq_dvi = cygwin-x-faq.dvi
extra_faq_tex = cygwin-x-faq.tex
extra_faq_rtf = cygwin-x-faq.rtf
else
extra_faq_ps =
extra_faq_ps_gz =
extra_faq_pdf =
extra_faq_dvi =
extra_faq_tex =
extra_faq_rtf =
endif
extra_faq_txt = cygwin-x-faq.txt

faqdir = $(docdir)/faq
faq_DATA = cygwin-x-faq.html $(extra_faq_html) $(extra_faq_ps_gz) \
	$(extra_faq_pdf) $(extra_faq_txt) $(extra_faq_rtf)
EXTRA_DIST = $(faq_xml_source) $(extra_faq_xml_source)

## Dependency rules follow

cygwin-x-faq.html $(extra_faq_html): $(HTML_SS) $(faq_xml_source)	\
	$(extra_faq_xml_source) $(ENTITIES) $(FDL)

$(extra_faq_tex): $(faq_xml_source) $(extra_faq_xml_source) $(ENTITIES) $(FDL)

$(extra_faq_dvi): $(extra_faq_tex)

$(extra_faq_ps): $(extra_faq_dvi)

$(extra_faq_ps_gz): $(extra_faq_ps)

$(extra_faq_pdf): $(extra_faq_dvi)

$(extra_faq_txt): $(faq_xml_source) $(extra_faq_xml_source) $(ENTITIES) $(FDL)

$(extra_faq_rtf): $(faq_xml_source) $(extra_faq_xml_source) $(ENTITIES) $(FDL)

## General rules follow

clean-local:
	rm -f *.htm *.html *.dvi *.tex *.ps *.pdf \
	*.txt *.log *.aux *.rtf *.gz *.out

validate:
	$(NSGMLS) -wmin-tag -s $(srcdir)/$(faq_xml_source)

## Support rules follow

$(extra_faq_tex):
	$(JADE) -t tex -V tex-backend -d $(PRINT_SS) $(JADE_INCLUDE) -o $@ $(XML_DECL) $(srcdir)/$(faq_xml_source)

## Trick from Adam Di Carlo <adam@onshore.com> to recurse jadetex 
## "just enough".
$(extra_faq_dvi):
	-cp -pf prior.aux pprior.aux
	-cp -pf $(shell basename $< .tex).aux prior.aux
	$(JADETEX) $<
	if ! cmp $(shell basename $< .tex).aux prior.aux &&		\
	   ! cmp $(shell basename $< .tex).aux pprior.aux &&		\
	   expr $(MAKELEVEL) '<' $(MAX_TEX_RECURSION); then		\
		rm -f $@						;\
		$(MAKE) $@						;\
	fi
	rm -f prior.aux pprior.aux

## Target rules follow

$(extra_faq_ps):
	dvips -f $< > $@

$(extra_faq_ps_gz):
	cat $< | gzip -f > $@

$(extra_faq_pdf):
	dvipdf -f $< > $@

cygwin-x-faq.html:
	$(NSGMLS) -wmin-tag -s $<
	$(JADE) -t xml -ihtml -d $(HTML_SS) $(JADE_INCLUDE) -o $@ $(XML_DECL) $(srcdir)/$(faq_xml_source)

$(extra_faq_txt):
	$(JADE) -t xml -V nochunks -d $(HTML_SS) $(JADE_INCLUDE) $(XML_DECL) $(srcdir)/$(faq_xml_source) > dump.html
	$(LYNX) -force_html -dump -nolist dump.html > $@
	-rm -f dump.html

$(extra_faq_rtf):
	$(JADE) -t rtf -d $(PRINT_SS) $(JADE_INCLUDE) -o $@ $(XML_DECL) $(srcdir)/$(faq_xml_source)
