GEOMROOT=
BINDIR=/usr/local/bin
MANDIR=/usr/catman/local
MMAPACKAGEDIR=

SHELL=/bin/sh
INSTALL = ./tools/inst
DIRSEQ = ./tools/dirseq
INSUREDIR=./tools/insuredir

install:	install_all

install_all:	demand_GEOMROOT install_script install_bin install_man install_mma 

install_script: 
	@/bin/rm -f geomview.old
	@cp geomview geomview.old
	@/bin/rm -f geomview
	@sed -e 's|^GEOMROOT=.*$$|GEOMROOT=${GEOMROOT}|' < geomview.old > geomview
	@chmod a+x geomview;
	@echo 'Edited "geomview" to set GEOMROOT=${GEOMROOT}.'
	@${INSUREDIR} ${BINDIR}
	@${INSTALL} geomview ${BINDIR}

install_bin:
	@${INSUREDIR} ${BINDIR} ; \
	if ${DIRSEQ} ./bin/sgi ${BINDIR} ; then \
	  echo 'The executable files are in ${GEOMROOT}/bin/sgi (not' ; \
	  echo '  installed outside the Geomview distribution directory).' ; \
	else \
	  for f in `find bin/sgi -type f -print` ; do \
	    name=`basename $$f` ; \
	    if [ "$$name" != "gvx" ] ; then \
	      ${INSTALL} $$f ${BINDIR} ; \
	    fi ; \
	  done ; \
	fi
	
install_man:
	@mandir=${MANDIR}; \
	if ${DIRSEQ} ./man ${MANDIR} ; then \
	  echo 'The manual page files are in ${GEOMROOT}/man (not' ; \
	  echo '  installed outside the Geomview distribution directory).';\
	else \
	  for f in `find man -name '*.[1-9]' -print` ; do \
	    mdir=$$mandir/`expr "$$f" : "man/\([^/]*\)/.*"` ; \
	    ${INSUREDIR} $$mdir ; \
	    ${INSTALL} $$f $$mdir ; \
	  done ; \
	fi

install_mma:
	@mmapackagedir=${MMAPACKAGEDIR}; \
	if [ "$$mmapackagedir" != "" ] ; then \
	  if ${DIRSEQ} ./mathematica ${MMAPACKAGEDIR} ; then \
	    echo 'The Mathematica packages are in ${GEOMROOT}/mathematica (not';\
	    echo '  installed outside the Geomview distribution directory).';\
	  else \
	    ${INSUREDIR} $$mmapackagedir ; \
	    for f in `find mathematica -name '*.m' -print` ; do \
	      ${INSTALL} $$f $$mmapackagedir ; \
	    done ; \
	  fi ; \
	fi

demand_GEOMROOT:
	@if [ -z "${GEOMROOT}" ]; then \
	    echo "Error: GEOMROOT variable not set." >&2; \
	    exit 1; \
	fi
	@if [ ! -d "${GEOMROOT}" ]; then \
	    echo "Error: GEOMROOT directory ${GEOMROOT} does not exist." >&2;\
	    exit 1; \
	fi
	@if [ ! -x ./tools/insuredir ] ; then \
	    echo "Error: you do not appear to be in the Geomview root." >&2;\
	    echo "  directory.">&2; \
	fi
