#CSC = mcs -o+
#RUN = mono
CSC = csc -o+
RUN = run

all: Out.txt Times.png

Out.txt:main.exe
	$(RUN) $< >$@ 2>log

Times.png:out.times.txt Makefile
	echo '\
	set term $(subst .,,$(suffix $@)); \
	set out "$@"; \
	set key left; \
	b=1; a=100; c=3; \
	f(x)=b+(x/a)**c ;\
	fit f(x) "$<" via a,b,c; \
	plot \
	"$<" \
	, f(x) title sprintf("fit: (n/%.f)^{%.2f}+%.3f",a,c,b) \
	'| gnuplot

out.times.txt:main.exe Makefile
	>$@
	>out.steps.txt
	for N in $(shell seq 50 10 150); do \
	echo "N=$$N"; \
	time -ao $@ -f "$$N %U" $(RUN) $< $$N 1>>out.steps.txt 2>/dev/null; \
	done
	

main.exe:main.cs eigen.dll matlib.dll
	$(CSC) $< -r:$(call clist,$(filter %.dll,$^))

geneig.exe:geneig.cs matlib.dll
	$(CSC) $< -r:$(call clist,$(filter %.dll,$^))

steep.exe:steep.cs matlib.dll
	$(CSC) $< -r:$(call clist,$(filter %.dll,$^))

LIBDIR=../../matlib
LIBSRC=\
	$(LIBDIR)/matrix/vector.cs\
	$(LIBDIR)/matrix/matrix.cs
matlib.dll:$(LIBSRC)
	$(CSC) $^ -target:library -out:$@

eigen.dll: eigen0.cs geneig.cs givensqr.cs matlib.dll
	$(CSC) -t:library \
	-out:$@ $(addprefix -r:,$(filter %.dll,$^)) $(filter %.cs,$^)

clean:
	$(RM) *.exe *.dll [Oo]ut* [Ll]og* *.png *.svg

comma:=,
empty:=
space:=$(empty) $(empty)
clist = $(subst $(space),$(comma),$(1))
