sources := $(wildcard *.w)
cfiles := $(sources:.w=.c)
objects := $(sources:.w=.o)
includefiles := $(sources:.w=.h)
dvifiles := $(sources:.w=.dvi)

ldflags = -lX11 -lXext

CWEAVE = cweave +mde +I/usr/include/
CTANGLE = ctangle


.PHONY: clean documentation
.SUFFIXES: .tex .dvi .w

%.tex : %.w   ; $(CWEAVE) $*
%.dvi : %.tex ; tex $*.tex
%.c   : %.w   ; $(CTANGLE) $*
%.h   : %.w   ; $(CTANGLE) $*
#%.dvi : %.w   ;	make $*.tex; make $*.dvi
#%.o   : %.w   ;	make $*.c  ; make $*.o

pictures: $(objects)
	$(CC) -o pictures $(objects) $(ldflags)

$(objects) $(dvifiles): $(includefiles)

clean:
	$(RM) pictures $(objects) $(includefiles) $(dvifiles)
documentation: $(dvifiles)
