#!/bin/bash

CWD="`dirname \"$0\"`"

STUDIO_STRING=studio
BUILD_STRING=build
VISION2_DEMO_STRING=vision2_demo
CONSOLE_STRING=console

# Setup Environment Variables and create settings files
export ISE_EIFFEL=$CWD/../../..

if [ `uname -p` == "powerpc" ]; then
	export ISE_PLATFORM=macosx-ppc
elif [ `uname -p` == "i386" ]; then
	if (( `uname -r|cut -f1 -d.` >= 10 )) && [[ `sysctl hw.cpu64bit_capable` == "hw.cpu64bit_capable: 1" ]]; then
		export ISE_PLATFORM=macosx-x86-64
	else
		export ISE_PLATFORM=macosx-x86
	fi
fi

export PATH=$ISE_EIFFEL/studio/spec/$ISE_PLATFORM/bin:$ISE_EIFFEL/library/gobo/spec/$ISE_PLATFORM/bin:$PATH

if [ $1 = $STUDIO_STRING ]
then
	osascript -e "tell application \"Terminal\"
    				set newTab to do script \"export PATH=$PATH; export ISE_EIFFEL=$ISE_EIFFEL; export ISE_PLATFORM=$ISE_PLATFORM; clear; estudio;\"
    				set custom title of newTab to \"Eiffel Console\"
				  end tell"
fi

if [ $1 = $BUILD_STRING ]
then
	$ISE_EIFFEL/esbuilder/spec/$ISE_PLATFORM/bin/esbuilder
fi

if [ $1 = $VISION2_DEMO_STRING ]
then
	$ISE_EIFFEL/vision2_demo/spec/$ISE_PLATFORM/bin/vision2_demo
fi

if [ $1 = $CONSOLE_STRING ]
then
	osascript -e "tell application \"Terminal\"
    				set newTab to do script \"export PATH=$PATH; export ISE_EIFFEL=$ISE_EIFFEL; export ISE_PLATFORM=$ISE_PLATFORM; clear;\"
    				set custom title of newTab to \"Eiffel Console\"
					activate
				  end tell"
fi
