vp-build/common/environment/setup/options.sh
maxice8 daf68c6d59 rename vopt_onoff to vopt_bool which returns -D<prop>=true|false
This makes it more generic and allows us to use it freely between
cmake and meson build styles.
2018-05-04 10:56:26 +02:00

41 lines
1010 B
Bash

# vim: set ts=4 sw=4 et:
vopt_if() {
local name="build_option_$1" t="$2" f="$3"
if [ ${!name} ]; then
echo -n "$t"
else
echo -n "$f"
fi
}
vopt_with() {
local opt="$1" flag="${2:-$1}"
vopt_if "$opt" "--with-${flag}" "--without-${flag}"
}
vopt_enable() {
local opt="$1" flag="${2:-$1}"
if [ "$#" -gt "2" ]; then
msg_error "vopt_enable $opt: $(($# - 2)) excess parameter(s)\n"
fi
vopt_if "$1" "--enable-${flag}" "--disable-${flag}"
}
vopt_conflict() {
local opt1="$1" opt2="$2" n1="build_option_$1" n2="build_option_$2"
if [ "${!n1}" -a "${!n2}" ]; then
msg_error "options '${opt1}' and '${opt2}' conflict\n"
fi
}
vopt_bool() {
local opt="$1" prop="$2"
if [ "$#" -lt "2" ]; then
msg_error "vopt_bool <build_option> <property>: missing values\n"
elif [ "$#" -gt "2" ]; then
msg_error "vopt_bool $opt: $(($# - 2)) excess parameter(s)\n"
fi
vopt_if "$1" "-D${prop}=true" "-D${prop}=false"
}