DLLS = $(addprefix -reference:,$(filter %.dll,$^))
CODE = $(filter %.cs,$^)
MKEXE = mcs -target:exe -out:$@ $(DLLS) $(CODE)
MKDLL = mcs -target:library -out:$@ $(DLLS) $(CODE)

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 [][:10]'higgs.data' using 1:2:3 with errorbars title 'experiment'\
	, '$<' using 1:2 with lines title 'Breit-Wigner fit' \
	, '$<' using 1:3 with lines title 'm+dm' \
	, '$<' using 1:4 with lines title 'm-dm' \
	, '$<' using 1:5 with lines title 'Γ+dΓ' \
	, '$<' using 1:6 with lines title 'Γ-dΓ' \
	" > $@

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

main.exe: main.cs qnewton.dll matlib.dll
	$(MKEXE) -main:main

LIBDIR=../../matlib
LIBSRC=\
	$(LIBDIR)/matrix/vector.cs\
	$(LIBDIR)/matrix/matrix.cs
matlib.dll: $(LIBSRC)
	$(MKDLL)

qnewton.dll: \
	../../matlib/minim/gaussnewton.cs \
	$(LIBDIR)/minim/qnewton.cs \
	$(LIBDIR)/minim/newton.cs \
	$(LIBDIR)/minim/newton2.cs \
	$(LIBDIR)/QR/givensqr.cs \
	$(LIBDIR)/minim/simplex.cs \
	$(LIBDIR)/optim/swarm.cs \
	$(LIBDIR)/optim/rndstart.cs \
	$(LIBDIR)/optim/prernd.cs \
	$(LIBDIR)/optim/bbpso.cs \
	matlib.dll
	$(MKDLL)

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

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