1*4fde40d9SSimon J. Gerraty# $NetBSD: opt-query.mk,v 1.7 2022/08/18 05:37:05 rillig Exp $ 22c3632d1SSimon J. Gerraty# 32c3632d1SSimon J. Gerraty# Tests for the -q command line option. 42c3632d1SSimon J. Gerraty# 52c3632d1SSimon J. Gerraty# The -q option only looks at the dependencies between the targets. 62c3632d1SSimon J. Gerraty# None of the commands in the targets are run, not even those that are 72c3632d1SSimon J. Gerraty# prefixed with '+'. 82c3632d1SSimon J. Gerraty 9*4fde40d9SSimon J. Gerraty# This test consists of several parts: 10*4fde40d9SSimon J. Gerraty# 11*4fde40d9SSimon J. Gerraty# main Delegates to the actual tests. 12*4fde40d9SSimon J. Gerraty# 13*4fde40d9SSimon J. Gerraty# commands Ensures that none of the targets is made. 14*4fde40d9SSimon J. Gerraty# 15*4fde40d9SSimon J. Gerraty# variants Ensures that the up-to-date status is correctly 16*4fde40d9SSimon J. Gerraty# reported in both compat and jobs mode, and for several 17*4fde40d9SSimon J. Gerraty# kinds of make targets. 18*4fde40d9SSimon J. GerratyPART?= main 19*4fde40d9SSimon J. Gerraty 20*4fde40d9SSimon J. Gerraty.if ${PART} == "main" 21*4fde40d9SSimon J. Gerraty 22*4fde40d9SSimon J. Gerratyall: .PHONY variants cleanup 23*4fde40d9SSimon J. Gerraty 24*4fde40d9SSimon J. Gerraty_!= touch -f opt-query-file.up-to-date 25*4fde40d9SSimon J. Gerraty 26*4fde40d9SSimon J. Gerratyvariants: .PHONY 27*4fde40d9SSimon J. Gerraty 28*4fde40d9SSimon J. Gerraty. for target in commands 29*4fde40d9SSimon J. Gerraty @echo 'Making ${target}': 30*4fde40d9SSimon J. Gerraty @${MAKE} -r -f ${MAKEFILE} -q ${mode:Mjobs:%=-j1} ${target} PART=commands \ 31*4fde40d9SSimon J. Gerraty && echo "${target}: query status $$?" \ 32*4fde40d9SSimon J. Gerraty || echo "${target}: query status $$?" 33*4fde40d9SSimon J. Gerraty @echo 34*4fde40d9SSimon J. Gerraty. endfor 35*4fde40d9SSimon J. Gerraty 36*4fde40d9SSimon J. Gerraty. for mode in compat jobs 37*4fde40d9SSimon J. Gerraty. for target in opt-query-file.out-of-date opt-query-file.up-to-date phony 38*4fde40d9SSimon J. Gerraty @echo 'Making ${target} in ${mode} mode': 39*4fde40d9SSimon J. Gerraty @${MAKE} -r -f ${MAKEFILE} -q ${mode:Mjobs:%=-j1} ${target} PART=variants \ 40*4fde40d9SSimon J. Gerraty && echo "${target} in ${mode} mode: query status $$?" \ 41*4fde40d9SSimon J. Gerraty || echo "${target} in ${mode} mode: query status $$?" 42*4fde40d9SSimon J. Gerraty @echo 43*4fde40d9SSimon J. Gerraty. endfor 44*4fde40d9SSimon J. Gerraty. endfor 45*4fde40d9SSimon J. Gerraty 46*4fde40d9SSimon J. Gerraty# Between 1994 and before 2022-08-17, the exit status for '-q' was always 1, 47*4fde40d9SSimon J. Gerraty# the cause for that exit code varied over time though. 48*4fde40d9SSimon J. Gerraty# 49*4fde40d9SSimon J. Gerraty# expect: opt-query-file.out-of-date in compat mode: query status 1 50*4fde40d9SSimon J. Gerraty# expect: opt-query-file.up-to-date in compat mode: query status 0 51*4fde40d9SSimon J. Gerraty# expect: phony in compat mode: query status 1 52*4fde40d9SSimon J. Gerraty# expect: opt-query-file.out-of-date in jobs mode: query status 1 53*4fde40d9SSimon J. Gerraty# expect: opt-query-file.up-to-date in jobs mode: query status 0 54*4fde40d9SSimon J. Gerraty# expect: phony in jobs mode: query status 1 55*4fde40d9SSimon J. Gerraty 56*4fde40d9SSimon J. Gerratycleanup: .PHONY 57*4fde40d9SSimon J. Gerraty @rm -f opt-query-file.up-to-date 58*4fde40d9SSimon J. Gerraty 59*4fde40d9SSimon J. Gerraty.elif ${PART} == "commands" 60e2eeea75SSimon J. Gerraty 612c3632d1SSimon J. Gerraty# This command cannot be prevented from being run since it is used at parse 622c3632d1SSimon J. Gerraty# time, and any later variable assignments may depend on its result. 632c3632d1SSimon J. Gerraty!= echo 'command during parsing' 1>&2; echo 642c3632d1SSimon J. Gerraty 652c3632d1SSimon J. Gerraty# None of these commands are run. 662c3632d1SSimon J. Gerraty.BEGIN: 672c3632d1SSimon J. Gerraty @echo '$@: hidden command' 682c3632d1SSimon J. Gerraty @+echo '$@: run always' 692c3632d1SSimon J. Gerraty 702c3632d1SSimon J. Gerraty# None of these commands are run. 71*4fde40d9SSimon J. Gerratycommands: 722c3632d1SSimon J. Gerraty @echo '$@: hidden command' 732c3632d1SSimon J. Gerraty @+echo '$@: run always' 74*4fde40d9SSimon J. Gerraty# The exit status 1 is because the "commands" target has to be made, that is, 752c3632d1SSimon J. Gerraty# it is not up-to-date. 76*4fde40d9SSimon J. Gerraty 77*4fde40d9SSimon J. Gerraty.elif ${PART} == "variants" 78*4fde40d9SSimon J. Gerraty 79*4fde40d9SSimon J. Gerratyopt-query-file.out-of-date: ${MAKEFILE} 80*4fde40d9SSimon J. Gerratyopt-query-file.up-to-date: ${MAKEFILE} 81*4fde40d9SSimon J. Gerratyphony: .PHONY 82*4fde40d9SSimon J. Gerraty 83*4fde40d9SSimon J. Gerraty.else 84*4fde40d9SSimon J. Gerraty. error Invalid part '${PART}' 85*4fde40d9SSimon J. Gerraty.endif 86