McClain
McClain

Reputation: 27

Makefile variables using include directive and targe specific variable

Here is a very simple test and I cannot understand where I am wrong:

File Makefile.inc

MSG = I am

myprog: USE_FOO = 1

ifeq ($(USE_FOO), 1)
  MSG += using foo
else
  MSG += not using foo
endif

File Makefile

include Makefile.inc

all: myprog

myprog:
    @echo "USE_FOO = $(USE_FOO)"
    @echo $(MSG)

And I obtain:

$> make
USE_FOO = 1
I am not using foo

Could you tell me please, why my message is not "I am using foo" ?

Upvotes: 0

Views: 187

Answers (1)

gedare
gedare

Reputation: 126

The ifeq is not evaluated in the context of the target myprog, so it is evaluated to false and the MSG is set to "I am not using foo."

You could instead use File Makefile.inc:

MSG = I am not using foo

myprog: USE_FOO = 1
myprog: MSG=I am using foo

Upvotes: 2

Related Questions