1*9f45a3c8SSimon J. Gerraty# $NetBSD: directive-ifdef.mk,v 1.5 2022/01/23 21:48:59 rillig Exp $ 22c3632d1SSimon J. Gerraty# 3*9f45a3c8SSimon J. Gerraty# Tests for the .ifdef directive, which evaluates bare words by calling 4*9f45a3c8SSimon J. Gerraty# 'defined(word)'. 52c3632d1SSimon J. Gerraty 6e2eeea75SSimon J. GerratyDEFINED= defined 7e2eeea75SSimon J. Gerraty 8*9f45a3c8SSimon J. Gerraty# There is no variable named 'UNDEF', therefore the condition evaluates to 9*9f45a3c8SSimon J. Gerraty# false. 10*9f45a3c8SSimon J. Gerraty.ifdef UNDEF 11*9f45a3c8SSimon J. Gerraty. error 12*9f45a3c8SSimon J. Gerraty.endif 13*9f45a3c8SSimon J. Gerraty 14*9f45a3c8SSimon J. Gerraty# There is a variable named 'DEFINED', so the condition evaluates to true. 15*9f45a3c8SSimon J. Gerraty.ifdef DEFINED 16*9f45a3c8SSimon J. Gerraty.else 17*9f45a3c8SSimon J. Gerraty. error 18*9f45a3c8SSimon J. Gerraty.endif 19*9f45a3c8SSimon J. Gerraty 20*9f45a3c8SSimon J. Gerraty# Since a bare word is an abbreviation for 'defined(word)', these can be 21*9f45a3c8SSimon J. Gerraty# used to construct complex conditions. 22*9f45a3c8SSimon J. Gerraty.ifdef UNDEF && DEFINED 23*9f45a3c8SSimon J. Gerraty. error 24*9f45a3c8SSimon J. Gerraty.endif 25*9f45a3c8SSimon J. Gerraty.ifdef UNDEF || DEFINED 26*9f45a3c8SSimon J. Gerraty.else 27*9f45a3c8SSimon J. Gerraty. error 28*9f45a3c8SSimon J. Gerraty.endif 29*9f45a3c8SSimon J. Gerraty 30e2eeea75SSimon J. Gerraty# It looks redundant to have a call to defined() in an .ifdef, but it's 31*9f45a3c8SSimon J. Gerraty# possible. The '.ifdef' only affects bare words, not function calls. 32e2eeea75SSimon J. Gerraty.ifdef defined(DEFINED) 33e2eeea75SSimon J. Gerraty.else 34e2eeea75SSimon J. Gerraty. error 35e2eeea75SSimon J. Gerraty.endif 36e2eeea75SSimon J. Gerraty 37*9f45a3c8SSimon J. Gerraty# String literals are handled the same in all variants of the '.if' directive, 38*9f45a3c8SSimon J. Gerraty# they evaluate to true if they are not empty, therefore this particular 39*9f45a3c8SSimon J. Gerraty# example looks confusing and is thus not found in practice. 40dba7b0efSSimon J. Gerraty.ifdef "" 41dba7b0efSSimon J. Gerraty. error 42dba7b0efSSimon J. Gerraty.else 43dba7b0efSSimon J. Gerraty.endif 44dba7b0efSSimon J. Gerraty 45*9f45a3c8SSimon J. Gerraty# Whitespace counts as non-empty as well. 46dba7b0efSSimon J. Gerraty.ifdef " " 47dba7b0efSSimon J. Gerraty.else 48dba7b0efSSimon J. Gerraty. error 49dba7b0efSSimon J. Gerraty.endif 50dba7b0efSSimon J. Gerraty 51*9f45a3c8SSimon J. Gerratyall: .PHONY 52