1# $NetBSD: posix-execution.mk,v 1.1 2025/04/13 09:29:32 rillig Exp $
2#
3# https://pubs.opengroup.org/onlinepubs/9799919799/utilities/make.html#tag_20_76_13_03
4#
5
6.POSIX:
7
8
9# The target consists of two commands, which are executed separately.
10# The second command thus does not see the shell variable from the first
11# command.
12# expect: one-at-a-time: shell_variable is 'second'
13all: one-at-a-time
14one-at-a-time:
15          @shell_variable=first
16          @echo "$@: shell_variable is '$${shell_variable:-second}'"
17
18
19# expect: echo "prefixes: ignore errors"; exit 13
20# expect: prefixes: ignore errors
21# expect-not: echo "prefixes: no echo"
22# expect: prefixes: no echo
23# expect: prefixes: always, no echo
24all: prefixes
25prefixes:
26          -echo "$@: ignore errors"; exit 13
27          @echo "$@: no echo"
28          +@echo "$@: always, no echo"
29
30
31# Deviation from POSIX: The shell "-e" option is not in effect.
32# expect: shell-e-option: before
33# expect: shell-e-option: after
34all: shell-e-option
35shell-e-option:
36          @echo '$@: before'; false; echo '$@: after'
37
38
39# expect-not-matches: ^do%-prefix%-plus: a regular command
40# expect: do-prefix-plus: prefixed by plus
41# expect: do-prefix-plus: prefixed by plus
42all: prefix-plus
43prefix-plus:
44          @${MAKE} -f ${MAKEFILE} -n do-prefix-plus
45          @${MAKE} -f ${MAKEFILE} -n -j1 do-prefix-plus
46do-prefix-plus:
47          @echo '$@: a regular command'
48          @+echo '$@: prefixed by plus'
49          @echo '$@: a regular command'
50
51
52# expect: do-error-not-ignored: successful
53# expect-not: do-error-not-ignored: after an error
54all: error-not-ignored
55error-not-ignored:
56          @${MAKE} -f ${MAKEFILE} do-error-not-ignored || :
57do-error-not-ignored:
58          @echo '$@: successful'; exit 13
59          @echo '$@: after an error'
60