CXX = g++
CXXFLAGS = -W -Wall -O3 -fomit-frame-pointer $(DEFS)
#CXXFLAGS = -W -Wall -O0 $(DEFS)
CXXCOMPILE = $(CXX) $(INCLUDES) $(CXXFLAGS)
CXXLINK = $(CXX) $(CXXFLAGS) -o $@
INCLUDES = -I/home/obata/build/boost_1_30_0

# Cache parameters
NREG = 8
L1_SIZE = 8192
L1_BLOCK = 32
L1_ASSOC = 2
L1_LATENCY = 1
L1_WB = true
MAIN_LATENCY = 32

SOURCES = bestuse.cpp example1a.cpp example1b.cpp example2.cpp lackdtor.cpp \
	localaddr.cpp smat.bib smat.h smatcount.cpp smatnod.cpp smatopt.cpp \
	smatplot smatrange.cpp smatsim.cpp smatsim.h smatview.cpp \
	stl_tempbuf.h stlsort.cpp early.h lomuto.h tiled.h timer.h \
	test-smat.cpp test-readlog.cpp test-random.cpp test-exec.sh \
	test-sort.sh ans-random.txt ans-reg-count.txt ans-reg-opt.txt \
	ans-reg-plot.txt ans-reg-sim.txt ans-reg-simopt.txt test-reg.log

.SUFFIXES:
.SUFFIXES: .c .cpp .o .w .ps .dvi

all: all-redirect
all-redirect: all-am
all-am: Makefile

Makefile: smat.w
	pdfnuweb smat

doc: smat.pdf
examples: example1a example1b example2
tools: smatopt smatsim smatview smatcount smatrange smatplot
	chmod +x smatplot

smat.pdf: smat.w
	pdfnuweb smat; pdflatex smat; bibtex smat; pdfnuweb smat
	pdflatex smat; pdfnuweb smat; pdflatex smat

smatsim.o: smatsim.cpp smatsim.h smat.h
	$(CXXCOMPILE) \
	 -DNREG=$(NREG) -DL1_SIZE=$(L1_SIZE) -DL1_BLOCK=$(L1_BLOCK) \
	 -DL1_ASSOC=$(L1_ASSOC) -DL1_LATENCY=$(L1_LATENCY) -DL1_WB=$(L1_WB) \
	 -DMAIN_LATENCY=$(MAIN_LATENCY) -c smatsim.cpp -o smatsim.o

stlsort-timer.o: stlsort.cpp smat.h timer.h
	$(CXXCOMPILE) -DTIMER -DSMAT_DISABLE -c stlsort.cpp -o stlsort-timer.o

check: test-smat test-readlog test-random
	@chmod +x test-exec.sh test-sort.sh
	./test-exec.sh
	./test-sort.sh

clean:
	rm -f *.o smatopt smatsim smatview smatcount smatrange smatplot \
	  stlsort stlsort-timer test-exec example1a example1b example2 \
	  smat.aux smat.log smat.out smat.pdf smat.tex smat.toc \
	  smat.brf smat.bib smat.bbl smat.blg smat.ps smat.dvi \
	  $(SOURCES) *.tps *.dps

smatopt.o: smatopt.cpp smat.h
smatview.o: smatview.cpp smat.h
smatcount.o: smatcount.cpp smat.h
smatrange.o: smatrange.cpp smat.h smatsim.h
stlsort.o: stlsort.cpp smat.h early.h lomuto.h tiled.h
stlsort-timer.o: stlsort.cpp early.h lomuto.h tiled.h
example1a.o: example1a.cpp
example1b.o: example1b.cpp smat.h
example2.o: example2.cpp smat.h
test-smat.o: smat.h
test-readlog.o: test-readlog.cpp
test-random.o: test-random.cpp

%: %.o
	$(CXXLINK) $< $(LIBS)

%: %.cpp
	$(CXXCOMPILE) -o $@ $< $(LIBS)

%.o: %.cpp
	$(CXXCOMPILE) -c $<
