CC=/tmp/gcc332/bin/gcc
CFLAGS= -g -Wall -O2 -msse -march=pentium4
TFLAGS=-L\#'line %L "%F"%N'

sources = dwf.nw

targets.c = main.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

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

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 -latex -delay $< > $@

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

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

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