1# $NetBSD: opt-debug-file.mk,v 1.10 2023/11/19 21:47:52 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 ApplyModifier_Subst, which calls Error. 58.MAKEFLAGS: -dFstdout 59: This goes to stderr only, once. ${:U:S 60.MAKEFLAGS: -dFstderr 61: This goes to stderr only, once. ${:U:S 62.MAKEFLAGS: -dFopt-debug-file.debuglog 63: This goes to stderr, and in addition to the debug log. ${:U:S 64.MAKEFLAGS: -dFstderr -d0c 65.if ${:!cat opt-debug-file.debuglog!:Mdelimiter:[#]} != 1 66. error 67.endif 68 69 70# If the debug log file cannot be opened, make prints an error message and 71# exits immediately since the debug log file is usually selected from the 72# command line. 73_:= ${:!rm opt-debug-file.debuglog!} 74.MAKEFLAGS: -dF/nonexistent-6f21c672-a22d-4ef7/opt-debug-file.debuglog 75