opt-query.mk revision 1.5 1 # $NetBSD: opt-query.mk,v 1.5 2022/08/17 20:05:41 rillig Exp $
2 #
3 # Tests for the -q command line option.
4 #
5 # The -q option only looks at the dependencies between the targets.
6 # None of the commands in the targets are run, not even those that are
7 # prefixed with '+'.
8
9 # This test consists of several parts:
10 #
11 # main Delegates to the actual tests.
12 #
13 # commands Ensures that none of the targets is made.
14 #
15 # variants Ensures that the up-to-date status is correctly
16 # reported in both compat and jobs mode, and for several
17 # kinds of make targets.
18 PART?= main
19
20 .if ${PART} == "main"
21
22 all: .PHONY variants cleanup
23
24 _!= touch -f opt-query-file.up-to-date
25
26 variants: .PHONY
27 . for target in commands
28 @echo 'Making ${target}':
29 @${MAKE} -r -f ${MAKEFILE} -q ${mode:Mjobs:%=-j1} ${target} PART=commands \
30 && echo "${target}: query status $$?" \
31 || echo "${target}: query status $$?"
32 @echo
33 . endfor
34 . for mode in compat jobs
35 . for target in opt-query-file.out-of-date opt-query-file.up-to-date phony
36 @echo 'Making ${target} in ${mode} mode':
37 @${MAKE} -r -f ${MAKEFILE} -q ${mode:Mjobs:%=-j1} ${target} PART=variants \
38 && echo "${target} in ${mode} mode: query status $$?" \
39 || echo "${target} in ${mode} mode: query status $$?"
40 @echo
41 . endfor
42 . endfor
43
44 # expect: opt-query-file.out-of-date in compat mode: query status 1
45
46 # FIXME: must be 0, not 1.
47 # expect: opt-query-file.up-to-date in compat mode: query status 1
48
49 # expect: phony in compat mode: query status 1
50
51 # expect: opt-query-file.out-of-date in jobs mode: query status 1
52
53 # FIXME: must be 0, not 1.
54 # expect: opt-query-file.up-to-date in jobs mode: query status 1
55
56 # expect: phony in jobs mode: query status 1
57
58 cleanup: .PHONY
59 @rm -f opt-query-file.up-to-date
60
61 .elif ${PART} == "commands"
62
63 # This command cannot be prevented from being run since it is used at parse
64 # time, and any later variable assignments may depend on its result.
65 != echo 'command during parsing' 1>&2; echo
66
67 # None of these commands are run.
68 .BEGIN:
69 @echo '$@: hidden command'
70 @+echo '$@: run always'
71
72 # None of these commands are run.
73 commands:
74 @echo '$@: hidden command'
75 @+echo '$@: run always'
76 # The exit status 1 is because the "commands" target has to be made, that is,
77 # it is not up-to-date.
78
79 .elif ${PART} == "variants"
80
81 opt-query-file.out-of-date: ${MAKE}
82 opt-query-file.up-to-date: ${MAKE}
83 phony: .PHONY
84
85 .else
86 . error Invalid part '${PART}'
87 .endif
88