Home > Software engineering >  Why does the Makefile expression "export INTEGER_VAR ?= $(if $(BOOL_VAR),2,5)" result in I
Why does the Makefile expression "export INTEGER_VAR ?= $(if $(BOOL_VAR),2,5)" result in I

Time:04-29

My Makefile has a line which reads:

export INTEGER_VAR ?= $(if $(BOOL_VAR),2,5)

Then INTEGER_VAR is used to make some decisions in the following lines.

When I do make BOOL_VAR=false the INTEGER_VAR takes the value of 2

Can anyone help me figure out why?

I am using GNU Make version 4.2.1

CodePudding user response:

Because $(if just checks for empty/non-empty. It has no concept of types or things like true or false. So with BOOL_VAR=false the tested thing $(BOOL_VAR) is not an empty string and so is logically true.

  • Related