USE Flag Conditional Code

Often a particular block of code must only be executed if a given USE flag is set (or unset). For large blocks, if use foo is best, or for inverse tests either if ! use foo or if use !foo can be used (the former is more common and is recommended for readability). For single-statement conditions, the use foo && blah (or use foo || blah for negatives) form is often more readable.

The if [ "`use foo`" ] and if [ -n "`use foo`" ] forms which are occasionally seen in older code must not be used. This is because, since portage-2.1, the 'use' portage helper does not produce any output when the use flag is enabled or disabled so the [ "`use foo`" ] statement is pretty much identical to [ "" ] which always evaluates to false.

	# USE conditional blocks...
	if use livecd ; then
		# remove some extra files for a small livecd install
		rm -fr "${vimfiles}"/{compiler,doc,ftplugin,indent}

	# Inverse USE conditional blocks...
	if ! use cscope ; then
		# the --disable-cscope configure arg doesn't quite work properly,
		# so sed it out of feature.h if we're not USEing cscope.
		sed -i -e '/# define FEAT_CSCOPE/d' src/feature.h || die "couldn't disable cscope"

	# USE conditional statements...
	use ssl && epatch "${FILESDIR}/${P}-ssl.patch"
	use sparc && filter-flags -fomit-frame-pointer

	# Inverse USE conditional statements...
	use ncurses || epatch "${FILESDIR}/${P}-no-ncurses.patch"

For echoing content based upon a USE flag, there is often a better helper function available.

It is guaranteed that use produces no output. If you need output displayed, use the usev function; it echoes the USE flag's name if the condition is met. The useq function is a deprecated synonym for use, don't use it in new code.