#!/bin/sh

echo Welcome to the ISE Eiffel 5 installer

ERROR_ENV=""
if [ ! "$ISE_EIFFEL" ]; then
	echo "The environment variable ISE_EIFFEL should be set to the directory where ISE Eiffel 5 is installed (typically the current directory: `pwd`)"
	ERROR_ENV=TRUE
fi
if [ ! "$ISE_PLATFORM" ]; then
	echo The environment variable ISE_PLATFORM should be set to one of these values, depending on your platform:
	echo linux-glibc2.1, linux-glibc, sgi, sgi-64, solaris, solaris-2.5+, alpha or unixware.
	ERROR_ENV=TRUE
fi
if [ "ERROR_ENV" = "TRUE" ]; then
	echo "When the needed environment variable(s) are set, launch $0 again."
	exit
fi

echo "Do you want to precompile EiffelBase (required to compile examples) ? [y/n]"
read prec_base
echo "Do you want to precompile EiffelVision (might take a while) ? [y/n]"
read prec_vision2

INIT_DIR=`pwd`

if [ "$prec_base" != "n" ]; then
	echo Precompile EiffelBase
	cd $ISE_EIFFEL/precomp/spec/$ISE_PLATFORM
	$ISE_EIFFEL/studio/spec/$ISE_PLATFORM/bin/ec -precompile -config base.ecf -c_compile -clean
fi
if [ "$prec_vision2" = "y" ]; then
	if which pkg-config > /dev/null 2>&1 ; then
		if pkg-config --atleast-version=2.4 gtk+-2.0 ; then
			echo Precompile EiffelVision
			cd $ISE_EIFFEL/precomp/spec/$ISE_PLATFORM
			$ISE_EIFFEL/studio/spec/$ISE_PLATFORM/bin/ec -precompile -config vision2.ecf -c_compile -clean
		else
			echo "GTK 2.4 does not seem to be installed"
			echo "Precompilation of EiffelVision interrupted."
		fi
	else
		echo "GTK 2.4 does not seem to be installed"
		echo "Precompilation of EiffelVision interrupted."
	fi
fi

cd $INIT_DIR
