Gentoo Archives: gentoo-dev

From: "Michał Górny" <gentoo@××××××××××.pl>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] use_echo() as a universal '?:' operator-like function
Date: Wed, 08 Sep 2010 19:05:16
Message-Id: 20100908210347.165ef637@pomiocik.lan
Hello,

We already have a variety of use_*() functions with their specific
uses. But what I miss is a single, simple and universal use_echo()
function, behaving similarly to ?: operator in C. In other words, a
simple function replacing monsters like:
	$(use foo && echo bar || echo baz)

Such a function could be implemented inside eutils eclass. The synopsis
could be:
	use_echo use1 [val1 [use2 val2 [...]] [otherwise]]

The idea is to echo 'valN' if 'useN' flag applies, or 'otherwise' if
none of them do. If called with a single arg, it would assume
val1=use1. If called with an even number of args (i.e. no 'otherwise'),
it would not output anything if none of the flags match.

For example, the code recalled above could be then rewritten as:
	$(use_echo foo bar baz)

The multi-argument version could be used with one-of cases like:
	GUI=$(use_echo gtk GTK2 qt4 QT4 NONE)
(for games-emulation/mupen64plus).

The resulting function would certainly find use in packages using plain
make. For an example, in net-misc/autoupnp (sunrise overlay) I use:
	WANT_LIBNOTIFY=$(use libnotify && echo true || echo false)
That would be much shorter as:
	WANT_LIBNOTIFY=$(use_echo libnotify true false)

The function could be used to reimplement some of use_*() functions
within other eclasses too.

-- 
Best regards,
Michał Górny

<http://mgorny.alt.pl>
<xmpp:mgorny@××××××.ru>

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies