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

Higgs.png: out.plot.data Makefile
	gnuplot -e "\
	set term png notruecolor 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' \
	" > $@

#	set term $(subst .,,$(suffix $@)) background rgb 'white';\
#	, '$<' 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Γ' \

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

main.exe: main.cs minimum.dll matrix.dll
	$(MKEXE) -main:main

matrix.dll: \
	../matrix/vector.cs \
	../matrix/matrix.cs \
	../lineq/qr.cs \
	Makefile
	$(MKDLL)
minimum.dll: \
	../minimum/newton/newton.cs \
	../minimum/newton/newton2.cs \
	../minimum/qnewton/qnewton.cs \
	../minimum/simplex.cs \
	../minimum/bfgs.cs \
	matrix.dll Makefile; $(MKDLL)

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