1# $NetBSD: depsrc-ignore.mk,v 1.4 2020/08/29 16:13:27 rillig Exp $
2#
3# Tests for the special source .IGNORE in dependency declarations,
4# which ignores any command failures for that target.
5#
6# Even though ignore-errors fails, the all target is still made.
7# Since the all target is not marked with .IGNORE, it stops at the
8# first failing command.
9#
10# XXX: The ordering of the messages in the output is confusing.
11# The "ignored" comes much too late to be related to the "false
12# ignore-errors".  This is due to stdout being buffered.
13#
14# The "continuing" message comes from the -k option.  If there had been
15# other targets independent of "all", these would be built as well.
16#
17# Enabling the debugging option -de changes the order in which the messages
18# appear.  Now the "ignored" message is issued in the correct position.
19# The explanation for the output reordering is that the output is buffered.
20# As the manual page says, in debugging mode stdout is line buffered.
21# In these tests the output is redirected to a file, therefore stdout is
22# fully buffered.
23#
24# This is what actually happens, as of 2020-08-29.  To verify it, set the
25# following breakpoints in CompatRunCommand:
26#
27# * the "!silent" line, to see all commands.
28# * the "fflush" line, to see stdout being flushed.
29# * the "status = WEXITSTATUS" line
30# * the "(continuing)" line
31# * the "(ignored)" line
32#
33# The breakpoints are visited in the following order:
34#
35# "ignore-errors begin"
36#	Goes directly to STDOUT_FILENO since it is run in a child process.
37# "false ignore-errors"
38#	Goes to the stdout buffer (CompatRunCommand, keyword "!silent") and
39#	the immediate call to fflush(stdout) copies it to STDOUT_FILENO.
40# "*** Error code 1 (ignored)"
41#	Goes to the stdout buffer but is not flushed (CompatRunCommand, near
42#	the end).
43# "ignore-errors end"
44#	Goes directly to STDOUT_FILENO.
45# "all begin"
46#	Goes directly to STDOUT_FILENO.
47# "false all"
48#	Goes to the stdout buffer, where the "*** Error code 1 (ignored)" is
49#	still waiting to be flushed.  These two lines are flushed now.
50# "*** Error code 1 (continuing)"
51#	Goes to the stdout buffer.
52# "Stop."
53#	Goes to the stdout buffer.
54# exit(1)
55#	Flushes the stdout buffer to STDOUT_FILENO.
56
57all: ignore-errors
58
59ignore-errors: .IGNORE
60	@echo $@ begin
61	false $@
62	@echo $@ end
63
64all:
65	@echo $@ begin
66	false $@
67	@echo $@ end
68