bugmake - Bugs: bug #52209, Support for ifeq function

 
 

bug #52209: Support for ifeq function

Submitter:  None
Submitted:  Wed 11 Oct 2017 07:59:03 PM UTC
   
 
Severity:  3 - Normal Item Group:  Enhancement
Status:  None Privacy:  Public
Assigned to:  None Open/Closed:  Open
Component Version:  None Operating System:  Any
Fixed Release:  None Triage Status:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 23 Jan 2023 04:17:10 PM UTC, comment #5: 

I strongly agree with the need but suggest a different syntax:

$(eq lhs,rhs)
$(neq lhs,rhs)

Each function expands lhs and rhs. If the results are identical or nonidentical, respectively, the function expands to T. Otherwise, it expands to empty.

The rationale is that this syntax is more readable than the proposed $(ifeq lhs,rhs,1). For me, readability trumps the slight burden of committing to a particular "true" string. (I've suggested T, following the GMSL, but it doesn't matter much; I'm okay with 1.)

Function-heavy code is sometimes necessary, but I find it difficult to read. String equality primitives will help, but let's make them as concise and readable as possible.

One more issue: should string equality functions be bug-for-bug compatible with bug #59584? I would say no; they should be consistent with what functions normally do, which I think is to trim whitespace to the left of each argument before expansion.

Sam Kendall <sckendall>
Sun 15 Oct 2017 12:59:01 PM UTC, comment #4: 

Patch added.

The rational is that this is an operation needed to support rebuilding of targets when recipes change.

Support for rebuilding of targets on recipe change requires the recipe of every target to be expanded and compared with its previously used recipe. These happens on every build, even if all targets are up-to-date, so can contribute a significant amount to the processing time of a large mostly up-to-date project. A more efficient way to compare previous and current recipes than that in the first post would help reduce processing time.

I have only created the $(ifeq ...) function and added nothing to .FEATURES, or test suite, or documentation. I can do this if the patch is accepted.


(file #42159)

Rob <robw_ty>
Thu 12 Oct 2017 06:26:11 AM UTC, comment #3: 

Thanks Paul for dealing with this so quickly.

For the benefit of clarity (and the poster of comment #1), the parallel between what I propose and the existing preprocessor version is deliberate as I value consistency in design.

There has been an eq function in the source code for a long time, but it is disabled behind an experimental flag. I think the problem is that eq introduces a fixed idea of a true result as it always returns 1 for true. Introducing eq would effectively change the representation of true from non-empty to 1 on a conceptual level - and conceptual changes are always risky.

The ifeq function proposal is an attempt to allow support for testing equality without needing to change the concept of true. It also allows the same flexibility of the existing $(if..) function where an action could be taken on the result, for example to generate an error if strings don't match:

$(ifeq $(first),$(second),,$(error something broke))

I will try and contribute a patch, but I don't know when I'll have time and I wanted to make an enhancement request in the meantime.

To the poster of comment #1. Yes, I posted anonymously for reasons I don't need to explain here. It's unfortunate you think that makes me an idiot and my contribution only worth mocking and I'm very glad that Paul never thinks that way. I'm not keen on sharing my email address with the world, and your response makes me want to do that even less. This is not a point-scoring teenage forum and I'm only interested in talking technical, but after taking your own advice, if you still feel the need to insult me personally my name is below.

regards,
Rob.

Anonymous
Thu 12 Oct 2017 03:04:18 AM UTC, comment #2: 

Those (ifeq, ifneq) are not functions, they're preprocessor conditionals.  Only $(if ...) (and $(or ...) and $(and ...)) are functions.

Paul D. Smith <psmith>
Group administrator
Wed 11 Oct 2017 09:40:19 PM UTC, comment #1: 

Ummm ... is this some kind of meta-April-fools joke, offset by 6 months?

On the off chance that it's serious I refer you to the descriptions of the (yes) $(ifeq ...), $(ifneq ...), and $(if ...) functions in https://www.gnu.org/software/make/manual/make.html#Conditional-Syntax

Sorry, I wouldn't normally poke fun at someone online but you're anonymous anyway so what the heck.

Anonymous
Wed 11 Oct 2017 07:59:03 PM UTC, original submission:  

My makefiles frequently need to check for equality of two string. I'm doing this during expansion of recipes so this happens many time during every build.

Currently I need to do this:

$(if $(findstring X$(second),$(findstring X$(first),X$(second))),same,different)

this looks clumsy and the strings can be very long (10s of kbytes) so is probably inefficient as there need to be two findstrings.

Support for an ifeq function would be useful. Something like:

$(ifeq $(first),$(second),same,different)

This would allow different actions depend on the whether the string are equal. It could also be used to generate boolean results as follows:

$(ifeq $(first),$(second),1)

where a non-empty result is true and an empty is false.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #42159:  function.c.patch added by robw_ty (2KiB - text/x-patch - Add support for $(ifeq ...) function)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by sckendall (Posted a comment)
  • -email is unavailable- added by robw_ty (Updated the item)
  • -email is unavailable- added by psmith (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-10-15 robw_ty Attached File- Added function.c.patch, #42159

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code