Sunday, June 5, 2022

[SOLVED] Why does the Makefile expression "export INTEGER_VAR ?= $(if $(BOOL_VAR),2,5)" result in INTEGER_VAR=2 when BOOL_VAR is false?

Issue

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


Solution

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.



Answered By - Chris Dodd
Answer Checked By - Willingham (WPSolving Volunteer)