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 <[email protected]> Sent: Tuesday, October 2, 2018 7:04 AM To: S Tao; [email protected] 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! _______________________________________________ Help-make mailing list [email protected] https://lists.gnu.org/mailman/listinfo/help-make
