xref: /freebsd/contrib/bmake/unit-tests/dir.mk (revision 994297b01b98816bea1abf45ae4bac1bc69ee7a0)
1# $NetBSD: dir.mk,v 1.9 2021/01/23 10:48:49 rillig Exp $
2#
3# Tests for dir.c.
4
5.MAKEFLAGS: -m /		# hide /usr/share/mk from the debug log
6
7# Dependency lines may use braces for expansion.
8# See DirExpandCurly for the implementation.
9all: {one,two,three}
10
11# XXX: The above dependency line is parsed as a single node named
12# "{one,two,three}".  There are no individual targets "one", "two", "three"
13# yet.  The node exists but is not a target since it never appeared
14# on the left-hand side of a dependency operator.  However, it is listed
15# in .ALLTARGETS (which lists all nodes, not only targets).
16.if target(one)
17.  error
18.endif
19.if target({one,two,three})
20.  error
21.endif
22.if ${.ALLTARGETS:M{one,two,three}} != "{one,two,three}"
23.  error
24.endif
25
26one:
27	: 1
28two:
29	: 2
30three:
31	: 3
32
33# The braces may start in the middle of a word.
34all: f{our,ive}
35
36four:
37	: 4
38five:
39	: 5
40six:
41	: 6
42
43# Nested braces work as expected since 2020-07-31 19:06 UTC.
44# They had been broken at least since 2003-01-01, probably even longer.
45all: {{thi,fou}r,fif}teen
46
47thirteen:
48	: 13
49fourteen:
50	: 14
51fifteen:
52	: 15
53
54# There may be multiple brace groups side by side.
55all: {pre-,}{patch,configure}
56
57pre-patch patch pre-configure configure:
58	: $@
59
60# Empty pieces are allowed in the braces.
61all: {fetch,extract}{,-post}
62
63fetch fetch-post extract extract-post:
64	: $@
65
66# The expansions may have duplicates.
67# When the source of the dependency line is expanded later, each of the
68# expanded words will be the same.
69all: dup-{1,1,1,1,1,1,1}
70
71dup-1:
72	: $@
73
74# Other than in Bash, the braces are also expanded if there is no comma.
75all: {{{{{{{{{{single-word}}}}}}}}}}
76
77single-word:
78	: $@
79
80# Demonstrate debug logging for filename expansion, especially curly braces.
81.MAKEFLAGS: -dd
82# The below line does not call SearchPath_Expand yet.
83# It is expanded only when necessary, that is, when the 'debug' target is
84# indeed made.
85debug: {{thi,fou}r,fif}twen
86# Therefore, keep the debug logging active.
87
88.PHONY: one two three four five six
89.PHONY: thirteen fourteen fifteen
90.PHONY: single-word
91.PHONY: pre-patch patch pre-configure configure
92.PHONY: fetch fetch-post extract extract-post
93.PHONY: dup-1 single-word
94.PHONY: all
95