# Makefile for Gri documentation files.

            DOC_DIR = $(prefix)/share/gri/doc
           HTML_DIR = $(DOC_DIR)/html
       EXAMPLES_DIR = $(DOC_DIR)/examples
                 RM = rm -f
            REFCARD = refcard
        CMD_REFCARD = cmdrefcard
     HTML_LONG_NAME = gri-long
           INFO_DIR = $(prefix)/info
            INSTALL = install

FORCE:

all:
	make info
	make html

install:
	make info-install
	make html-install

read:
	chmod a+r Makefile
	chmod a+rx texinfo2HTML
	chmod a+rx HTML_subdivide
	chmod a+r gri*

FAQ: FORCE
	rm -f FAQ
	lynx -dump FAQ.html > FAQ

the_resources:
	cd resources ; make

test:
	cat test.texi | texinfo2HTML > test.html

html: gri.texi gri.info texinfo2HTML HTML_subdivide
	cd examples ; make png
	-cp examples/*.png ./
	cd examples ; make html
	cp examples/*.html ./
	cd tst_suite ; make html
	cd screenshots; make png
	cat gri.texi     		>  TMP
	perl make_html_index		>> TMP
	perl make_html_commandindex	>> TMP
	perl make_html_builtinindex	>> TMP
	cat TMP | perl texinfo2HTML	>  $(HTML_LONG_NAME)
	rm -f TMP
	make read
	rm -f gri[1-9]*.html
	perl HTML_subdivide  $(HTML_LONG_NAME) "The Gri graphing language"
	rm -f $(HTML_LONG_NAME)
	rm -f *.pass2
	if test ! -f index.html ; then ln -s gri1.html index.html ; fi
#	perl archive-to-html.pl > Newsgroup.html
	touch html

card-install-redhat: FORCE
	$(INSTALL) -m 644 refcard.ps    $(CARD_DIR)
	$(INSTALL) -m 644 cmdrefcard.ps $(CARD_DIR)

html-tar: html
	make html-install DOC_DIR=./gridoc
	tar -c -f gridoc.tar ./gridoc
	gzip -f --best gridoc.tar

html-install:	html
	$(INSTALL) -d          $(HTML_DIR)
	chmod a+rx             $(HTML_DIR)
	$(INSTALL) -d          $(HTML_DIR)/resources
	chmod a+rx             $(HTML_DIR)/resources
	cp resources/*.gif     $(HTML_DIR)/resources
	chmod 644              $(HTML_DIR)/resources/*.gif
	$(INSTALL) -d          $(HTML_DIR)/tst_suite
	chmod a+rx             $(HTML_DIR)/tst_suite
	cp tst_suite/*html     $(HTML_DIR)/tst_suite
	-cp examples/*.png     $(HTML_DIR)/
	-chmod 644             $(HTML_DIR)/*.png
	$(INSTALL) -d          $(HTML_DIR)/screenshots
	chmod a+rx             $(HTML_DIR)/screenshots
	cp screenshots/*.png   $(HTML_DIR)/screenshots
	chmod a+rx             $(HTML_DIR)/screenshots
	chmod 644              $(HTML_DIR)/screenshots/*.png
	cp *.html              $(HTML_DIR)
	chmod 644              $(HTML_DIR)/*.html
#       Now install the examples
	$(INSTALL) -d          $(EXAMPLES_DIR)
	chmod a+rx             $(EXAMPLES_DIR)
	cp examples/model*     $(EXAMPLES_DIR)
	chmod 644              $(EXAMPLES_DIR)/model*
	cp examples/*.dat      $(EXAMPLES_DIR)
	chmod 644              $(EXAMPLES_DIR)/*.dat
	cp examples/*.gri      $(EXAMPLES_DIR)
	chmod 644              $(EXAMPLES_DIR)/*.gri
	cp examples/*.ps       $(EXAMPLES_DIR)
	chmod 644              $(EXAMPLES_DIR)/*.ps
	cp examples/FEM.pl     $(EXAMPLES_DIR)
	chmod 755              $(EXAMPLES_DIR)/FEM.pl
	(cd $(HTML_DIR); rm -rf examples ; ln -sf ../examples)

card-clean:
	-rm -f refcard.dvi refcard.log refcard.ps
	-rm -f cmdrefcard.dvi cmdrefcard.log cmdrefcard.ps
	-rm -f card

html-clean:
	rm -rf HIDE_FILE
	mkdir HIDE_FILE
	mv FAQ.html HIDE_FILE
	-rm -f *.html *.png html
	mv HIDE_FILE/FAQ.html .
	rm -rf HIDE_FILE

gri.texi: gri.texim
	perl texim2texi <gri.texim >gri.texi

info:	gri.texi
	makeinfo gri.texi
	touch info

gri.info: gri.texi
	makeinfo gri.texi

info-install:
	$(INSTALL) -d $(INFO_DIR)
	cp gri.info* $(INFO_DIR)
	(cd $(INFO_DIR) ; gzip -f --best gri.info gri.info-[0-9] gri.info-[0-9][0-9])
	chmod 644 $(INFO_DIR)/gri.info*

info-install-solaris:
	$(INSTALL) -d $(INFO_DIR_SOLARIS)
	cp gri.info* $(INFO_DIR_SOLARIS)
	chmod 644 $(INFO_DIR_SOLARIS)/gri.info*

info-clean:
	rm -f gri.info* info

refcard.ps:	refcard.tex
	tex refcard.tex
	dvips -o refcard.ps -t landscape -t letter refcard.dvi

cmdrefcard.ps:
	tex cmdrefcard.tex
	dvips -o cmdrefcard.ps -t landscape -t letter cmdrefcard.dvi

clean:	info-clean html-clean card-clean
	$(RM)				\
		gri.pdf gri.dvi gri.ps	\
		gri.hlp			\
		*~			\
		*.log *.dvi *.aux	\
		gri.toc			\
		gri.cp gri.cps		\
		gri.fn gri.fns		\
		gri.ky gri.kys		\
		gri.pg gri.pgs		\
		gri.tp gri.tps		\
		gri.vr gri.vrs 		\
		FAQ cmdrefcard.ps refcard.ps
	$(RM) gri.texi
	(cd examples    ; make clean)
	(cd screenshots ; make clean)
#	(cd resources   ; make clean)
	(cd tst_suite   ; make clean)
	-rm -rf gridoc
	-rm -f gridoc.tar.gz

help:
	@echo "Options:"
	@grep '^[^ ]*:' Makefile | sed -e "s/^/  make /" -e "s/:.*//"

linux_redhat:
	make info
	make html
	make refcard.ps
	make cmdrefcard.ps

gri.ps: gri.texi
	cd examples    ; make eps
	cd screenshots ; make eps
	cd tst_suite   ; make texi
	tex gri.texi
	texindex gri.cp
	texindex gri.fn
	texindex gri.ky
	texindex gri.pg
	texindex gri.tp
	texindex gri.vr
	tex gri.texi
	dvips -o gri.ps -t letter gri.dvi

gri.pdf: gri.texi
	cd examples    ; make pdf
	cd screenshots ; make pdf
	cd tst_suite   ; make texi
	pdftex gri.texi
	texindex gri.cp
	texindex gri.fn
	texindex gri.ky
	texindex gri.pg
	texindex gri.tp
	texindex gri.vr
	pdftex gri.texi

### Debian stuff follows

# make debian   (does not install; only makes the files)
debian: refcard.ps cmdrefcard.ps info

# make debian-html DOC_DIR=../debian/gri-html-doc/usr/share/doc/gri
# builds and installs under $(DOC_DIR)
debian-html:
	make html-install

# make debian-ps DOC_DIR=../debian/gri-ps-doc/usr/share/doc/gri
# builds and installs under $(DOC_DIR)
debian-ps: gri.ps
	$(INSTALL) -d $(DOC_DIR)
	$(INSTALL) -m 644 gri.ps $(DOC_DIR)
