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