SDKDIR=$(HOME)/.dotnet/sdk/6.0.102# or whatever your sdk is
CSCPATH=$(SDKDIR)/Roslyn/bincore/csc.dll
NETSTANDARD=$(SDKDIR)/ref/netstandard.dll
CONFIG=$(SDKDIR)/vstest.console.runtimeconfig.json
DOTNET=DOTNET_CLI_TELEMETRY_OPTOUT=1; dotnet
CSC=$(DOTNET) $(CSCPATH) -reference:$(NETSTANDARD)
RUN=$(DOTNET) exec --runtimeconfig $(CONFIG)
CSC = mcs
RUN = mono

DATA-ERF = out.erf.data.txt
PLOT-ERF = Plot.erf.svg

all: $(PLOT-ERF) Out.txt

Out.txt: main.exe
	mono $< > $@

$(DATA-ERF): main-erf.exe
	$(RUN) $< 1> $@ 2> log-erf

main.exe: main.cs matlib.dll
	$(CSC) -out:$@ -reference:matlib.dll $(filter %.cs,$^)

main-erf.exe: main-erf.cs matlib.dll
	$(CSC) -out:$@ -reference:matlib.dll $(filter %.cs,$^)

matlib.dll: integrate.cs adapt3.cs ../../matlib/integrate/integrate.cs
	$(CSC) -target:library -out:$@ $^

clean:
	rm -f *.dll *.png *.exe out* *.svg [Ll]og*

$(PLOT-ERF): $(DATA-ERF) Makefile
	echo '\
	set term svg;\
	set out "$@";\
	set key out;\
	set tics out;\
	set grid;\
	set xlabel "x";\
	set title "erf(x) as definite integral";\
	plot [][-1.1:1.1]\
	 "$<" index 0 using 1:2 with line title "erf(x)" \
	,"$<" index 1 using 1:2 with points pt 5 title "table" \
	'|gnuplot
	
