# common configure script

SELF=$(readlink -f "$0")
SCRIPTS=$(dirname "$SELF")
SOURCE=$(dirname "$SCRIPTS")
SBUILD=$(pwd)
BUILD=$(readlink -f "$SBUILD")

if [ -d "$1" ]
then
	SOURCE=$(readlink -f "$1")
fi

if [ "$SOURCE" = "$BUILD" ]
then
	if echo $* | grep FORCE_IN_SOURCE_BUILD=ON
	then
		echo "Warning: in source build!"
		echo "It is recommended to create a new directory and run $SELF there"
		echo "Proceeding as requested"
	else
		echo "Error: in source build!"
		echo "It is recommended to create a new directory and run $SELF there"
		echo "You can force an in-tree build with -DFORCE_IN_SOURCE_BUILD=ON"
		exit 1
	fi
fi

if [ "$SCRIPTS" = "$BUILD" ]
then
	echo "You seem to be in the scripts directory, create a new directory and run $SELF there"
	exit 1
fi
