2022-07-26 15:52:53 +00:00
|
|
|
# $NetBSD: opt-define.mk,v 1.4 2022/06/12 14:27:06 rillig Exp $
|
2020-09-05 16:11:04 +00:00
|
|
|
#
|
2022-02-05 20:03:50 +00:00
|
|
|
# Tests for the -D command line option, which defines global variables to the
|
|
|
|
# value 1, like in the C preprocessor.
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2022-02-05 20:03:50 +00:00
|
|
|
.MAKEFLAGS: -DVAR
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2022-02-05 20:03:50 +00:00
|
|
|
# The variable has the exact value "1", not "1.0".
|
|
|
|
.if ${VAR} != "1"
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
|
|
|
# The variable can be overwritten by assigning another value to it. This
|
|
|
|
# would not be possible if the variable had been specified on the command line
|
|
|
|
# as 'VAR=1' instead of '-DVAR'.
|
|
|
|
VAR= overwritten
|
|
|
|
.if ${VAR} != "overwritten"
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
|
|
|
# The variable can be undefined. If the variable had been defined in the
|
2022-07-26 15:52:53 +00:00
|
|
|
# "Internal" or in the "Command" scope instead, undefining it would have no
|
|
|
|
# effect.
|
2022-02-05 20:03:50 +00:00
|
|
|
.undef VAR
|
|
|
|
.if defined(VAR)
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
2022-07-26 15:52:53 +00:00
|
|
|
# The C preprocessor allows to define a macro with a specific value. Make
|
|
|
|
# behaves differently, it defines a variable with the name 'VAR=value' and the
|
|
|
|
# value 1.
|
|
|
|
.MAKEFLAGS: -DVAR=value
|
|
|
|
.if defined(VAR)
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
.if ${VAR=value} != "1"
|
|
|
|
. error
|
|
|
|
.endif
|
|
|
|
|
2022-02-05 20:03:50 +00:00
|
|
|
all: .PHONY
|