#!/bin/bash
# sets up source tree for building

if echo $0 | grep -q force; then
	force=1
fi

if ! (test -f configure.ac || test -f CMakeLists.txt); then
	echo "sorry, no configure.ac or CMakeLists.txt in this directory"
	echo "you have to run this command in the root of source tree"
	exit 1
fi

if test -f ../configure.ac || test -f ../CMakeLists.txt; then
	if test -z "$force"; then
		echo "beware, there is a configure.ac or CMakeLists.txt in my parent"
		echo "directory -- if you are sure you are in a source tree root"
		echo "run otb-setup-force instead"
		exit 1
	fi
fi

echo you win, setting up otb

echo please do not remove this file, otb uses it to find root \
of the source tree > source-tree-root

# set up default build tree
otb-run :default touch build-tree-root

if test -e CMakeLists.txt; then
	echo "using cmake build system"
else
	echo "using autotools: sorry, cluttering your source tree"
	autoreconf -i
fi
