CFLAGS +=
CWEAVE = cweavex +d
CTANGLE = ctanglex

all: treeprint treeprint.pdf wc wc.pdf wmerge wmerge.pdf

.SUFFIXES: .tex .dvi .w .pdf

.w.tex:
	$(CWEAVE) $*

.tex.dvi:
	tex $*

.tex.pdf:
	pdftex $*

.w.c:
	$(CTANGLE) $*

.w.dvi:
	$(MAKE) $*.tex
	$(MAKE) $*.dvi

.w.pdf:
	$(MAKE) $*.tex
	$(MAKE) $*.pdf

.w.o:
	$(MAKE) $*.c
	$(MAKE) $*.o

treeprint: treeprint.w
	$(MAKE) treeprint.o
	$(CC) $(CFLAGS) -o treeprint treeprint.o

wc: wc.w
	$(MAKE) wc.o
	$(CC) $(CFLAGS) -o wc wc.o

wmerge: wmerge.w common.o
	$(MAKE) wmerge.o
	$(CC) $(CFLAGS) -o wmerge wmerge.o common.o

.PHONY: clean

clean:
	rm -f *.o *.c *.tex *.dvi *.pdf *.log *.toc
	rm -f treeprint wc wmerge common.h
