Port Makefile Conditional Options

I'm not sure how to best describe this but let's say I have the following in a port's Makefile:

Code:
OPTIONS_DEFINE=	X11
OPTIONS_GROUP=	X11
OPTIONS_GROUP_X11=	QRCODES

The X11 option will enable a graphical interface and the QRCODES option pulls in the dependent graphics/libqrencode library.

Code:
QRCODES_LIB_DEPENDS=	libqrencode.so:${PORTSDIR}/graphics/libqrencode

My problem is I am not able to figure out how to prevent the QRCODES option from being selected if the X11 option is deselected. For example it's possible to end up with an invalid configuration like:

Code:
     X11=off: X11 (graphics) support
====> X11 (graphics) support
     QRCODES=on: Build with QR code display

The above will pull in the unnecessary dependency along with its dependencies. What can be done to prevent this?
 
Unfortunately I don't know this off the top of my head, but as a port maintainer I find it an interesting question. I'll look into it if I can find the time, but if it turns out that neither me nor anyone else here knows, you'd best ask on the freebsd-ports@ mailing list. That's where most of the real ports gurus hang out.
 
The Makefile can certainly detect invalid combinations afterwards:
Code:
.if ${PORT_OPTIONS:MQRCODES}
.if empty(PORT_OPTIONS:MX11}
        @${ECHO_CMD} "X11 option is required for QRCODES"
        @${FALSE}
.endif
.endif

Of course, it would be better for the options screen to only enable the QRCODES option after X11 has been selected.
 
wblock@ said:
Of course, it would be better for the options screen to only enable the QRCODES option after X11 has been selected.
Exactly. However, I'm not sure whether the current options framework allows that sort of thing.
 
Why not use OPTIONS_SINGLE and give the user three choices: command line interface, graphical interface, and GUI with QR code display. With OPTIONS_SINGLE, only one setting of the group can be selected. The library dependencies, etc. would then be set to the appropriate values by logic in the port Makefile based on the option selected.
 
ljboiler said:
Why not use the OPTIONS_SINGLE and give the user 3 choices: Command line interface, Graphical interface, and GUI with QR code display.
With OPTIONS_SINGLE, only one setting of the group can be selected. The library dependencies, etc. would then be set to the appropriate values by logic in the port Makefile based on the option selected.

I considered this direction, but I can no longer take advantage of the ability to automatically disable the GUI when the X11 option is unset in the /etc/make.conf file.
 
wblock@ said:
The Makefile can certainly detect invalid combinations afterwards:
Code:
.if ${PORT_OPTIONS:MQRCODES}
.if empty(PORT_OPTIONS:MX11}
        @${ECHO_CMD} "X11 option is required for QRCODES"
        @${FALSE}
.endif
.endif

Of course, it would be better for the options screen to only enable the QRCODES option after X11 has been selected.

Would the best place to put this be under the pre-check-config target?

Code:
pre-check-config:
.if ${PORT_OPTIONS:MQRCODES}
.if empty(PORT_OPTIONS:MX11)
	@${ECHO_CMD} "X11 option is required for QRCODES"
	@${FALSE}
.endif
.endif
 
tuaris said:
ljboiler said:
Why not use the OPTIONS_SINGLE and give the user 3 choices: Command line interface, Graphical interface, and GUI with QR code display.
With OPTIONS_SINGLE, only one setting of the group can be selected. The library dependencies, etc. would then be set to the appropriate values by logic in the port Makefile based on the option selected.

I considered this direction, but I can no longer take advantage of the ability to automatically disable the GUI when the X11 option is unset in the /etc/make.conf file.

Ok, so make it:
Code:
QRCODES=on: Enable QR code display when building graphical interface

This wording to me would make it clear that the QR display was an extra feature of the GUI version of this port, and not to expect it otherwise.
 
tuaris said:
ljboiler said:
Why not use the OPTIONS_SINGLE and give the user 3 choices: Command line interface, Graphical interface, and GUI with QR code display.
With OPTIONS_SINGLE, only one setting of the group can be selected. The library dependencies, etc. would then be set to the appropriate values by logic in the port Makefile based on the option selected.

I considered this direction, but I can no longer take advantage of the ability to automatically disable the GUI when the X11 option is unset in the /etc/make.conf file.

Right. The Makefile always has to check, because the user may not even see the options configuration screen. I did ask if the config screen could do this in IRC yesterday, and @bapt said no,

In many ports, there is just a manual notice, (requires X11) in the description of the option that needs it. databases/phpmyadmin, for example:
Code:
GD_DESC=        PHP GD library support (requires X11)
 
Last edited by a moderator:
tuaris said:
wblock@ said:
The Makefile can certainly detect invalid combinations afterwards:
Code:
.if ${PORT_OPTIONS:MQRCODES}
.if empty(PORT_OPTIONS:MX11}
        @${ECHO_CMD} "X11 option is required for QRCODES"
        @${FALSE}
.endif
.endif

Of course, it would be better for the options screen to only enable the QRCODES option after X11 has been selected.

Would the best place to put this be under the pre-check-config target?

I'd put it as soon as possible, immediately after .include <bsd.port.options.mk>. It can't be earlier than that because the options have not been evaluated until after that line. From /usr/ports/emulators/virtualbox-ose/Makefile:
Code:
...
.include <bsd.port.options.mk>

.if empty(PORT_OPTIONS:MQT4) && !empty(PORT_OPTIONS:MNLS)
BROKEN=         NLS support requires QT4 frontend. Run 'make config' again!
.endif

.if empty(PORT_OPTIONS:MX11) && !empty(PORT_OPTIONS:MQT4)
BROKEN=         QT4 frontend requires X11 support. Run 'make config' again!
.endif

Here, they use BROKEN and show a helpful message. This is a more elegant and useful way to do it than I showed earlier.
 
Why not create a slave port (with -nox11 like PKGNAMESUFFIX)? In the main port you add the NLS option, and when the slave port is selected you disable X11 (and Qt).
 
To me, a single port with options is easier for the user, because they can choose all the options from the configuration screen. It's also easier for the maintainer, because although option combinations may need to be tested, it's all in the same port.
 
Back
Top