bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

New conditional assignment facility


From: Paul Smith
Subject: New conditional assignment facility
Date: Thu, 11 Jan 2024 01:44:19 -0500
User-agent: Evolution 3.50.2 (by Flathub.org)

I've implemented a new capability for conditional assignments (not
pushed yet).

After these changes, a "?" can precede any type of assignment
operation, not just "=", and make it conditional (that is, it only
takes effect if the variable is not already set).

So for example, in addition to "?=" which creates a recursive variable
if the variable is not set yet, GNU Make will support "?:=" which
creates a simple variable if the variable is not set yet.  Of course if
it's already set then the right-hand side of the assignment is not
expanded.

Similarly the assignments "?::=" and "?:::=" are also supported.


There is one question I wanted to ask for opinions on: what should we
do with the "?+=" operator?

On its face this operator is useless; it's identical to "?=" since if
we only append if the variable was not set we're just "appending" to
the empty value.

Maybe this is right and we should do it this way just to make sure all
uses are aligned.

Or maybe we should say the "?+=" operator isn't supported and give an
error since it has no function, lest people be confused by it.

Another option would be to do the inverse for this operator, so "?+="
would only append if the variable WAS already set, else do nothing. 
I'm pretty uncomfortable with this inversion of expectation, and I'm
not sure I see a good use-case for it.  But I thought I'd mention it in
case others do.

-- 
Paul D. Smith <psmith@gnu.org>            Find some GNU make tips at:
https://www.gnu.org                       http://make.mad-scientist.net
"Please remain calm...I may be mad, but I am a professional." --Mad
Scientist



reply via email to

[Prev in Thread] Current Thread [Next in Thread]