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