# Port Makefile Conditional Options



## tuaris (Jul 30, 2014)

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


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


```
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:


```
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?


----------



## fonz (Jul 30, 2014)

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.


----------



## wblock@ (Jul 30, 2014)

The Makefile can certainly detect invalid combinations afterwards:

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


----------



## fonz (Jul 30, 2014)

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.


----------



## ljboiler (Jul 31, 2014)

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.


----------



## tuaris (Jul 31, 2014)

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.


----------



## tuaris (Jul 31, 2014)

wblock@ said:
			
		

> The Makefile can certainly detect invalid combinations afterwards:
> 
> ```
> .if ${PORT_OPTIONS:MQRCODES}
> ...



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


```
pre-check-config:
.if ${PORT_OPTIONS:MQRCODES}
.if empty(PORT_OPTIONS:MX11)
	@${ECHO_CMD} "X11 option is required for QRCODES"
	@${FALSE}
.endif
.endif
```


----------



## ljboiler (Jul 31, 2014)

tuaris said:
			
		

> ljboiler said:
> 
> 
> 
> ...



Ok, so make it:
	
	



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


----------



## wblock@ (Jul 31, 2014)

tuaris said:
			
		

> ljboiler said:
> 
> 
> 
> ...



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:

```
GD_DESC=        PHP GD library support (requires X11)
```


----------



## wblock@ (Jul 31, 2014)

tuaris said:
			
		

> wblock@ said:
> 
> 
> 
> ...



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:

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


----------



## fonz (Jul 31, 2014)

wblock@ said:
			
		

> This is a more elegant and useful way to do it than I showed earlier.


Noted for future reference. Feel free to imagine a _Thanks_ button being clicked.


----------



## olivierd (Aug 2, 2014)

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


----------



## wblock@ (Aug 2, 2014)

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.


----------

