libk  Artifact [0ffa5553a2]

Artifact 0ffa5553a210343cdf97c7ef85a9ca2347389d698d7024c3431c4e3c07252659:


me=$0
say() { echo >&2 "($me) $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 ./build.sh in the root directory instead!"
	exit 2
}

reqpack() {
	if ! has "$1"; then
		say "to $2 for libk, install the $1 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 " → [38;5;$color;1m$cmd"
		for a in "$@"; do
			if test ${a:0:1} = "-"; then
				printf " $a";
			else
				printf " $a";
			fi
		done
		echo
	}
else
	announce() { shift; 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 $@; $@; }