[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: $(if C,A,B) seems to always select B
From: |
Paul Smith |
Subject: |
Re: $(if C,A,B) seems to always select B |
Date: |
Tue, 27 Mar 2018 08:56:18 -0400 |
On Mon, 2018-03-26 at 19:38 -0700, warnerme wrote:
> TEST_COREx := $(if ifeq ($(shell expr $(TEST_CORE) \< $(NUM_CORES)),
> 1), $(TEST_CORE), $(shell expr $(NUM_CORES) - 1))
> TEST_COREy := $(if ifeq ($(shell expr $(TEST_CORE) \>= $(NUM_CORES)),
> 1), $(shell expr $(NUM_CORES) - 1), $(TEST_CORE))
I can't see how this ever would have worked, other than by accident...
there are a number of misunderstandings of how GNU make functions work.
First, you can't use ifeq inside an if-function. It's a preprocessor
statement, that only has any meaning by itself as the first thing on a
makefile line.
Also remember that make's "true" condition for an if function is a non-
empty string. Any non-empty string is true; only empty strings are
false.
Basically, your if-function here will ALWAYS be true, because the
result of expanding the condition:
ifeq ($(shell expr $(TEST_CORE) \< $(NUM_CORES)), 1)
will be the string:
ifeq (1, 1)
(or maybe "ifeq (0, 1)") which is never false (because it's not the
empty string).
Why not perform the entire condition inside the shell, instead?
TEST_COREx := $(shell [ '$(TEST_CORE)' -lt '$(NUM_CORES)' ] && echo
'$(TEST_CORE)' || expr '$(NUM_CORES)' - 1)