5.13. Makefile Options

Many applications can be built with optional or differing configurations. Examples include choice of natural (human) language, GUI versus command-line, or type of database to support. Users may need a different configuration than the default, so the ports system provides hooks the port author can use to control which variant will be built. Supporting these options properly will make users happy, and effectively provide two or more ports for the price of one.

5.13.1. OPTIONS

5.13.1.1. Background

OPTIONS_* give the user installing the port a dialog showing the available options, and then saves those options to ${PORT_DBDIR}/${OPTIONS_NAME}/options. The next time the port is built, the options are reused. PORT_DBDIR defaults to /var/db/ports. OPTIONS_NAME is to the port origin with an underscore as the space separator, for example, for dns/bind99 it will be dns_bind99.

When the user runs make config (or runs make build for the first time), the framework checks for ${PORT_DBDIR}/${OPTIONS_NAME}/options. If that file does not exist, the values of OPTIONS_* are used, and a dialog box is displayed where the options can be enabled or disabled. Then options is saved and the configured variables are used when building the port.

If a new version of the port adds new OPTIONS, the dialog will be presented to the user with the saved values of old OPTIONS prefilled.

make showconfig shows the saved configuration. Use make rmconfig to remove the saved configuration.

5.13.1.2. Syntax

OPTIONS_DEFINE contains a list of OPTIONS to be used. These are independent of each other and are not grouped:

OPTIONS_DEFINE=	OPT1 OPT2

Once defined, OPTIONS are described (optional, but strongly recommended):

OPT1_DESC=	Describe OPT1
OPT2_DESC=	Describe OPT2
OPT3_DESC=	Describe OPT3
OPT4_DESC=	Describe OPT4
OPT5_DESC=	Describe OPT5
OPT6_DESC=	Describe OPT6

ports/Mk/bsd.options.desc.mk has descriptions for many common OPTIONS. While often useful, override them if the description is insufficient for the port.

Tip:

When describing options, view it from the perspective of the user: What functionality does it change? and Why would I want to enable this? Do not just repeat the name. For example, describing the NLS option as include NLS support does not help the user, who can already see the option name but may not know what it means. Describing it as Native Language Support via gettext utilities is much more helpful.

Important:

Option names are always in all uppercase. They cannot use mixed case or lowercase.

OPTIONS can be grouped as radio choices, where only one choice from each group is allowed:

OPTIONS_SINGLE=		SG1
OPTIONS_SINGLE_SG1=	OPT3 OPT4

Warning:

There must be one of each OPTIONS_SINGLE group selected at all times for the options to be valid. One option of each group must be added to OPTIONS_DEFAULT.

OPTIONS can be grouped as radio choices, where none or only one choice from each group is allowed:

OPTIONS_RADIO=		RG1
OPTIONS_RADIO_RG1=	OPT7 OPT8

OPTIONS can also be grouped as multiple-choice lists, where at least one option must be enabled:

OPTIONS_MULTI=		MG1
OPTIONS_MULTI_MG1=	OPT5 OPT6

OPTIONS can also be grouped as multiple-choice lists, where none or any option can be enabled:

OPTIONS_GROUP=		GG1
OPTIONS_GROUP_GG1=	OPT9 OPT10

OPTIONS are unset by default, unless they are listed in OPTIONS_DEFAULT:

OPTIONS_DEFAULT=	OPT1 OPT3 OPT6

OPTIONS definitions must appear before the inclusion of bsd.port.options.mk. PORT_OPTIONS values can only be tested after the inclusion of bsd.port.options.mk. Inclusion of bsd.port.pre.mk can be used instead, too, and is still widely used in ports written before the introduction of bsd.port.options.mk. But be aware that some variables will not work as expected after the inclusion of bsd.port.pre.mk, typically some USE_* flags.

Example 5.39. Simple Use of OPTIONS
OPTIONS_DEFINE=	FOO BAR
OPTIONS_DEFAULT=FOO

FOO_DESC=	Option foo support
BAR_DESC=	Feature bar support

# Will add --with-foo / --without-foo
FOO_CONFIGURE_WITH=	foo
BAR_RUN_DEPENDS=	bar:bar/bar

.include <bsd.port.mk>

Example 5.40. Check for Unset Port OPTIONS
.if ! ${PORT_OPTIONS:MEXAMPLES}
CONFIGURE_ARGS+=--without-examples
.endif

The form shown above is discouraged. The preferred method is using a configure knob to really enable and disable the feature to match the option:

# Will add --with-examples / --without-examples
EXAMPLES_CONFIGURE_WITH=	examples

Example 5.41. Practical Use of OPTIONS
OPTIONS_DEFINE=		EXAMPLES
OPTIONS_DEFAULT=	PGSQL LDAP SSL

OPTIONS_SINGLE=		BACKEND
OPTIONS_SINGLE_BACKEND=	MYSQL PGSQL BDB

OPTIONS_MULTI=		AUTH
OPTIONS_MULTI_AUTH=	LDAP PAM SSL

EXAMPLES_DESC=		Install extra examples
MYSQL_DESC=		Use MySQL as backend
PGSQL_DESC=		Use PostgreSQL as backend
BDB_DESC=		Use Berkeley DB as backend
LDAP_DESC=		Build with LDAP authentication support
PAM_DESC=		Build with PAM support
SSL_DESC=		Build with OpenSSL support

# Will add USE_PGSQL=yes
PGSQL_USE=	pgsql=yes
# Will add --enable-postgres / --disable-postgres
PGSQL_CONFIGURE_ENABLE=	postgres

ICU_LIB_DEPENDS=	libicuuc.so:devel/icu

# Will add --with-examples / --without-examples
EXAMPLES_CONFIGURE_WITH=	examples

# Check other OPTIONS

.include <bsd.port.mk>

5.13.1.3. Default Options

These options are always on by default.

  • DOCS — build and install documentation.

  • NLS — Native Language Support.

  • EXAMPLES — build and install examples.

  • IPV6 — IPv6 protocol support.

Note:

There is no need to add these to OPTIONS_DEFAULT. To have them active, and show up in the options selection dialog, however, they must be added to OPTIONS_DEFINE.

5.13.2. Feature Auto-Activation

When using a GNU configure script, keep an eye on which optional features are activated by auto-detection. Explicitly disable optional features that are not needed by adding --without-xxx or --disable-xxx in CONFIGURE_ARGS.

Example 5.42. Wrong Handling of an Option
.if ${PORT_OPTIONS:MFOO}
LIB_DEPENDS+=		libfoo.so:devel/foo
CONFIGURE_ARGS+=	--enable-foo
.endif

In the example above, imagine a library libfoo is installed on the system. The user does not want this application to use libfoo, so he toggled the option off in the make config dialog. But the application's configure script detects the library present in the system and includes its support in the resulting executable. Now when the user decides to remove libfoo from the system, the ports system does not protest (no dependency on libfoo was recorded) but the application breaks.

Example 5.43. Correct Handling of an Option
FOO_LIB_DEPENDS=		libfoo.so:devel/foo
# Will add --enable-foo / --disable-foo
FOO_CONFIGURE_ENABLE=	foo

Note:

Under some circumstances, the shorthand conditional syntax can cause problems with complex constructs. The errors are usually Malformed conditional, an alternative syntax can be used.

.if !empty(VARIABLE:MVALUE)

as an alternative to

.if ${VARIABLE:MVALUE}

5.13.3. Options Helpers

There are some macros to help simplify conditional values which differ based on the options set. For easier access, a comprehensive list is provided:

PLIST_SUB, SUB_LIST

For automatic %%OPT%% and %%NO_OPT%% generation, see Section 5.13.3.1, “OPTIONS_SUB.

For more complex usage, see Section 5.13.3.11, “Generic Variables Replacement, OPT_VARIABLE and OPT_VARIABLE_OFF.

CONFIGURE_ARGS

For --enable-x and --disable-x, see Section 5.13.3.3.1, “OPT_CONFIGURE_ENABLE.

For --with-x and --without-x, see Section 5.13.3.3.2, “OPT_CONFIGURE_WITH.

For all other cases, see Section 5.13.3.3.3, “OPT_CONFIGURE_ON and OPT_CONFIGURE_OFF.

CMAKE_ARGS

For arguments that are booleans (on, off, true, false, 0, 1) see Section 5.13.3.4.2, “OPT_CMAKE_BOOL and OPT_CMAKE_BOOL_OFF.

For all other cases, see Section 5.13.3.4.1, “OPT_CMAKE_ON and OPT_CMAKE_OFF.

MESON_ARGS

For arguments that take true or false, see Section 5.13.3.5.2, “OPT_MESON_TRUE and OPT_MESON_FALSE.

For arguments that take yes or no, use Section 5.13.3.5.3, “OPT_MESON_YES and OPT_MESON_NO.

For arguments that take enabled or disabled, see Section 5.13.3.5.4, “OPT_MESON_ENABLED and OPT_MESON_DISABLED.

For all other cases, use Section 5.13.3.5.1, “OPT_MESON_ON and OPT_MESON_OFF.

QMAKE_ARGS

See Section 5.13.3.6, “OPT_QMAKE_ON and OPT_QMAKE_OFF.

USE_*

See Section 5.13.3.2, “OPT_USE and OPT_USE_OFF.

*_DEPENDS

See Section 5.13.3.10, “Dependencies, OPT_DEPTYPE and OPT_DEPTYPE_OFF.

* (Any variable)

The most used variables have direct helpers, see Section 5.13.3.11, “Generic Variables Replacement, OPT_VARIABLE and OPT_VARIABLE_OFF.

For any variable without a specific helper, see Section 5.13.3.9, “OPT_VARS and OPT_VARS_OFF.

Options dependencies

When an option need another option to work, see Section 5.13.3.7, “OPT_IMPLIES.

Options conflicts

When an option cannot work if another is also enabled, see Section 5.13.3.8, “OPT_PREVENTS and OPT_PREVENTS_MSG.

Build targets

When an option need some extra processing, see Section 5.13.3.12, “Additional Build Targets, target-OPT-on and target-OPT-off.

5.13.3.1. OPTIONS_SUB

If OPTIONS_SUB is set to yes then each of the options added to OPTIONS_DEFINE will be added to PLIST_SUB and SUB_LIST, for example:

OPTIONS_DEFINE=	OPT1
OPTIONS_SUB=	yes

is equivalent to:

OPTIONS_DEFINE=	OPT1

.include <bsd.port.options.mk>

.if ${PORT_OPTIONS:MOPT1}
PLIST_SUB+=	OPT1="" NO_OPT1="@comment "
SUB_LIST+=	OPT1="" NO_OPT1="@comment "
.else
PLIST_SUB+=	OPT1="@comment " NO_OPT1=""
SUB_LIST+=	OPT1="@comment " NO_OPT1=""
.endif

Note:

The value of OPTIONS_SUB is ignored. Setting it to any value will add PLIST_SUB and SUB_LIST entries for all options.

5.13.3.2. OPT_USE and OPT_USE_OFF

When option OPT is selected, for each key=value pair in OPT_USE, value is appended to the corresponding USE_KEY. If value has spaces in it, replace them with commas and they will be changed back to spaces during processing. OPT_USE_OFF works the same way, but when OPT is not selected. For example:

OPTIONS_DEFINE=	OPT1
OPT1_USES=	xorg
OPT1_USE=	mysql=yes xorg=x11,xextproto,xext,xrandr
OPT1_USE_OFF=	openssl=yes

is equivalent to:

OPTIONS_DEFINE=	OPT1

.include <bsd.port.options.mk>

.if ${PORT_OPTIONS:MOPT1}
USE_MYSQL=	yes
USES+=		xorg
USE_XORG=	x11 xextproto xext xrandr
.else
USE_OPENSSL=	yes
.endif

5.13.3.3. CONFIGURE_ARGS Helpers

5.13.3.3.1. OPT_CONFIGURE_ENABLE

When option OPT is selected, for each entry in OPT_CONFIGURE_ENABLE then --enable-entry is appended to CONFIGURE_ARGS. When option OPT is not selected, --disable-entry is appended to CONFIGURE_ARGS. An optional argument can be specified with an = symbol. This argument is only appended to the --enable-entry configure option. For example:

OPTIONS_DEFINE=	OPT1 OPT2
OPT1_CONFIGURE_ENABLE=	test1 test2
OPT2_CONFIGURE_ENABLE=	test2=exhaustive

is equivalent to:

OPTIONS_DEFINE=	OPT1

.include <bsd.port.options.mk>

.if ${PORT_OPTIONS:MOPT1}
CONFIGURE_ARGS+=	--enable-test1 --enable-test2
.else
CONFIGURE_ARGS+=	--disable-test1 --disable-test2
.endif

.if ${PORT_OPTIONS:MOPT2}
CONFIGURE_ARGS+=	--enable-test2=exhaustive
.else
CONFIGURE_ARGS+=	--disable-test2
.endif
5.13.3.3.2. OPT_CONFIGURE_WITH

When option OPT is selected, for each entry in OPT_CONFIGURE_WITH then --with-entry is appended to CONFIGURE_ARGS. When option OPT is not selected, --without-entry is appended to CONFIGURE_ARGS. An optional argument can be specified with an = symbol. This argument is only appended to the --with-entry configure option. For example:

OPTIONS_DEFINE=	OPT1 OPT2
OPT1_CONFIGURE_WITH=	test1
OPT2_CONFIGURE_WITH=	test2=exhaustive

is equivalent to:

OPTIONS_DEFINE=	OPT1 OPT2

.include <bsd.port.options.mk>

.if ${PORT_OPTIONS:MOPT1}
CONFIGURE_ARGS+=	--with-test1
.else
CONFIGURE_ARGS+=	--without-test1
.endif

.if ${PORT_OPTIONS:MOPT2}
CONFIGURE_ARGS+=	--with-test2=exhaustive
.else
CONFIGURE_ARGS+=	--without-test2
.endif
5.13.3.3.3. OPT_CONFIGURE_ON and OPT_CONFIGURE_OFF

When option OPT is selected, the value of OPT_CONFIGURE_ON, if defined, is appended to CONFIGURE_ARGS. OPT_CONFIGURE_OFF works the same way, but when OPT is not selected. For example:

OPTIONS_DEFINE=	OPT1
OPT1_CONFIGURE_ON=	--add-test
OPT1_CONFIGURE_OFF=	--no-test

is equivalent to:

OPTIONS_DEFINE=	OPT1

.include <bsd.port.options.mk>

.if ${PORT_OPTIONS:MOPT1}
CONFIGURE_ARGS+=	--add-test
.else
CONFIGURE_ARGS+=	--no-test
.endif

Tip:

Most of the time, the helpers in Section 5.13.3.3.1, “OPT_CONFIGURE_ENABLE and Section 5.13.3.3.2, “OPT_CONFIGURE_WITH provide a shorter and more comprehensive functionality.

5.13.3.4. CMAKE_ARGS Helpers

5.13.3.4.1. OPT_CMAKE_ON and OPT_CMAKE_OFF

When option OPT is selected, the value of OPT_CMAKE_ON, if defined, is appended to CMAKE_ARGS. OPT_CMAKE_OFF works the same way, but when OPT is not selected. For example:

OPTIONS_DEFINE=	OPT1
OPT1_CMAKE_ON=	-DTEST:BOOL=true -DDEBUG:BOOL=true
OPT1_CMAKE_OFF=	-DOPTIMIZE:BOOL=true

is equivalent to:

OPTIONS_DEFINE=	OPT1

.include <bsd.port.options.mk>

.if ${PORT_OPTIONS:MOPT1}
CMAKE_ARGS+=	-DTEST:BOOL=true -DDEBUG:BOOL=true
.else
CMAKE_ARGS+=	-DOPTIMIZE:BOOL=true
.endif

Tip:

See Section 5.13.3.4.2, “OPT_CMAKE_BOOL and OPT_CMAKE_BOOL_OFF for a shorter helper when the value is boolean.

5.13.3.4.2. OPT_CMAKE_BOOL and OPT_CMAKE_BOOL_OFF

When option OPT is selected, for each entry in OPT_CMAKE_BOOL then -Dentry:BOOL=true is appended to CMAKE_ARGS. When option OPT is not selected, -Dentry:BOOL=false is appended to CONFIGURE_ARGS. OPT_CMAKE_BOOL_OFF is the opposite, -Dentry:BOOL=false is appended to CMAKE_ARGS when the option is selected, and -Dentry:BOOL=true when the option is not selected. For example:

OPTIONS_DEFINE=	OPT1
OPT1_CMAKE_BOOL=	TEST DEBUG
OPT1_CMAKE_BOOL_OFF=	OPTIMIZE

is equivalent to:

OPTIONS_DEFINE=	OPT1

.include <bsd.port.options.mk>

.if ${PORT_OPTIONS:MOPT1}
CMAKE_ARGS+=	-DTEST:BOOL=true -DDEBUG:BOOL=true \
		-DOPTIMIZE:BOOL=false
.else
CMAKE_ARGS+=	-DTEST:BOOL=false -DDEBUG:BOOL=false \
		-DOPTIMIZE:BOOL=true
.endif

5.13.3.5. MESON_ARGS Helpers

5.13.3.5.1. OPT_MESON_ON and OPT_MESON_OFF

When option OPT is selected, the value of OPT_MESON_ON, if defined, is appended to MESON_ARGS. OPT_MESON_OFF works the same way, but when OPT is not selected. For example:

OPTIONS_DEFINE=	OPT1
OPT1_MESON_ON=	-Dopt=1
OPT1_MESON_OFF=	-Dopt=2

is equivalent to:

OPTIONS_DEFINE=	OPT1

.include <bsd.port.options.mk>

.if ${PORT_OPTIONS:MOPT1}
MESON_ARGS+=	-Dopt=1
.else
MESON_ARGS+=	-Dopt=2
.endif
5.13.3.5.2. OPT_MESON_TRUE and OPT_MESON_FALSE

When option OPT is selected, for each entry in OPT_MESON_TRUE then -Dentry=true is appended to MESON_ARGS. When option OPT is not selected, -Dentry=false is appended to MESON_ARGS. OPT_MESON_FALSE is the opposite, -Dentry=false is appended to MESON_ARGS when the option is selected, and -Dentry=true when the option is not selected. For example:

OPTIONS_DEFINE=	OPT1
OPT1_MESON_TRUE=	test debug
OPT1_MESON_FALSE=	optimize

is equivalent to:

OPTIONS_DEFINE=	OPT1

.include <bsd.port.options.mk>

.if ${PORT_OPTIONS:MOPT1}
MESON_ARGS+=	-Dtest=true -Ddebug=true \
		-Doptimize=false
.else
MESON_ARGS+=	-Dtest=false -Ddebug=false \
		-Doptimize=true
.endif
5.13.3.5.3. OPT_MESON_YES and OPT_MESON_NO

When option OPT is selected, for each entry in OPT_MESON_YES then -Dentry=yes is appended to MESON_ARGS. When option OPT is not selected, -Dentry=no is appended to MESON_ARGS. OPT_MESON_NO is the opposite, -Dentry=no is appended to MESON_ARGS when the option is selected, and -Dentry=yes when the option is not selected. For example:

OPTIONS_DEFINE=	OPT1
OPT1_MESON_YES=	test debug
OPT1_MESON_NO=	optimize

is equivalent to:

OPTIONS_DEFINE=	OPT1

.include <bsd.port.options.mk>

.if ${PORT_OPTIONS:MOPT1}
MESON_ARGS+=	-Dtest=yes -Ddebug=yes \
		-Doptimize=no
.else
MESON_ARGS+=	-Dtest=no -Ddebug=no \
		-Doptimize=yes
.endif
5.13.3.5.4. OPT_MESON_ENABLED and OPT_MESON_DISABLED

When option OPT is selected, for each entry in OPT_MESON_ENABLED then -Dentry=enabled is appended to MESON_ARGS. When option OPT is not selected, -Dentry=disabled is appended to MESON_ARGS. OPT_MESON_DISABLED is the opposite, -Dentry=disabled is appended to MESON_ARGS when the option is selected, and -Dentry=enabled when the option is not selected. For example:

OPTIONS_DEFINE=	OPT1
OPT1_MESON_ENABLED=	test
OPT1_MESON_DISABLED=	debug

is equivalent to:

OPTIONS_DEFINE=	OPT1

.include <bsd.port.options.mk>

.if ${PORT_OPTIONS:MOPT1}
MESON_ARGS+=	-Dtest=enabled -Ddebug=disabled
.else
MESON_ARGS+=	-Dtest=disabled -Ddebug=enabled
.endif

5.13.3.6. OPT_QMAKE_ON and OPT_QMAKE_OFF

When option OPT is selected, the value of OPT_QMAKE_ON, if defined, is appended to QMAKE_ARGS. OPT_QMAKE_OFF works the same way, but when OPT is not selected. For example:

OPTIONS_DEFINE=	OPT1
OPT1_QMAKE_ON=	-DTEST:BOOL=true
OPT1_QMAKE_OFF=	-DPRODUCTION:BOOL=true

is equivalent to:

OPTIONS_DEFINE=	OPT1

.include <bsd.port.options.mk>

.if ${PORT_OPTIONS:MOPT1}
QMAKE_ARGS+=	-DTEST:BOOL=true
.else
QMAKE_ARGS+=	-DPRODUCTION:BOOL=true
.endif

5.13.3.7. OPT_IMPLIES

Provides a way to add dependencies between options.

When OPT is selected, all the options listed in this variable will be selected too. Using the OPT_CONFIGURE_ENABLE described earlier to illustrate:

OPTIONS_DEFINE=	OPT1 OPT2
OPT1_IMPLIES=	OPT2

OPT1_CONFIGURE_ENABLE=	opt1
OPT2_CONFIGURE_ENABLE=	opt2

Is equivalent to:

OPTIONS_DEFINE=	OPT1 OPT2

.include <bsd.port.options.mk>

.if ${PORT_OPTIONS:MOPT1}
CONFIGURE_ARGS+=	--enable-opt1
.else
CONFIGURE_ARGS+=	--disable-opt1
.endif

.if ${PORT_OPTIONS:MOPT2} || ${PORT_OPTIONS:MOPT1}
CONFIGURE_ARGS+=	--enable-opt2
.else
CONFIGURE_ARGS+=	--disable-opt2
.endif
Example 5.44. Simple Use of OPT_IMPLIES

This port has a X11 option, and a GNOME option that needs the X11 option to be selected to build.

OPTIONS_DEFINE=	X11 GNOME
OPTIONS_DEFAULT=	X11

X11_USES=	xorg
X11_USE=	xorg=xi,xextproto
GNOME_USE=	gnome=gtk30
GNOME_IMPLIES=	X11

5.13.3.8. OPT_PREVENTS and OPT_PREVENTS_MSG

Provides a way to add conflicts between options.

When OPT is selected, all the options listed in OPT_PREVENTS must be un-selected. If OPT_PREVENTS_MSG is set and a conflict is triggered, its content will be shown explaining why they conflict. For example:

OPTIONS_DEFINE=	OPT1 OPT2
OPT1_PREVENTS=	OPT2
OPT1_PREVENTS_MSG=	OPT1 and OPT2 enable conflicting options

Is roughly equivalent to:

OPTIONS_DEFINE=	OPT1 OPT2

.include <bsd.port.options.mk>

.if ${PORT_OPTIONS:MOPT2} && ${PORT_OPTIONS:MOPT1}
BROKEN=	Option OPT1 conflicts with OPT2 (select only one)
.endif

The only difference is that the first one will write an error after running make config, suggesting changing the selected options.

Example 5.45. Simple Use of OPT_PREVENTS

This port has X509 and SCTP options. Both options add patches, but the patches conflict with each other, so they cannot be selected at the same time.

OPTIONS_DEFINE=	X509 SCTP

SCTP_PATCHFILES=	${PORTNAME}-6.8p1-sctp-2573.patch.gz:-p1
SCTP_CONFIGURE_WITH=	sctp

X509_PATCH_SITES=	http://www.roumenpetrov.info/openssh/x509/:x509
X509_PATCHFILES=	${PORTNAME}-7.0p1+x509-8.5.diff.gz:-p1:x509
X509_PREVENTS=		SCTP
X509_PREVENTS_MSG=	X509 and SCTP patches conflict

5.13.3.9. OPT_VARS and OPT_VARS_OFF

Provides a generic way to set and append to variables.

Warning:

Before using OPT_VARS and OPT_VARS_OFF, see if there is already a more specific helper available in Section 5.13.3.11, “Generic Variables Replacement, OPT_VARIABLE and OPT_VARIABLE_OFF.

When option OPT is selected, and OPT_VARS defined, key=value and key+=value pairs are evaluated from OPT_VARS. An = cause the existing value of KEY to be overwritten, an += appends to the value. OPT_VARS_OFF works the same way, but when OPT is not selected.

OPTIONS_DEFINE=	OPT1 OPT2 OPT3
OPT1_VARS=	also_build+=bin1
OPT2_VARS=	also_build+=bin2
OPT3_VARS=	bin3_build=yes
OPT3_VARS_OFF=	bin3_build=no

MAKE_ARGS=	ALSO_BUILD="${ALSO_BUILD}" BIN3_BUILD="${BIN3_BUILD}"

is equivalent to:

OPTIONS_DEFINE=	OPT1 OPT2

MAKE_ARGS=	ALSO_BUILD="${ALSO_BUILD}" BIN3_BUILD="${BIN3_BUILD}"

.include <bsd.port.options.mk>

.if ${PORT_OPTIONS:MOPT1}
ALSO_BUILD+=	bin1
.endif

.if ${PORT_OPTIONS:MOPT2}
ALSO_BUILD+=	bin2
.endif

.if ${PORT_OPTIONS:MOPT2}
BIN3_BUILD=	yes
.else
BIN3_BUILD=	no
.endif

Important:

Values containing whitespace must be enclosed in quotes:

OPT_VARS=	foo="bar baz"

This is due to the way make(1) variable expansion deals with whitespace. When OPT_VARS= foo=bar baz is expanded, the variable ends up containing two strings, foo=bar and baz. But the submitter probably intended there to be only one string, foo=bar baz. Quoting the value prevents whitespace from being used as a delimiter.

Also, do not add extra spaces after the var= sign and before the value, it would also be split into two strings. This will not work:

OPT_VARS=	foo=	bar

5.13.3.10. Dependencies, OPT_DEPTYPE and OPT_DEPTYPE_OFF

For any of these dependency types:

  • PKG_DEPENDS

  • EXTRACT_DEPENDS

  • PATCH_DEPENDS

  • FETCH_DEPENDS

  • BUILD_DEPENDS

  • LIB_DEPENDS

  • RUN_DEPENDS

When option OPT is selected, the value of OPT_DEPTYPE, if defined, is appended to DEPTYPE. OPT_DEPTYPE_OFF works the same, but when OPT is not selected. For example:

OPTIONS_DEFINE=	OPT1
OPT1_LIB_DEPENDS=	liba.so:devel/a
OPT1_LIB_DEPENDS_OFF=	libb.so:devel/b

is equivalent to:

OPTIONS_DEFINE=	OPT1

.include <bsd.port.options.mk>

.if ${PORT_OPTIONS:MOPT1}
LIB_DEPENDS+=	liba.so:devel/a
.else
LIB_DEPENDS+=	libb.so:devel/b
.endif

5.13.3.11. Generic Variables Replacement, OPT_VARIABLE and OPT_VARIABLE_OFF

For any of these variables:

  • ALL_TARGET

  • BINARY_ALIAS

  • BROKEN

  • CATEGORIES

  • CFLAGS

  • CONFIGURE_ENV

  • CONFLICTS

  • CONFLICTS_BUILD

  • CONFLICTS_INSTALL

  • CPPFLAGS

  • CXXFLAGS

  • DESKTOP_ENTRIES

  • DISTFILES

  • EXTRACT_ONLY

  • EXTRA_PATCHES

  • GH_ACCOUNT

  • GH_PROJECT

  • GH_SUBDIR

  • GH_TAGNAME

  • GH_TUPLE

  • GL_ACCOUNT

  • GL_COMMIT

  • GL_PROJECT

  • GL_SITE

  • GL_SUBDIR

  • GL_TUPLE

  • IGNORE

  • INFO

  • INSTALL_TARGET

  • LDFLAGS

  • LIBS

  • MAKE_ARGS

  • MAKE_ENV

  • MASTER_SITES

  • PATCHFILES

  • PATCH_SITES

  • PLIST_DIRS

  • PLIST_FILES

  • PLIST_SUB

  • PORTDOCS

  • PORTEXAMPLES

  • SUB_FILES

  • SUB_LIST

  • TEST_TARGET

  • USES

When option OPT is selected, the value of OPT_ABOVEVARIABLE, if defined, is appended to ABOVEVARIABLE. OPT_ABOVEVARIABLE_OFF works the same way, but when OPT is not selected. For example:

OPTIONS_DEFINE=	OPT1
OPT1_USES=	gmake
OPT1_CFLAGS_OFF=	-DTEST

is equivalent to:

OPTIONS_DEFINE=	OPT1

.include <bsd.port.options.mk>

.if ${PORT_OPTIONS:MOPT1}
USES+=		gmake
.else
CFLAGS+=	-DTEST
.endif

Note:

Some variables are not in this list, in particular PKGNAMEPREFIX and PKGNAMESUFFIX. This is intentional. A port must not change its name when its option set changes.

Warning:

Some of these variables, at least ALL_TARGET, DISTFILES and INSTALL_TARGET, have their default values set after the options are processed.

With these lines in the Makefile:

ALL_TARGET=	all

DOCS_ALL_TARGET=	doc

If the DOCS option is enabled, ALL_TARGET will have a final value of all doc; if the option is disabled, it would have a value of all.

With only the options helper line in the Makefile:

DOCS_ALL_TARGET=	doc

If the DOCS option is enabled, ALL_TARGET will have a final value of doc; if the option is disabled, it would have a value of all.

5.13.3.12. Additional Build Targets, target-OPT-on and target-OPT-off

These Makefile targets can accept optional extra build targets:

  • pre-fetch

  • do-fetch

  • post-fetch

  • pre-extract

  • do-extract

  • post-extract

  • pre-patch

  • do-patch

  • post-patch

  • pre-configure

  • do-configure

  • post-configure

  • pre-build

  • do-build

  • post-build

  • pre-install

  • do-install

  • post-install

  • post-stage

  • pre-package

  • do-package

  • post-package

When option OPT is selected, the target TARGET-OPT-on, if defined, is executed after TARGET. TARGET-OPT-off works the same way, but when OPT is not selected. For example:

OPTIONS_DEFINE=	OPT1

post-patch-OPT1-on:
	@${REINPLACE_CMD} -e '/opt1/s|/usr/bin/|${EXAMPLESDIR}/|' ${WRKSRC}/Makefile

post-patch-OPT1-off:
	@${REINPLACE_CMD} -e '/opt1/s|/usr/bin/|${PREFIX}/bin/|' ${WRKSRC}/Makefile

is equivalent to:

OPTIONS_DEFINE=	OPT1

.include <bsd.port.options.mk>

post-patch:
.if ${PORT_OPTIONS:MOPT1}
	@${REINPLACE_CMD} -e '/opt1/s|/usr/bin/|${EXAMPLESDIR}/|' ${WRKSRC}/Makefile
.else
	@${REINPLACE_CMD} -e '/opt1/s|/usr/bin/|${PREFIX}/bin/|' ${WRKSRC}/Makefile
.endif

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>.