# Mono compiler and runtime for C-sharp:
#compiler = /usr/users/wwwifa/docs/subatom/nucltheo/bin/mcs
compiler = /usr/users/wwwifa/docs/subatom/nucltheo/bin/gmcs
runtime = /usr/users/wwwifa/docs/subatom/nucltheo/bin/mono

# Pnet compiler and runtime for C-sharp:
#compiler = /usr/users/wwwifa/docs/subatom/nucltheo/bin/cscc
#runtime = /usr/users/wwwifa/docs/subatom/nucltheo/bin/ilrun

GRAPH = /usr/users/wwwifa/docs/subatom/nucltheo/bin/graph

comma:=,
empty:=
space:=$(empty) $(empty)

# the default rule to compile .cs file into a .dll file:
%.dll: %.cs
	$(compiler) $*.cs /target:library /out:$*.dll

dlls = vector.dll vmatrix.dll qr.dll lsfit.dll
refs = $(subst $(space),$(comma),$(dlls))

all: plot.png

plot.png: main.cs $(dlls) makefile
	$(compiler) main.cs /reference:$(refs) /out:main.exe
	$(runtime) main.exe > points.dat
	$(GRAPH) --symbol 1 0.03\
		--width 0.65 --height 0.65 \
		--display-type png \
		--x-label "x" --y-label "y" \
		--top-label "linear least-squares fit" \
		points.dat > plot.png

qr.dll: qr.cs vmatrix.dll
	$(compiler) qr.cs /target:library \
	/reference:vector.dll,vmatrix.dll \
	/out:qr.dll

vmatrix.dll: vector.dll vmatrix.cs
	$(compiler) vmatrix.cs \
	/target:library \
	/reference:vector.dll \
	/out:vmatrix.dll

lsfit.dll: vector.dll lsfit.cs
	$(compiler) lsfit.cs \
	/target:library \
	/reference:vector.dll,vmatrix.dll,qr.dll \
	/out:lsfit.dll

clean:
	rm -f $(dlls) *.exe core* out.txt *.png points.dat
