#!/bin/sh

# common configure script
SCRIPTS_DIR=$(dirname "$0")
. "${SCRIPTS_DIR}/include-common"

SBUILD=$(pwd)
BUILD=$(readlink -f "$SBUILD")

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

# set JAVA_HOME if you want to use a non-default Java.
#cd /opt
#JAVA_IN_OPT=$(readlink -f $(find . -maxdepth 1 -name 'jdk*' -print -quit))
#
#if [ "x$JAVA_HOME" = "x" -a "x$JAVA_IN_OPT" != "x" ]
#then
#	export JAVA_HOME="$JAVA_IN_OPT"
#fi
#echo "Using java home: $JAVA_HOME"

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
