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 16 all: .PHONY 17 18 opt-ignerr.yes= -i 19 opt-jobs.yes= -j1 20 opt-loud.no= -d0 # side effect: make stdout unbuffered 21 opt-loud.yes= -dl # side effect: make stdout unbuffered 22 opt-no-action.yes= -n 23 opt-silent.yes= -s 24 opt-xtrace.yes= -dx 25 tgt-always.yes= .MAKE 26 tgt-ignerr.yes= .IGNORE 27 tgt-silent.yes= .SILENT 28 cmd-always.yes= + 29 cmd-ignerr.yes= - 30 cmd-silent.yes= @ 31 32 letter.always.yes= a 33 letter.ignerr.yes= i 34 letter.jobs.yes= j 35 letter.loud.yes= l 36 letter.no-action.yes= n 37 letter.silent.yes= s 38 letter.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 51 target= opt- 52 target+= ${letter.ignerr.${opt-ignerr}:U_} 53 target+= ${letter.jobs.${opt-jobs}:U_} 54 target+= ${letter.loud.${opt-loud}:U_} 55 target+= ${letter.no-action.${opt-no-action}:U_} 56 target+= ${letter.silent.${opt-silent}:U_} 57 target+= ${letter.xtrace.${opt-xtrace}:U_} 58 59 .for target in ${target:ts} 60 61 MAKE_CMD.${target}= ${MAKE} 62 MAKE_CMD.${target}+= ${opt-ignerr.${opt-ignerr}} 63 MAKE_CMD.${target}+= ${opt-jobs.${opt-jobs}} 64 MAKE_CMD.${target}+= ${opt-loud.${opt-loud}} 65 MAKE_CMD.${target}+= ${opt-no-action.${opt-no-action}} 66 MAKE_CMD.${target}+= ${opt-silent.${opt-silent}} 67 MAKE_CMD.${target}+= ${opt-xtrace.${opt-xtrace}} 68 MAKE_CMD.${target}+= -f ${MAKEFILE} 69 MAKE_CMD.${target}+= OPT_TARGET=${target} 70 MAKE_CMD.${target}+= ${target} 71 72 all: ${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 85 SILENT.yes= @ 86 ALWAYS.yes= + 87 IGNERR.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 97 target= ${OPT_TARGET}-tgt- 98 target+= ${letter.always.${tgt-always}:U_} 99 target+= ${letter.ignerr.${tgt-ignerr}:U_} 100 target+= ${letter.silent.${tgt-silent}:U_} 101 target+= -cmd- 102 target+= ${letter.always.${cmd-always}:U_} 103 target+= ${letter.ignerr.${cmd-ignerr}:U_} 104 target+= ${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 119 RUNFLAGS.${target}= ${SILENT.${cmd-silent}}${ALWAYS.${cmd-always}}${IGNERR.${cmd-ignerr}} 120 .if ${OPT_TARGET:M*i*} || ${tgt-ignerr} == yes || ${cmd-ignerr} == yes 121 CMD.${target}= echo running; false 122 .else 123 CMD.${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