CCC=/usr/local/gcc-3.3.2/bin/gcc
CCFLAGS= -O2 -msse -march=pentium4
TFLAGS=-L\#'line %L "%F"%N'

sources = kostas.nw sse.nw

targets.k = kostas.hh \
            kostas.cc \
            k-main.cc

targets.s = qcd.hh \
            qcd-c.hh \
            qcd-gcc-sse.hh

.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++ $< > $@

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


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

c.compile: $(targets.k) qcd.hh qcd-c.hh
	gcc -DUSE_C -O2 -Wall -c kostas.cc k-main.cc
	objdump -drC kostas.o > kostas.s

gcc.compile: $(targets.k) qcd.hh qcd-gcc-sse.hh
	$(CCC) $(CCFLAGS) -DUSE_GCC_SSE -o sse-g k-main.cc kostas.cc -lm -lstdc++
