7.2. Using FLAVORS

To declare a port having multiple flavors, add FLAVORS to its Makefile. The first flavor in FLAVORS is the default flavor.

Tip:

It can help simplify the logic of the Makefile to also define FLAVOR as:

FLAVOR?=	${FLAVORS:[1]}

Important:

To distinguish flavors from options, which are always uppercase letters, flavor names can only contain lowercase letters, numbers, and the underscore _.

Example 7.1. Basic Flavors Usage

If a port has a lite slave port, the slave port can be removed, and the port can be converted to flavors with:

FLAVORS=	default lite
lite_PKGNAMESUFFIX=	-lite
[...]
.if ${FLAVOR:U} != lite
[enable non lite features]
.endif

Note:

The first flavor is the default one, and is called, here, default. It is not an obligation, and if possible, use a more specific flavor name, like in Example 7.2, “Another Basic Flavors Usage”.


Example 7.2. Another Basic Flavors Usage

If a port has a -nox11 slave port, the slave port can be removed, and the port can be converted to flavors with:

FLAVORS=	x11 nox11
FLAVOR?=	${FLAVORS:[1]}
nox11_PKGNAMESUFFIX=	-nox11
[...]
.if ${FLAVOR} = x11
[enable x11 features]
.endif

Example 7.3. More Complex Flavors Usage

Here is a slightly edited excerpt of what is present in devel/libpeas, a port that uses the Python flavors. With the default Python 2 and 3 versions being 2.7 and 3.6, it will automatically get FLAVORS=py27 py36

USES=		gnome python
USE_PYTHON=	flavors 1

.if ${FLAVOR:Upy27:Mpy2*} 2
USE_GNOME=	pygobject3 3

CONFIGURE_ARGS+=	--enable-python2 --disable-python3

BUILD_WRKSRC=	${WRKSRC}/loaders/python 4
INSTALL_WRKSRC=	${WRKSRC}/loaders/python 5
.else # py3*
USE_GNOME+=	py3gobject3 6

CONFIGURE_ARGS+=	--disable-python2 --enable-python3 \
			ac_cv_path_PYTHON3_CONFIG=${LOCALBASE}/bin/python${PYTHON_VER}-config 7

BUILD_WRKSRC=	${WRKSRC}/loaders/python3 8
INSTALL_WRKSRC=	${WRKSRC}/loaders/python3 9
.endif

py34_PLIST=	${.CURDIR}/pkg-plist-py3 10
py35_PLIST=	${.CURDIR}/pkg-plist-py3 11
py36_PLIST=	${.CURDIR}/pkg-plist-py3 12

1

This port does not use USE_PYTHON=distutils but needs Python flavors anyway.

2

To guard against FLAVOR being empty, which would cause a make(1) error, use ${FLAVOR:U} in string comparisons instead of ${FLAVOR}.

3 6

The Gnome Python gobject3 bindings have two different names, one for Python 2, pygobject3 and one for Python 3, py3gobject3.

4 5 8 9

The configure script has to run in ${WRKSRC}, but we are only interested in building and installing the Python 2 or Python 3 parts of the software, so set the build and install base directories appropriately.

7

Hint about the correct Python 3 config script path name.

10 11 12

The packing list is different when the built with Python 3. As there are three possible Python 3 versions, set PLIST for all three using the helper.


7.2.1. Flavors Helpers

To make the Makefile easier to write, a few flavors helpers exist.

This list of helpers will set their variable:

  • flavor_PKGNAMEPREFIX

  • flavor_PKGNAMESUFFIX

  • flavor_PLIST

  • flavor_DESCR

This list of helpers will append to their variable:

  • flavor_CONFLICTS

  • flavor_CONFLICTS_BUILD

  • flavor_CONFLICTS_INSTALL

  • flavor_PKG_DEPENDS

  • flavor_EXTRACT_DEPENDS

  • flavor_PATCH_DEPENDS

  • flavor_FETCH_DEPENDS

  • flavor_BUILD_DEPENDS

  • flavor_LIB_DEPENDS

  • flavor_RUN_DEPENDS

  • flavor_TEST_DEPENDS

Example 7.4. Flavor Specific PKGNAME

As all packages must have a different package name, flavors must change theirs, using flavor_PKGNAMESUFFIX and flavor_PKGNAMESUFFIX makes this easy:

FLAVORS=	normal lite
lite_PKGNAMESUFFIX=	-lite

All FreeBSD documents are available for download at https://download.freebsd.org/ftp/doc/

Questions that are not answered by the documentation may be sent to <freebsd-questions@FreeBSD.org>.
Send questions about this document to <freebsd-doc@FreeBSD.org>.