#!/bin/sh
#
# Script used to create the button.swf file on Unix machines
# Written by Alexis Wilke for Made to Order Software, Ltd. (c) 2002-2006
#
# Copyright (c) 2002-2006 Made to Order Software, Ltd.
#
# Permission is hereby granted, free of charge, to any
# person obtaining a copy of this software and
# associated documentation files (the "Software"), to
# deal in the Software without restriction, including
# without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom
# the Software is furnished to do so, subject to the
# following conditions:
#
# The above copyright notice and this permission notice
# shall be included in all copies or substantial
# portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
# ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
# EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
set -e

# Try to find the sswf binary
#	AMake puts the result in a bin folder
#	./configure leaves them in the source directory
#	A binary installation puts them in some bin directory
SSWF=
for x in ../../bin/sswf ../../../bin/sswf ../../../../bin/sswf \
		../../src/sswf/sswf \
		`whereis sswf` /usr/bin/sswf /usr/local/bin/sswf
do
	# Note: if whereis returns a path with a space, this search is
	#	totally broken!
	if test -x $x -a ! -d $x
	then
		SSWF=$x
		break
	fi
done
if test "$SSWF" = ""
then
	# This is a default in case it was installed in some unconvential
	# place it still will work (unconventional for even whereis to
	# not find it that is...)
	SSWF=sswf
fi

# Now try to locate our include files
INC=
for i in ../../include/sswf/scripts ../../../include/sswf/scripts \
		../../../../include/sswf/scripts ../../scripts \
		../../../share/sswf/scripts ../../../../share/sswf/scripts \
		/usr/include/sswf/scripts /usr/share/sswf/scripts \
		/usr/local/include/sswf/scripts /usr/local/share/sswf/scripts
do
	if test -d $i
	then
		INC=$i
		break
	fi
done
if test "$INC" = ""
then
	# This we can't do anything more...
	echo "ERROR: can't locate the sswf/scripts include directory"
	exit 1
fi

# Print info about what we just found
echo "INFO: running sswf found here: \"$SSWF\"."
echo "INFO: using the include scripts from: \"$INC\"."
