xref: /freebsd/contrib/bmake/unit-tests/sh-flags.mk (revision 06b9b3e0ad0dc3f0166b3e8f26ced68c271cf527)
1# $NetBSD: sh-flags.mk,v 1.4 2020/12/12 12:19:18 rillig Exp $
2#
3# Tests for the effective RunFlags of a shell command (run/skip, echo/silent,
4# error check, trace), which are controlled by 12 different switches.  These
5# switches interact in various non-obvious ways.  To analyze the interactions,
6# this test runs each possible combination of these switches, for now.
7#
8# As soon as an interaction of switches is identified as obvious and expected,
9# this particular interaction may be removed from the test, to focus on the
10# remaining ones.
11#
12# See also:
13#	Compat_RunCommand
14#	JobPrintSpecials
15
16all: .PHONY
17
18opt-ignerr.yes=		-i
19opt-jobs.yes=		-j1
20opt-loud.no=		-d0	# side effect: make stdout unbuffered
21opt-loud.yes=		-dl	# side effect: make stdout unbuffered
22opt-no-action.yes=	-n
23opt-silent.yes=		-s
24opt-xtrace.yes=		-dx
25tgt-always.yes=		.MAKE
26tgt-ignerr.yes=		.IGNORE
27tgt-silent.yes=		.SILENT
28cmd-always.yes=		+
29cmd-ignerr.yes=		-
30cmd-silent.yes=		@
31
32letter.always.yes=	a
33letter.ignerr.yes=	i
34letter.jobs.yes=	j
35letter.loud.yes=	l
36letter.no-action.yes=	n
37letter.silent.yes=	s
38letter.xtrace.yes=	x
39
40.if !defined(OPT_TARGET)
41.for opt-ignerr in no yes
42.for opt-jobs in no yes
43.for opt-loud in no yes
44.for opt-no-action in no yes
45# Only 'no', not 'yes', since job->echo is based trivially on opts.silent.
46.for opt-silent in no
47# Only 'no', not 'yes', since that would add uncontrollable output from
48# reading /etc/profile or similar files.
49.for opt-xtrace in no
50
51target=		opt-
52target+=	${letter.ignerr.${opt-ignerr}:U_}
53target+=	${letter.jobs.${opt-jobs}:U_}
54target+=	${letter.loud.${opt-loud}:U_}
55target+=	${letter.no-action.${opt-no-action}:U_}
56target+=	${letter.silent.${opt-silent}:U_}
57target+=	${letter.xtrace.${opt-xtrace}:U_}
58
59.for target in ${target:ts}
60
61MAKE_CMD.${target}=	${MAKE}
62MAKE_CMD.${target}+=	${opt-ignerr.${opt-ignerr}}
63MAKE_CMD.${target}+=	${opt-jobs.${opt-jobs}}
64MAKE_CMD.${target}+=	${opt-loud.${opt-loud}}
65MAKE_CMD.${target}+=	${opt-no-action.${opt-no-action}}
66MAKE_CMD.${target}+=	${opt-silent.${opt-silent}}
67MAKE_CMD.${target}+=	${opt-xtrace.${opt-xtrace}}
68MAKE_CMD.${target}+=	-f ${MAKEFILE}
69MAKE_CMD.${target}+=	OPT_TARGET=${target}
70MAKE_CMD.${target}+=	${target}
71
72all: ${target}
73${target}: .PHONY
74	@${MAKE_CMD.${target}:M*}
75
76.endfor
77.endfor
78.endfor
79.endfor
80.endfor
81.endfor
82.endfor
83.endif
84
85SILENT.yes=	@
86ALWAYS.yes=	+
87IGNERR.yes=	-
88
89.if defined(OPT_TARGET)
90.for tgt-always in no yes
91.for tgt-ignerr in no yes
92.for tgt-silent in no yes
93.for cmd-always in no yes
94.for cmd-ignerr in no yes
95.for cmd-silent in no yes
96
97target=		${OPT_TARGET}-tgt-
98target+=	${letter.always.${tgt-always}:U_}
99target+=	${letter.ignerr.${tgt-ignerr}:U_}
100target+=	${letter.silent.${tgt-silent}:U_}
101target+=	-cmd-
102target+=	${letter.always.${cmd-always}:U_}
103target+=	${letter.ignerr.${cmd-ignerr}:U_}
104target+=	${letter.silent.${cmd-silent}:U_}
105
106.for target in ${target:ts}
107
108${OPT_TARGET}: .WAIT ${target} .WAIT
109.if ${tgt-always} == yes
110${target}: .MAKE
111.endif
112.if ${tgt-ignerr} == yes
113${target}: .IGNORE
114.endif
115.if ${tgt-silent} == yes
116${target}: .SILENT
117.endif
118
119RUNFLAGS.${target}=	${SILENT.${cmd-silent}}${ALWAYS.${cmd-always}}${IGNERR.${cmd-ignerr}}
120.if ${OPT_TARGET:M*i*} || ${tgt-ignerr} == yes || ${cmd-ignerr} == yes
121CMD.${target}=		echo running; false
122.else
123CMD.${target}=		echo running
124.endif
125
126${target}: .PHONY
127	@+echo hide-from-output
128	@+echo hide-from-output ${target}
129	${RUNFLAGS.${target}} ${CMD.${target}}
130.endfor
131
132.endfor
133.endfor
134.endfor
135.endfor
136.endfor
137.endfor
138.endif
139