#!gmake -k -R

#
# Update .eepic files from gnuplot files
#
# Handles the problem that the output file names
# often don't have the same stem as the plot file.
#


# set path for gnuplot
PATH := /igd/a4/software/gnuplot/bin:$(PATH)

.SUFFIXES:
.SUFFIXES: .plt .d .eepic

# don't remove intermediate files
.SECONDARY:

#PICDIR := ../Pic_plt
PICDIR := .
ifeq "$(wildcard $(PICDIR))" ""
$(warning making directory $(PICDIR))
$(shell mkdir $(PICDIR))
endif

DEPDIR := depend
ifeq "$(wildcard $(DEPDIR))" ""
$(warning making directory $(DEPDIR))
$(shell mkdir $(DEPDIR))
endif

.PHONY: all dep pic

all: pic

PICS := $(shell cat $(wildcard *.plt) | \
			    sed -e '/^[    ]*\#/d' \
				    -e '/set output/!d' \
				    -e '/\.eepic/!d' \
				    -e 's|.*/\(.*\)"|$(PICDIR)/\1|')

pic: $(PICDIR) $(PICS)
	@echo eepic finished.

DEPENDENCIES := $(addprefix $(DEPDIR)/,$(subst .plt,.d,$(wildcard *.plt)))

-include $(DEPENDENCIES)

dep: $(DEPENDENCIES)

$(DEPDIR)/%.d : %.plt
	@echo creating dependencies from $< ..
	@sed -e '/^[ 	]*#/d' \
		 -e '/set output/!d' \
		 -e '/\.eepic/!d' \
		 -e "s|.*/\(.*\)\.eepic\"|$(PICDIR)/\1.eepic : $<|" \
		 $< > $@

%.eepic:
	@echo plotting $< ..
	@gnuplot $<
# no prerequisites, because a prerequisite (.plt file) does not necessarily
# have the same stem as the eepic file.
# Prerequisites are generated explicitely anyway.

clean:
	rm -f *.bak $(PICDIR)/*.eepic

