Anycorn
Anycorn

Reputation: 51465

Makefile ${if ... , ...} syntax

Found syntax like this in some Makefile

${if ${VERBOSE},-DVERBOSE=true} ${if $G,-G "$G"}

I can guess what it does but cant find documentation. Can someone point me to proper name/docs for this?

Upvotes: 1

Views: 4966

Answers (1)

Svetlomir Hristozkov
Svetlomir Hristozkov

Reputation: 151

Edited following correct observation that I wasn't pointing to the exact correct location.

Conditionals usually use the ifeq/ifneq/ifdef/ifndef directives (or if function as it turns out is the case). See Conditional Parts of Makefiles, Section 7 for directives or Section 8.4 for the if function in https://www.gnu.org/software/make/manual/

Taken directly from there:

$(if condition,then-part[,else-part])

The if function provides support for conditional expansion in a functional context (as opposed to the GNU make makefile conditionals such as ifeq (see Syntax of Conditionals).

The first argument, condition, first has all preceding and trailing whitespace stripped, then is expanded. If it expands to any non-empty string, then the condition is considered to be true. If it expands to an empty string, the condition is considered to be false.

Upvotes: 2

Related Questions