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

sources = kostas.nw

targets.k = main.c \
            qcd.c \
            qcd.h

targets.s = 

.PHONY: all clean realclean tar pdf programs execs
.PHONY: c.compile gcc.compile icc.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.k) $(targets.s) c sse-g sse-i

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

pdf: $(f.pdf)

programs: $(targets.k) $(targets.s)

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

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

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

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

all.execs: c.compile gcc.compile icc.compile


$(targets.s): sse.nw
	notangle $(TFLAGS) -R$@ -c $< > $@

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