1*d5e0a182SSimon J. Gerraty# $NetBSD: cond-func-defined.mk,v 1.11 2023/11/19 21:47:52 rillig Exp $ 22c3632d1SSimon J. Gerraty# 32c3632d1SSimon J. Gerraty# Tests for the defined() function in .if conditions. 42c3632d1SSimon J. Gerraty 52c3632d1SSimon J. GerratyDEF= defined 62c3632d1SSimon J. Gerraty${:UA B}= variable name with spaces 72c3632d1SSimon J. Gerraty 82c3632d1SSimon J. Gerraty.if !defined(DEF) 92c3632d1SSimon J. Gerraty. error 102c3632d1SSimon J. Gerraty.endif 112c3632d1SSimon J. Gerraty 12956e45f6SSimon J. Gerraty# Horizontal whitespace (space tab) after the opening parenthesis is ignored. 132c3632d1SSimon J. Gerraty.if !defined( DEF) 142c3632d1SSimon J. Gerraty. error 152c3632d1SSimon J. Gerraty.endif 162c3632d1SSimon J. Gerraty 17956e45f6SSimon J. Gerraty# Horizontal whitespace (space tab) before the closing parenthesis is ignored. 182c3632d1SSimon J. Gerraty.if !defined(DEF ) 192c3632d1SSimon J. Gerraty. error 202c3632d1SSimon J. Gerraty.endif 212c3632d1SSimon J. Gerraty 222c3632d1SSimon J. Gerraty# The argument of a function must not directly contain whitespace. 23148ee845SSimon J. Gerraty# expect+1: Missing closing parenthesis for defined() 242c3632d1SSimon J. Gerraty.if !defined(A B) 252c3632d1SSimon J. Gerraty. error 262c3632d1SSimon J. Gerraty.endif 272c3632d1SSimon J. Gerraty 28*d5e0a182SSimon J. Gerraty# If necessary, the whitespace can be generated by an expression. 292c3632d1SSimon J. Gerraty.if !defined(${:UA B}) 302c3632d1SSimon J. Gerraty. error 312c3632d1SSimon J. Gerraty.endif 322c3632d1SSimon J. Gerraty 33148ee845SSimon J. Gerraty# expect+1: Missing closing parenthesis for defined() 34e2eeea75SSimon J. Gerraty.if defined(DEF 35e2eeea75SSimon J. Gerraty. error 36e2eeea75SSimon J. Gerraty.else 37e2eeea75SSimon J. Gerraty. error 38e2eeea75SSimon J. Gerraty.endif 39e2eeea75SSimon J. Gerraty 40e2eeea75SSimon J. Gerraty# Variables from .for loops are not defined. 41e2eeea75SSimon J. Gerraty# See directive-for.mk for more details. 42e2eeea75SSimon J. Gerraty.for var in value 43e2eeea75SSimon J. Gerraty. if defined(var) 44e2eeea75SSimon J. Gerraty. error 45e2eeea75SSimon J. Gerraty. else 46*d5e0a182SSimon J. Gerraty# expect+1: In .for loops, expressions for the loop variables are 47*d5e0a182SSimon J. Gerraty. info In .for loops, expressions for the loop variables are 48148ee845SSimon J. Gerraty# expect+1: substituted at evaluation time. There is no actual variable 49e2eeea75SSimon J. Gerraty. info substituted at evaluation time. There is no actual variable 50148ee845SSimon J. Gerraty# expect+1: involved, even if it feels like it. 51e2eeea75SSimon J. Gerraty. info involved, even if it feels like it. 52e2eeea75SSimon J. Gerraty. endif 53e2eeea75SSimon J. Gerraty.endfor 54e2eeea75SSimon J. Gerraty 55954401e6SSimon J. Gerraty# Neither of the conditions is true. Before July 2020, the right-hand 56954401e6SSimon J. Gerraty# condition was evaluated even though it was irrelevant. 57954401e6SSimon J. Gerraty.if defined(UNDEF) && ${UNDEF:Mx} != "" 58954401e6SSimon J. Gerraty. error 59954401e6SSimon J. Gerraty.endif 60954401e6SSimon J. Gerraty 61954401e6SSimon J. Gerratyall: .PHONY 62