1# $NetBSD: opt-debug-file.mk,v 1.12 2025/07/06 08:48:34 rillig Exp $ 2# 3# Tests for the -dF command line option, which redirects the debug log 4# to a file instead of writing it to stderr. 5 6# Enable debug logging for variable assignments and evaluation (-dv) 7# and redirect the debug logging to the given file. 8.MAKEFLAGS: -dvFopt-debug-file.debuglog 9 10# This output goes to the debug log file. 11VAR= value ${:Uexpanded} 12 13# Hide the logging output for the remaining actions. 14# Before main.c 1.362 from 2020-10-03, it was not possible to disable debug 15# logging again. Since then, an easier way is the undocumented option '-d0'. 16.MAKEFLAGS: -dF/dev/null 17 18# Make sure that the debug logging file contains some logging. 19DEBUG_OUTPUT:= ${:!cat opt-debug-file.debuglog!} 20# Grmbl. Because of the := operator in the above line, the variable 21# value contains ${:Uexpanded}. This expression is expanded 22# when it is used in the condition below. Therefore, be careful when storing 23# untrusted input in variables. 24#.MAKEFLAGS: -dc -dFstderr 25.if !${DEBUG_OUTPUT:tW:M*VAR = value expanded*} 26. error ${DEBUG_OUTPUT} 27.endif 28 29# To get the unexpanded text that was actually written to the debug log 30# file, the content of that log file must not be stored in a variable 31# directly. Instead, it can be processed in a single expression by a chain 32# of modifiers. 33# 34# XXX: In the :M modifier, a dollar is escaped using '$$', not '\$'. This 35# escaping scheme unnecessarily differs from all other modifiers. 36.if !${:!cat opt-debug-file.debuglog!:tW:M*VAR = value $${:Uexpanded}*} 37. error 38.endif 39 40# To get the unexpanded text that was actually written to the debug log 41# file, the content of that log file must not be stored in a variable 42# directly. Instead, each dollar sign must be escaped first. 43DEBUG_OUTPUT:= ${:!cat opt-debug-file.debuglog!:S,\$,\$\$,g} 44.if ${DEBUG_OUTPUT:M*Uexpanded*} != "\${:Uexpanded}" 45. error 46.endif 47 48.MAKEFLAGS: -d0 49 50 51# See Parse_Error. 52.MAKEFLAGS: -dFstdout 53# expect+1: This goes to stderr only, once. 54. info This goes to stderr only, once. 55.MAKEFLAGS: -dFstderr 56# expect+1: This goes to stderr only, once. 57. info This goes to stderr only, once. 58.MAKEFLAGS: -dFopt-debug-file.debuglog 59# expect+1: This goes to stderr, and in addition to the debug log. 60. info This goes to stderr, and in addition to the debug log. 61.MAKEFLAGS: -dFstderr -d0c 62.if ${:!cat opt-debug-file.debuglog!:Maddition:[#]} != 1 63. error 64.endif 65 66 67# See Main_ParseArgLine, which calls Error. 68.MAKEFLAGS: -dFstdout 69# expect: make: Unterminated quoted string [make 'This goes to stdout only, once.] 70.MAKEFLAGS: 'This goes to stdout only, once. 71.MAKEFLAGS: -dFstderr 72# expect: make: Unterminated quoted string [make 'This goes to stderr only, once.] 73.MAKEFLAGS: 'This goes to stderr only, once. 74.MAKEFLAGS: -dFopt-debug-file.debuglog 75# expect: make: Unterminated quoted string [make 'This goes to stderr, and in addition to the debug log.] 76.MAKEFLAGS: 'This goes to stderr, and in addition to the debug log. 77.MAKEFLAGS: -dFstderr -d0c 78.if ${:!cat opt-debug-file.debuglog!:MUnterminated:[#]} != 1 79. error 80.endif 81 82 83# If the debug log file cannot be opened, make prints an error message and 84# exits immediately since the debug log file is usually selected from the 85# command line. 86_:= ${:!rm opt-debug-file.debuglog!} 87.MAKEFLAGS: -dF/nonexistent-6f21c672-a22d-4ef7/opt-debug-file.debuglog 88