1 |
Hello, |
2 |
|
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) |
8 |
|
9 |
Such a function could be implemented inside eutils eclass. The synopsis |
10 |
could be: |
11 |
use_echo use1 [val1 [use2 val2 [...]] [otherwise]] |
12 |
|
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. |
17 |
|
18 |
For example, the code recalled above could be then rewritten as: |
19 |
$(use_echo foo bar baz) |
20 |
|
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). |
24 |
|
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) |
30 |
|
31 |
The function could be used to reimplement some of use_*() functions |
32 |
within other eclasses too. |
33 |
|
34 |
-- |
35 |
Best regards, |
36 |
Michał Górny |
37 |
|
38 |
<http://mgorny.alt.pl> |
39 |
<xmpp:mgorny@××××××.ru> |