CFLAGS = -Wall -std=gnu1x -O2
LDLIBS = -lm

all:Out.splines.svg test.svg

Out.splines.svg: out.data.txt Makefile
	echo "\
	set term svg ;\
	set out '$@';\
	set xlabel 'x';\
	set ylabel 'y';\
	set key right bottom;\
	set tics out;\
	set title 'Linear/quadratic/cubic splines of random data';\
	plot '$<' index 0 with points title 'data'\
	,'$<' index 1 using 1:2 with lines title 'linear spline'\
	,'$<' index 1 using 1:3 with lines title 'quadratic spline'\
	,'$<' index 1 using 1:4 with lines title 'cubic spline'\
	,'$<' index 0 smooth csplines lw 4 dashtype (10,10) title 'gnuplot cubic spline'\
	" | tee log.txt | gnuplot
	sed -i 's/;/;\n/g;s/,/,\n/g' log.txt

out.data.txt test.txt:main
	./$< 1>out.data.txt 2>test.txt
test.svg:test.txt Makefile
	graph --output-format svg --toggle-use-color <$< >$@

main: main.o linterp.o qspline.o cspline.o
main.o qspline.o: qspline.h
main.o cspline.o: cspline.h

.PHONEY:clean
clean:
	find . -type f -executable -delete
	$(RM) *.o out* log* test* *.svg *~
