help-make
[Top][All Lists]
Advanced

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

Re: ifeq problem?


From: F L
Subject: Re: ifeq problem?
Date: Tue, 2 Oct 2018 15:20:05 +0000

Thank you very much Paul and Philip. I still need to read what you pointed out.

What I want is very straightforward. during make/build process, I want to run a 
shell command to extract two numbers from two different files. If they are 
same(or different), then I do something.

That is why my prototype uses echo to get the number?

$(eval v1=$(shell sh -c "echo 1"))

________________________________
From: Paul Smith <address@hidden>
Sent: Tuesday, October 2, 2018 7:04 AM
To: S Tao; address@hidden
Subject: Re: ifeq problem?

On Tue, 2018-10-02 at 03:23 +0000, S Tao wrote:
> test-test:
>     $(eval v1=$(shell sh -c "echo 1"))
>     $(eval v2=$(shell sh -c "echo 2"))
>     @echo "v1=$(strip $(v1))="
>     @echo "v2=$(strip $(v2))="
> ifeq ("$(strip $(v1))", "$(strip $(v2))")
>     @echo "v1 == v2"
> endif
> .PHONY: test-test

Using 'eval' and 'shell' functions inside a recipe is an anti-pattern.

It can be useful in advanced situations that you likely won't run into
until you've been writing complex makefiles for a long time.  You
should avoid it until that time.

Philip's answer is right on as to where you should go to read more
about why this doesn't work, but for this:

> C) do what everyone has done for 40 years: use shell conditionals,
> ala @ if [ "$(v1)" = "$(v2)" ]; then echo...; fi

I would go farther and say the ENTIRE rule should be rewritten using
the shell without any 'eval' or 'shell' make functions, as in:

  test-test:
        @v1=1; \
         v2=2; \
         if [ $$v1 = $$v2 ]; then echo 'v1 == v2'; fi

Of course when written this way this recipe isn't really useful, so it
would be better if instead you asked us about the problem you're really
trying to solve.

Cheers!



reply via email to

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