xref: /freebsd/contrib/bmake/unit-tests/varcmd.mk (revision 2b8331622f0b212cf3bb4fc4914a501e5321d506)
1# $NetBSD: varcmd.mk,v 1.6 2021/02/16 19:43:09 rillig Exp $
2#
3# Test behaviour of recursive make and vars set on command line.
4#
5# FIXME: The purpose of this test is unclear.  The test uses six levels of
6# sub-makes, which makes it incredibly hard to understand.  There must be at
7# least an introductory explanation about what _should_ happen here.
8# The variable names are terrible, as well as their values.
9#
10# This test produces different results if the large block with the condition
11# "scope == SCOPE_GLOBAL" in Var_SetWithFlags is removed.  This test should
12# be rewritten to make it clear why there is a difference and why this is
13# actually intended.  Removing that large block of code makes only this test
14# and vardebug.mk fail, which is not enough.
15
16FU=	fu
17FOO?=	foo
18.if !empty(.TARGETS)
19TAG=	${.TARGETS}
20.endif
21TAG?=	default
22
23all:	one
24
25show:
26	@echo "${TAG} FU=<v>${FU}</v> FOO=<v>${FOO}</v> VAR=<v>${VAR}</v>"
27
28one:	show
29	@${.MAKE} -f ${MAKEFILE} FU=bar FOO+=goo two
30
31two:	show
32	@${.MAKE} -f ${MAKEFILE} three
33
34three:	show
35	@${.MAKE} -f ${MAKEFILE} four
36
37
38.ifmake two
39# this should not work
40FU+= oops
41FOO+= oops
42_FU:= ${FU}
43_FOO:= ${FOO}
44two: immutable
45immutable:
46	@echo "$@ FU='${_FU}'"
47	@echo "$@ FOO='${_FOO}'"
48.endif
49.ifmake four
50VAR=Internal
51.MAKEOVERRIDES+= VAR
52.endif
53
54four:	show
55	@${.MAKE} -f ${MAKEFILE} five
56
57M=	x
58V.y=	is y
59V.x=	is x
60V:=	${V.$M}
61K:=	${V}
62
63show-v:
64	@echo '${TAG} v=${V} k=${K}'
65
66five:	show show-v
67	@${.MAKE} -f ${MAKEFILE} M=y six
68
69six:	show-v
70	@${.MAKE} -f ${MAKEFILE} V=override show-v
71