all: Erf.svg Gamma.svg

Erf.svg  : erf.gpi   out.erf.txt   ; gnuplot $<
Gamma.svg: gamma.gpi out.gamma.txt ; gnuplot $<

out.erf.txt  : main-erf.exe
	mono $< > $@ 2> log.erf.txt
out.gamma.txt: main-gamma.exe
	mono $< > $@ 2> log.gamma.txt

main-erf.exe: main-erf.cs math.dll
	mcs -r:math.dll $<
main-gamma.exe: main-gamma.cs math.dll
	mcs -r:math.dll $<

math.dll: erf.cs gamma.cs integ.cs
	mcs -t:library -out:$@ $^

clean:
	rm -f *.exe *.dll out* *.svg *.png gamma.gpi erf.gpi log* table*

table.erf.txt: erf.c
	tcc -run $< > $@

table.gamma.txt: gamma.c
	tcc -run $< > $@

gamma.gpi: Makefile table.gamma.txt
	echo 'set title "Gamma function: computed vs. tabulated"' > $@
	echo 'set term svg' >> $@
	echo 'set out "Gamma.svg"' >> $@
	echo 'set xlabel "x"' >> $@
	echo 'set ylabel "y"' >> $@
	echo 'set xzeroaxis' >> $@
	echo 'set yzeroaxis' >> $@
	echo 'set tics out' >> $@
	echo 'set key bottom right' >> $@
	echo 'plot [:5][-5:5] \' >> $@
	echo ' "table.gamma.txt" with points pt 7 \' >> $@
	echo ',"out.gamma.txt" with lines title "gamma(x)" ' >> $@

erf.gpi: Makefile table.erf.txt
	echo 'set title "Error function: computed vs. tabulated"' > $@
	echo 'set term svg' >> $@
	echo 'set out "Erf.svg"' >> $@
	echo 'set xlabel "x"' >> $@
	echo 'set ylabel "y"' >> $@
	echo 'set xzeroaxis' >> $@
	echo 'set yzeroaxis' >> $@
	echo 'set tics out' >> $@
	echo 'set key bottom right' >> $@
	echo 'plot [][-1.5:1.5] \' >> $@
	echo ' "out.erf.txt" with lines title "erf(x)" \' >> $@
	echo ',"table.erf.txt" with points pt 7' >> $@
