#!/bin/sh
# NAME
#	papaya-config.in - source code for papaya-config which prints
#			   configulation information for papaya
# VERSION
#	$Id$
# CHANGELOG
#	$Log$
# SYNOPSYS
#	papaya-config [options]
#  [options]
#    --bin-path [command] : output the path of "bin" directory or full path of
#			    command @var{command} if it is given.
#    --data-path          : output the path of "share" directory.
#    --exec command [arg] : execute @var{command} in @file{bin} directory
#    --lib-path           : output the path of "lib" directory.
#    --libexec-path       : output the path of "libexec" directory.
#    --version		  : output the version information of papaya.
# COPYRIGHT
#  Copyright (C) 2000,2001 Steel Wheels Project.
#  This file is a apart of the papaya utilities. 
#  If you need the information of copyright of this file, see COPYING
#  file distributed with file or see http://www.asahi-net.or.jp/~em7t-hmd
#  web page.
# REFERENCE
#  `gtk-config' distributed with gtk+-1.2.6

# variables which defined by configure 
this="papaya-config" ;
prefix="/usr/pkg" ;
exec_prefix="${prefix}" ;
libdir="${exec_prefix}/lib" ;
bindir="${exec_prefix}/bin" ;
libexecdir="${exec_prefix}/libexec" ;
datadir="${prefix}/share" ;
version="0.1.7" ;

# subroutine: usage - printout usage
usage() {
	cat << END_USAGE
Usage: papaya-config OPTION
Options:
	--bin-path [command]
	--data-path
	--exec command [arg1 arg2 ...]
	--lib-path
	--libexec-path
	--version
Libraries:
	papaya
END_USAGE
	exit $1 ;
}

echo_path() {
	if test "X$2" = "X" ; then
		echo $1 ;
	else	
		echo "$1/$2" ;
	fi
}

exec_command() {
	CMD="$bindir/$1" ;
	if [ -x $CMD ] ; then
		shift 2> /dev/null ;
		if $CMD $* ; then
			exit 0 ;
		else
			echo "$this [ERROR] execution of \"$CMD\" is failed" ;
			exit 1 ;
		fi
	else
		echo "$this [ERROR] There are no executable: \"$CMD\"" ;
		exit 1 ;
	fi
}

# main
{
	# if no arguments are given, display usage
	if test $# -eq 0 ; then
		usage 1 1>&2 ;
	fi

	# analyze arguments
	while test $# -gt 0 ; do
		case "$1" in
		  --bin-path )
		  	echo_path "${exec_prefix}/bin" $2 ;
			shift 2> /dev/null ;
			shift 2> /dev/null ;;
		  --data-path )
		  	echo_path "$datadir" $2 ;
			shift 2> /dev/null ;
			shift 2> /dev/null ;;
		  --exec )
			shift 2> /dev/null ;
			exec_command $* ;;
		  --lib-path )
		  	echo_path "$libdir" $2 ;
			shift 2> /dev/null ;
			shift 2> /dev/null ;;
		  --libexec-path )
		  	echo_path "$libexecdir" $2 ;
			shift 2> /dev/null ;
			shift 2> /dev/null ;;
		  --version )
		  	echo "${version}" ;
			shift 2> /dev/null ;;
		  *) echo "$this [ERROR] unknown option \"$1\"" ;
		     usage ;;
		esac
	done
	exit 0 ;
}

