xref: /freebsd/contrib/bmake/unit-tests/varcmd.mk (revision d0b2dbfa)
1# $NetBSD: varcmd.mk,v 1.7 2023/04/07 05:54:16 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#
16# See also:
17#	var-scope-cmdline.mk
18#	varname-makeflags.mk
19
20FU=	fu
21FOO?=	foo
22.if !empty(.TARGETS)
23TAG=	${.TARGETS}
24.endif
25TAG?=	default
26
27all:	one
28
29show:
30	@echo "${TAG} FU=<v>${FU}</v> FOO=<v>${FOO}</v> VAR=<v>${VAR}</v>"
31
32one:	show
33	@${.MAKE} -f ${MAKEFILE} FU=bar FOO+=goo two
34
35two:	show
36	@${.MAKE} -f ${MAKEFILE} three
37
38three:	show
39	@${.MAKE} -f ${MAKEFILE} four
40
41
42.ifmake two
43# this should not work
44FU+= oops
45FOO+= oops
46_FU:= ${FU}
47_FOO:= ${FOO}
48two: immutable
49immutable:
50	@echo "$@ FU='${_FU}'"
51	@echo "$@ FOO='${_FOO}'"
52.endif
53.ifmake four
54VAR=Internal
55.MAKEOVERRIDES+= VAR
56.endif
57
58four:	show
59	@${.MAKE} -f ${MAKEFILE} five
60
61M=	x
62V.y=	is y
63V.x=	is x
64V:=	${V.$M}
65K:=	${V}
66
67show-v:
68	@echo '${TAG} v=${V} k=${K}'
69
70five:	show show-v
71	@${.MAKE} -f ${MAKEFILE} M=y six
72
73six:	show-v
74	@${.MAKE} -f ${MAKEFILE} V=override show-v
75