Pregunta

I am facing the problem with the below code in gmake, where as it works ok with clearmake.

TEST_ENV :=
TEST_ENV +=
ifdef TEST_ENV
     TEST_ENV += Hello
endif
all:
        echo TEST_ENV=${TEST_ENV}

When we run this makefile in clearmake, TEST_ENV is not defined and it is not entered into ifdef block, where as in gmake, TEST_ENV is getting defined and entering into ifdef block.

Output:

In clearmake : TEST_ENV=

In gmake : TEST_ENV=Hello

How to write conditional statement which is common to clearmake and gmake

¿Fue útil?

Solución 2

Thanks for your response's.

It is working with strip function.

TEST_ENV := TEST_ENV += ifeq ($(strip $(TEST_ENV)),) endif

Otros consejos

If you're running clearmake in GNU make emulation mode, this is a bug in clearmake that should be reported. Other than that, you didn't say which of the two behaviors you preferred so we can't really help you.

Whenever you append a value to a variable, a space is always added between the old value and the new value. Even if one or both of the values is an empty string, the space is still added. So your example:

TEST_ENV :=
TEST_ENV +=

actually leaves TEST_ENV as containing a space, and that is not empty according to make (to make, empty means a zero-length string).

If you want to treat a string containing only whitespace as empty, you can use this:

ifeq($(strip $(TEST_ENV)),)
    TEST_ENV += Hello
endif

Or alternatively you can use:

TEST_ENV :=
TEST_ENV +=

TEST_ENV := $(strip $(TEST_ENV))
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top