CFLAGS += -I../matrix -I../qr -Wall -O #`gsl-config --cflags`
#LDLIBS += `gsl-config --libs`
LDLIBS += -lm -lgc
CC = gcc --std=c99
CC = tcc
OBJ = main.o lsfit.o qrdec.o qrback.o qrinverse.o matrix.o vector.o backsub.o

all: plot.png fit.eps
qrdec.o:../qr/qrdec.c ;$(CC) $(CFLAGS) -c $< -o $@
backsub.o:../qr/backsub.c ;$(CC) $(CFLAGS) -c $< -o $@
qrback.o:../qr/qrback.c ;$(CC) $(CFLAGS) -c $< -o $@
qrinverse.o:../qr/qrinverse.c ;$(CC) $(CFLAGS) -c $< -o $@
matrix.o:../matrix/matrix.c ;$(CC) $(CFLAGS) -c $< -o $@
vector.o:../matrix/vector.c ;$(CC) $(CFLAGS) -c $< -o $@
plot.png: plot.dat makefile
	graph --display-type png \
	--width 0.7 --height 0.7 \
	--x-label "x" --y-label "F\sbc\eb(x), F\sbc-dc\eb(x), F\sbc+dc\eb(x)" \
	--top-label "LS fit with c +- deltac" \
	$< > $@
fit.eps: fit.dat makefile
	echo 'set term eps monochrome' > tmp
	echo 'set width 6' >> tmp
	echo 'set output "$@"' >> tmp
	echo 'set key left' >> tmp
	echo 'set xtics 0.5 ; set ytics 2' >> tmp
	echo 'set xlabel "$$x$$"; set ylabel "$$y$$"' >> tmp
	echo 'plot [-1:1] "$<" index 0 title "data" with yerrorbars \ ' >> tmp
	echo ', "$<" index 1 t "$$F_\mathbf{c}(x)$$" w l \ ' >> tmp
	echo ', "$<" index 2 t "$$F_{\mathbf{c}+\Delta\mathbf{c}}(x)$$" w l \' >> tmp
	echo ', "$<" index 3 t "$$F_{\mathbf{c}-\Delta\mathbf{c}}(x)$$" w l \' >> tmp
	pyxplot tmp
	rm -f tmp
plot.dat fit.dat: main makefile
	./main 1> plot.dat 2> fit.dat
main: $(OBJ)
clean:
	rm --force *.o main plot.dat plot.png fit.dat fit.eps
