xref: /freebsd/contrib/bmake/unit-tests/varname-makeflags.mk (revision 5956d97f4b3204318ceb6aa9c77bd0bc6ea87a41)
1# $NetBSD: varname-makeflags.mk,v 1.5 2022/01/16 18:16:06 sjg Exp $
2#
3# Tests for the special MAKEFLAGS variable, which is basically just a normal
4# environment variable.  It is closely related to .MAKEFLAGS but captures the
5# state of .MAKEFLAGS at the very beginning of make, before any makefiles are
6# read.
7
8# TODO: Implementation
9
10.MAKEFLAGS: -d0
11
12# The unit tests are run with an almost empty environment.  In particular,
13# the variable MAKEFLAGS is not set.  The '.MAKEFLAGS:' above also doesn't
14# influence the environment variable MAKEFLAGS, therefore it is still
15# undefined at this point.
16.if ${MAKEFLAGS:Uundefined} != "undefined"
17.  error
18.endif
19
20# The special variable .MAKEFLAGS is influenced though.
21# See varname-dot-makeflags.mk for more details.
22.if ${.MAKEFLAGS} != " -r -k -d 0"
23.  error
24.endif
25
26
27# In POSIX mode, the environment variable MAKEFLAGS can contain letters only,
28# for compatibility.  These letters are exploded to form regular options.
29OUTPUT!=	env MAKEFLAGS=ikrs ${MAKE} -f /dev/null -v .MAKEFLAGS
30.if ${OUTPUT} != " -i -k -r -s -V .MAKEFLAGS"
31.  error
32.endif
33
34# As soon as there is a single non-alphabetic character in the environment
35# variable MAKEFLAGS, it is no longer split.  In this example, the word
36# "d0ikrs" is treated as a target, but the option '-v' prevents any targets
37# from being built.
38OUTPUT!=	env MAKEFLAGS=d0ikrs ${MAKE} -r -f /dev/null -v .MAKEFLAGS
39.if ${OUTPUT} != " -r -V .MAKEFLAGS"
40.  error ${OUTPUT}
41.endif
42
43
44all:
45