xref: /freebsd/contrib/bmake/unit-tests/varname-makefile.mk (revision e2eeea75eb8b6dd50c1298067a0655880d186734)
1*e2eeea75SSimon J. Gerraty# $NetBSD: varname-makefile.mk,v 1.3 2020/11/09 22:36:44 rillig Exp $
2956e45f6SSimon J. Gerraty#
3956e45f6SSimon J. Gerraty# Tests for the special MAKEFILE variable, which contains the current
4956e45f6SSimon J. Gerraty# makefile from the -f command line option.
5956e45f6SSimon J. Gerraty#
6956e45f6SSimon J. Gerraty# When there are multiple -f options, the variable MAKEFILE is set
7956e45f6SSimon J. Gerraty# again for each of these makefiles, before the file is parsed.
8956e45f6SSimon J. Gerraty# Including a file via .include does not influence the MAKEFILE
9956e45f6SSimon J. Gerraty# variable though.
10956e45f6SSimon J. Gerraty
11956e45f6SSimon J. Gerraty.if ${MAKEFILE:T} != "varname-makefile.mk"
12956e45f6SSimon J. Gerraty.  error
13956e45f6SSimon J. Gerraty.endif
14956e45f6SSimon J. Gerraty
15956e45f6SSimon J. Gerraty# This variable lives in the "Internal" namespace.
16956e45f6SSimon J. Gerraty# TODO: Why does it do that, and what consequences does this have?
17956e45f6SSimon J. Gerraty
18956e45f6SSimon J. Gerraty# Deleting the variable does not work since this variable does not live in
19956e45f6SSimon J. Gerraty# the "Global" namespace but in "Internal", which is kind of a child
20956e45f6SSimon J. Gerraty# namespace.
21956e45f6SSimon J. Gerraty#
22956e45f6SSimon J. Gerraty.undef MAKEFILE
23956e45f6SSimon J. Gerraty.if ${MAKEFILE:T} != "varname-makefile.mk"
24956e45f6SSimon J. Gerraty.  error
25956e45f6SSimon J. Gerraty.endif
26956e45f6SSimon J. Gerraty
27956e45f6SSimon J. Gerraty# Overwriting this variable is possible since the "Internal" namespace
28956e45f6SSimon J. Gerraty# serves as a fallback for the "Global" namespace (see VarFind).
29956e45f6SSimon J. Gerraty#
30956e45f6SSimon J. GerratyMAKEFILE=	overwritten
31956e45f6SSimon J. Gerraty.if ${MAKEFILE:T} != "overwritten"
32956e45f6SSimon J. Gerraty.  error
33956e45f6SSimon J. Gerraty.endif
34956e45f6SSimon J. Gerraty
35956e45f6SSimon J. Gerraty# When the overwritten value is deleted, the fallback value becomes
36956e45f6SSimon J. Gerraty# visible again.
37956e45f6SSimon J. Gerraty#
38956e45f6SSimon J. Gerraty.undef MAKEFILE
39956e45f6SSimon J. Gerraty.if ${MAKEFILE:T} != "varname-makefile.mk"
40956e45f6SSimon J. Gerraty.  error
41956e45f6SSimon J. Gerraty.endif
42956e45f6SSimon J. Gerraty
43956e45f6SSimon J. Gerratyall:
44*e2eeea75SSimon J. Gerraty	# MAKEFILE is the file that appeared last in the command line.
45*e2eeea75SSimon J. Gerraty	: In the end, MAKEFILE is ${MAKEFILE}.
46*e2eeea75SSimon J. Gerraty
47*e2eeea75SSimon J. Gerraty# Additional makefiles can be added while reading a makefile.  They will be
48*e2eeea75SSimon J. Gerraty# read in order.
49*e2eeea75SSimon J. Gerraty.MAKEFLAGS: -f /dev/null
50