help-make
[Top][All Lists]
Advanced

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

Re: ifeq problem?


From: Paul Smith
Subject: Re: ifeq problem?
Date: Tue, 02 Oct 2018 10:04:07 -0400

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]