diff --git a/Manual.md b/Manual.md
index 9ea8dfbf89..4d8a5b884f 100644
--- a/Manual.md
+++ b/Manual.md
@@ -514,7 +514,26 @@ should be added to `common/options.description` instead.
After defining those required variables, you can check for the
`build_option_` variable to know if it has been set and adapt the source
-package accordingly.
+package accordingly. Additionally, the following functions are available:
+
+- *vopt_if()* `vopt_if []`
+
+ Outputs `if_true` if `option` is set, or `if_false` if it isn't set.
+
+- *vopt_with()* `vopt_with []`
+
+ Outputs `--with-` if the option is set, or `--without-`
+ otherwise. If `flag` isn't set, it defaults to `option`.
+
+ Examples:
+
+ - `vopt_with dbus`
+ - `vopt_with xml xml2`
+
+- *vopt_enable()* `vopt_enable []`
+
+ Same as `vopt_with`, but uses `--enable-` and
+ `--disable-` respectively.
The following example shows how to change a source package that uses GNU
configure to enable a new build option to support PNG images:
@@ -525,6 +544,8 @@ pkgname=foo
version=1.0
revision=1
build_style=gnu-configure
+configure_args="... $(vopt_with png)"
+makedepends="... $(vopt_if png libpng-devel)"
...
# Package build options
@@ -535,12 +556,6 @@ desc_option_png="Enable support for PNG images"
#
# build_options_default="png"
-if [ "$build_option_png" ]; then
- configure_args+=" --with-png"
- makedepends+=" libpng-devel"
-else
- configure_args+=" --without-png"
-fi
...
```
diff --git a/common/xbps-src/shutils/common.sh b/common/xbps-src/shutils/common.sh
index 3183add3c2..33efc57cd9 100644
--- a/common/xbps-src/shutils/common.sh
+++ b/common/xbps-src/shutils/common.sh
@@ -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}"
+}
+