#!/bin/sh
# Copyright (C) 2000-2001 Open Source Telecom Corporation.
#
# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
#
root=""
system="false"

case "$1" in
--root)
	root="$2"
	shift
	shift
	;;
--sysroot)
	system="true"
	root="$2"
	shift
	shift
	;;
--system)
	system="true"
	shift
esac

INSTALL="/usr/bin/install -c"
INSTALL_DIR="$INSTALL -d -g bayonne -m 660"
INSTALL_DATA="$INSTALL -g bayonne -m 660"
DSOPATH=$root"/usr/local/lib/bayonne/1.0.11"
OPTIONS="-g -O2 -I/usr/local/include/cc++2 -I/usr/local/include -D_GNU_SOURCE -DXML_SCRIPTS"
SCRIPTS=$root"/usr/local/share/aascripts"
PROMPTS=$root"/usr/local/share/aaprompts"
LIBEXEC=$root"/usr/local/libexec/tgi"
WRAPPERS=$root"/usr/local/share/aawrappers"
opt="$1"
shift

HOME=$root`grep ^bayonne: /etc/passwd | cut -d: -f6`
APPS=$HOME/apps

if test "$system" = "true" ; then
	APPVOICE="$PROMPTS"
	APPSCRIPT="$SCRIPTS"
	APPHOME="$root/usr/local/share/bayonne"
else
	APPVOICE="$APPS"
	APPSCRIPT="$APPS/aascripts"
	APPHOME="$HOME"
fi

case "$opt" in
	-d | --dialog)
		$INSTALL_DATA *$ $DSOPATH
		;;
	-a | --apphome)
		subdir="$1"
		shift
		$INSTALL_DIR "$APPHOME/$subdir"
		$INSTALL_DATA $* "$APPHOME/$subdir"
		;;
	-l | --libexec)
		$INSTALL_DATA *$ "$LIBEXEC"
		;;
	-w | --wrapper)
		$INSTALL_DATA *$ $WRAPPERS
		;;
	-v | --voice)
		lib="$1"
		shift
		$INSTALL_DIR "$APPVOICE/$libs"
		$INSTALL_DATA $* "$APPVOICE/$lib"
		;;
	-s | --script)
		$INSTALL_DIR "$APPSCRIPT"
		$INSTALL_DATA $* "$APPSCRIPT"
		;;
	-c | --compile)
		for path in $* ; do
			c++ $OPTIONS -c $path
		done
		;;
	-i | --install)
		name=$1
		shift
		libtool --mode=link c++ -o $DSOPATH/$name -module -shared $*
		;;
	*)
		echo "use: baxs --compile sourcefiles | --install name files"
		exit -1
		;;
esac

