111111Syan# $NetBSD: opt-query.mk,v 1.7 2022/08/18 05:37:05 rillig Exp $ 211111Syan# 311111Syan# Tests for the -q command line option. 411111Syan# 511111Syan# The -q option only looks at the dependencies between the targets. 611111Syan# None of the commands in the targets are run, not even those that are 711111Syan# prefixed with '+'. 811111Syan 911111Syan# This test consists of several parts: 1011111Syan# 1111111Syan# main Delegates to the actual tests. 1211111Syan# 1311111Syan# commands Ensures that none of the targets is made. 1411111Syan# 1511111Syan# variants Ensures that the up-to-date status is correctly 1611111Syan# reported in both compat and jobs mode, and for several 1711111Syan# kinds of make targets. 1811111SyanPART?= main 1911111Syan 2011111Syan.if ${PART} == "main" 2111111Syan 2211111Syanall: .PHONY variants cleanup 2311111Syan 2411111Syan_!= touch -f opt-query-file.up-to-date 2511111Syan 2611111Syanvariants: .PHONY 2711111Syan 2811111Syan. for target in commands 2911111Syan @echo 'Making ${target}': 3011111Syan @${MAKE} -r -f ${MAKEFILE} -q ${mode:Mjobs:%=-j1} ${target} PART=commands \ 3111111Syan && echo "${target}: query status $$?" \ 3211111Syan || echo "${target}: query status $$?" 3311111Syan @echo 3411111Syan. endfor 3511111Syan 3611111Syan. for mode in compat jobs 3711111Syan. for target in opt-query-file.out-of-date opt-query-file.up-to-date phony 3811111Syan @echo 'Making ${target} in ${mode} mode': 3911111Syan @${MAKE} -r -f ${MAKEFILE} -q ${mode:Mjobs:%=-j1} ${target} PART=variants \ 4011111Syan && echo "${target} in ${mode} mode: query status $$?" \ 4111111Syan || echo "${target} in ${mode} mode: query status $$?" 4211111Syan @echo 4311111Syan. endfor 4411111Syan. endfor 4511111Syan 4611111Syan# Between 1994 and before 2022-08-17, the exit status for '-q' was always 1, 4711111Syan# the cause for that exit code varied over time though. 4811111Syan# 4911111Syan# expect: opt-query-file.out-of-date in compat mode: query status 1 5011111Syan# expect: opt-query-file.up-to-date in compat mode: query status 0 5111111Syan# expect: phony in compat mode: query status 1 5211111Syan# expect: opt-query-file.out-of-date in jobs mode: query status 1 5311111Syan# expect: opt-query-file.up-to-date in jobs mode: query status 0 5411111Syan# expect: phony in jobs mode: query status 1 5511111Syan 5611111Syancleanup: .PHONY 5711111Syan @rm -f opt-query-file.up-to-date 5811111Syan 5911111Syan.elif ${PART} == "commands" 6011111Syan 6111111Syan# This command cannot be prevented from being run since it is used at parse 6211111Syan# time, and any later variable assignments may depend on its result. 6311111Syan!= echo 'command during parsing' 1>&2; echo 6411111Syan 6511111Syan# None of these commands are run. 6611111Syan.BEGIN: 6711111Syan @echo '$@: hidden command' 6811111Syan @+echo '$@: run always' 6911111Syan 7011111Syan# None of these commands are run. 7111111Syancommands: 7211111Syan @echo '$@: hidden command' 7311111Syan @+echo '$@: run always' 7411111Syan# The exit status 1 is because the "commands" target has to be made, that is, 7511111Syan# it is not up-to-date. 7611111Syan 7711111Syan.elif ${PART} == "variants" 7811111Syan 7911111Syanopt-query-file.out-of-date: ${MAKEFILE} 8011111Syanopt-query-file.up-to-date: ${MAKEFILE} 8111111Syanphony: .PHONY 8211111Syan 8311111Syan.else 8411111Syan. error Invalid part '${PART}' 8511111Syan.endif 8611111Syan