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