1 1.4 rillig # $NetBSD: opt-define.mk,v 1.4 2022/06/12 14:27:06 rillig Exp $ 2 1.1 rillig # 3 1.3 rillig # Tests for the -D command line option, which defines global variables to the 4 1.3 rillig # value 1, like in the C preprocessor. 5 1.1 rillig 6 1.3 rillig .MAKEFLAGS: -DVAR 7 1.1 rillig 8 1.3 rillig # The variable has the exact value "1", not "1.0". 9 1.3 rillig .if ${VAR} != "1" 10 1.3 rillig . error 11 1.3 rillig .endif 12 1.3 rillig 13 1.3 rillig # The variable can be overwritten by assigning another value to it. This 14 1.3 rillig # would not be possible if the variable had been specified on the command line 15 1.3 rillig # as 'VAR=1' instead of '-DVAR'. 16 1.3 rillig VAR= overwritten 17 1.3 rillig .if ${VAR} != "overwritten" 18 1.3 rillig . error 19 1.3 rillig .endif 20 1.3 rillig 21 1.3 rillig # The variable can be undefined. If the variable had been defined in the 22 1.4 rillig # "Internal" or in the "Command" scope instead, undefining it would have no 23 1.4 rillig # effect. 24 1.3 rillig .undef VAR 25 1.3 rillig .if defined(VAR) 26 1.3 rillig . error 27 1.3 rillig .endif 28 1.3 rillig 29 1.4 rillig # The C preprocessor allows to define a macro with a specific value. Make 30 1.4 rillig # behaves differently, it defines a variable with the name 'VAR=value' and the 31 1.4 rillig # value 1. 32 1.4 rillig .MAKEFLAGS: -DVAR=value 33 1.4 rillig .if defined(VAR) 34 1.4 rillig . error 35 1.4 rillig .endif 36 1.4 rillig .if ${VAR=value} != "1" 37 1.4 rillig . error 38 1.4 rillig .endif 39 1.4 rillig 40 1.3 rillig all: .PHONY 41