#!/usr/bin/env sh

BOLD="\033[1m"
RED="\033[91m"
GREEN="\033[92m"
YELLOW="\033[93m"
CYAN="\033[96m"
NORMAL="\033[0m"

# Make sure cmake is available.
if command -v cmake >/dev/null 2>&1;
then
	CMAKE=cmake
else
	echo "Error - cmake is not available!"
	exit 2
fi


help=false
build="debug"	# release
prefix=/usr/local

# Parse the args
for i in "$@"
do
	case $i in
		--help )				help=true ;;
		--debug )				build="debug" ;;
		--release )				build="release" ;;
		--prefix=* )			prefix="${i#--prefix=}" ;;
		* )						echo "Unrecognised argument $i" ;;
	esac
done

if [ "$help" = "true" ]
then
    echo "-----------------------------------------------"
    echo "nvidia-texture-tools "`cat VERSION`" configuration script"
    echo "-----------------------------------------------"
	echo
	echo "--help			Show this message."
	echo "--debug			Configure debug build."
	echo "--release			Configure release build."
	echo "--prefix=path		Installation prefix."
	echo "--include=path	Include path."
	echo "--lib=path		Library path."
	exit 0
fi

echo "-- Configuring nvidia-texture-tools "`cat VERSION`

mkdir -p ./build-$build
cd ./build-$build
$CMAKE .. -DNVTT_SHARED=0 -DCMAKE_BUILD_TYPE=$build -DCMAKE_INSTALL_PREFIX=$prefix -G "Unix Makefiles" || exit 1
cd ..

echo ""
echo -e "Your configure completed "$GREEN"successfully"$NORMAL", now type "$BOLD"make"$NORMAL
echo ""

cat > Makefile << EOF
all:
	@+make --no-print-directory -C build-$build/
install:
	@+make install --no-print-directory -C build-$build/
package:
	@+make package --no-print-directory -C build-$build/
test:
	@+make test --no-print-directory -C build-$build/
clean:
	@+make clean --no-print-directory -C build-$build/
distclean:
	@rm -Rf build-$build/
EOF
