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
1 Hello,
3 We already have a variety of use_*() functions with their specific
4 uses. But what I miss is a single, simple and universal use_echo()
5 function, behaving similarly to ?: operator in C. In other words, a
6 simple function replacing monsters like:
7 $(use foo && echo bar || echo baz)
9 Such a function could be implemented inside eutils eclass. The synopsis
10 could be:
11 use_echo use1 [val1 [use2 val2 [...]] [otherwise]]
13 The idea is to echo 'valN' if 'useN' flag applies, or 'otherwise' if
14 none of them do. If called with a single arg, it would assume
15 val1=use1. If called with an even number of args (i.e. no 'otherwise'),
16 it would not output anything if none of the flags match.
18 For example, the code recalled above could be then rewritten as:
19 $(use_echo foo bar baz)
21 The multi-argument version could be used with one-of cases like:
22 GUI=$(use_echo gtk GTK2 qt4 QT4 NONE)
23 (for games-emulation/mupen64plus).
25 The resulting function would certainly find use in packages using plain
26 make. For an example, in net-misc/autoupnp (sunrise overlay) I use:
27 WANT_LIBNOTIFY=$(use libnotify && echo true || echo false)
28 That would be much shorter as:
29 WANT_LIBNOTIFY=$(use_echo libnotify true false)
31 The function could be used to reimplement some of use_*() functions
32 within other eclasses too.
34 --
35 Best regards,
36 Michał Górny
38 <>
39 <xmpp:mgorny@××××××.ru>


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