Higgs.svg: plot.data Makefile
	gnuplot -e "\
	set term $(subst .,,$(suffix $@)) background rgb 'white';\
	set title 'Higgs production signal';\
	set xlabel 'Energy [GeV]';\
	set ylabel 'Signal [arb.u.]';\
	plot 'higgs.data' using 1:2:3 with errorbars title 'experiment'\
	, '$<' using 1:2 with lines title 'Breit-Wigner fit' ;\
	" > $@

plot.data:main.exe
	mono $< <higgs.data 2>Out.txt 1>$@

main.exe:main.cs qnewton.dll matlib.dll
	src="$(filter %.cs,$^)"; libs="$(call clist,$(filter %.dll,$^))";\
	mcs $$src -t:exe -r:$$libs -out:$@

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

qnewton.dll: \
	$(LIBDIR)/minim/qnewton.cs \
	$(LIBDIR)/minim/simplex.cs \
	$(LIBDIR)/optim/swarm.cs \
	matlib.dll
	src="$(filter %.cs,$^)"; libs="$(call clist,$(filter %.dll,$^))";\
	mcs $$src -t:library -r:$$libs -out:$@

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

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