CFLAGS = -Wall
CFLAGS += $(shell gsl-config --cflags)
LDLIBS += $(shell gsl-config --libs)

all:Out.plot.png

Out.plot.png: Out.data.txt Makefile
	echo '\
	set term pngcairo noenhanced ;\
	set title "Illustration of gsl_interp_eval and gsl_interp_eval_integ" ;\
	set key left ;\
	set xlabel "x" ;\
	set ylabel "y" ;\
	set out "$@" ;\
	plot \
 "$<" index 0 with points pointtype 4 linecolor rgb "black" title "data" \
,"$<" index 2 using 1:2 with lines linecolor rgb "red" title "linear-spline" \
,"$<" index 2 using 1:3 with lines linecolor rgb "green" title "cubic-spline" \
,"$<" index 2 using 1:4 with lines linecolor rgb "blue" title "polynomial" \
,"$<" index 1 with points linecolor rgb "black" title "exact integral" \
,"$<" index 3 using 1:2 with lines linecolor rgb "red" title "integral(linear-spline)" \
,"$<" index 3 using 1:3 with lines linecolor rgb "green" title "integral(cubic-spline)" \
,"$<" index 3 using 1:4 with lines linecolor rgb "blue" title "integral(polynomial)" \
	' | gnuplot

Out.data.txt: main
	./$< > $@

clean:
	$(RM) Out* main
