Wierd if function behaviour

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

Wierd if function behaviour

zxuiji
I ran out of time to continue trying this today so I will see if you
experts can make heads or tails of this.

These 3 lines:

> $(eval $(0)_CALL=$(if ifeq "$($(0)_PREVMOD)"
> "$($(0)_LASTMOD)",_UPTODATE,_UPDATECC))
> $(info $(0)_CALL=(if ifeq "$($(0)_PREVMOD)"
> "$($(0)_LASTMOD)",_UPTODATE,_UPDATECC))
> $(info $(0)_CALL=$($(0)_CALL),$($(0)_PREVMOD),$($(0)_LASTMOD))
>

are resulting in this:

CODIT_GEN_DEP_CALL=(if ifeq "0" "25/07/2016;10:38",_UPTODATE,_UPDATECC)
> CODIT_GEN_DEP_CALL=_UPTODATE,0,25/07/2016;10:38
>

when the 2nd info call should be resulting in this:

CODIT_GEN_DEP_CALL=_UPDATECC,0,25/07/2016;10:38​

​I'll check this late tommorrow (got work in early morning to afternoon)​

--
We will die a permanent death unless we trust in Jesus Christ our saviour
and repent our sinful ways
_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Wierd if function behaviour

Paul Smith-20
On Sat, 2016-07-30 at 12:24 +0100, Lee Shallis wrote:
> > $(info $(0)_CALL=(if ifeq "$($(0)_PREVMOD)"
> > "$($(0)_LASTMOD)",_UPTODATE,_UPDATECC))

The strange formatting makes this hard to read, but:

  $(info $(0)_CALL=(if ifeq ...
                  ^^^
                  missing $

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

Re: Wierd if function behaviour

Paul Smith-20
Please always reply to the mailing list, not to me personally.

On Sat, 2016-07-30 at 22:39 +0100, Lee Shallis wrote:

> On 30 July 2016 at 13:47, Paul Smith <[hidden email]> wrote:
> > The strange formatting makes this hard to read, but:
> >
> >   $(info $(0)_CALL=(if ifeq ...
> >                   ^^^
> >                   missing $
> >
>
> No that was deliberate, it's meant to tell me which value I'm looking
> at in the output.
> As for the if not having a $ that was so I could see what the previous
> statement looked like was before it was fully evaluated.
>
> It's just this bit I need you to analyse:
> > $(eval $(0)_CALL=$(if ifeq "$($(0)_PREVMOD)" "$($(0)_LASTMOD)",_UPTODATE,_UPDATECC))
>                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Well, $(if ifeq ...) is always true, because the result of expanding
that value will never be the empty string.

You seem to be under the impression that the "condition" passed to the
if-function is related to the ifeq/ifneq/ifdef/ifndef conditional
syntax; it's not.

The docs say:

> The first argument, condition, first has all preceding and trailing
> whitespace stripped, then is expanded. If it expands to any non-empty
> string, then the condition is considered to be true. If it expands to
> an empty string, the condition is considered to be false.

In your example, the condition argument is:

    ifeq "$($(0)_PREVMOD)" "$($(0)_LASTMOD)"

After that is expanded, it will be this string:

    ifeq "0" "25/07/2016;10:38"

That string is manifestly a non-empty string, so the condition will be
considered true.

You probably want to use filter-out to see if the value of the first is
identical to the second; something like:

   $(if $(filter-out <first>,<second>),<run-if-not-equal>,<run-if-equal>)

Note the reversal of the then- and else-arguments: here if the values
are equal then the filter-out returns an empty string, which means the
condition is considered false.

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

Re: Wierd if function behaviour

zxuiji
On 30 July 2016 at 22:55, Paul Smith <[hidden email]> wrote:

> Please always reply to the mailing list, not to me personally.
>

​Sorry didn't realise I was, still not used to using mailing lists.​



> On Sat, 2016-07-30 at 22:39 +0100, Lee Shallis wrote:
> > On 30 July 2016 at 13:47, Paul Smith <[hidden email]> wrote:
> > > The strange formatting makes this hard to read, but:
> > >
> > >   $(info $(0)_CALL=(if ifeq ...
> > >                   ^^^
> > >                   missing $
> > >
> >
> > No that was deliberate, it's meant to tell me which value I'm looking
> > at in the output.
> > As for the if not having a $ that was so I could see what the previous
> > statement looked like was before it was fully evaluated.
> >
> > It's just this bit I need you to analyse:
> > > $(eval $(0)_CALL=$(if ifeq "$($(0)_PREVMOD)"
> "$($(0)_LASTMOD)",_UPTODATE,_UPDATECC))
> >                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> Well, $(if ifeq ...) is always true, because the result of expanding
> that value will never be the empty string.
>
> You seem to be under the impression that the "condition" passed to the
> if-function is related to the ifeq/ifneq/ifdef/ifndef conditional
> syntax; it's not.
>

​Ah that, I saw ​it in another thread on stackoverflow while I was looking
for something else and assume it was correct method of usage, thank you for
correcting me


> You probably want to use filter-out to see if the value of the first is
> identical to the second; something like:
>
>    $(if $(filter-out <first>,<second>),<run-if-not-equal>,<run-if-equal>)
>
> Note the reversal of the then- and else-arguments: here if the values
> are equal then the filter-out returns an empty string, which means the
> condition is considered false.
>

​Thank you, I expanded on your advice to create this:

if_eql=$(if $(filter-out $(1),$(2)),$(4),$(3))​

if_neq=$(if $(filter-out $(1),$(2)),$(3),$(4))
>

​which​ helped me get the result I was expecting


--
We will die a permanent death unless we trust in Jesus Christ our saviour
and repent our sinful ways
_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make