prefix = @prefix@
docdir = $(prefix)/doc/gps
sharedir = $(prefix)/share/gps

DVIPS= @DVIPS@
MAKEINFO= @MAKEINFO@
TEXI2DVI= @TEXI2DVI@
MKDIR = mkdir -p
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
CONVERT = convert
CP = cp -p
IMAGES = gps_title.jpg *.gif

TEXI2HTML_FLAGS=-split_chapter -menu
TEXI=gps.texi ../gvd/docs/gvd_contents.texi

all: cp_gvd stamp-eps doc tutorial gps_pg clean-temp-files
distrib: cp_gvd stamp-eps doc tutorial clean-temp-files
non-ps: common clean-temp-files
static:

cp_gvd:
	@-for img in main-window breakpoints memory-view call-stack \
	     assembly canvas process colors tasks explorer tooltips; do \
	  $(CP) ../gvd/docs/$${img}.gif .; \
	done

stamp-eps: $(IMAGES)
	@echo "Converting images to Encapsulated postscript"
	@-for img in [^g]*.gif; do \
	  $(CONVERT) $${img} `basename $${img} .gif`.eps; \
	done
	touch stamp-eps

tutorial: gps-tutorial.html
doc:      gps.txt gps.html gps.info gps.ps
gps_pg:   gps_pg.ps gps_pg.html

gps-tutorial.html:                tutorial.texi
	perl ./texi2html -out_file $@ $< -menu

gps_pg.html gps_pg.ps:            gps_pg.texi
gps.html gps.ps gps.info gps.txt: ${TEXI}

%.html::
	perl ./texi2html $< ${TEXI2HTML_FLAGS}

%.ps::
ifneq (${TEXI2DVI},)
	echo x | ${TEXI2DVI} $<
ifneq (${DVIPS},)
	${DVIPS} ${<:.texi=.dvi} -o $@
else
	@echo "------------------------------------------------------"
	@echo "dvips not found, cannot build POSTSCRIPT documentation"
	@echo "------------------------------------------------------"
endif
else
	@echo "--------------------------------------------------------"
	@echo "texi2dvi not found, cannot build DVI or PS documentation"
	@echo "--------------------------------------------------------"
endif

%.info: ${TEXI}
ifneq (${MAKEINFO},)
	${MAKEINFO} --force -o $@ $<
else
	@echo "----------------------------------------------------"
	@echo "makeinfo not found, cannot build INFO documentation"
	@echo "----------------------------------------------------"
endif

%.txt: ${TEXI}
ifneq (${MAKEINFO},)
	${MAKEINFO} --force --no-headers --no-split -o $@ $<
else
	@echo "----------------------------------------------------"
	@echo "makeinfo not found, cannot build TXT documentation"
	@echo "----------------------------------------------------"
endif


install:
	$(MKDIR) $(docdir)
	$(MKDIR) $(sharedir)
	$(MKDIR) $(docdir)/html
	$(MKDIR) $(docdir)/info
	$(MKDIR) $(docdir)/ps
	$(MKDIR) $(docdir)/txt
	-$(INSTALL_DATA) gps-welcome.html $(docdir)/html
	-$(INSTALL_DATA) gps-tutorial.html $(docdir)/html
	-for file in gps.html $(wildcard gps_*.html); do \
	  $(INSTALL_DATA) $$file $(docdir)/html; \
	done
	-cd ../design; ./convert.pl > $(docdir)/html/TODO.html
	-for file in $(wildcard gps.info*); do \
	  $(INSTALL_DATA) $$file $(docdir)/info; \
	done
	-$(INSTALL_DATA) gps.ps  $(docdir)/ps
	-$(INSTALL_DATA) gps.txt  $(docdir)/txt
	-for img in $(IMAGES); do \
	  $(INSTALL_DATA) $$img $(docdir)/html; \
	done
	-$(INSTALL_DATA) gps-animation.gif $(sharedir)
	-$(INSTALL_DATA) gps-splash.jpg $(sharedir)
	-${INSTALL_DATA} gps_index.xml ${docdir}/html
	-${INSTALL_DATA} help_index.html ${docdir}/html

clean-temp-files:
	-$(RM) *.aux
	-$(RM) *.cp
	-$(RM) *.cps
	-$(RM) *.dvi
	-$(RM) *.fn
	-$(RM) *.ky
	-$(RM) *.log
	-$(RM) *.pg
	-$(RM) *.toc
	-$(RM) *.tp
	-$(RM) *.vr

clean: clean-temp-files
	-$(RM) gps.info*
	-$(RM) gps-tutorial*.html gps.html gps_*.html gps.ps gps.txt stamp-*

mostlyclean: clean

distclean: mostlyclean
	-$(RM) Makefile

maintainer-clean: distclean

