me=$0
say() { echo >&2 "[1m($me)[m $1";      }
has() { command -v $1 >/dev/null 2>&1; return $?; }
check() {
	var=$1
	test "${!var}" == "" || return 0
	say "we were not able to detect a default value for the configuration variable \$$var. please set this variable to $2 and try again."
	exit 1
}

#test "$to" = "" && {
#	say "\$to environment variable must be set to your build directory - are you running this script by hand? run [1m./build.sh[m in the root directory instead!"
#	exit 2
#}

reqpack() {
	if ! has "$1"; then
		say "to $2 for [1mlibk[m, install the [1m$1[m package and try again"
		exit 3
	fi
}

noimpl() {
	say "$1 is not currently implemented on your system. an exciting chance for you to contribute, no?"
	exit 1
}

timestamp() { date "+%H:%M:%S %A"; }

scan() { find "$1" -name "$2"; }

if test "$COLORTERM" != ""; then
	announce() {
		test "$verbose" = "silent" && return
		local cmd="$1"; shift;
		local color=225;
		case "$cmd" in
			rm) color=196;; $asm) color=198;;
			$cc) color=213;; ar) color=120;;
			ranlib) color=105;; ld) color=216;;
			global/build-manpage.sh) color=177;;
			$m4) color=207;;
		esac

		printf " [1;95m→ [38;5;$color;1m$cmd[m"
		for a in "$@"; do
			if test ${a:0:1} = "-"; then
				printf " [91;3m$a[m";
			else
				printf " [94;4m$a[m";
			fi
		done
		echo
	}
else
	announce() { echo " --> " $@; }
fi

# the following function is called to report a command invocation
# the person compiling the library. the first argument should be
# an ansi format string; this is used to color-code the tool being
# launched and thus should be different for each one.

report() {
	announce $@; $@;
	status=$?
	if test $status -ne 0; then
		args=($@)
		say "process ${args[0]} failed with status code $status"
		exit $status
	fi
}
