manpagez: man pages & more
info make
Home | html | info | man

File: make.info,  Node: Conditional Functions,  Next: Let Function,  Prev: Functions.php">File Name Functions,  Up: Functions

8.4 Functions for Conditionals
==============================

There are four functions that provide conditional expansion.  A key
aspect of these functions is that not all of the arguments are expanded
initially.  Only those arguments which need to be expanded, will be
expanded.

'$(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' (*note Syntax of Conditionals:
     Conditional Syntax.)).

     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.

     If the condition is true then the second argument, THEN-PART, is
     evaluated and this is used as the result of the evaluation of the
     entire 'if' function.

     If the condition is false then the third argument, ELSE-PART, is
     evaluated and this is the result of the 'if' function.  If there is
     no third argument, the 'if' function evaluates to nothing (the
     empty string).

     Note that only one of the THEN-PART or the ELSE-PART will be
     evaluated, never both.  Thus, either can contain side-effects (such
     as 'shell' function calls, etc.)

'$(or CONDITION1[,CONDITION2[,CONDITION3...]])'
     The 'or' function provides a "short-circuiting" OR operation.  Each
     argument is expanded, in order.  If an argument expands to a
     non-empty string the processing stops and the result of the
     expansion is that string.  If, after all arguments are expanded,
     all of them are false (empty), then the result of the expansion is
     the empty string.

'$(and CONDITION1[,CONDITION2[,CONDITION3...]])'
     The 'and' function provides a "short-circuiting" AND operation.
     Each argument is expanded, in order.  If an argument expands to an
     empty string the processing stops and the result of the expansion
     is the empty string.  If all arguments expand to a non-empty string
     then the result of the expansion is the expansion of the last
     argument.

'$(intcmp LHS,RHS[,LT-PART[,EQ-PART[,GT-PART]]])'
     The 'intcmp' function provides support for numerical comparison of
     integers.  This function has no counterpart among the GNU 'make'
     makefile conditionals.

     The left-hand side, LHS, and right-hand side, RHS, are expanded and
     parsed as integral numbers in base 10.  Expansion of the remaining
     arguments is controlled by how the numerical left-hand side
     compares to the numerical right-hand side.

     If there are no further arguments, then the function expands to
     empty if the left-hand side and right-hand side do not compare
     equal, or to their numerical value if they do compare equal.

     Else if the left-hand side is strictly less than the right-hand
     side, the 'intcmp' function evaluates to the expansion of the third
     argument, LT-PART.  If both sides compare equal, then the 'intcmp'
     function evaluates to the expansion of the fourth argument,
     EQ-PART.  If the left-hand side is strictly greater than the
     right-hand side, then the 'intcmp' function evaluates to the
     expansion of the fifth argument, GT-PART.

     If GT-PART is missing, it defaults to EQ-PART.  If EQ-PART is
     missing, it defaults to the empty string.  Thus both '$(intcmp
     9,7,hello)' and '$(intcmp 9,7,hello,world,)' evaluate to the empty
     string, while '$(intcmp 9,7,hello,world)' (notice the absence of a
     comma after 'world') evaluates to 'world'.

© manpagez.com 2000-2025
Individual documents may contain additional copyright information.