CFLAGS += -Wall -Ofast -std=gnu1x `gsl-config --cflags`
LDLIBS += `gsl-config --libs`

all: Out.txt Out.times.png
	cat $<
Out.txt: main
	./$< 4 3 > $@

Out.times.png: Out.times.txt Makefile
	echo '\
	set term png ;\
	set title "QR-decomposition times as function of matrix size" ;\
	set xlabel "matrix size N" ;\
	set ylabel "time, sec" ;\
	set key left ;\
	set out "$@" ;\
	N=10 ;\
	f(x)=(x/N)**3 ;\
	fit f(x) "$<" via N ;\
	plot \
	 "$<" with linespoints title "measurement" \
	, f(x) with lines title sprintf("(x/%3.0f)^3",N);\
	'| gnuplot

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

main: main.o qr.o
main.o qr.o:qr.h

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