xref: /freebsd/contrib/bmake/unit-tests/varname-dot-make-mode.mk (revision 02e9120893770924227138ba49df1edb3896112a)
1# $NetBSD: varname-dot-make-mode.mk,v 1.3 2022/05/07 17:49:47 rillig Exp $
2#
3# Tests for the special .MAKE.MODE variable.
4
5# TODO: test .MAKE.MODE "meta", or see meta mode tests.
6# TODO: test .MAKE.MODE "compat"
7
8
9# See Makefile, POSTPROC for the postprocessing that takes place.
10# See the .rawout file for the raw output before stripping the digits.
11all: .PHONY make-mode-randomize-targets
12
13
14# By adding the word "randomize-targets" to the variable .MAKE.MODE, the
15# targets are not made in declaration order, but rather in random order.  This
16# mode helps to find undeclared dependencies between files.
17#
18# History
19#	Added on 2022-05-07.
20#
21# See also
22#	https://gnats.netbsd.org/45226
23make-mode-randomize-targets: .PHONY
24	@echo "randomize compat mode:"
25	@${MAKE} -r -f ${MAKEFILE} randomize-targets
26
27	@echo "randomize jobs mode (-j1):"
28	@${MAKE} -r -f ${MAKEFILE} -j1 randomize-targets
29
30	@echo "randomize jobs mode (-j5):"
31	@${MAKE} -r -f ${MAKEFILE} -j5 randomize-targets | grep '^:'
32
33.if make(randomize-targets)
34randomize-targets: .WAIT a1 a2 a3 .WAIT b1 b2 b3 .WAIT c1 c2 c3 .WAIT
35a1 a2 a3 b1 b2 b3 c1 c2 c3:
36	: Making ${.TARGET}
37
38# .MAKE.MODE is evaluated after parsing all files, so it suffices to switch
39# the mode after defining the targets.
40.MAKE.MODE+=	randomize-targets
41.endif
42