1*22619282SSimon J. Gerraty# $NetBSD: opt-debug-file.mk,v 1.11 2024/06/30 15:21:24 rillig Exp $ 2956e45f6SSimon J. Gerraty# 3956e45f6SSimon J. Gerraty# Tests for the -dF command line option, which redirects the debug log 4956e45f6SSimon J. Gerraty# to a file instead of writing it to stderr. 5956e45f6SSimon J. Gerraty 6956e45f6SSimon J. Gerraty# Enable debug logging for variable assignments and evaluation (-dv) 7956e45f6SSimon J. Gerraty# and redirect the debug logging to the given file. 8956e45f6SSimon J. Gerraty.MAKEFLAGS: -dvFopt-debug-file.debuglog 9956e45f6SSimon J. Gerraty 10956e45f6SSimon J. Gerraty# This output goes to the debug log file. 11956e45f6SSimon J. GerratyVAR= value ${:Uexpanded} 12956e45f6SSimon J. Gerraty 13956e45f6SSimon J. Gerraty# Hide the logging output for the remaining actions. 149f45a3c8SSimon J. Gerraty# Before main.c 1.362 from 2020-10-03, it was not possible to disable debug 159f45a3c8SSimon J. Gerraty# logging again. Since then, an easier way is the undocumented option '-d0'. 16956e45f6SSimon J. Gerraty.MAKEFLAGS: -dF/dev/null 17956e45f6SSimon J. Gerraty 18956e45f6SSimon J. Gerraty# Make sure that the debug logging file contains some logging. 19956e45f6SSimon J. GerratyDEBUG_OUTPUT:= ${:!cat opt-debug-file.debuglog!} 20956e45f6SSimon J. Gerraty# Grmbl. Because of the := operator in the above line, the variable 21d5e0a182SSimon J. Gerraty# value contains ${:Uexpanded}. This expression is expanded 229f45a3c8SSimon J. Gerraty# when it is used in the condition below. Therefore, be careful when storing 239f45a3c8SSimon J. Gerraty# untrusted input in variables. 24956e45f6SSimon J. Gerraty#.MAKEFLAGS: -dc -dFstderr 25956e45f6SSimon J. Gerraty.if !${DEBUG_OUTPUT:tW:M*VAR = value expanded*} 26956e45f6SSimon J. Gerraty. error ${DEBUG_OUTPUT} 27956e45f6SSimon J. Gerraty.endif 28956e45f6SSimon J. Gerraty 29956e45f6SSimon J. Gerraty# To get the unexpanded text that was actually written to the debug log 30956e45f6SSimon J. Gerraty# file, the content of that log file must not be stored in a variable. 319f45a3c8SSimon J. Gerraty# 329f45a3c8SSimon J. Gerraty# XXX: In the :M modifier, a dollar is escaped using '$$', not '\$'. This 339f45a3c8SSimon J. Gerraty# escaping scheme unnecessarily differs from all other modifiers. 34956e45f6SSimon J. Gerraty.if !${:!cat opt-debug-file.debuglog!:tW:M*VAR = value $${:Uexpanded}*} 35956e45f6SSimon J. Gerraty. error 36956e45f6SSimon J. Gerraty.endif 37956e45f6SSimon J. Gerraty 389f45a3c8SSimon J. Gerraty.MAKEFLAGS: -d0 39956e45f6SSimon J. Gerraty 409f45a3c8SSimon J. Gerraty 419f45a3c8SSimon J. Gerraty# See Parse_Error. 429f45a3c8SSimon J. Gerraty.MAKEFLAGS: -dFstdout 43148ee845SSimon J. Gerraty# expect+1: This goes to stderr only, once. 449f45a3c8SSimon J. Gerraty. info This goes to stderr only, once. 459f45a3c8SSimon J. Gerraty.MAKEFLAGS: -dFstderr 46148ee845SSimon J. Gerraty# expect+1: This goes to stderr only, once. 479f45a3c8SSimon J. Gerraty. info This goes to stderr only, once. 489f45a3c8SSimon J. Gerraty.MAKEFLAGS: -dFopt-debug-file.debuglog 49148ee845SSimon J. Gerraty# expect+1: This goes to stderr, and in addition to the debug log. 509f45a3c8SSimon J. Gerraty. info This goes to stderr, and in addition to the debug log. 519f45a3c8SSimon J. Gerraty.MAKEFLAGS: -dFstderr -d0c 529f45a3c8SSimon J. Gerraty.if ${:!cat opt-debug-file.debuglog!:Maddition:[#]} != 1 539f45a3c8SSimon J. Gerraty. error 549f45a3c8SSimon J. Gerraty.endif 559f45a3c8SSimon J. Gerraty 569f45a3c8SSimon J. Gerraty 57*22619282SSimon J. Gerraty# See Main_ParseArgLine, which calls Error. 589f45a3c8SSimon J. Gerraty.MAKEFLAGS: -dFstdout 59*22619282SSimon J. Gerraty# expect: make: Unterminated quoted string [make 'This goes to stdout only, once.] 60*22619282SSimon J. Gerraty.MAKEFLAGS: 'This goes to stdout only, once. 619f45a3c8SSimon J. Gerraty.MAKEFLAGS: -dFstderr 62*22619282SSimon J. Gerraty# expect: make: Unterminated quoted string [make 'This goes to stderr only, once.] 63*22619282SSimon J. Gerraty.MAKEFLAGS: 'This goes to stderr only, once. 649f45a3c8SSimon J. Gerraty.MAKEFLAGS: -dFopt-debug-file.debuglog 65*22619282SSimon J. Gerraty# expect: make: Unterminated quoted string [make 'This goes to stderr, and in addition to the debug log.] 66*22619282SSimon J. Gerraty.MAKEFLAGS: 'This goes to stderr, and in addition to the debug log. 679f45a3c8SSimon J. Gerraty.MAKEFLAGS: -dFstderr -d0c 68*22619282SSimon J. Gerraty.if ${:!cat opt-debug-file.debuglog!:MUnterminated:[#]} != 1 699f45a3c8SSimon J. Gerraty. error 709f45a3c8SSimon J. Gerraty.endif 719f45a3c8SSimon J. Gerraty 729f45a3c8SSimon J. Gerraty 739f45a3c8SSimon J. Gerraty# If the debug log file cannot be opened, make prints an error message and 749f45a3c8SSimon J. Gerraty# exits immediately since the debug log file is usually selected from the 759f45a3c8SSimon J. Gerraty# command line. 769f45a3c8SSimon J. Gerraty_:= ${:!rm opt-debug-file.debuglog!} 779f45a3c8SSimon J. Gerraty.MAKEFLAGS: -dF/nonexistent-6f21c672-a22d-4ef7/opt-debug-file.debuglog 78