Using empty $(else) variable for readability

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Using empty $(else) variable for readability

Tony Theodore
Hi,

I’m looking at tidying up some existing makefile logic and noticed there isn’t a lot of consistency in the format of conditionals - especially from myself over the years. We use make for build automation, not directly for compilation, and don’t use any pre-processor conditionals in this context, only the inline functions.

I’ve started replacing constructs like:

    $(if $(value foo)…

with:

    $(and $(foo)…

the short-circuit `and` and `or` are really helpful for most cases when `if` doesn’t have an `else` or `else` is a longer list.

When there is an `else` in a complex section, it sometimes looks like:

    $(if <condition>, \
        <do something> \
    , \
        <do something else>)

These can be deeply nested and the dangling `, \` can get really hard to parse. Constructs like:

    $(if <condition>, \
        <do something> \
    $(else), \
        <do something else>)

help readability and seem to work. I know I can use any misspelling or mangling of `else`, or something like $(otherwise), but `else` is really easy to read and parse.

Is this a reasonable idea and is there any chance $(else) will have some defined value in the future?

Cheers,

Tony




_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Using empty $(else) variable for readability

Paul Smith-20
On Sat, 2015-10-17 at 22:40 +1100, Tony Theodore wrote:
> Is this a reasonable idea and is there any chance $(else) will have
> some defined value in the future?

"else" as a variable will never have another value.  The POSIX standard
for make reserves variables that start with "." and are all capitalized
for the implementation.

I suppose it's possible that there could be a function $(else ...)
created, but I can't imagine what that would be and it wouldn't conflict
with the variable "else" anyway.

So, you're good.


_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Using empty $(else) variable for readability

Rakesh Sharma-6
In reply to this post by Tony Theodore
Tony Theodore <tony.t <at> me.com> writes:

>
> When there is an `else` in a complex section, it sometimes looks like:
>
>     $(if <condition>, \
>         <do something> \
>     , \
>         <do something else>)
>
> These can be deeply nested and the dangling `, \` can get really hard to
parse. Constructs like:
>
>     $(if <condition>, \
>         <do something> \
>     $(else), \
>         <do something else>)
>
> help readability and seem to work. I know I can use any misspelling or
mangling of `else`, or something like
> $(otherwise), but `else` is really easy to read and parse.
>
> Is this a reasonable idea and is there any chance $(else) will have some
defined value in the future?
>

This is not at all a good idea, since it's very easy in make to slip in
a variable $(else) whose value whenever it's non-null will cause your
carefully constructed clauses to come crashing down.

--Rakesh


_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Using empty $(else) variable for readability

Tony Theodore

> On 18 Oct 2015, at 01:12, Rakesh Sharma <[hidden email]> wrote:
>
> Tony Theodore <tony.t <at> me.com> writes:
>
>>
>> Is this a reasonable idea and is there any chance $(else) will have some
>> defined value in the future?
>>
>
> This is not at all a good idea, since it's very easy in make to slip in
> a variable $(else) whose value whenever it's non-null will cause your
> carefully constructed clauses to come crashing down.


Ah! I wasn’t thinking about all the ways a variable could be set. We have
reasonable control over inputs at the moment but I’m doing this sweep
in  preparation for a plugin system where people can load whatever
arbitrary makefiles they want...


> On 18 Oct 2015, at 01:10, Paul Smith <[hidden email]> wrote:
>
> "else" as a variable will never have another value.  The POSIX standard
> for make reserves variables that start with "." and are all capitalized
> for the implementation.
>
> I suppose it's possible that there could be a function $(else ...)
> created, but I can't imagine what that would be and it wouldn't conflict
> with the variable "else" anyway.
>
> So, you're good.

Thanks, I think I’ll run with it and see what happens.

Cheers,

Tony


_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make