#!/bin/bash
shopt -s extglob

MODULES=( base color messages checks substitute )

for mod in ${MODULES[@]}; do
	source $PWD/.configure/$mod
done

xcount=0
pcount=$#

while [[ $xcount -lt $pcount ]]; do
	case $1 in
		*maintainer )
			MODE=MAINTAINER
		;;

		*prefix* )
			PREFIX="${1/*=}"
		;;

		*dirinfo-disable )
			DIRINFO_ENABLE="false"
		;;

		*dirinfo-enable )
			DIRINFO_ENABLE="true"
		;;

		*quiet )
			QUIET="true"
		;;

		*help )
			MODE=HELP
		;;
	esac
	shift
	xcount=$(($xcount+1))
done

unset xcount pcount

if [[ ! $PREFIX ]]; then
	PREFIX="/usr"
fi

if [[ ! $DIRINFO_ENABLE ]]; then
	DIRINFO_ENABLE="false"
fi

if [[ ! $MODE ]]; then
	MODE=USER
fi

if [[ $MODE == HELP ]]; then

	help_message

elif [[ $MODE == MAINTAINER ]]; then

	maintainer_message
	copy_in_files
	substitute_values
	end_message
	export_result

elif [[ $MODE == USER ]]; then

	start_message
	check_apps
	check_libs
	check_pymods
	copy_in_files
	substitute_values
	end_message
	export_result

fi
