1# $NetBSD: opt-debug-file.mk,v 1.11 2024/06/30 15:21:24 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# 32# XXX: In the :M modifier, a dollar is escaped using '$$', not '\$'. This 33# escaping scheme unnecessarily differs from all other modifiers. 34.if !${:!cat opt-debug-file.debuglog!:tW:M*VAR = value $${:Uexpanded}*} 35. error 36.endif 37 38.MAKEFLAGS: -d0 39 40 41# See Parse_Error. 42.MAKEFLAGS: -dFstdout 43# expect+1: This goes to stderr only, once. 44. info This goes to stderr only, once. 45.MAKEFLAGS: -dFstderr 46# expect+1: This goes to stderr only, once. 47. info This goes to stderr only, once. 48.MAKEFLAGS: -dFopt-debug-file.debuglog 49# expect+1: This goes to stderr, and in addition to the debug log. 50. info This goes to stderr, and in addition to the debug log. 51.MAKEFLAGS: -dFstderr -d0c 52.if ${:!cat opt-debug-file.debuglog!:Maddition:[#]} != 1 53. error 54.endif 55 56 57# See Main_ParseArgLine, which calls Error. 58.MAKEFLAGS: -dFstdout 59# expect: make: Unterminated quoted string [make 'This goes to stdout only, once.] 60.MAKEFLAGS: 'This goes to stdout only, once. 61.MAKEFLAGS: -dFstderr 62# expect: make: Unterminated quoted string [make 'This goes to stderr only, once.] 63.MAKEFLAGS: 'This goes to stderr only, once. 64.MAKEFLAGS: -dFopt-debug-file.debuglog 65# expect: make: Unterminated quoted string [make 'This goes to stderr, and in addition to the debug log.] 66.MAKEFLAGS: 'This goes to stderr, and in addition to the debug log. 67.MAKEFLAGS: -dFstderr -d0c 68.if ${:!cat opt-debug-file.debuglog!:MUnterminated:[#]} != 1 69. error 70.endif 71 72 73# If the debug log file cannot be opened, make prints an error message and 74# exits immediately since the debug log file is usually selected from the 75# command line. 76_:= ${:!rm opt-debug-file.debuglog!} 77.MAKEFLAGS: -dF/nonexistent-6f21c672-a22d-4ef7/opt-debug-file.debuglog 78