#! /bin/sh -
##
## octave-config - reports some configuration values for Octave
##
## Copyright (C) 2001, 2003, 2006, 2007 John W. Eaton
##
## This file is part of Octave.
##
## Octave is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or (at
## your option) any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, see
## <http://www.gnu.org/licenses/>.
## 
## Original version by Rafael Laboissiere <rafael@laboissiere.net>
## distributed as free software in the public domain.

API_VERSION="api-v32"
CANONICAL_HOST_TYPE="sparc64-unknown-openbsd4.9"
DEFAULT_PAGER="less"
ARCHLIBDIR="/usr/local/libexec/octave/3.0.5/exec/sparc64-unknown-openbsd4.9"
BINDIR="/usr/local/bin"
DATADIR="/usr/local/share"
DATAROOTDIR="/usr/local/share"
EXEC_PREFIX="/usr/local"
FCNFILEDIR="/usr/local/share/octave/3.0.5/m"
IMAGEDIR="/usr/local/share/octave/3.0.5/imagelib"
INCLUDEDIR="/usr/local/include"
INFODIR="/usr/local/info"
INFOFILE="/usr/local/info/octave.info"
LIBDIR="/usr/local/lib"
LIBEXECDIR="/usr/local/libexec"
LOCALAPIARCHLIBDIR="/usr/local/libexec/octave/api-v32/site/exec/sparc64-unknown-openbsd4.9"
LOCALAPIFCNFILEDIR="/usr/local/share/octave/site/api-v32/m"
LOCALAPIOCTFILEDIR="/usr/local/libexec/octave/site/oct/api-v32/sparc64-unknown-openbsd4.9"
LOCALARCHLIBDIR="/usr/local/libexec/octave/site/exec/sparc64-unknown-openbsd4.9"
LOCALFCNFILEDIR="/usr/local/share/octave/site/m"
LOCALOCTFILEDIR="/usr/local/libexec/octave/site/oct/sparc64-unknown-openbsd4.9"
LOCALSTARTUPFILEDIR="/usr/local/share/octave/site/m/startup"
LOCALVERARCHLIBDIR="/usr/local/libexec/octave/3.0.5/site/exec/sparc64-unknown-openbsd4.9"
LOCALVERFCNFILEDIR="/usr/local/share/octave/3.0.5/site/m"
LOCALVEROCTFILEDIR="/usr/local/libexec/octave/3.0.5/site/oct/sparc64-unknown-openbsd4.9"
MAN1DIR="/usr/local/man/man1"
MAN1EXT=".1"
MANDIR="/usr/local/man"
OCTFILEDIR="/usr/local/libexec/octave/3.0.5/oct/sparc64-unknown-openbsd4.9"
OCTINCLUDEDIR="/usr/local/include/octave-3.0.5"
OCTLIBDIR="/usr/local/lib"
PREFIX="/usr/local"
STARTUPFILEDIR="/usr/local/share/octave/3.0.5/m/startup"
VERSION="3.0.5"

if [ -n "$OCTAVE_HOME" ]; then
  ARCHLIBDIR="`echo $ARCHLIBDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  BINDIR="`echo $BINDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  DATADIR="`echo $DATADIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  DATAROOTDIR="`echo $DATAROOTDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  EXEC_PREFIX="`echo $EXEC_PREFIX | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  FCNFILEDIR="`echo $FCNFILEDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  IMAGEDIR="`echo $IMAGEDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  INCLUDEDIR="`echo $INCLUDEDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  INFODIR="`echo $INFODIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  INFOFILE="`echo $INFOFILE | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  LIBDIR="`echo $LIBDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  LIBEXECDIR="`echo $LIBEXECDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  LOCALAPIARCHLIBDIR="`echo $LOCALAPIARCHLIBDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  LOCALAPIFCNFILEDIR="`echo $LOCALAPIFCNFILEDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  LOCALAPIOCTFILEDIR="`echo $LOCALAPIOCTFILEDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  LOCALARCHLIBDIR="`echo $LOCALARCHLIBDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  LOCALFCNFILEDIR="`echo $LOCALFCNFILEDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  LOCALOCTFILEDIR="`echo $LOCALOCTFILEDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  LOCALSTARTUPFILEDIR="`echo $LOCALSTARTUPFILEDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  LOCALVERARCHLIBDIR="`echo $LOCALVERARCHLIBDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  LOCALVERFCNFILEDIR="`echo $LOCALVERFCNFILEDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  LOCALVEROCTFILEDIR="`echo $LOCALVEROCTFILEDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  MAN1DIR="`echo $MAN1DIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  MANDIR="`echo $MANDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  OCTFILEDIR="`echo $OCTFILEDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  OCTINCLUDEDIR="`echo $OCTINCLUDEDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  OCTLIBDIR="`echo $OCTLIBDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"
  STARTUPFILEDIR="`echo $STARTUPFILEDIR | sed "s,^$PREFIX,$OCTAVE_HOME,"`"

  PREFIX="$OCTAVE_HOME"
fi

usage_msg="usage: octave-config [options]"

if [ $# -eq 0 ]; then
  echo "$usage_msg" 1>&2
  exit 1
fi

while [ $# -gt 0 ]
do
  case "$1" in
    -h | -\? | --help)
      echo "$usage_msg"
      cat << EOF

Options:

  -h, -?, --help        Print this message.

  --m-site-dir          Print the name of the directory where Octave
                        expects to find locally installed .m files.

  --oct-site-dir        Print the name of the directory where Octave
                        expects to find locally installed .oct files.

  -p VAR, --print VAR   Print the value of the given configuration
		        variable VAR.  Recognized variables are:

			  API_VERSION	         LOCALAPIARCHLIBDIR
			  CANONICAL_HOST_TYPE	 LOCALAPIFCNFILEDIR
			  DEFAULT_PAGER	         LOCALAPIOCTFILEDIR
			  ARCHLIBDIR	         LOCALARCHLIBDIR
			  BINDIR	         LOCALFCNFILEDIR
			  DATADIR	         LOCALOCTFILEDIR
			  EXEC_PREFIX	         LOCALSTARTUPFILEDIR
			  FCNFILEDIR	         LOCALVERARCHLIBDIR
			  LOCALVEROCTFILEDIR	 LOCALVERFCNFILEDIR
			  IMAGEDIR	         MAN1DIR
			  MAN1EXT	         MANDIR
			  INCLUDEDIR	         OCTFILEDIR
			  INFODIR	         OCTINCLUDEDIR
			  INFOFILE	         OCTLIBDIR
			  LIBDIR	         PREFIX
			  LIBEXECDIR	         STARTUPFILEDIR
			  LIBEXECDIR		 VERSION

  -v, --version         Print the Octave version number.

EOF
      exit 0
    ;;
    --m-site-dir)
      echo $LOCALVERFCNFILEDIR
    ;;
    --oct-site-dir)
      echo $LOCALVEROCTFILEDIR
    ;;
    -v | --version)
      echo $VERSION
    ;;
    -p | --print)
      opt="$1"
      shift
      if [ $# -eq 0 ]; then
        echo "octave-config: $opt option requires argument" 1>&2
        exit 1
      fi
      eval echo \${$1}
    ;;
    *)
      echo "octave-config: unrecognized argument $1" 2>&1
      exit 1
    ;;
  esac
  shift
done
