
#---------------------------------------------------------------
# Project         : Mandrake Linux
# Module          : Borges
# File            : Makefile.images
# Author          : Camille Bgnis
# Created On      : Mon May  1 16:25:21 2001
# Copyright       : Camille Bgnis camille@mandrakesoft.com,
#                    MandrakeSoft under the GPL license
#---------------------------------------------------------------
# This Makefile is responsible for converting all acceptable 
# input graphics into pdf for print output.

include /home/stew/RPM/BUILD/Borges-0.12.2/doc/Makefile.include

# Missing default image
MISSING=$(ROOTDIR)/images/missing.jpg

# The eps file format is used as an intermediate format for most 
# transformations to avoid having n rules in here.

# copy identic files if not get EPS and convert
%.png: force
	newer=$(shell ls -t $(wildcard $(ROOTDIR)/images/$(LANG)/$*.* $(ROOTDIR)/images/$*.*) | head -n 1 ); \
	if [ "$(wildcard $(ROOTDIR)/images/$(LANG)/$*.png $(ROOTDIR)/images/$*.png)" != "" ] ; then \
		if [ -e $(ROOTDIR)/images/$(LANG)/$*.png ] && [ $@ -ot $(ROOTDIR)/images/$(LANG)/$*.png ]; then \
			echo "********* Copying $(ROOTDIR)/images/$(LANG)/$*.png to $@"; \
			cp -f $(ROOTDIR)/images/$(LANG)/$*.png $@; \
		elif [ $@ -ot $(ROOTDIR)/images/$*.png ]; then \
			echo "********* Copying $(ROOTDIR)/images/$*.png to $@"; \
			cp -f $(ROOTDIR)/images/$*.png $@; \
		fi; \
	elif [ $$newer -nt $@ ] ; then \
		$(MAKE) $*.tmp.eps; convert $*.tmp.eps $@; rm -f $*.tmp.eps; \
	fi

%.pdf: force
	newer=$(shell ls -t $(wildcard $(ROOTDIR)/images/$(LANG)/$*.* $(ROOTDIR)/images/$*.*) | head -n 1 ); \
	if [ "$(wildcard $(ROOTDIR)/images/$(LANG)/$*.pdf $(ROOTDIR)/images/$*.pdf)" != "" ] ; then \
		if [ -e $(ROOTDIR)/images/$(LANG)/$*.pdf ] && [ $@ -ot $(ROOTDIR)/images/$(LANG)/$*.pdf ]; then \
			echo "********* Copying $@"; \
			cp -f $(ROOTDIR)/images/$(LANG)/$*.pdf $@; \
		elif [ $@ -ot $(ROOTDIR)/images/$*.pdf ]; then \
			echo "********* Copying $@"; \
			cp -f $(ROOTDIR)/images/$*.pdf $@; \
		fi; \
	elif [ $$newer -nt $@ ] ; then \
		echo "********* Making $@"; \
		$(MAKE) $*.tmp.eps; epstopdf -o=$@ $*.tmp.eps; rm -f $*.tmp.eps; \
	fi

%.eps: %.tmp.eps
	@echo "********* Making $@"
	mv $< $@


# temporary eps files

%.tmp.eps: $(ROOTDIR)/images/$(LANG)/%.eps
	cp -f $< $@
%.tmp.eps: $(ROOTDIR)/images/%.eps
	cp -f $< $@

%.tmp.eps: $(ROOTDIR)/images/$(LANG)/%.jpg
	convert $< $@
%.tmp.eps: $(ROOTDIR)/images/%.jpg
	convert $< $@

#%.tmp.eps: $(ROOTDIR)/images/$(LANG)/%.dia
# dia must use the --nosplash option when no X available
# But then fails for some images...
# This is why I must use a virtual X server...
# The sleep time is needed on some machines, don't know why.
#	+trap "killall Xvfb; rm -f /tmp/.X5-lock" 0; \
#	Xvfb :5 -screen 0 100x100x8& sleep 5; \
#	xauth add :5 . `mcookie` ;\
#	DISPLAY=:5 dia -e $@ $<
#	-killall Xvfb
#	rm -f /tmp/.X5-lock
#%.tmp.eps: $(ROOTDIR)/images/%.dia
#	+trap "killall Xvfb; rm -f /tmp/.X5-lock" 0; \
#	Xvfb :5 -screen 0 100x100x8& sleep 5; \
#	xauth add :5 . `mcookie` ;\
#	DISPLAY=:5 dia -e $@ $<
#	-killall Xvfb
#	rm -f /tmp/.X5-lock

%.tmp.eps: $(ROOTDIR)/images/$(LANG)/%.fig
	fig2dev -j -L eps $< $@
%.tmp.eps: $(ROOTDIR)/images/%.fig
	fig2dev -j -L eps $< $@

%.tmp.eps: $(MISSING)
	if [ -e $(ROOTDIR)/images/$(LANG)/$*.png ]; \
		then convert $(ROOTDIR)/images/$(LANG)/$*.png $@; \
	elif [ -e $(ROOTDIR)/images/$*.png ]; then \
		 convert $(ROOTDIR)/images/$*.png $@;  \
	elif [ -e $(ROOTDIR)/images/$(LANG)/$*.eps ]; then \
		cp -f $(ROOTDIR)/images/$(LANG)/$*.eps $@; \
	elif [ -e $(ROOTDIR)/images/$*.eps ]; then \
		cp -f $(ROOTDIR)/images/$*.eps $@;  \
	else echo "******* $* missing! ********"; \
		convert $(MISSING) $@; \
		echo $* >> missing.img; \
	fi


# Local variables:
# mode: makefile
# End: