#
# Rules for misc litprog tools
# (c) 1999 Yann Dirson <dirson@debian.org>
#

#  Ideally we should not have to explicitely use the *Products rules,
# but I don't know yet how to autocompute files to be produced.  Could this
# be a Jam limitation ?
#  For now the *Products rules are used to trigger the weave process.  They
# should be invoked by the same wrappers that should invoke *Products.

# Use with something like:
#
# include "Jamrules-litprog" ;
# FunnelwebProducts ydSLitProg.dtd : ydSLitProg.fw ;
# FwebProducts ydSLitProg.dtd : ydSLitProg.fweb ;
#


NOTFILE tex html ;

# Fweb

rule FwebProducts
{
	# tangle
	Depends $(<) : $(>) ;
	Clean clean : $(<) ;

	# weave
	FwebLatex $(>:S=.tex) : $(>) ;
	Depends tex : $(>:S=.tex) ;
}

actions FwebProducts { ftangle $(>) }

rule FwebLatex
{
	Depends $(<) : $(>) ;
	Clean clean : $(<) MODULES.tex INDEX.tex ;
	# FIXME: the following should be autodetected by LatexDvi instead
	Depends $(<:S=.dvi) : MODULES.tex INDEX.tex ;

	Latex $(<) ;
}

actions FwebLatex { fweave $(>) }


# Cweb

rule CwebProducts
{
	Depends $(<) : $(>) ;
}

actions CwebProducts
{
	ctangle $(>)
}


# Funnelweb
#  note: we attempt to emulate standard UN*X behaviour by using the .lis
# output file, which we do not leave behind.

rule FunnelwebProducts
{
	Depends $(<) : $(>) ;
	Clean clean : $(<) ;
}

actions FunnelwebProducts
{
	# tangle
	fw +L $(>)
	cat $(>:S=.lis)
	rm -f $(>:S=.lis)

	# weave
	FunnelwebTex $(>:S=.tex) : $(>) ;
	Depends tex : $(>:S=.tex) ;
	FunnelwebHtml $(>:S=.html) : $(>) ;
	Depends html : $(>:S=.html) ;
}

rule FunnelwebTex
{
	Depends $(<) : $(>) ;
	Clean clean : $(<) ;

	Tex $(<) ;
}

actions FunnelwebTex
{
	fw +L -O +T $(>)
	cat $(>:S=.lis)
	rm -f $(>:S=.lis)
}

rule FunnelwebHtml
{
	Depends $(<) : $(>) ;
	Clean clean : $(<) ;
}

actions FunnelwebHtml
{
	fw +L -O +U $(>)
	cat $(>:S=.lis)
	rm -f $(>:S=.lis)
}


# Tex / LaTeX

NOTFILE dvi ;

rule Latex
{
	LatexDvi $(<:S=.dvi) : $(<) ;
	Depends dvi : $(<:S=.dvi) ;
}

rule LatexDvi
{
	Depends $(<) : $(>) ;
	Clean clean : $(<) $(<:S=.log) $(<:S=.toc) $(<:S=.aux) ;
}

actions LatexDvi
{
	while latex $(>) |
		tee /dev/tty |
		fgrep "Label(s) may have changed." >/dev/null
	do :
	done
}
