#!/bin/sh

echo
echo OBSOLETE: This precompilation builder wizard is now obsolete as precompiled libraries
echo OBSOLETE: are automatically built when needed in a user specific directory.
echo OBSOLETE:
echo OBSOLETE: If you intend to use it, it should only be used if you have write
echo OBSOLETE: permission to the following directory:
echo OBSOLETE: $ISE_EIFFEL
echo

ERROR_ENV=""
if [ ! "$ISE_EIFFEL" ]; then
	echo "The environment variable ISE_EIFFEL should be set to the directory where"
	echo "EiffelStudio is installed (typically the current directory)."
	echo "Current directory is `pwd`"
	ERROR_ENV=TRUE
fi
if [ ! "$ISE_PLATFORM" ]; then
	echo "The environment variable ISE_PLATFORM should be set to one of the following values,"
	echo "depending on your platform:"
	echo " "
	echo "   freebsd-x86"
	echo "   freebsd-x86-64"
	echo "   irix-mips"
	echo "   irix-mips-64"
	echo "   linux-sparc"
	echo "   linux-x86"
	echo "   linux-x86-64"
	echo "   macosx-x86"
	echo "   macosx-x86-64"
	echo "   openbsd-x86"
	echo "   openbsd-x86-64"
	echo "   solaris-sparc"
	echo "   solaris-sparc-64"
	echo "   solaris-x86"
	echo "   solaris-x86-64"
	echo " "
	ERROR_ENV=TRUE
fi
if [ "$ERROR_ENV" = "TRUE" ]; then
	echo "When the needed environment variable(s) are set, launch $0 again."
	exit 1
fi

ERROR_COMPILER=""
compiler="$ISE_EIFFEL/studio/spec/$ISE_PLATFORM/bin/ec"
if [ ! -f "$compiler" ]; then
	echo "Eiffel compiler $compiler not found or not a plain file"
	ERROR_COMPILER=TRUE
elif [ ! -x "$compiler" ]; then
	echo "Eiffel compiler $compiler not executable"
	ERROR_COMPILER=TRUE
elif [ ! -s "$compiler" ]; then
	echo "Eiffel compiler $compiler has size 0"
	ERROR_COMPILER=TRUE
fi    
if [ "$ERROR_COMPILER" = "TRUE" ]; then
	echo "Cannot precompile due to missing or nonexecutable compiler."
	echo "Please check that EiffelStudio was installed correctly."
	exit 1
fi

echo "Do you want to precompile EiffelBase (required to compile examples) ? [y/n]"
read prec_base
echo "Do you want to precompile void-safe EiffelBase ? [y/n]"
read prec_base_safe
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 " "
	echo Precompiling EiffelBase
	cd $ISE_EIFFEL/precomp/spec/$ISE_PLATFORM
	$compiler -precompile -config base.ecf -c_compile -clean
	echo " "
	echo Precompiling multithreaded EiffelBase
	$compiler -precompile -config base-mt.ecf -c_compile -clean
fi
if [ "$prec_base_safe" != "n" ]; then
	echo " "
	echo Precompiling void-safe EiffelBase
	cd $ISE_EIFFEL/precomp/spec/$ISE_PLATFORM
	$compiler -precompile -config base-safe.ecf -c_compile -clean
	echo " "
	echo Precompiling multithreaded void-safe EiffelBase
	$compiler -precompile -config base-mt-safe.ecf -c_compile -clean
	echo " "
	echo Precompiling SCOOP EiffelBase
	$compiler -precompile -config base-scoop-safe.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 " "
			echo Precompiling EiffelVision
			cd $ISE_EIFFEL/precomp/spec/$ISE_PLATFORM
			$compiler -precompile -config vision2.ecf -c_compile -clean
			echo " "
			echo Precompiling multithreaded EiffelVision
			$compiler -precompile -config vision2-mt.ecf -c_compile -clean
		else
			echo "GTK version 2.4 or later does not seem to be installed"
			echo "Precompilation of EiffelVision skipped."
		fi
	else
		echo "pkg-config does not seem to be installed"
		echo "Precompilation of EiffelVision skipped."
	fi
fi

cd $INIT_DIR
