add helpers for working with options

Add the helpers vopt_if, vopt_with and vopt_enable that simplify common
option-based operations.

Instead of a bunch of

if [ "$build_option_foo" ]; then
	configure_args+=" --with-foo"
	makedepends+=" foo-devel"
else
	configure_args+=" --without-foo"
fi

one can use

configure_args="... $(vopt_with foo)
makedepends="... $(vopt_if foo foo-devel)"

instead.

We're adding these functions to common/xbps-src/shutils/common.sh but
that might not be the ideal place. I would've preferred
common/helpers/options.sh, but helpers are only available in the
individual phases, not when the template itself gets parsed.
This commit is contained in:
Dominik Honnef 2014-08-30 00:29:33 +02:00
parent a81950142e
commit cdd2ce0da4
2 changed files with 43 additions and 7 deletions

View file

@ -566,3 +566,24 @@ remove_cross_pkg() {
msg_error "failed to remove cross-${XBPS_CROSS_TRIPLET} (error $rval)\n"
fi
}
vopt_if() {
local opt="$1" t="$2" f="$3"
name="build_option_$opt"
if [ ${!name} ]; then
echo -n "$t"
else
echo -n "$f"
fi
}
vopt_with() {
local opt="$1" flag="${2:-$1}"
vopt_if "$1" "--with-${flag}" "--without-${flag}"
}
vopt_enable() {
local opt="$1" flag="${2:-$1}"
vopt_if "$1" "--enable-${flag}" "--disable-${flag}"
}