1# $NetBSD: varname-make_stack_trace.mk,v 1.8 2026/03/10 05:02:00 sjg Exp $ 2# 3# Tests for the MAKE_STACK_TRACE environment variable, which controls whether 4# to print inter-process stack traces that are useful to narrow down where an 5# erroneous expression comes from. 6# 7# While inter-process stack traces are useful to narrow down errors, they are 8# disabled by default since the stack trace is stored in an environment 9# variable and a stack trace can grow large depending on the shell commands in 10# the sub-make processes. The space used for the stack traces would compete 11# with the space for the command line arguments, and long command lines are 12# already written to a temporary file by Cmd_Exec to not overwhelm this space. 13 14_make ?= .make${.MAKE.PID} 15.export _make 16 17all: .PHONY 18 @${MAKE} -f ${MAKEFILE} disabled-compat || : 19 @${MAKE} -f ${MAKEFILE} -j1 disabled-parallel || : 20 @MAKE_STACK_TRACE=yes ${MAKE} -f ${MAKEFILE} enabled-compat || : 21 @MAKE_STACK_TRACE=yes ${MAKE} -f ${MAKEFILE} -j1 enabled-parallel || : 22 @MAKE_STACK_TRACE=yes ${MAKE} -f ${MAKEFILE} -j1 multi-stage-1 23 @rm -f ${_make} 24 25# expect-not-matches: in target "disabled%-compat" 26disabled-compat: .PHONY 27 @${MAKE} -f ${MAKEFILE} provoke-error 28 29# expect-not-matches: in target "disabled%-parallel" 30disabled-parallel: .PHONY 31 @${MAKE} -f ${MAKEFILE} provoke-error 32 33# expect: in target "enabled-compat" from varname-make_stack_trace.mk:35 34enabled-compat: .PHONY 35 @${MAKE} -f ${MAKEFILE} provoke-error 36 37# expect: in target "enabled-parallel" from varname-make_stack_trace.mk:39 38enabled-parallel: .PHONY 39 @${MAKE} -f ${MAKEFILE} provoke-error 40 41provoke-error: .PHONY 42 @echo ${:Z} 43 44# The stack trace must be printed exactly once. 45# expect: in target "multi-stage-4" from varname-make_stack_trace.mk:56 46# expect: in target "multi-stage-1" from varname-make_stack_trace.mk:50 47# expect-not-matches: in target "multi%-stage%-4" 48# expect-not-matches: in target "multi%-stage%-1" 49multi-stage-1: .PHONY ${_make} 50 @${MAKE} -f ${MAKEFILE} -j1 multi-stage-2 51multi-stage-2: .PHONY 52 @${MAKE} -f ${MAKEFILE} -j1 multi-stage-3 53multi-stage-3: .PHONY 54 @${MAKE} -f ${MAKEFILE} -j1 multi-stage-4 55multi-stage-4: .PHONY 56 @./${_make} -f ${MAKEFILE} -j1 multi-stage-5 57multi-stage-5: .PHONY 58 59${_make}: 60 @ln -s ${MAKE} ${.TARGET} 61 62# for FreeBSD and similar make sure we get the expected errors. 63.MAKE.ALWAYS_PASS_JOB_QUEUE= no 64