#!/bin/sh

# This file is automatically-generated by automake and autoconf from k3d.in ... do not edit manually!

###################################################
# Setup our default configured paths

prefix=/usr
exec_prefix=${prefix}
bindir=${exec_prefix}/bin
sbindir=${exec_prefix}/sbin
libexecdir=${exec_prefix}/libexec
datadir=${prefix}/share
sysconfdir=${prefix}/etc
sharedstatedir=${prefix}/com
localstatedir=${prefix}/var
libdir=${exec_prefix}/lib
infodir=${prefix}/share/info
mandir=${prefix}/share/man
includedir=${prefix}/include
oldincludedir=/usr/include
pkgdatadir=$datadir/k3d
pkglibdir=$libdir/k3d
pkgincludedir=$includedir/k3d

k3d_default_dialogs=$pkgdatadir/dialogtemplates
k3d_default_libs=$pkglibdir
k3d_default_shader_sources=$pkgdatadir/shaders
k3d_default_shader_cache=~/.k3d/shadercache
k3d_default_share=$pkgdatadir
k3d_default_tutorials=$pkgdatadir/tutorials
k3d_default_options=~/.k3d/options.k3d

#####################################################
# Setup paths that can be overridden ...

k3d_dialogs=$k3d_default_dialogs
k3d_libs=$k3d_default_libs
k3d_shader_sources=$k3d_default_shader_sources
k3d_shader_cache=$k3d_default_shader_cache
k3d_share=$k3d_default_share
k3d_tutorials=$k3d_default_tutorials
k3d_options=$k3d_default_options

######################################################
# Override paths with environment variables

if test -n "$K3D_DIALOG_TEMPLATES_PATH"; then
	k3d_dialogs=$K3D_DIALOG_TEMPLATES_PATH
fi

if test -n "$K3D_LIB_PATHS"; then
	k3d_libs=$K3D_LIB_PATHS
fi

if test -n "$K3D_SHADER_SOURCE_PATHS"; then
	k3d_shader_sources=$K3D_SHADER_SOURCE_PATHS
fi

if test -n "$K3D_SHADER_CACHE_PATH"; then
	k3d_shader_cache=$K3D_SHADER_CACHE_PATH
fi

if test -n "$K3D_SHARE_PATH"; then
	k3d_share=$K3D_SHARE_PATH
fi

if test -n "$K3D_TUTORIALS_PATH"; then
	k3d_tutorials=$K3D_TUTORIALS_PATH
fi

if test -n "$K3D_OPTIONS_PATH"; then
	k3d_options=$K3D_OPTIONS_PATH
fi

#####################################################
# Look for arguments that allow us to return immediately ...

while test -n "$1"; do
	case $1 in
		-h | --help )
			cat << eof
			
usage: k3d [options]

      -h, --help                  prints this help information and exits
      --dialogpath [path]         overrides the path for storing dialog templates [default: $k3d_default_dialogs]
      --libpaths [path]           overrides the path(s) for loading plugin libraries [default: $k3d_default_libs]
      --shadersourcepaths [paths] overrides the path(s) for loading shader source code [default: $k3d_default_shader_sources]
      --shadercachepath [paths]   overrides the path for storing compiled shaders [default: $k3d_default_shader_cache]
      --sharepath [path]          overrides the path for loading shared data files [default: $k3d_default_share]
      --tutorialspath [path]      overrides the path for loading interactive tutorials [default: $k3d_default_tutorials]
      --optionsfile [file]        overrides the filepath for storing user options [default: $k3d_default_options]
  -n, --new                       creates a new document after startup
  -o, --open [file]               opens the given file after startup
      --tutorials                 opens the tutorials menu immediately after startup
      --record-tutorials          opens the tutorial recorder immediately after startup
      --script [file]             play the given script after startup (use - for stdin)
      --batch                     operate in batch (no user intervention) mode
      --exit                      exits the program (useful after running scripts in batch mode)
      --show-timestamps           prints timestamps next to log messages
      --show-process              prints the process name next to log messages
      --color                     color-codes log messages based on their level
      --syslog                    logs messages to syslog
      --log-level [level]         specifies the minimum message priority to log - 
                                       valid values are "warning", "information", "debug" [default: warning]
      --version                   prints program version information and exits
      --nosplash                  disables the startup splash screen
      --gui [gui type]            specifies the type of GUI to provide - valid values are "none" or "gtk" [default: gtk]
      --blackbox [file]           starts the Black Box Recorder, recording to [file]
      
eof
			exit 0;;
		
		--version )
			cat << eof
			
K-3D Version 0.4.3.0
Copyright (c) 1995-2004, Timothy M. Shead.  See the AUTHORS file for contributors.
Licensed by the GNU General Public License.  See the COPYING file for details.
K-3D Home Page: http://k3d.sourceforge.net
Bug reports to tshead@k-3d.com

eof
			exit 0;;

		--show-arguments ) k3d_show_arguments="yes"; shift;;
		
		--dialogpath ) k3d_dialogs=$2; shift 2;;
		
		--libpaths ) k3d_libs=$2; shift 2;;
		
		--shadersourcepaths ) k3d_shader_sources=$2; shift 2;;
		
		--shadercachepath ) k3d_shader_cache=$2; shift 2;;
		
		--sharepath ) k3d_share=$2; shift 2;;
		
		--tutorialspath ) k3d_tutorials=$2; shift 2;;
		
		--optionsfile ) k3d_options=$2; shift 2;;
		
		*) arguments="$arguments $1"; shift;;
	esac
done

######################################################
# Allow "&" as a synonym for the default paths
# in selected cases

k3d_libs=`echo "$k3d_libs" | sed -e "s|&|$k3d_default_libs|g"`

k3d_shader_sources=`echo "$k3d_shader_sources" | sed -e "s|&|$k3d_default_shader_sources|g"`

######################################################
# By default, we run the binary from its configured directory,
# but it can be overridden by specifying k3d_execdir when run
# (we use this for the "make test" target)

if test x$k3d_execdir = "x"; then
	k3d_execdir=${exec_prefix}/bin
fi

######################################################
# Make it happen!

export PATH=$k3d_execdir:$PATH

command="$k3d_execdir/k3d-bin \
	--dialogpath $k3d_dialogs \
	--libpaths $k3d_libs \
	--shadersourcepaths $k3d_shader_sources \
	--shadercachepath $k3d_shader_cache \
	--sharepath $k3d_share \
	--tutorialspath $k3d_tutorials \
	--optionsfile $k3d_options \
	$arguments"

if test x$k3d_show_arguments = "xyes"; then
	echo $command
else
	eval $command
fi

