1*d5e0a182SSimon J. Gerraty# $NetBSD: directive-ifndef.mk,v 1.9 2023/10/19 18:24:33 rillig Exp $ 22c3632d1SSimon J. Gerraty# 3956e45f6SSimon J. Gerraty# Tests for the .ifndef directive, which can be used for multiple-inclusion 4956e45f6SSimon J. Gerraty# guards. In contrast to C, where #ifndef and #define nicely line up the 5956e45f6SSimon J. Gerraty# macro name, there is no such syntax in make. Therefore, it is more 6956e45f6SSimon J. Gerraty# common to use .if !defined(GUARD) instead. 7148ee845SSimon J. Gerraty# 8148ee845SSimon J. Gerraty# See also: 9148ee845SSimon J. Gerraty# directive-include-guard.mk 102c3632d1SSimon J. Gerraty 11956e45f6SSimon J. Gerraty.ifndef GUARD 12956e45f6SSimon J. GerratyGUARD= # defined 13148ee845SSimon J. Gerraty# expect+1: guarded section 14956e45f6SSimon J. Gerraty. info guarded section 15956e45f6SSimon J. Gerraty.endif 16956e45f6SSimon J. Gerraty 17956e45f6SSimon J. Gerraty.ifndef GUARD 18956e45f6SSimon J. GerratyGUARD= # defined 19956e45f6SSimon J. Gerraty. info guarded section 20956e45f6SSimon J. Gerraty.endif 21956e45f6SSimon J. Gerraty 22956e45f6SSimon J. Gerraty.if !defined(GUARD) 23956e45f6SSimon J. GerratyGUARD= # defined 24956e45f6SSimon J. Gerraty. info guarded section 25956e45f6SSimon J. Gerraty.endif 262c3632d1SSimon J. Gerraty 27148ee845SSimon J. Gerraty 28148ee845SSimon J. Gerraty# The '.ifndef' directive can be used with multiple arguments, even negating 29148ee845SSimon J. Gerraty# them. Since these conditions are confusing for humans, they should be 30148ee845SSimon J. Gerraty# replaced with easier-to-understand plain '.if' directives. 31148ee845SSimon J. GerratyDEFINED= 32148ee845SSimon J. Gerraty.ifndef UNDEFINED && UNDEFINED 33148ee845SSimon J. Gerraty.else 34148ee845SSimon J. Gerraty. error 35148ee845SSimon J. Gerraty.endif 36148ee845SSimon J. Gerraty.ifndef UNDEFINED && DEFINED 37148ee845SSimon J. Gerraty. error 38148ee845SSimon J. Gerraty.endif 39148ee845SSimon J. Gerraty.ifndef DEFINED && DEFINED 40148ee845SSimon J. Gerraty. error 41148ee845SSimon J. Gerraty.endif 42148ee845SSimon J. Gerraty.ifndef !UNDEFINED && !UNDEFINED 43148ee845SSimon J. Gerraty. error 44148ee845SSimon J. Gerraty.endif 45148ee845SSimon J. Gerraty.ifndef !UNDEFINED && !DEFINED 46148ee845SSimon J. Gerraty. error 47148ee845SSimon J. Gerraty.endif 48148ee845SSimon J. Gerraty.ifndef !DEFINED && !DEFINED 49148ee845SSimon J. Gerraty.else 50148ee845SSimon J. Gerraty. error 51148ee845SSimon J. Gerraty.endif 52148ee845SSimon J. Gerraty 53*d5e0a182SSimon J. Gerraty 54*d5e0a182SSimon J. Gerraty# The negation from the 'if-not-defined' directive only applies to bare words, 55*d5e0a182SSimon J. Gerraty# but not to numbers, quoted strings or expressions. Those are evaluated 56*d5e0a182SSimon J. Gerraty# without extra negation, just like in a plain '.if' directive. 57*d5e0a182SSimon J. Gerraty.ifndef 0 58*d5e0a182SSimon J. Gerraty. error 59*d5e0a182SSimon J. Gerraty.endif 60*d5e0a182SSimon J. Gerraty.ifndef 1 61*d5e0a182SSimon J. Gerraty.else 62*d5e0a182SSimon J. Gerraty. error 63*d5e0a182SSimon J. Gerraty.endif 64*d5e0a182SSimon J. Gerraty.ifndef "" 65*d5e0a182SSimon J. Gerraty. error 66*d5e0a182SSimon J. Gerraty.endif 67*d5e0a182SSimon J. Gerraty.ifndef "word" 68*d5e0a182SSimon J. Gerraty.else 69*d5e0a182SSimon J. Gerraty. error 70*d5e0a182SSimon J. Gerraty.endif 71*d5e0a182SSimon J. Gerraty.ifndef ${:UUNDEFINED} 72*d5e0a182SSimon J. Gerraty.else 73*d5e0a182SSimon J. Gerraty. error 74*d5e0a182SSimon J. Gerraty.endif 75*d5e0a182SSimon J. Gerraty.ifndef ${:UDEFINED} 76*d5e0a182SSimon J. Gerraty. error 77*d5e0a182SSimon J. Gerraty.endif 78*d5e0a182SSimon J. Gerraty.ifndef ${:U0} 79*d5e0a182SSimon J. Gerraty. error 80*d5e0a182SSimon J. Gerraty.endif 81*d5e0a182SSimon J. Gerraty.ifndef ${:U1} 82*d5e0a182SSimon J. Gerraty.else 83*d5e0a182SSimon J. Gerraty. error 84*d5e0a182SSimon J. Gerraty.endif 85*d5e0a182SSimon J. Gerraty 86*d5e0a182SSimon J. Gerraty 872c3632d1SSimon J. Gerratyall: 88