xref: /freebsd/contrib/bmake/unit-tests/varname-makefile.mk (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1# $NetBSD: varname-makefile.mk,v 1.3 2020/11/09 22:36:44 rillig Exp $
2#
3# Tests for the special MAKEFILE variable, which contains the current
4# makefile from the -f command line option.
5#
6# When there are multiple -f options, the variable MAKEFILE is set
7# again for each of these makefiles, before the file is parsed.
8# Including a file via .include does not influence the MAKEFILE
9# variable though.
10
11.if ${MAKEFILE:T} != "varname-makefile.mk"
12.  error
13.endif
14
15# This variable lives in the "Internal" namespace.
16# TODO: Why does it do that, and what consequences does this have?
17
18# Deleting the variable does not work since this variable does not live in
19# the "Global" namespace but in "Internal", which is kind of a child
20# namespace.
21#
22.undef MAKEFILE
23.if ${MAKEFILE:T} != "varname-makefile.mk"
24.  error
25.endif
26
27# Overwriting this variable is possible since the "Internal" namespace
28# serves as a fallback for the "Global" namespace (see VarFind).
29#
30MAKEFILE=	overwritten
31.if ${MAKEFILE:T} != "overwritten"
32.  error
33.endif
34
35# When the overwritten value is deleted, the fallback value becomes
36# visible again.
37#
38.undef MAKEFILE
39.if ${MAKEFILE:T} != "varname-makefile.mk"
40.  error
41.endif
42
43all:
44	# MAKEFILE is the file that appeared last in the command line.
45	: In the end, MAKEFILE is ${MAKEFILE}.
46
47# Additional makefiles can be added while reading a makefile.  They will be
48# read in order.
49.MAKEFLAGS: -f /dev/null
50