CXX=g++
MATRIX = ../matrix
CXXFLAGS += -Wall -std=c++17 -I$(MATRIX)
LDLIBS   += -L/usr/local/lib -lgc -lstdc++ -lm
CXXFLAGS += -DNDEBUG -Ofast -march=native

all:Out.txt Out.times.png

Out.times.png:out.times.txt Makefile
	echo '\
set term png ;\
set key left ;\
set xlabel "matrix size n" ;\
set ylabel "time, sec" ;\
set title "Givens QR-decomposition times [$(shell uname --machine)]" ;\
set out "$@" ;\
N=100; s=0.1 ;\
f(x)=s+(x/N)**3 ;\
fit f(x) "$<" via s,N ;\
plot \
 "$<" with p \
,f(x) with lines title sprintf("%3.1f+(n/%3.0f)^3",s,N) \
	'|gnuplot

out.times.txt:main Makefile
	>$@
	for n in $$(seq 190 10 290); do \
	time --output $@ --format "$$n %U" --append ./$< $$n; done

Out.txt:main
	./$< > $@ 2>log

main: main.o vec.o mat.o qr.o
main.o: $(MATRIX)/vec.h $(MATRIX)/mat.h
vec.o: $(MATRIX)/vec.cc $(MATRIX)/vec.h
	$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
mat.o: $(MATRIX)/mat.cc $(MATRIX)/mat.h $(MATRIX)/vec.h
	$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<

clean:
	find -type f -executable -delete
	rm -rf [Oo]ut* *.o log* *log
