

all: ctex ctex.dvi


cweb/cweave.w: cweave.patch 
	patch --verbose cweb/cweave.w cweave.patch

cweb/ctangle.w: ctangle.patch 
	patch --verbose cweb/ctangle.w ctangle.patch

cweb/common.w: common.patch 
	patch --verbose cweb/common.w common.patch

CWEAVE=cweb/cweave
CTANGLE=cweb/ctangle

cweb/ctangle: cweb/ctangle.w cweb/common.w
	cd cweb ;\
	if [ ! -x ./ctangle ] ; then $(CC) $(CFLAGS) -o ctangle ctangle.c common.c ; fi ;\
	./ctangle ctangle.w ; \
	./ctangle common.w ; \
	$(CC) $(CFLAGS) -o ctangle ctangle.c common.c ; \
	cd ..

cweb/cweave: $(CTANGLE) cweb/cweave.w cweb/common.w
	cd cweb ;\
	./ctangle cweave.w ; \
	./ctangle common.w ; \
	$(CC) $(CFLAGS) -o cweave cweave.c common.c ; \
	cd ..


web.lex.c : web.l web2w.h pascal.tab.h
	flex -o web.lex.c web.l

pascal.tab.c pascal.tab.h: pascal.y
	bison -d -v $(NAMEPREFIX) pascal.y

web2w.c web2w.h: $(CTANGLE) web2w.w
	$(CTANGLE) web2w.w


web2w: web2w.c web.lex.c pascal.tab.c
	$(CC) -o web2w web2w.c web.lex.c pascal.tab.c

web2w.tex: $(CWEAVE) web2w.w
	$(CWEAVE) web2w.w

ctex.w: tex.w
	patch --verbose -o ctex.w tex.w ctex.patch

tex.w: web2w
	./web2w -o tex.w tex/tex.web

ctex.c: $(CTANGLE) ctex.w
	$(CTANGLE) ctex.w

ctex.tex: $(CWEAVE) ctex.w
	$(CWEAVE) ctex.w

ctex: ctex.c 
	$(CC) ctex.c -lm -o ctex

cinitex: ctex.c 
	$(CC) -DINIT ctex.c -lm -o cinitex


ctex.pdf: ctex.tex
	pdftex ctex.tex


plain.fmt: cinitex
	echo "plain \\dump" | ./cinitex 
	cp plain.fmt TeXformats/

ctex.dvi: ctex ctex.tex plain.fmt
	echo "&plain ctex" | ./ctex



clean:
	rm -f *.idx *.log *.dvi *.scn *.toc *~
	rm -f cinitex ctex web2w
	$(MAKE) -C cweb clean

