1 1.6 rillig # $NetBSD: opt-debug-file.mk,v 1.6 2021/12/28 01:04:04 rillig Exp $ 2 1.1 rillig # 3 1.1 rillig # Tests for the -dF command line option, which redirects the debug log 4 1.1 rillig # to a file instead of writing it to stderr. 5 1.1 rillig 6 1.4 rillig # Enable debug logging for variable assignments and evaluation (-dv) 7 1.4 rillig # and redirect the debug logging to the given file. 8 1.4 rillig .MAKEFLAGS: -dvFopt-debug-file.debuglog 9 1.4 rillig 10 1.4 rillig # This output goes to the debug log file. 11 1.4 rillig VAR= value ${:Uexpanded} 12 1.4 rillig 13 1.4 rillig # Hide the logging output for the remaining actions. 14 1.4 rillig # As of 2020-10-03, it is not possible to disable debug logging again. 15 1.4 rillig .MAKEFLAGS: -dF/dev/null 16 1.4 rillig 17 1.4 rillig # Make sure that the debug logging file contains some logging. 18 1.4 rillig DEBUG_OUTPUT:= ${:!cat opt-debug-file.debuglog!} 19 1.4 rillig # Grmbl. Because of the := operator in the above line, the variable 20 1.4 rillig # value contains ${:Uexpanded}. This variable expression is expanded 21 1.4 rillig # upon further processing. Therefore, don't read from untrusted input. 22 1.4 rillig #.MAKEFLAGS: -dc -dFstderr 23 1.4 rillig .if !${DEBUG_OUTPUT:tW:M*VAR = value expanded*} 24 1.4 rillig . error ${DEBUG_OUTPUT} 25 1.4 rillig .endif 26 1.4 rillig 27 1.4 rillig # To get the unexpanded text that was actually written to the debug log 28 1.4 rillig # file, the content of that log file must not be stored in a variable. 29 1.4 rillig # XXX: In the :M modifier, a dollar is escaped as '$$', not '\$'. 30 1.4 rillig .if !${:!cat opt-debug-file.debuglog!:tW:M*VAR = value $${:Uexpanded}*} 31 1.4 rillig . error 32 1.4 rillig .endif 33 1.4 rillig 34 1.5 rillig 35 1.6 rillig # If the debug log file cannot be opened, make prints an error message and 36 1.6 rillig # exits immediately since the debug log file is usually selected from the 37 1.6 rillig # command line. 38 1.5 rillig .MAKEFLAGS: -dFopt-debug-file.debuglog/file 39 1.5 rillig 40 1.1 rillig all: 41