#
# Create:
# - tangleboot from a saved bootstrap
# - tangle from tangleboot 
# - weave from tangle
#
PROG=	tangle weave
MAN=	${PROG:=.1} 
PC=	fpc
PFLAGS=	-Miso -Cr -Co
#PFLAGS+= -dDEBUG -dSTAT 	# weave has trouble with DEBUG, more .ch needed


all: tangleboot ${PROG} ${PROG:=.tex}

.SUFFIXES:		# GNU make wants to use its own .p compile rule.
.SUFFIXES: .ch .tex .p
.ch.tex:
	./weave dist/web/$*.web $*.ch $*.tex
.ch.p:
	./tangle dist/web/$*.web $*.ch $*.p $*.pool
.p:
	${PC} ${PFLAGS} $?

clean:
	rm -f ${PROG:=.p} *.o ${PROG} *.log *.pool tangleboot *.tex

#
# tangle needs tangle to create itself, tangleboot is a previous copy 
# provided to do that.
#
tangle.p: tangleboot
	./tangleboot dist/web/tangle.web tangle.ch tangle.p tangle.pool

tangle.tex: weave
weave.tex: weave

install:
	${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} \
		-m ${BINMODE} ${PROG} ${PREFIX}/bin
	cd local/man1 && ${INSTALL} ${INSTALL_COPY} -m 0644 ${MAN} \
		${PREFIX}/man/man1

	mkdir -p ${PREFIX}/share/doc/tex
	${INSTALL} ${INSTALL_COPY}  -m 0644 dist/web/webman.tex ${PROG:=.tex} \
		${PREFIX}/share/doc/tex
