xref: /freebsd/contrib/bmake/unit-tests/depsrc-usebefore.mk (revision 8ddb146abcdf061be9f2c0db7e391697dafad85c)
1# $NetBSD: depsrc-usebefore.mk,v 1.9 2022/04/18 14:41:42 rillig Exp $
2#
3# Tests for the special source .USEBEFORE in dependency declarations,
4# which allows to prepend common commands to other targets.
5#
6# If a target depends on several .USE or .USEBEFORE nodes, the commands get
7# appended or prepended in declaration order.  For .USE nodes, this is the
8# expected order, for .USEBEFORE nodes the order is somewhat reversed, and for
9# .USE or .USEBEFORE nodes that depend on other .USE or .USEBEFORE nodes, it
10# gets even more complicated.
11#
12# See also:
13#	.USE
14#	depsrc-use.mk
15
16# Before make.h 1.280 from 2021-12-28, a .USEBEFORE target was accidentally
17# regarded as a candidate for the main target.  On the other hand, a .USE
18# target was not.
19not-a-main-candidate: .USEBEFORE
20
21all:
22	@${MAKE} -r -f ${MAKEFILE} ordering
23	@${MAKE} -r -f ${MAKEFILE} directly
24
25ordering: before-1 before-2 after-1 after-2
26
27before-1: .USEBEFORE before-1-before-1 before-1-before-2 before-1-after-1 before-1-after-2
28	@echo before-1 1
29	@echo before-1 2
30
31before-1-before-1: .USEBEFORE
32	@echo before-1-before-1 1
33	@echo before-1-before-1 2
34
35before-1-before-2: .USEBEFORE
36	@echo before-1-before-2 1
37	@echo before-1-before-2 2
38
39before-1-after-1: .USE
40	@echo before-1-after-1 1
41	@echo before-1-after-1 2
42
43before-1-after-2: .USE
44	@echo before-1-after-2 1
45	@echo before-1-after-2 2
46
47before-2: .USEBEFORE before-2-before-1 before-2-before-2 before-2-after-1 before-2-after-2
48	@echo before-2 1
49	@echo before-2 2
50
51before-2-before-1: .USEBEFORE
52	@echo before-2-before-1 1
53	@echo before-2-before-1 2
54
55before-2-before-2: .USEBEFORE
56	@echo before-2-before-2 1
57	@echo before-2-before-2 2
58
59before-2-after-1: .USE
60	@echo before-2-after-1 1
61	@echo before-2-after-1 2
62
63before-2-after-2: .USE
64	@echo before-2-after-2 1
65	@echo before-2-after-2 2
66
67after-1: .USE after-1-before-1 after-1-before-2 after-1-after-1 after-1-after-2
68	@echo after-1 1
69	@echo after-1 2
70
71after-1-before-1: .USEBEFORE
72	@echo after-1-before-1 1
73	@echo after-1-before-1 2
74
75after-1-before-2: .USEBEFORE
76	@echo after-1-before-2 1
77	@echo after-1-before-2 2
78
79after-1-after-1: .USE
80	@echo after-1-after-1 1
81	@echo after-1-after-1 2
82
83after-1-after-2: .USE
84	@echo after-1-after-2 1
85	@echo after-1-after-2 2
86
87after-2: .USE after-2-before-1 after-2-before-2 after-2-after-1 after-2-after-2
88	@echo after-2 1
89	@echo after-2 2
90
91after-2-before-1: .USEBEFORE
92	@echo after-2-before-1 1
93	@echo after-2-before-1 2
94
95after-2-before-2: .USEBEFORE
96	@echo after-2-before-2 1
97	@echo after-2-before-2 2
98
99after-2-after-1: .USE
100	@echo after-2-after-1 1
101	@echo after-2-after-1 2
102
103after-2-after-2: .USE
104	@echo after-2-after-2 1
105	@echo after-2-after-2 2
106
107# It is possible but uncommon to have a .USEBEFORE target with no commands.
108# This may happen as the result of expanding a .for loop.
109empty: .USEBEFORE
110
111# It is technically possible to directly make a .USEBEFORE target, but it
112# doesn't make sense since GNode_IsOODate considers such a target to always be
113# up to date.
114directly: .USEBEFORE
115	@echo directly
116