Variants are a way for port authors to provide options that may be invoked at install time. They are declared in the global section of a Portfile using the “variant” keyword, and should include carefully chosen variant descriptions.
The most common actions for user-selected variants is to add or remove dependencies, configure arguments, and build arguments according to various options a port author wishes to provide. Here is an example of several variants that modify depends_lib and configure arguments for a port.
variant fastcgi description {Add fastcgi binary} { configure.args-append \ --enable-fastcgi \ --enable-force-cgi-redirect \ --enable-memory-limit } variant gmp description {Add GNU MP functions} { depends_lib-append port:gmp configure.args-append --with-gmp=${prefix} } variant sqlite description {Build sqlite support} { depends_lib-append \ port:sqlite3 configure.args-delete \ --without-sqlite \ --without-pdo-sqlite configure.args-append \ --with-sqlite \ --with-pdo-sqlite=${prefix} \ --enable-sqlite-utf8 }
Variant names may contain only the characters A-Z, a-z, and the underscore character “_”. Therefore, take care to never use hyphens in variant names.
In the example variant declaration below, the configure argument
--without-x
is removed and a number of others are
appended.
variant x11 description {Builds port as an X11 program with Lucid widgets} { configure.args-delete --without-x configure.args-append --with-x-toolkit=lucid \ --without-carbon \ --with-xpm \ --with-jpeg \ --with-tiff \ --with-gif \ --with-png depends_lib-append lib:libX11:XFree86 \ lib:libXpm:XFree86 \ port:jpeg \ port:tiff \ port:libungif \ port:libpng }
If a variant requires options in addition to those provided by keywords using -append and/or -delete, in other words, any actions that would normally take place within a port installation phase, do not try to do this within the variant declaration. Rather, modify the behavior of any affected phases when the variant is invoked using the variant_isset keyword.
post-destroot { xinstall -m 755 -d ${destroot}${prefix}/etc/ xinstall ${worksrcpath}/examples/foo.conf \ ${destroot}${prefix}/etc/ if {[variant_isset carbon]} { delete ${destroot}${prefix}/bin/emacs delete ${destroot}${prefix}/bin/emacs-${version} } }
Variants are used to specify actions that lie outside the core functions of an application or port, but there may be some cases where you wish to specify these non-core functions by default. For this purpose you may use the keyword default_variants.
default_variants +foo +bar
The default_variant keyword may only be used in the global Portfile section.