CC=/usr/local/gcc-3.3.2/bin/gcc
CFLAGS= -g -Wall -O2 -msse -march=pentium4 -Ixmp -I.
TFLAGS=-L\#'line %L "%F"%N'
#CC=/usr/local/gcc-3.3.2/bin/gcc
#CFLAGS= -g -Wall -msse -march=pentium4 -Ixmp
#TFLAGS=

sources = dwf.nw interface.nw

targets.c = dwf.c

targets.h = sse.h

.PHONY: all clean realclean tar pdf programs execs
.PHONY: compile

f.tex=$(sources:%.nw=%.tex)
f.dvi=$(sources:%.nw=%.dvi)
f.pdf=$(sources:%.nw=%.pdf)

all: pdf programs

clean:
	$(RM) *.tex *.log *.dvi *.aux *.toc *.nwi *.out $(targets.c:%.c=%.o)

realclean: clean
	$(RM) *.pdf $(targets.c) $(targets.h)

tar: clean
	base=`basename $$PWD` ; \
	cd .. ; \
	tar -cvf - $$base | bzip2 -9 > $$base.tar.bz2

pdf: $(f.pdf)

programs: $(targets.c) $(targets.h)

$(f.pdf): %.pdf: %.dvi
	dvipdfm $<

$(f.dvi): %.dvi: %.tex
	latex $<
	latex $<

$(f.tex): %.tex: %.nw
	noweave -index -latex -delay $< > $@

$(targets.c): $(sources)
	notangle $(TFLAGS) -R$@ -c $< > $@ \
	|| (rm -f $@ ; exit 1)

sse.h: dwf.nw
	notangle $(TFLAGS) -R$@ -c $< > $@ \
	|| (rm -f $@ ; exit 1)

sse-dwf-cg.h: interface.nw
	notangle $(TFLAGS) -R$@ -c $< > $@ \
	|| (rm -f $@ ; exit 1)

compile: $(targets.c) $(targets.h)
	$(CC) $(CFLAGS) -c $(targets.c)
