LIFA = $(findstring lifa, $(shell hostname))
JS = $(if $(LIFA), /usr/users/fedorov/bin/js, js)
GRAPH = $(if $(LIFA), /usr/users/fedorov/bin/graph, graph)
GraphFlags = \
		--width 0.7 \
		--height 0.7 \
		--x-label "x" \
		--y-label "y" \
		--top-label "y=sin(x) and y=cos(x)"

all: plot.png plot.gif plot.svg plot.ps error-bars.png

plot.png: points.dat makefile
	$(GRAPH) $(GraphFlags) --display-type png < points.dat > plot.png

plot.gif: points.dat makefile
	$(GRAPH) $(GraphFlags) --display-type gif < points.dat > plot.gif

plot.svg: points.dat makefile
	$(GRAPH) $(GraphFlags) --display-type svg < points.dat > plot.svg

plot.ps: points.dat makefile
	$(GRAPH) $(GraphFlags) --display-type ps < points.dat > plot.ps

points.dat: main.js
	$(JS) main.js > points.dat

error-bars.png: makefile
	echo '1 1 0.3' >  error-bars.dat
	echo '2 2 0.3' >> error-bars.dat
	echo '3 3 0.5' >> error-bars.dat
	echo '4 4 0.1' >> error-bars.dat
	$(GRAPH) $(GraphFlags)\
		--x-limits 0 5\
		--y-limits 0 5\
		--line-mode 0\
		--top-label "Some random error bars"\
		--input-format e \
		--display-type png \
		< error-bars.dat > error-bars.png
	rm -f error-bars.dat

clean:
	rm -f *.dat *.png *.ps *.svg
