Home | History | Annotate | only in /src/usr.bin/make
History log of /src/usr.bin/make
RevisionDateAuthorComments
 1.3 28-Sep-2020  sjg Revert last
 1.2 28-Sep-2020  sjg more unit-tests
 1.1 27-Jul-2020  rillig make(1): ignore gcov files for CVS
 1.128 19-Jan-2025  rillig make: fix code coverage counts

See tests/usr.bin/gcov/t_gcov.sh.
 1.127 19-Dec-2023  rillig branches: 1.127.2;
make: clean up code coverage report files

Remove trailing whitespace.

Remove the first line, as it only repeats the filename.

Remove the line numbers, as they are mostly the same as in the original
source file.
 1.126 17-Dec-2023  rillig make: on cleandir, clean the unit-tests as well
 1.125 19-Jun-2023  rillig make: sort files in coverage report alphabetically
 1.124 03-Jun-2023  lukem bsd.own.mk: rename GCC_NO_* to CC_WNO_*

Rename compiler-warning-disable variables from
GCC_NO_warning
to
CC_WNO_warning
where warning is the full warning name as used by the compiler.

GCC_NO_IMPLICIT_FALLTHRU is CC_WNO_IMPLICIT_FALLTHROUGH

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.123 27-Sep-2022  rillig make: set WARNS to 6, from the default 5

No binary change on x86_64.
 1.122 03-May-2022  rillig make: remove test scenarios for old GCC versions

These had been useful for NetBSD 8, which used GCC 5.
 1.121 26-Jan-2022  rillig make: generate coverage summary on 'make test-coverage'
 1.120 09-Jan-2022  rillig make: in Cmd_Exec, return error message instead of format string

This change leaves only literal format strings in parse.c. It allows
for more detailed error messages than the current "non-zero status" or
"exited on a signal".

No functional change.
 1.119 12-Dec-2021  rillig make: do not report '?' for fully covered header files
 1.118 12-Dec-2021  rillig make: only define target report-coverage if USE_COVERAGE is yes

Without USE_COVERAGE, GCOV was undefined, the '2>&1' passed all error
messages to GCOV_PERL, when then discarded them. If the error messages
had been left on stderr, the error message 'sh: arch.o.gcda: not found'
would have been a clear indicator of the actual cause of an empty
coverage report.
 1.117 28-Nov-2021  rillig make: replace bloated bit-set-to-string code with simple code

It was a nice idea to implement a bit-set using an enum type and have a
generic ToString function for them. In the end, the implementation
involved really heavy preprocessor magic and was probably difficult to
understand. Replace all the code with a few bits of straight-forward
preprocessor magic that can be readily understood by just looking 5
lines around, instead of digging through 130 lines of lengthy macro
definitions.

Curiously, this reduces the binary size even though the 3 ToString
functions now have a few lines of duplicate code and there are more
explicit function calls.

The ToString functions are only seldom used, so the additional memory
allocation is acceptable.

No functional change.
 1.116 31-Jul-2021  rillig make: fix lint warnings

The string functions from str.h are declared as 'static __unused' when
compiled with GCC, but lint explicitly undefines __GCC__ during
preprocessing. Therefore, make those functions inline, to prevent
warnings that they are unused.

The macro UNCONST is used in a few places, and (again) since lint
undefines __GCC__, that macro expanded to a simple type cast, which lint
warned about. To prevent this warning, implement UNCONST as a function
that works everywhere and hides the type cast.

In filemon_open, the code for closing F->in was obviously unreachable.

No functional change.
 1.115 30-May-2021  rillig make: fix reported code coverage for *.h

In 'make test-coverage', the number of uncovered lines for inline
functions in headers was reported too high. The cause for this is that
gcov reports the coverage for these functions multiple times, once per
translation unit. If some of the translation units don't use these
inline functions, summing the lines containing '#####' quickly leads to
numbers that are obviously too high.
 1.114 11-Apr-2021  rillig branches: 1.114.2;
make: clean up Makefile

The dependencies on the header files are handled by 'make depend'. They
do not need to be spelled out.
 1.113 22-Feb-2021  rillig make: fix report-coverage

On NetBSD 8.0 it still worked. Maybe gcov doesn't support .c files as
arguments anymore. Using the .gcda files works and is more reliable
anyway since it covers the inline functions in the headers as well.
 1.112 30-Jan-2021  rillig make(1): run lint with strict bool mode

The make code is not supposed to use constructs such as "if (strcmp(s1,
s2))" or "if (p && *p)", instead all boolean expressions have a form
that would be accepted by a C#, Go or Java compiler as well. This also
ensures that pre-C99 compilers generate equivalent code as C99
compilers, at least regarding boolean expressions.
 1.111 12-Dec-2020  rillig make(1): add number of uncovered lines to coverage report
 1.110 12-Dec-2020  rillig make(1): add target test-coverage
 1.109 06-Dec-2020  rillig make(1): move .include lines as far down as possible
 1.108 06-Dec-2020  rillig make(1): move COPTS above <bsd.prog.mk>
 1.107 03-Dec-2020  rillig make(1): format coverage summary as a table

This is only used interactively, not in the official builds, therefore
the additional dependency on Perl doesn't matter. The same result could
have been achieved in any other programming language, but probably not
as concisely.
 1.106 25-Oct-2020  rillig make(1): remove unused strlist_t
 1.105 23-Oct-2020  rillig make(1): add target-specific COPTS when generating cpre or casm
 1.104 18-Oct-2020  rillig make(1): fix GCC warning about small buffer for cohort_num

Since unmade_cohorts is a signed number (the code contains an underflow
check), the result of the '%' operator could be negative and result in
"#-999999", which would overflow the buffer, truncating the last digit.
 1.103 05-Oct-2020  rillig make(1): enable format string truncation warnings for parse.c

No node is ever going to have a million or more cohorts. And even if
there were, this name is only used for printing informational messages.
 1.102 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.101 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.100 05-Oct-2020  rillig make(1): allow easy creation of preprocessed source and assembler

To be used during development, to see how changes in the source code
affect the generated machine code.
 1.99 01-Sep-2020  rillig make(1): remove filemon object files on clean
 1.98 31-Aug-2020  rillig make(1): fix compilation with GCC 8
 1.97 31-Aug-2020  rillig make(1): fix copy-and-paste mistake for compiling with GCC10
 1.96 28-Aug-2020  rillig make(1): remove redundant MAKEFLAGS from subdir make

The make flags are passed via the environment, not via the command line.
This is not as obvious and visible, but it works.
 1.95 27-Aug-2020  rillig make(1): pass the command-line variables to the subdir make
 1.94 26-Aug-2020  rillig make(1): remove header sprite.h

Make is independent of the Sprite operating system.
 1.93 25-Aug-2020  rillig make(1): allow custom build options
 1.92 23-Aug-2020  rillig make(1): allow to run only selected tests via the command line
 1.91 22-Aug-2020  sjg Use TEST_MAKE to run unit-tests

This lets us take advantage of new features like ${.SHELL}
 1.90 19-Aug-2020  rillig make(1): don't optimize when measuring the code coverage

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96622
 1.89 15-Aug-2020  rillig make(1): fix archive test

Even though it is commented out in this Makefile, it is still run by
atf, on purpose. This test is broken on FreeBSD, but on NetBSD it
should still be run.

Without removing the archive first, it could be left over from a
previous test failure and thus be newer than all its members, leading to
${.OODATE} being empty.
 1.88 12-Aug-2020  rillig make(1): enable -Wcast-qual for var.c again

When it became disabled 9 years ago, there were 15 instances of UNCONST
in the code. These have been removed in the latest cleanup sessions.

Tested with GCC 5 from NetBSD 8 and GCC 10 from pkgsrc.
 1.87 12-Aug-2020  rillig make(1): allow optional compilation with GCC 10, use gcov from GCC
 1.86 10-Aug-2020  rillig make(1): make gcov command line configurable

Some useful options are -a or -f.
 1.85 10-Aug-2020  rillig make(1): clean up coverage files even if USE_COVERAGE is not set
 1.84 09-Aug-2020  rillig make(1): allow to build using GCC 9 during development
 1.83 08-Aug-2020  rillig make(1): add more detailed debug logging for variable modifiers

Before a modifier is applied to a variable, it is not yet parsed,
therefore it is only possible to log a rough estimate of the modifier.
But after applying it, the parsing position has advanced, and the full
modifier can be logged.

In addition, to fully understand how the modifiers work, it's not enough
to just know the variable names and values, there are also some flags
that influence how the modifiers behave. The most influential is
VARE_WANTRES.

Thanks to sjg for the extensive review and valuable feedback on the
first drafts.
 1.82 07-Aug-2020  rillig make(1): one file per line in the Makefile

Suggested by sjg.
 1.81 06-Aug-2020  rillig make(1): revert previous commit; "make retest" was already possible

What I really meant to allow was to run "make sync-mi" directly from the
main directory. But adding that to TARGETS didn't do anything.
 1.80 06-Aug-2020  rillig make(1): allow "make retest" directly from the main directory
 1.79 03-Aug-2020  rillig make(1): no declaration-after-statement anymore

NetBSD make is intended to be maximally portable, therefore it uses only
C89. This was not declared in the Makefile before.

There are still a few places in parse.c and metachar.c that use
end-of-line comments. These will be fixed in a follow-up commit.
 1.78 01-Aug-2020  rillig make(1): remove line numbers from generated code coverage files

The line numbers make it difficult to spot changes in the code and
coverage if a line is added or removed from the code.
 1.77 31-Jul-2020  rillig make(1): fix undefined behavior in malformed :S modifier

The unit tests failed on Ubuntu, and by looking closely at the code, it
was trivial to see the out-of-bounds memory read.

Other modifiers may have the same problem and will be inspected later.
 1.76 29-Jul-2020  rillig make(1): use specialized return type for ApplyModifier functions

This makes it immediately obvious what happens after a modifier has been
applied, instead of having to translate single-character mnemonics or
booleans to their actual intention.

This also reduces the size of the binary since there are fewer jumps.
 1.75 26-Jul-2020  rillig make(1): explicitly add dependencies on headers

This prevents partial builds after changing a header. The declared
dependencies are more than strictly necessary, but that's still better
than having inconsistent partial builds because too few dependencies are
declared.
 1.74 26-Jul-2020  rillig make(1): condense the list library into a single file

The list library is only used in make(1). Having it spread out over 28
files made it look more complex than it really is. In fact, it's just a
versatile generic data type like in hash.c.

Having all the list functions in a single file reduces the code size,
both by omitting the many RCS Ids and by inlining commonly used code.
 1.73 25-Jul-2020  rillig make(1): make it easy to run gcov on the code

There seems to be no gcov support in share/mk yes, but it's still good
to have, especially for a complex program like make(1).
 1.72 25-Jul-2020  rillig make(1): indent Makefile directives like in pkgsrc

This makes it easier to see the corresponding .if/.endif, even without
comments.
 1.71 25-Jul-2020  rillig make(1): format Makefile consistently
 1.70 25-Jul-2020  rillig make(1): regroup source files
 1.69 06-Feb-2020  sjg Fix meta_compat mode.

We need to call meta_job_output() from meta_compat_parent()
Also, the need for extra fds for meta mode only applies when
using filemon_ktrace.c.
Since we hope to see more interfaces like that, test for
USE_FILEMON_DEV being not defined.

Reviewed by: riastradh
 1.68 19-Jan-2020  riastradh Tweak makefile for USE_FILEMON=dev, from sjg.
 1.67 19-Jan-2020  riastradh Per sjg's suggestion, split filemon API into separate back ends.

By default we use the ktrace back end, but the /dev/filemon back end
is available as a compile-time option, by setting USE_FILEMON=dev in
make. sjg raised concerns about ktrace performance and would like to
continue using /dev/filemon on FreeBSD (which has seen more
maintenance kernel-side) without forking make.
 1.66 19-Jan-2020  riastradh Reimplement make(1) meta mode without filemon(4).
 1.65 19-Dec-2019  maxv Revert the filemon removal in bmake, as pointed out by maya we do care
about not introducing divergence with FreeBSD, and the cost of unused
is acceptable here.
 1.64 18-Dec-2019  maxv Retire filemon, discussed on tech-kern@.
 1.63 13-Oct-2019  mrg introduce some common variables for use in GCC warning disables:

GCC_NO_FORMAT_TRUNCATION -Wno-format-truncation (GCC 7/8)
GCC_NO_STRINGOP_TRUNCATION -Wno-stringop-truncation (GCC 8)
GCC_NO_STRINGOP_OVERFLOW -Wno-stringop-overflow (GCC 8)
GCC_NO_CAST_FUNCTION_TYPE -Wno-cast-function-type (GCC 8)

use these to turn off warnings for most GCC-8 complaints. many
of these are false positives, most of the real bugs are already
commited, or are yet to come.


we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."
 1.62 29-Sep-2019  mrg convert HAVE_GCC == 7 to HAVE_GCC >= 7.
 1.61 04-Feb-2019  mrg - use -Wno-error=format-truncation
 1.60 10-Jun-2018  christos branches: 1.60.2;
use SUBDIR.roff suggested by uwe@
 1.59 18-Feb-2016  sjg branches: 1.59.14;
Adapt to changed Var_Subst()
 1.58 17-Jun-2015  christos Centralize the "is a meta char" test, instead of using two different arrays.
 1.57 05-Jul-2014  dholland Rework /usr/share/doc.

Update the <bsd.doc.mk> infrastructure, and update the docs to match
the new infrastructure.

- Build and install text, ps, pdf, and/or html, not roff sources.

- Don't wire the chapter numbers into the build system, or use them in
the installed pathnames. This didn't matter much when the docs were a
museum, but now that we're theoretically going to start maintaining
them again, we're going to add and remove documents periodically and
having the chapter numbers baked in creates a lot of thrashing for no
purpose.

- Specify the document name explicitly, rather than implicitly in a
path. Use this name (instead of other random strings) as the name
of the installed files.

- Specify the document section, which is the subdirectory of
/usr/share/doc to install into.

- Allow multiple subdocuments. (That is, multiple documents in one
output directory.)

- Enumerate the .png files groff emits along with html so they can be
installed.

- Remove assorted hand-rolled rules for running roff and roff widgetry
and add enough variable settings to make these unnecessary. This
includes support for
- explicit use of soelim
- refer
- tbl
- pic
- eqn

- Forcibly apply at least minimal amounts of sanity to certain
autogenerated roff files.

- Don't exclude USD.doc, SMM.doc, and PSD.doc directories from the
build, as they now actually do stuff.

Note: currently we can't generate pdf. This turns out to be a
nontrivial problem with no immediate solution forthcoming. So for now,
as a workaround, install compressed .ps as the printable form.
 1.56 30-May-2012  sjg branches: 1.56.2; 1.56.8;
Don't pass debug flags etc. to unit-tests
 1.55 14-Aug-2011  christos branches: 1.55.2;
- remove gcc-4.5 warnings
- simplify job printing code
- document non-literal format strings
 1.54 22-Jun-2011  mrg apply some -Wno-error and/or -fno-strict-aliasing.


all of this should be looked at closer, but some of them are not
very trivial.
 1.53 18-May-2011  dsl Back out a local change
 1.52 17-May-2011  dsl If a makefile if a multiple of the page size and doesn't end with a
newline, then it all goes horribly wrong when make tries to terminate
the last input line.
This was all ok before the mmap changes (rev 1.169) because the last
32 bytes of the input buffer were never read into.
The non-mmap case has a similar problem.
Bug found because my .depend files don't have a newline at the end of
the .OPTIO|NAL line (don't know if that is a local change).
 1.51 13-Sep-2010  sjg Add meta.c which implements "meta" mode for make.
In this mode, a .meta file is created for each target, capturing
the expanded commands used, any command output, and if filemon(9)
is available, a record of system calls which are of interest.
Not enabled unless USE_META=yes is set when building make.
Also, if FILEMON_H exists, meta.c will be compiled to use filemon(9).
 1.50 22-Apr-2010  sjg PR: 42850
Reviewed by:

modmisc: since we apply an exists() test to $paths, be conservative
in what we expect.

Run the unit tests with -r -m / so that we do not fail if there
is no sys.mk present.
 1.49 14-Apr-2009  lukem Enable WARNS=4 by default for usr.bin, except for:
awk bdes checknr compile_et error gss hxtool kgetcred kinit
klist ldd less lex locale login m4 man menuc mk_cmds
mklocale msgc openssl rpcgen rpcinfo sdiff spell ssh
string2key telnet tn3270 verify_krb5_conf xlint
 1.48 24-Mar-2009  perry remove unneeded special rule for main.o
 1.47 20-Mar-2009  perry The Makefile and main.c arranged to put "netbsd-${DATE}" into the
executable. Remove this so that different compiles can be binary
compared. rcsid's for all files are already embedded in the executable
so versions can be easily distinguished. (I didn't catch this on
previous passes because I did my builds on the same day.)

Note: there's a special rule for main.o in Makefile with a purpose I
can't actually discern -- I think it isn't needed, and I've flagged it
with a comment.
 1.46 24-Jan-2009  dsl branches: 1.46.2;
Move the bmake_malloc() functions into their own .c and .h files.
Include instead of make.h in a few places.
 1.45 20-Dec-2008  dsl Add functions for processing extendable arrays of pointers to strings.
Use for the .for variables and substution items - changing the latter from
make's all conquering lst.lib functions.
Being able to index everything makes the code simpler.
No functional changes intended.
 1.44 06-Oct-2008  joerg Don't use emalloc and friends directly, but call them consistently
bmake_malloc and friends. Implement them via macros for the native case
and provide fallback implementations otherwise. Avoid polluting the
namespace by not defining enomem globally. Don't bother to provide
strdup and strndup, they were only used for the estrdup and estrndup
comapt code.

This addresses the presence of emalloc in system libraries on A/UX and
resulted strange issues as reported by Timothy E. Larson.
 1.43 14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.42 25-Sep-2007  uwe Revert 1.34 (CFLAGS+=-g) that have been commited by mistake (hi, xtos).
 1.41 01-Nov-2006  sjg branches: 1.41.2; 1.41.4; 1.41.8;
Use of libutil to provide emalloc et al, should be predicated on
a native NetBSD build using TOOLDIR etc.
Otherwise use the local versions.

Reviewed by: christos
 1.40 25-Oct-2006  dsl Fix previous - need to add a lstPrev()
 1.39 08-Oct-2006  peter WFORMAT is no more...
 1.38 29-Aug-2006  christos protect libutil with HOSTPROG
 1.37 26-Aug-2006  christos More programs using efun.
 1.36 15-Jun-2006  skrll Remove a hack that's no longer needed with gcc 3.3.6.
 1.35 08-May-2006  he branches: 1.35.2;
Our gcc 3.3.3 (nb3) for hppa gets an "unrecognized insn" internal
compiler error when building buf.c with -O2, so reduce optimization
level to -O1 for this single file.
To be documented in docs/HACKS, discussed with skrll.
 1.34 22-Apr-2006  christos Coverity CID 529: Call VarFreeEnv to prevent leak.
 1.33 07-May-2004  ross Simplify build, no functional changes.

Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().

It's now possible to build make on some hosts with: cc *.c */*.c
 1.32 06-May-2004  ross Instead of including from the wrong directory and then fixing it (-I)
in the Makefile, how about just doing the right include?
 1.31 15-Feb-2004  sjg branches: 1.31.2;
Use ${.MAKE:S,^./,${.CURDIR}/,} so that when someone does
./make test
it works. Note use .CURDIR rather than .OBJDIR since the later
_may_ not always be correct (eg. symlink in .CURDIR for make).
 1.30 01-Aug-2003  sjg Fix for TEST_MAKE from Alan Barrett
 1.29 28-Jul-2003  sjg Fix parsing bug for :ts - patch from Alan Barrett <apb@cequrux.com>
Also add simple unit-test jig (regress/usr.bin/make will use it too)
but having it local here makes inclusion in bmake simpler.
 1.28 26-Jul-2003  mrg build var.c with -Wno-cast-qual - gcc3.3 complains about VarWordCompare()
 1.27 14-Jul-2003  christos Pass WARNS=3
 1.26 27-Jan-2002  reinoud Fix major bug in make(1) ... due to shadowing of the dotLast path used for
the .DOTLAST primitive by a boolean variable with the same name, this whole
mechanism was broken ... it doesn't save much stat calls but it was wrong.

Thanks to Jason Thorpe for the other shadow-variable fixing patches he
made.
 1.25 31-Oct-2001  tv Overhaul the initialization and handling of .OBJDIR:

* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)

* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.

* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
 1.24 09-Jun-2001  sjg Provide a useful? MAKE_VERSION.
 1.23 30-Dec-2000  sommerfeld Back out debug cruft.
 1.22 30-Dec-2000  sommerfeld Add a token-passing scheme to allow a recursive make to successfully
use -j; all make's in a recursive build cooperate to limit the total
number of jobs, using a token-passing scheme.

The current token passing algorithm is similar to the one implemented
by gmake; there is a single pipe which is inherited through the entire
process hierarchy; tokens are obtained by reading a byte from the
"read end" of the pipe, and are returned by writing them to the "write
end". This exact algorithm is likely to change in the future.

Implementation details:
- Use the new trace facility to allow measurement of the
effectiveness of different token-passing schemes
- Get a token in MakeStartJobs(), return it in Make_Update()
- Eliminate Job_Full() and the jobFull global since they are
redundant with token system.
- Add an "internal" -J option (to pass the token pipe fd's down to
submakes) and a -T option for tracing.
- Change how compatMake is forced so that -j means something when
inherited by submakes.
- When waiting for a token, poll the token-passing pipe as well as
the output pipes of existing jobs.
 1.21 11-Oct-2000  is More format string cleanup by sommerfeld.
 1.20 04-Aug-1999  ross branches: 1.20.8;
Back out part of previous, only the parse.c mod was intended.
 1.19 04-Aug-1999  ross Trivial speed hack.
 1.18 24-Oct-1997  lukem branches: 1.18.2;
use CPPFLAGS instead of CFLAGS
 1.17 19-Oct-1997  lukem branches: 1.17.2;
don't define WARNS=1 here
 1.16 11-Oct-1997  mycroft Use bsd.subdir.mk as appropriate.
 1.15 01-Jul-1997  christos Add WARNS=1
RCSID police
 1.14 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.13 06-May-1997  gwr Use .PATH.c: ...
 1.12 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.11 28-May-1996  christos - Move -D flags from Makefile to config.h and explain what they do. Add
-Wall -Wno-unused to CFLAGS. Add new define SYSVVARSUB to enable SysV
style variable substitutions and enable them.
- Add SunOS style command substitutions via SUNSHCMD
- Fix core dump with '{variable = value'
 1.10 11-Mar-1996  christos branches: 1.10.4;
Jonathan Stone's fixes:
main.c: Remove double include of <sys/resource.h>; if MACHINE is defined, use
that instead of uname.
Makefile: Add util.c.
 1.9 04-Feb-1996  christos fix pr/1421 and pr/1997
 1.8 14-Jun-1995  christos - $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.7 03-May-1995  jtc None of the functions in util.c are needed by NetBSD, so don't
bother to compile it.
 1.6 30-Jun-1994  cgd deal with new share/doc strategy
 1.5 25-Jun-1994  cgd update for new doc-make/install strategy
 1.4 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.3 14-Dec-1993  jtc Compile with -DPOSIX --- enables reasonable behavior for MAKE and
MAKEFLAGS variables.
 1.2 31-Jul-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.10.4.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.17.2.1 08-Nov-1997  lukem sync with trunk (approved by thorpej)
 1.18.2.1 19-Oct-2000  he Pull up revision 1.21 (requested by he):
Format string cleanup.
 1.20.8.1 18-Oct-2000  tv Pullup usr.bin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.31.2.2 10-May-2004  tron Pull up revision 1.33 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.31.2.1 10-May-2004  tron Pull up revision 1.32 (requested by sjg in ticket #282):
Instead of including from the wrong directory and then fixing it (-I)
in the Makefile, how about just doing the right include?
 1.35.2.1 19-Jun-2006  chap Sync with head.
 1.41.8.2 23-Mar-2008  matt sync with HEAD
 1.41.8.1 06-Nov-2007  matt sync with HEAD
 1.41.4.1 30-Sep-2007  wrstuden Catch up on netbsd-4 as of a few days ago.
 1.41.2.1 27-Sep-2007  xtraeme Pull up following revision(s) (requested by uwe in ticket #903):
usr.bin/make/Makefile: revision 1.42

Revert 1.34 (CFLAGS+=-g) that have been commited by mistake (hi, xtos).
 1.46.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.55.2.1 30-Oct-2012  yamt sync with head
 1.56.8.1 10-Aug-2014  tls Rebase.
 1.56.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.59.14.1 25-Jun-2018  pgoyette Sync with HEAD
 1.60.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.60.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.60.2.1 10-Jun-2019  christos Sync with HEAD
 1.114.2.1 31-May-2021  cjep sync with head
 1.127.2.1 02-Aug-2025  perseant Sync with HEAD
 1.25 15-Apr-2022  rillig make: document the available preprocessor definitions for Makefile.boot
 1.24 12-Dec-2021  rillig make: remove enum.o from Makefile.boot

On 2021-11-18, enum.h and enum.c have been removed.
 1.23 25-Oct-2020  rillig make(1): remove unused strlist_t
 1.22 09-Aug-2020  rillig make(1): clean up Makefile.boot

The previous version stopped working in 2015, when metachar.c was added.
Since then, lst.c and enum.c have been added, and the lst.lib directory
has gone.

To build bmake on Cygwin, some extra CFLAGS are necessary for some of
the files. Compilation succeeded by first building the majority of
files with "bmake -f Makefile.boot EXTRA_CFLAGS=-DMAKE_NATIVE", and the
remaining files with "-UMAKE_NATIVE".

Reorganize the file structure to put the most likely configuration into
the top paragraph, with all variable values nicely aligned.
 1.21 24-Feb-2014  skrll Rename NetBSD/hp700 to NetBSD/hppa.

Unfortunately our VCS isn't very helpful here.
 1.20 26-Mar-2011  dholland branches: 1.20.4; 1.20.10;
Catch up to Makefile rev 1.40 (from 2006): add lstPrev.o. Closes PR 43466.
 1.19 24-Jan-2009  dsl Move the bmake_malloc() functions into their own .c and .h files.
Include instead of make.h in a few places.
 1.18 20-Dec-2008  dsl Add functions for processing extendable arrays of pointers to strings.
Use for the .for variables and substution items - changing the latter from
make's all conquering lst.lib functions.
Being able to index everything makes the code simpler.
No functional changes intended.
 1.17 07-May-2004  ross Simplify build, no functional changes.

Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().

It's now possible to build make on some hosts with: cc *.c */*.c
 1.16 06-May-2004  ross Instead of including from the wrong directory and then fixing it (-I)
in the Makefile, how about just doing the right include?
 1.15 11-Jun-2002  itojun branches: 1.15.2;
err/errx/warn/warnx do not need \n at the end
 1.14 30-Nov-2001  thorpej Clean up some MAKE_BOOTSTRAP issues wrt. MACHINE/MACHINE_ARCH.
 1.13 18-Jan-2001  thorpej Add trace.o
 1.12 03-Aug-2000  christos PR/10714: SUNAGAWA Keiki: Add newer hpux support, but without removing the
old hpux support.
 1.11 03-Apr-1999  gwr Uh... should have been ${MACHINE} not hard coded... Duh!
 1.10 03-Apr-1999  gwr Define CC=gcc -O and add -DMACHINE=...
 1.9 21-May-1998  tv Make a MAKE_BOOTSTRAP case work on NetBSD, too, for cross-compile cases
 1.8 31-Dec-1996  christos Use explicit .c.o rule so that the bootstrap process works.
 1.7 30-Aug-1996  thorpej Tidy up some RCS ids a bit.
 1.6 13-Aug-1996  christos Various cleanups from: Larry Schwimmer <rosebud@cyclone.Stanford.EDU>
 1.5 14-Jun-1995  christos branches: 1.5.6;
- $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.4 09-May-1994  glass bootstrap improvements
 1.3 17-Apr-1994  glass bootstrap changes
 1.2 09-Apr-1994  briggs Need for.o in list of objects when bootstrapping.
 1.1 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.5.6.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.15.2.2 10-May-2004  tron Pull up revision 1.17 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.15.2.1 10-May-2004  tron Pull up revision 1.16 (requested by sjg in ticket #282):
Instead of including from the wrong directory and then fixing it (-I)
in the Makefile, how about just doing the right include?
 1.20.10.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.20.4.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.5 05-Mar-1994  mycroft Clean up deleted files.
 1.4 04-Dec-1993  cgd add MACHINE_ARCH
 1.3 02-Aug-1993  mycroft Add RCS identifiers, remove some completely useless RCS logs and patchkit
headers, and a few other insignificant changes.
 1.2 27-May-1993  glass some compatibility fixes to ease bootstrapping:
Makefile.dist is now a decent Makefile and not one of these cc *.c disasters
RANLIBMAG now defaults if not otherwise defined
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.223 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.222 06-Aug-2024  rillig make: add details to error messages about missing ')'
 1.221 07-Jul-2024  rillig make: only generate code for cleanup functions in CLEANUP mode
 1.220 05-Jul-2024  rillig make: reduce lint-specific comments about ARGSUSED
 1.219 02-Jun-2024  rillig branches: 1.219.2;
make: sync VarEvalMode constant names with their debug log names
 1.218 31-May-2024  rillig make: clean up API for iterating over hash tables
 1.217 27-Apr-2024  rillig make: clean up, test .NOPATH

Trim down the comments in the archive module, as they mainly repeated
the code. Trim down the binary code size in the archive module, as it
is rarely used.

In Var_Parse, delay two variable assignments until they are actually
needed.
 1.216 27-Apr-2024  rillig make: simplify freeing of lists
 1.215 07-Feb-2024  rillig make: remove unneeded conditional-compilation toggles

The toggles INCLUDES, LIBRARIES, POSIX, SYSVINCLUDE, SYSVVARSUB,
GMAKEEXPORT and SUNSHCMD are no longer needed, they were unconditionally
set.

The toggle NO_REGEX was configurable from the command line, but
disabling it would result in various error messages about the unknown
':C' modifier.

OK sjg@.
 1.214 19-Nov-2023  rillig make: replace 'variable expression' with 'expression' in comments

No binary change.
 1.213 14-Feb-2023  rillig make: reduce complexity of evaluating expressions

No functional change.
 1.212 07-Dec-2022  rillig make: clean up comments
 1.211 27-Sep-2022  rillig make: set WARNS to 6, from the default 5

No binary change on x86_64.
 1.210 15-Jan-2022  rillig make: merge duplicate code for expanding variable expressions

No functional change.
 1.209 15-Dec-2021  rillig make: format comments according to /usr/share/misc/style

Assisted by indent(1), with manual corrections due to its many remaining
bugs.

No functional change.
 1.208 15-Dec-2021  rillig make: use consistent indentation for statements and continuations

No binary change, except for line numbers in assertions in suff.c.
 1.207 12-Dec-2021  rillig make: in Arch_ParseArchive, rename libName to lib

For symmetry with mem.

No binary change.
 1.206 12-Dec-2021  rillig make: in Arch_ParseArchive, replace MFStr with FStr

This was the only use of the type MFStr, which produced the same code as
FStr.

No binary change.
 1.205 12-Dec-2021  rillig make: use simpler memory management for parsing archive members

No functional change.
 1.204 28-Nov-2021  rillig make: convert GNodeFlags from enum into bit-fields

Now that Enum_ToString is implemented for each type separately, it's
easy to convert them to bit-fields. This gets rid of the magic numbers
12 for CYCLE and 13 for DONECYCLE that left a suspicious gap in the
numbers. This gap was not needed since the code didn't make use of the
relative ordering of the enum constants.

The effects of this conversion are fewer capital letters in the code,
smaller scope for the GNode flags, and clearer code especially when
setting a flag back to false.

One strange thing is that GCC 10.3.0 doesn't optimize GNodeFlags_IsNone
to an single bitmasking instruction, at least on x86_64. Instead it
generates a testb instruction for each of the flags, even loading bit 8
separately from the others. Clang 12.0.1 knows this optimization
though and generates the obvious sequence of movzwl, testl, jz.

No functional change.
 1.203 25-Aug-2021  rillig make: fix lint warnings on ilp32 platforms

The warnings in arch.c were about conversions from int to long.

The warnings in var.c were about conversions from long long to
ptrdiff_t.

No functional change.
 1.202 14-Aug-2021  rillig make: add ARGSUSED for lint
 1.201 14-Aug-2021  rillig make: extract RanlibOODate into separate function

No functional change.
 1.200 30-May-2021  rillig make: inline str_concat4

This function is only ever used for forming strings of the form
"archive(member)".

No functional change.
 1.199 03-Apr-2021  rillig branches: 1.199.2;
make: use C99 bool type instead of defining its own

No functional change.
 1.198 15-Mar-2021  rillig make: replace enum bit-field with struct bit-field for VarEvalFlags

This makes the code easier to read, especially in var.c. It also makes
debugging sessions easier since some debuggers don't show enum
bit-fields symbolically as soon as more than one bit is set.

The code outside var.c is basically unchanged, except that instead of
passing the individual flags, there are 4 predefined evaluation modes.
These suffice for all practical use cases. Only in the implementation
deep inside var.c, the value of the flags keepDollar and keepUndef
differs.

There is no way of passing the struct to EnumFlags_ToString, which means
the ToString function has to be spelled out explicitly. This allows for
fine-tuning the representation in the debug log, to reduce the amount of
uppercae letters.

No functional change.
 1.197 05-Feb-2021  rillig make: in the Var_ functions, move the scope to the front

This change provides for a more natural reading order in the code.
Placing the scope first makes it immediately clear in which context the
remaining parameters are interpreted.

No functional change.
 1.196 04-Feb-2021  rillig make: rename context and ctxt to scope

This continues the previous commit, in which VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE were renamed.

Renaming the variable 'ctxt' was trivial since that word is used nowhere
else. In the comments though, each occurrence of the word 'context' had
to be checked individually since the word 'context' was not only used
for referring to a variable scope. It is also used to distinguish
different situations where characters are escaped in a certain way
('parsing context') and in a few other expressions.
 1.195 04-Feb-2021  rillig make: merge duplicate code in Arch_FindLib

No functional change. Furthermore, this only affects builds that
explicitly disable LIBRARIES in config.h.
 1.194 23-Jan-2021  rillig make(1): rename Dir_Expand to SearchPath_Expand

The main subject of this function is the search path. In this search
path the pattern is expanded.
 1.193 09-Jan-2021  rillig make(1): fix lint warnings
 1.192 30-Dec-2020  rillig make(1): format multi-line comments
 1.191 20-Dec-2020  rillig make(1): eliminate libName_freeIt from Arch_ParseArchive
 1.190 20-Dec-2020  rillig make(1): return FStr from Var_Parse

This reduces the number of variable declarations at the call sites.
 1.189 18-Dec-2020  rillig make(1): spell nonexistent consistently
 1.188 13-Dec-2020  rillig make(1): add str_basename to reduce duplicate code

The function basename from POSIX has a few unfortunate properties, it is
allowed to return a pointer to static memory. This is too unreliable,
therefore this trivial own implementation.
 1.187 06-Dec-2020  rillig make(1): remove comment decoration
 1.186 05-Dec-2020  rillig make(1): remove redundant assignments
 1.185 05-Dec-2020  rillig make(1): remove unused variable from ArchFindMember
 1.184 04-Dec-2020  rillig make(1): improve variable names in Arch_ParseArchive

The variable buf used to be a Buffer, now it is a simple string pointer.
 1.183 04-Dec-2020  rillig make(1): use consistent variable names for list nodes
 1.182 29-Nov-2020  rillig make(1): reduce memory allocation for dirSearchPath
 1.181 28-Nov-2020  rillig make(1): reduce memory allocation in Arch_ParseArchive
 1.180 28-Nov-2020  rillig make(1): reduce pointer indirection for archives
 1.179 28-Nov-2020  rillig make(1): reduce memory allocation for GNode.parents and GNode.children
 1.178 23-Nov-2020  rillig make(1): indent arch.c with tabs instead of spaces
 1.177 14-Nov-2020  rillig make(1): replace a few HashTable_CreateEntry with HashTable_Set

Instead of HashTable_CreateEntry and HashEntry_Set, several places just
need the HashEntry for storing a value in it. This makes the calling
code simpler to understand.

These parts of the code are already hard enough to understand since they
are about memory management and aliasing. Having a too detailed API for
the HashTable only distracts from these topics.
 1.176 14-Nov-2020  rillig make(1): fix typo in comments

This typo may have been influenced by all the '$' in the code.
 1.175 08-Nov-2020  rillig make(1): clean up code related to VarEvalFlags

Mention VARE_WANTRES before VARE_UNDEFERR since the latter depends on
the former.

In ApplyModifier_Assign, VARE_KEEP_DOLLAR doesn't have to be removed
from eflags since ParseModifierPart does this already.

In EvalUndefined, testing for VARE_WANTRES is redundant if VARE_UNDEFERR
is already set.
 1.174 08-Nov-2020  rillig make(1): change return type of Arch_MTime to void

This makes it easier to prove that Dir_MTime always returns gn->mtime,
without looking at the implementation of Arch_UpdateMTime.
 1.173 08-Nov-2020  rillig make(1): change return type of Arch_MemberMTime to void

This makes it easier to prove that Dir_MTime always returns gn->mtime,
without looking at the implementation of Arch_UpdateMemberMTime.
 1.172 08-Nov-2020  rillig make(1): rename Make_OODate to GNode_IsOODate

It doesn't matter which of the make modules is in charge of determining
whether a node is out-of-date. Therefore, remove the module name from
the function name.
 1.171 07-Nov-2020  rillig make(1): clean up Arch_LibOODate
 1.170 07-Nov-2020  rillig make(1): document duplicate code in arch.c
 1.169 07-Nov-2020  rillig make(1): fix function names in archive debug output
 1.168 07-Nov-2020  rillig make(1): fix out-of-bounds pointer in ArchStatMember (since 1993-03-21)
 1.167 07-Nov-2020  rillig make(1): reduce indentation in ArchStatMember
 1.166 07-Nov-2020  rillig make(1): replace hashed with cached in comments

The hash table is just an implementation detail, not worth to be
mentioned in comments.
 1.165 07-Nov-2020  rillig make(1): fix access to undefined memory (since 1994-03-18)

This bug was added in arch.c 1.6, "Do extended-name archives".
 1.164 07-Nov-2020  rillig make(1): clean up ArchStatMember

Whether an archive entry is hashed or not is completely irrelevant. The
interesting thing is whether it ends up in a cache.
 1.163 07-Nov-2020  rillig make(1): properly handle errors for malformed archive target names

Error messages don't belong on stdout.
 1.162 07-Nov-2020  rillig make(1): rename local variable in Arch_ParseArchive
 1.161 07-Nov-2020  rillig make(1): rename parameter of ArchSVR4Entry

It cannot be made a const string, so rather document it clearly that the
string is modified.
 1.160 07-Nov-2020  rillig make(1): remove unused macro definitions from arch.c

These definitions have originally been added in arch.c 1.27 on
1998-05-21. Even back then they had been unused, at least they had not
been used directly. Since macros are expanded at their use site, there
could have been an indirect use, but that is not the case anymore.
 1.159 07-Nov-2020  rillig make(1): fix archive handling

It's no wonder that nobody is using the archive handling of make. The
archives created by GNU binutils cannot be processed using make since the
format of the archive names has changed. GNU binutils appends a slash to
the member names. Support that format from now on.

Add more debugging output in ArchFindMember. Since nobody uses this part
of make, it doesn't hurt that the debug output is now very verbose.

In Arch_Touch and Arch_TouchLib, move the snprintf to where it belongs.
There's no point modifying a local variable just to throw it away
afterwards.
 1.158 07-Nov-2020  rillig make(1): extract ArchiveMember_HasName from ArchFindMember

Comparing a string to a space-padded string is complicated enough to be
extracted to a separate function.

The behavior changes a little bit. Before, when searching for an archive
member with a short name (one that is space-padded in the archive), that
member was not searched using the AR_EFMT1 archive format. This doesn't
matter in practice though since no regular archive member has a name
starting with "#1/".
 1.157 07-Nov-2020  rillig make(1): clean up comments in arch.c
 1.156 07-Nov-2020  rillig make(1): clean up code stylistically

* Replace character literal 0 with '\0'.
* Replace pointer literal 0 with NULL.
* Remove redundant parentheses.
* Parentheses in multi-line conditions are not redundant at the
beginning of a line.
* Replace a few !ptr with ptr == NULL.
* Replace a few ptr with ptr != NULL.
* Replace (expr & mask) == 0 with !(expr & mask).
* Remove redundant braces for blocks in cases where the generated code
stays the same. (Assertions further down in the code would get
different line numbers.)
* Rename parameters in CondParser_String to reflect the data flow.
* Replace #ifdef notdef with #if 0.

The generated code stays exactly the same, at least with GCC 5.5.0 on
NetBSD 8.0 amd64 using the default configuration.
 1.155 06-Nov-2020  rillig make(1): rename Arch_MemMTime to Arch_MemberMTime

The abbreviation Mem was ambiguous, it could have meant memory as well.
 1.154 05-Nov-2020  rillig make(1): remove redundant parentheses from sizeof operator

The parentheses are only needed if the argument is a type, not an
expression.
 1.153 02-Nov-2020  rillig make(1): remove word "Ptr" from variable names

Whether or not a variable is a pointer is obvious from the context.
Since the introduction of function prototypes in C90, this information
is checked by the compiler and no longer needs to be encoded in the
variable names.
 1.152 02-Nov-2020  rillig make(1): use freeIt pattern in Arch_ParseArchive

This makes the memory management more obvious than before, where the
status of the variable libName depended on subLibName.
 1.151 31-Oct-2020  rillig make(1): format #include directives consistently
 1.150 31-Oct-2020  rillig make(1): do not look up local variables like .TARGET anywhere else

Nobody defines a global variable named .TARGET since that would have
many unpredictable effects, applying to all targets at once.

Nobody defines an environment variable named .TARGET since that's
against the naming conventions for environment variables and would have
the same effect.

Because of this, there is no point looking up the variables that are
local to a GNode anywhere else. This means they cannot come from the
environment and thus their value doesn't need to be freed after use,
which makes the code simpler.

The newly added accessor functions in make.h refer to external
functions, but since that header is not used anywhere outside of
usr.bin/make, it doesn't matter. Between 2020-08-25 and 2020-10-30,
that header had been referenced by usr.bin/xinstall.
 1.149 30-Oct-2020  rillig make(1): change char * to void * in Var_Value

The only purpose of the parameter freeIt is to free the memory
associated with the return value. To do this, no pointer arithmetic is
needed. Therefore, change to a void pointer, to catch accidental use of
that pointer.
 1.148 30-Oct-2020  rillig make(1): make iterating over HashTable simpler
 1.147 25-Oct-2020  rillig make(1): rename hash functions to identify the type name

This makes it easier to spot mismatches between the function name and
its first parameter, although the compiler should already catch most of
them. Except for void pointers.
 1.146 25-Oct-2020  rillig make(1): make Arch_FindLib simpler
 1.145 24-Oct-2020  rillig make(1): clean up code layout in arch.c

Combining #ifdef with else if is bad style. Mixing spaces and tabs in
indentation is bad style as well.

The generated code stays exactly the same.
 1.144 24-Oct-2020  rillig make(1): fix local variable name for determining the basename
 1.143 24-Oct-2020  rillig make(1): clean up comments and braces in arch.c
 1.142 24-Oct-2020  rillig make(1): make Arch_ParseArchive simpler

Neither '\0' nor ')' have ever been space characters.
 1.141 24-Oct-2020  rillig make(1): remove lengthy comments from archive handling

The relevant information is already documented on OP_ARCHV, but only
since a few weeks.
 1.140 23-Oct-2020  rillig make(1): rename GNode.cmgn to youngestChild

The name is longer than before but also clearer.
 1.139 23-Oct-2020  rillig make(1): negate OP_NOP and rename it to GNode_IsTarget
 1.138 22-Oct-2020  rillig make(1): remove redundant type casts

This mainly affects the void pointers in callback functions for lists.
These had been necessary once when the parameter type was still
ClientData instead of void pointer.
 1.137 19-Oct-2020  rillig make(1): inline simple Lst getters

The function call variant takes more screen space than the direct field
access. Having an abstract API is usually a good idea, in this case of
simple read-only member access it makes the code more difficult to read.

LstNode_Set has been kept as a function since it is not a read-only
accessor function.
 1.136 18-Oct-2020  rillig make(1): rename Lst_Init to Lst_New

For the other types such as HashTable and Buffer, the Init function does
not allocate the memory for the structure itself, it only fills it.
 1.135 18-Oct-2020  rillig make(1): remove underscore from Hash_Table and Hash_Entry

For consistency with the other type names, such as GNodeListNode.
 1.134 18-Oct-2020  rillig make(1): migrate ArchFree from Hash_Search to HashIter
 1.133 17-Oct-2020  rillig make(1): normalize initialization and cleanup of the modules
 1.132 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.131 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.130 03-Oct-2020  rillig make(1): clean up #include sections
 1.129 03-Oct-2020  rillig make(1): use consistent pattern for parsing whitespace

The pp and cpp in the function names stand for "parsing position" and
"const parsing position".
 1.128 03-Oct-2020  rillig make(1): format code in arch.c
 1.127 01-Oct-2020  rillig make(1): remove redundant function prototypes
 1.126 28-Sep-2020  rillig make(1): make debug logging simpler

This avoids referring to the debug_file variable in many places where
this implementation detail is not necessary.
 1.125 28-Sep-2020  rillig make(1): make debugging code shorter
 1.124 27-Sep-2020  rillig make(1): normalize whitespace in source code

There is no more space tab. Either only tabs or only spaces or tabs
followed by spaces, but not spaces followed by tabs.
 1.123 26-Sep-2020  rillig make(1): clean up API for finding and creating GNodes

The previous API had complicated rules for the cases in which the single
function returned NULL or what it did. The flags for that function were
confusing since passing TARG_NOHASH would create a new node even though
TARG_CREATE was not included in that bit mask.

Splitting the function into 3 separate functions avoids this confusion.
It also reveals several places where the complicated API led to
unreachable code. Such code has been removed.
 1.122 26-Sep-2020  rillig make(1): add Hash_FindValue, for direct access to hash table data
 1.121 25-Sep-2020  rillig make(1): inline ArchFindArchive into ArchStatMember

This avoids a few void pointers and unnecessary function calls.
 1.120 25-Sep-2020  rillig make(1): make code in ArchSVR4Entry simpler
 1.119 25-Sep-2020  rillig make(1): replace a few calls to Lst_Open with simple loops

This avoids relying on the internal iterator of the list, which is
supposed to be removed in the near future.
 1.118 22-Sep-2020  rillig make(1): prepare Var_Subst for proper error handling

Returning a VarParseResult instead of a string makes it possible to let
the error bubble up, until it reaches the main expression.
 1.117 22-Sep-2020  rillig make(1): use fine-grained type names for lists and their nodes

This is only intended to help the human reader. There is no additional
type safety yet.
 1.116 21-Sep-2020  rillig make(1): clean up Arch_ParseArchive

This code is so seldom used that it's not necessary to squeeze out every
little bit of performance. It's more important for the code to be clear
and simple.
 1.115 13-Sep-2020  rillig make(1): prepare Var_Parse for proper error handling and reporting

Right now, Var_Parse swallows many errors during parsing and evaluation.
Ideally, these errors should propagate from the deeply nested
expressions where they occur up to the top-level expressions. When such
an error occurs, the depending expressions should not be evaluated any
further. They may still be parsed, but side effects should be
minimized.

The goal is to prevent incomplete expressions like the "xy}" in
moderrs.exp:106 from being evaluated and eventually passed to the shell
for execution. This expression is a left-over from a parse error in the
mod-t-parse target in moderrs.mk:154.

This commit is a first step in analyzing and verifying the current state
of affairs. The modelling in VarParseErrors already looks complicated
but is expected to closely match reality.
 1.114 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.113 13-Sep-2020  rillig make(1): remove #endif comments for very short blocks
 1.112 12-Sep-2020  rillig make(1): rename Var_ParsePP back to Var_Parse

The migration to the "parsing position" pointer has been done.
 1.111 11-Sep-2020  rillig make(1): add wrappers around ctype.h functions

This avoids casting the argument to unsigned char, and to cast the
result of toupper/tolower back to char.
 1.110 07-Sep-2020  rillig make(1): migrate Var_Parse to Var_ParsePP in archive handling
 1.109 07-Sep-2020  rillig make(1): remove unnecessary cp-- from Arch_ParseArchive
 1.108 05-Sep-2020  rillig make(1): remove initial size argument from Hash_InitTable

In all but one case this argument was set to auto-detect anyway. The
one case where it was set was not worth keeping this complicated API.
 1.107 30-Aug-2020  rillig make(1): rename Lst_Datum to LstNode_Datum
 1.106 29-Aug-2020  rillig make(1): trust that Var_Parse never returns NULL

That function is quite long, but all its return paths lead either to the
expanded variable expression, or to var_Error or varNoError.
 1.105 29-Aug-2020  rillig make(1): remove ReturnStatus, SUCCESS and FAILURE

These are used in so few places now that it is easier to use a simple
Boolean for them.
 1.104 29-Aug-2020  rillig make(1): rename Lst_FindB back to Lst_Find

The migration from "comparison function" to "match function" is done,
the "B" in the names is no longer needed.
 1.103 29-Aug-2020  rillig make(1): start replacing Lst_Find with Lst_FindB

Lst_Find is called with a "comparison" function that returns the integer
0 if the desired node is found. This leads to confusion since there are
so many different return value conventions for int, such as 0/1 for
mimicking false/true, -1/0 as in close(2), and the sign as in strcmp(3).
This API is much easier to understand if the "comparison" function is
not called a comparison function (since that is too close to strcmp),
but a "match" function that just returns a boolean.

In Lst_FindFromB, the node argument may be null. This deviates from the
other Lst functions, which require Lst and LstNode to generally be
non-null. In this case it is useful though to make the calling code
simpler.

In arch.c, this makes a lot of the previous documentation redundant.

In cond.c, the documentation is reduced a little bit since it had
already been cleaned up before. It also removes the strange negation
from CondFindStrMatch.

In dir.c, the documentation collapses as well.

In main.c, separating the ReadMakefile function from the callbacks for
Lst_FindB allows the former to get back its natural function signature,
with proper types and no unused parameters.

To catch any accidental mistakes during the migration from Lst_Find to
Lst_FindB, the code can be compiled with -DUSE_DOUBLE_BOOLEAN, which
will complain about incompatible function pointer types.
 1.102 28-Aug-2020  rillig make(1): clean up arch.c

Remove redundant parts of the function comments. Move the "side
effects" to the main section, since these effects are main effects, not
side effects.

Remove the redundant prototype for ArchFree.
 1.101 28-Aug-2020  rillig make(1): remove trailing 'S' from names of Lst functions

The migration from null-passing Lst functions to argument-checking Lst
functions is completed.

There were 2 surprises: The targets list may be NULL, and in Dir_AddDir,
the path may be NULL. The latter case is especially surprising since
that function turns into an almost-nop in that case. This is another
case where probably 2 independent functions have been squeezed into a
single function. This may be improved in a follow-up commit.

All other lists were fine. They were always defined and thus didn't
need much work.
 1.100 28-Aug-2020  rillig make(1): migrate Lst_Find to Lst_FindS
 1.99 27-Aug-2020  rillig make(1): migrate Lst_IsEmpty to Lst_IsEmptyS
 1.98 27-Aug-2020  rillig make(1): convert Arch_ParseArchive from ReturnStatus to Boolean

There are only few functions left that use the ReturnStatus. These will
be converted as well, to get rid of the additional typedef.
 1.97 26-Aug-2020  rillig make(1): add stricter variants for remaining Lst functions

In most cases the Lst functions are only called when the arguments are
indeed valid. It's not guaranteed though, therefore each function call
needs to be analyzed and converted individually.

While here, remove a few statements that were only useful when the Lst
functions handled circular lists.
 1.96 23-Aug-2020  rillig make(1): make ArchFindMember ready for WARNS=6
 1.95 23-Aug-2020  rillig make(1): make ArchStatMember ready for WARNS=6
 1.94 23-Aug-2020  rillig make(1): make Arch_MemMTime ready for WARNS=6
 1.93 23-Aug-2020  rillig make(1): replace tricky malloc+realloc+strlen+snprintf with Buffer

The code for handling archives is not widely used. Therefore it does
not need to be fast. Clarity of the code is more important. Therefore
replace the malloc + strlen + realloc + snprintf string processing with
the Buffer type, which removes a lot of redundancy.

In the wildcard loop, the "if (sz > nsz)" looked like a mistake. Why
should it be useful to first allocate a large buffer and then resize it
to a smaller buffer, but still twice as large as necessary?
 1.92 23-Aug-2020  rillig make(1): reverse order of the Lst_Find parameters

The other callbacks all have (function, param), only the Lst_Find had
(param, function), which was inconsistent.
 1.91 22-Aug-2020  rillig make(1): use Lst_OpenS in Arch_MemMTime

The field GNode.parents is guaranteed to be a valid list.
 1.90 22-Aug-2020  rillig make(1): declare unused argument in Arch_TouchLib in a simpler way
 1.89 22-Aug-2020  rillig make(1): replace Lst_Datum with non-null guaranteeing Lst_DatumS
 1.88 22-Aug-2020  rillig make(1): convert Lst_Enqueue and Lst_Dequeue to nonnull variants

Except for once instance in parse.c, the usage pattern for Lst_Dequeue
was to first test whether the list is empty. This pattern allowed the
implementation of Lst_Dequeue to become simpler since the null check is
not needed anymore.

The calls to Lst_Enqueue never pass an invalid list or a null pointer,
therefore making them strict was trivial.
 1.87 22-Aug-2020  rillig make(1): replace "(void)Lst_AtEnd" with stricter "Lst_AppendS"

This change ensures that there is actually something added to the list.
Lst_AtEnd had silently skipped the addition if the list was invalid
(null pointer), which was not intended in these cases. The "(void)" is
assumed to mean "I know that this cannot fail", while it could also mean
"I don't care whether something actually happened".

Running "./build.sh -j6 tools" still succeeds after this change,
therefore chances are very low that this change breaks anything. If
there is any change, it's an obvious assertion failure. There is no
silent change in behavior though.
 1.86 21-Aug-2020  rillig make(1): use stricter list API for sequential access

In several places, it just doesn't make sense to have a null pointer
when a list is expected.

In the existing unit tests, the list passed to Lst_Open is always valid,
but that's not a guarantee for real-world usage. Therefore, Lst_Open
has been left for now, and Lst_OpenS is only the preferred alternative
to it.
 1.85 21-Aug-2020  rillig make(1): assert correct usage of the Lst_Open API

All calls to Lst_Next are properly protected by Lst_Open, so there is no
possible assertion failure here.
 1.84 21-Aug-2020  rillig make(1): remove unused code for circular lists

The list library had probably been imported from a general-purpose
library that also supported circular lists. These are not used by make
though.

After replacing Lst_Init(FALSE) with Lst_Init(), only a single call to
Lst_Init remained with a non-constant argument, and that was in
Lst_Concat, which was to be expected.
 1.83 12-Aug-2020  rillig make(1): remove unnecessary UNCONST from arch.c

Somewhere in the refactorings of the last month, the parameter types of
the Arch functions had their constness fixed, therefore the UNCONST is
no longer necessary.
 1.82 11-Aug-2020  rillig make(1): add str_concat4 to make the other code simpler

There's no need for arch.c to call strlen when there is a high-level API
for the same purpose.
 1.81 03-Aug-2020  rillig make(1): no declaration-after-statement anymore

NetBSD make is intended to be maximally portable, therefore it uses only
C89. This was not declared in the Makefile before.

There are still a few places in parse.c and metachar.c that use
end-of-line comments. These will be fixed in a follow-up commit.
 1.80 01-Aug-2020  rillig make(1): use consistent indentation in source code

Tabs for multiples of 8, then spaces.

The usage string has been kept as-is since the spaces there are
indentional and do influence the output.
 1.79 01-Aug-2020  rillig make(1): avoid calls to free(3) in the common case of a NULL pointer
 1.78 31-Jul-2020  rillig make(1): use snprintf instead of strncpy

strncpy is not suited for string processing, despite its name.

Even though the previous code used the correct code pattern for strncpy,
it still wasted cycles since strncpy always fills the whole target
buffer. That's not needed.
 1.77 28-Jul-2020  rillig make(1): remove dead code from Var_Subst

The first parameter from Var_Subst had been a literal NULL in all cases.
These have been fixed using this command:

sed -i 's|Var_Subst(NULL, |Var_Subst(|' *.c

The one remaining case was not found because the "NULL," was followed by
a line break instead of a space.

The removed code probably wouldn't have worked as expected anyway.
Expanding a single variable to a literal string would have led to
unexpected behavior for cases like ${VAR:M${pattern}}, in case pattern
would contain an unescaped ':' itself.
 1.76 27-Jul-2020  rillig make(1): improve const-correctness in archive handling

The return value of Var_Value must not be modified. Ideally it would be
declared as const char *, but that still takes a while, especially since
much of the make code is not yet covered by the unit tests.

The variable cp had to be changed to const char * as well, and while here
was split up into one variable per actual use case.
 1.75 26-Jul-2020  rillig make(1): make return value of Var_Parse constant

This return value is not supposed to be modified since it can be a string
literal. The modifiable part is returned via freePtr, but only for
freeing, not for actually modifying anything.
 1.74 19-Jul-2020  rillig make(1): rename Varf_Flags to VarEvalFlags

In var.c there are lots of different flag types. To make any accidental
mixture obvious, each flag group gets its own prefix.

The only flag group that is visible outside of var.c is concerned with
evaluating variables, therefore the "e", which replaces the former "f"
that probably just meant "flag".
 1.73 03-Jul-2020  rillig make(1): remove redundant parentheses around return values
 1.72 02-Jul-2020  rillig make(1): remove useless parameter from Var_Set

The enum corresponding to this int parameter is only defined in var.c,
which makes it impractical for the outside to set this parameter to
anything but 0.

On x86_64, this reduces the size of the resulting executable by 5 kB.
 1.71 05-Oct-2019  mrg use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.
 1.70 16-Apr-2017  riastradh branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276
 1.69 06-Apr-2016  gson branches: 1.69.2; 1.69.4;
Fully avoid the nonstandard types u_char, u_int, and u_long, which
were only used inconsistently in a few places anyway.
 1.68 18-Feb-2016  christos Collapse the 3 boolean parameter to 1 flags parameter. No functional change.
 1.67 17-Jan-2016  christos remove free NULL checks (Tilman Sauerbeck)
 1.66 17-Jan-2016  christos provide missing FD_CLOEXEC for the havenots.
 1.65 09-Jan-2016  christos Preserve $$ in := assignments..

FOO=\$$CRAP
BAR:=${FOO}

all:
echo ${FOO}
echo ${BAR}
 1.64 11-Oct-2015  sjg Add Boolean wantit to Var_Parse and Var_Subst

wantit will be FALSE when we are just consuming to discard
in which case we skip "expensive" things like Cmd_Exec.

Reviewed by: christos
 1.63 12-Jun-2012  joerg Replace __dead, __unused and the various printf format attributes
with versions prefixed by MAKE_ATTR_* to avoid modifying the
implementation namespace. Make sure they are available in all places
using nonints.h to fix bootstrap on Linux.
 1.62 27-Nov-2010  christos branches: 1.62.6;
fix typo (thanks simon)
 1.61 26-Nov-2010  christos check for NULL before de-referencing.
 1.60 25-Nov-2010  christos Instead of keeping around the mtime of the youngest child, keep a pointer
to it, so that we can print it when we do the out of date determination.
 1.59 23-Jan-2009  dsl Sprinkle some const.
In particular for Lst_Find() and Lst_FindFrom().
Remove some unneeded casts and some now-undeeded UNCONST().
 1.58 23-Jan-2009  dsl Change 'ClientData' to 'void *' so that relevant parameters can
be made 'const void *'.
 1.57 13-Dec-2008  dsl Use NULL instead of -1 cast to the relavant type (usually via NIL).
This was a suggestion from christos - so blame him if there is a deep
reason for using -1 :-)
 1.56 06-Oct-2008  joerg Don't use emalloc and friends directly, but call them consistently
bmake_malloc and friends. Implement them via macros for the native case
and provide fallback implementations otherwise. Avoid polluting the
namespace by not defining enomem globally. Don't bother to provide
strdup and strndup, they were only used for the estrdup and estrndup
comapt code.

This addresses the presence of emalloc in system libraries on A/UX and
resulted strange issues as reported by Timothy E. Larson.
 1.55 15-Feb-2008  christos back all changes out until I fix it properly.
 1.54 14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.53 27-Oct-2006  dsl Since 'ClientData' is 'void *', nuke almost all the (ClientData) casts.
 1.52 15-Oct-2006  dsl Output all debug trace output through 'debug_file' defaulting to 'stdout'.
(Almost all the debug output went there, but some went to stderr.)
Split the parsing of -d (debug flags) out into its own routine.
Allow the output filename to be changed by specifying -dF<file> to create
a log file, or -dF+<file> to append to it. <file> may be stdout or stderr.
Also change so that -d-<flags> acts on <flags> locally but doesn't copy
them to MAKEFLAGS so they aren't inherited by child makes.
I'm not 100% happy with the command line syntax for the above, so they are
currently undocumented.
 1.51 29-Jun-2006  rillig Fixed gcc warnings about signed vs. unsigned in comparisons.
 1.50 22-Apr-2006  christos Coverity CID 523: Fix off by one mistake.
 1.49 31-Mar-2006  christos Add some coverity allocation comments, and change the way the allocator
functions work. When they allocate storage that needs to be freed, instead
of setting a boolean, set the pointer to be freed. Plug some more memory
leaks found by inspection.
 1.48 08-Aug-2005  christos From Max Okumoto:
- Remove casts to NULL.
- Remove space between cast and object.
 1.47 05-Aug-2005  christos More KNF cleanups from Max Okumoto
 1.46 04-Aug-2005  christos remove unnecessary casts to void * functions (Max Okumoto)
 1.45 25-Jul-2005  christos Whitespace KNF cleanup from Max Okumoto
 1.44 16-Feb-2005  christos PR/29203, PR/29204: Max Okumoto: KNF changes to make [no functional changes]
 1.43 30-Oct-2004  dsl Add (unsigned char) cast to ctype functions
 1.42 01-Jul-2004  jmc Change to use __unused instead and provide a compat definition in make.h if
not already defined from cdefs.h
 1.41 01-Jul-2004  jmc Add some checks for gcc around a few function declarations and note the
unused variables. Also fix a few other warnings that PR#22118 shows when
trying to compile bmake on non-NetBSD hosts
 1.40 07-May-2004  ross Simplify build, no functional changes.

Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().

It's now possible to build make on some hosts with: cc *.c */*.c
 1.39 07-Aug-2003  agc branches: 1.39.2;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.38 14-Jul-2003  sjg Fix a couple of missing UNCONST's that hit bmake.
 1.37 14-Jul-2003  christos Pass WARNS=3
 1.36 02-Jun-2003  matt For a library, only check in cmtime (children's modification) if there are
children. This prevents spurious out-of-date failures when you have a
rules checking for a library's existance (and no children).
 1.35 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.34 30-Nov-2001  thorpej Clean up some MAKE_BOOTSTRAP issues wrt. MACHINE/MACHINE_ARCH.
 1.33 12-Jun-2001  sjg Add 4th arg (flags) to Var_Set so that VarLoopExpand can tell it not
to export interator variables when using context VAR_CMD.

Reviewed: christos
 1.32 15-Feb-2000  sjg Non-existent libs are always out of date.
This was not handled correctly on ELF where libs do not have T.O.C.

PR: 9393
Reviewed by: christos
 1.31 15-Sep-1999  mycroft Don't bother iterating through all the data structures to free(3) everything
right before exiting.
(The code is still present, `#ifdef CLEANUP', in case someone needs it...)
 1.30 04-Sep-1999  christos PR/8259: Chris Demetriou: Fix stack overflow bugs exposed by the glibc-2.1.1
Makefile. Use snprintf everywhere.
 1.29 11-Nov-1998  christos This patch fixes the problem introduced in the previous commit where
parents would be get remade, even if children were not really updated
by the commands executed for them. It also makes all the children have
the real modification time set if possible, so it should fix some other
timing weirdnesses...

- collapse childMade and make fields into flags and convert them to bits
CHILDMADE and REMAKE
- introduce FORCE flag that gets set in all the parents of a child that
has no sources and does not exist.
- set oodate if the FORCE flag is set, and not if CHILDMADE
- centralize the RECHECK into Make_Recheck() and use this in make.c and compat.c
- use Make_TimeStamp for all child -> parent timestamp propagations
 1.28 06-Nov-1998  christos - full prototypes
- more conservative printf
- char -> unsigned char
 1.27 21-May-1998  tv Make a MAKE_BOOTSTRAP case work on NetBSD, too, for cross-compile cases
 1.26 03-Oct-1997  thorpej If printing a u_long, use the %lu format.
 1.25 03-Oct-1997  enami Make this compile on NetBSD/alpha; use %ld and cast to u_long to print
a variable of type size_t.
 1.24 28-Sep-1997  lukem wrap #include <sys/cdefs.h>, __RCSID(...) stuff in #ifndef MAKE_BOOTSTRAP
 1.23 26-Sep-1997  christos PR/4140: David A. Holland: use svr4 style archives for ELF environments
 1.22 23-Sep-1997  fair fix some ints that should be "time_t" per PR#4139
 1.21 25-Aug-1997  kleink Lseek(2) usage cleanup: the use of L_SET/L_INCR/L_XTND is deprecated,
use SEEK_SET/SEEK_CUR/SEEK_END instead.
 1.20 01-Jul-1997  christos Add WARNS=1
RCSID police
 1.19 07-Jun-1997  christos Don't confuse `member' with `target'
 1.18 20-May-1997  mycroft Check the .PHONY attribute...
 1.17 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.16 13-Aug-1996  christos Add estrdup(), a checked version of strdup and use it.
 1.15 02-Jun-1996  christos Recognize SVR4 style long filename entries in archives.
 1.14 12-Mar-1996  christos branches: 1.14.4;
data and date aren't the same...
 1.13 04-Feb-1996  christos fix pr/1421 and pr/1997
 1.12 04-Feb-1996  christos Support SVR4 style archives.
 1.11 22-Nov-1995  christos Updates for POSIX/SVR4 compiling:

arch.c: Don't require ranlib stuff. Not everybody has it.
dir.c: SunOS-4 != Solaris; change #ifdef sun to #if sun && !__svr4__
job.c, compat.c: Don't use 'union wait', use int and the W*() macros.
main.c: Check for uname() == -1; some unames return > 0...
util.c, job.c: Add signal() with BSD semantics for svr4, don't use bsd
sigmask and friends.
 1.10 02-Nov-1995  christos Minor:
- ${.PREFIX} should never contain a full pathname
- Fixed gcc -Wall warnings
Major:
- compatMake is now FALSE. This means that we are now running in
full pmake mode:
* rules on dependency lines can be executed in parallel and or
out of sequence:

foo: bar baz

can fire the rule for baz before the rule for bar is fired.
To enforce bar to be fired before baz, another rule needs to be
added. [bar: baz]
* adjacent shell commands in a target are now executed by a single
invocation of the shell, not one invocation of the shell per line
(compatMake can be turned off using the -B flag)
- The -j flag now works... I.e. make -j 4 will fork up to four jobs in
parallel when it can. The target name is printed before each burst
of output caused by the target execution as '--- target ---', when j > 1
- I have changed all the Makefiles so that they work with make -j N, and
I have tested the whole netbsd by:
'make -j 4 cleandir; make -j 4 depend; make -j 4; make -j 4 install'
- I have not compiled or tested this version of make with -DREMOTE.
 1.9 14-Jun-1995  christos - $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.8 11-Jan-1995  christos Fixed PR/724, 'make' runs commands when $? is empty
This is not the perfect fix. I think that the whole __SYMDEF
checking code should be removed. [I should also teach myself
how to deal with the PR stuff to mark this closed :-)]
 1.7 06-Jun-1994  jtc Fixes from Christos Zoulas, who used purify, objectcenter and testcenter
to find memory leaks and illegal memory accesses.
 1.6 18-Mar-1994  pk Do extended-name archives.
 1.5 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.4 13-Jan-1994  jtc Include appropriate header files to bring prototypes into scope.
 1.3 01-Aug-1993  mycroft Add RCS identifiers.
 1.2 27-May-1993  glass some compatibility fixes to ease bootstrapping:
Makefile.dist is now a decent Makefile and not one of these cc *.c disasters
RANLIBMAG now defaults if not otherwise defined
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.14.4.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.39.2.1 10-May-2004  tron Pull up revision 1.40 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.62.6.1 30-Oct-2012  yamt sync with head
 1.69.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.69.2.1 26-Apr-2017  pgoyette Sync with HEAD
 1.70.12.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.199.2.1 31-May-2021  cjep sync with head
 1.219.2.1 02-Aug-2025  perseant Sync with HEAD
 1.8 30-Jul-2005  christos Remove unused files. From Max Okumoto.
 1.7 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.6 08-Nov-1997  lukem getopt returns -1 not EOF, use memmove instead of bcopy
 1.5 08-Nov-1995  christos branches: 1.5.2;
- Turn compat mode on by default. It gets turned off when the -j without
the -B flag is specified. [Thus you can use -j 1 to turn it off].
- Fix malloc -> emalloc as Gordon noted.
 1.4 14-Jun-1995  christos - $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.3 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.2.1 08-May-1998  mycroft Sync with trunk, per request of christos.
 1.58 28-Apr-2024  rillig make: don't reallocate memory after evaluating an expression

When an expression is evaluated, the resulting text is short-lived in
almost all cases. In particular, the compaction neither affects the
target names nor the global variable values, which are the prime
candidates for permanent memory usage.
 1.57 19-Dec-2023  rillig make: clean up comments

No binary change, except for line numbers in assertions.
 1.56 01-Jun-2023  rillig make: shorten function names, clean up comments

No functional change.
 1.55 08-Jan-2022  rillig make: inline Buf_Clear

No functional change.
 1.54 15-Dec-2021  rillig make: prevent memory leaks from buffers

The warning about unused function results would have prevented the
memory leak that was fixed in cond.c 1.303 from 2021-12-13.
 1.53 28-Nov-2021  rillig make: move duplicate function Buf_AddFlag to buf.c

It is used only for debug output, therefore performance doesn't matter.

No functional change.
 1.52 21-Jun-2021  rillig make: use simpler upper bound for length in Buf_AddInt

No functional change.
 1.51 30-Jan-2021  rillig make(1): remove __predict_false

The effect (at least on x86_64) is so minimal that it is not worth
cluttering the code.
 1.50 30-Jan-2021  rillig make(1): inline Buf_GetAll
 1.49 30-Jan-2021  rillig make(1): only clean up the Buffer data in CLEANUP mode

Cleaning up the members is only useful during debugging but not during
use in production.
 1.48 30-Jan-2021  rillig make(1): split Buf_Destroy into Buf_Done and Buf_DoneData

In all cases except one, the boolean argument to Buf_Destroy was
constant. Removing that argument by splitting the function into two
separate functions makes the intention clearer on the call site. It
also removes the possibility for using the return value of Buf_Done,
which would have made no sense.

The function Buf_Done now pairs with Buf_Init, just as in HashTable and
Lst.

Even though Buf_Done is essentially a no-op, it is kept as a function,
both for symmetry with Buf_Init and for clearing the Buffer members
after use (this will be done only in CLEANUP mode, in a follow-up
commit).
 1.47 30-Dec-2020  rillig make(1): format multi-line comments
 1.46 28-Dec-2020  rillig make(1): rename Buf_Expand_1 to Buf_Expand
 1.45 23-Nov-2020  rillig make(1): indent buf.c with tabs instead of spaces
 1.44 07-Nov-2020  rillig make(1): make API of Buf_Init simpler

In most cases, the caller doesn't want to specify the exact number of
preallocated bytes.
 1.43 07-Nov-2020  rillig make(1): clean up code stylistically

* Replace character literal 0 with '\0'.
* Replace pointer literal 0 with NULL.
* Remove redundant parentheses.
* Parentheses in multi-line conditions are not redundant at the
beginning of a line.
* Replace a few !ptr with ptr == NULL.
* Replace a few ptr with ptr != NULL.
* Replace (expr & mask) == 0 with !(expr & mask).
* Remove redundant braces for blocks in cases where the generated code
stays the same. (Assertions further down in the code would get
different line numbers.)
* Rename parameters in CondParser_String to reflect the data flow.
* Replace #ifdef notdef with #if 0.

The generated code stays exactly the same, at least with GCC 5.5.0 on
NetBSD 8.0 amd64 using the default configuration.
 1.42 24-Oct-2020  rillig make(1): remove macros MIN and MAX

These macros typically evaluate one of their arguments twice. Until
2020-08-31, they had not parenthesized their arguments properly. They
are only used in a few places, therefore it doesn't hurt much to have
them expanded.
 1.41 24-Oct-2020  rillig make(1): clean up comments in buf.c
 1.40 27-Sep-2020  rillig make(1): in the Buffer functions, rename bp to buf

It's not necessary to emphasize on the pointerness of the variable since
that's obvious from the context.
 1.39 27-Sep-2020  rillig make(1): rename Buffer fields

It was confusing to have a function Buf_Size that returns buf->count
even though there is also buf->size.
 1.38 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.37 23-Aug-2020  rillig make(1): clean up code in buf.c
 1.36 23-Aug-2020  rillig make(1): use common MAX macro instead of self-defined
 1.35 13-Aug-2020  rillig make(1): remove type alias Byte = char

This alias was only actually used in very few places, and changing it to
unsigned char or any other type would not be possible without generating
lots of compile-time errors. Therefore there was no abstraction, only
unnecessary complexity.
 1.34 09-Aug-2020  rillig make(1): format the source code consistently, at least per file

Some files use 4 spaces per indentation level, others use 8. At least
for the few files from this commit, they use a consistent style
throughout each file now.

In Cond_Eval, the #define has changed into an enum since the identifiers
need not be visible to the C preprocessor.
 1.33 09-Aug-2020  rillig make(1): fix variable length array in Buf_AddInt

GCC 5 complained about this, but only when make is build with both
USE_COVERAGE=yes and USE_FORT=yes.
 1.32 08-Aug-2020  rillig make(1): remove trailing Z from buffer functions

This Z had been useful during the migration from int to size_t. This
migration is finished, at least for the Buffer type, so the Z is no
longer necessary.
 1.31 03-Aug-2020  rillig make(1): no declaration-after-statement anymore

NetBSD make is intended to be maximally portable, therefore it uses only
C89. This was not declared in the Makefile before.

There are still a few places in parse.c and metachar.c that use
end-of-line comments. These will be fixed in a follow-up commit.
 1.30 01-Aug-2020  rillig make(1): remove redundant if clause from Buf_DestroyCompact

bmake_realloc can never return NULL.
 1.29 01-Aug-2020  rillig make(1): switch Buffer size from int to size_t

This change helps to make the various integer types compatible and is a
preparational step for setting WARNS=6 in the Makefile.

The documentation of buf.c has been cleaned up and condensed since it
was mostly redundant, and some statements were even slightly wrong.

All code changes are covered by the existing unit tests, except for the
few lines in for.c around for_var_len. These changes have been reviewed
thoroughly and manually, like all the others in this commit.

Those buffer functions that deal with sizes have been renamed by
appending a Z, to make sure that no function call was accidentally
forgotten. They will be renamed back in a follow-up commit.

As usual, the scope of a few affected variables has been reduced, and
some variables had to be split since they had been incorrectly merged
before.

The order of the arguments to Buf_AddBytes has changed from (mem_len,
mem) to (mem, mem_len), in order to make it consistent with the
functions from the C standard library, such as snprintf.
 1.28 26-Jul-2020  rillig make(1): add Buffer functions for common tasks

Adding a string or a substring to a buffer are common tasks when handling
variables. There is no need to spell out the strlen call or the pointer
subtraction at every call site.

Subtracting pointers results in a ptrdiff_t, which would have to be
converted to an int in each case for WARNS=6. Having this conversion in a
single place keeps the code clean.
 1.27 26-Jul-2020  rillig make(1): add Buf_AddInt to make the calling code simpler
 1.26 03-Jul-2020  rillig make(1): remove redundant parentheses around return values
 1.25 24-Apr-2012  sjg Var* are generally very liberal with memory, with the expectation
that none of it persists for long.
This isn't always true - for example a long running .for loop.

Buf_DestroyCompact() is used by Var_Subst(), rather than Buf_Destroy().
If it looks like we can save BUF_COMPACT_LIMIT (128) or more bytes,
call realloc. This can reduce memory consumption by about 20%
Setting BUF_COMPACT_LIMIT to 0 dissables this.
 1.24 17-Jan-2009  dsl branches: 1.24.8;
Change 'Buffer' so that it is the actual struct, not a pointer to it.
Saves having to malloc/free a fixed size structure.
Buf_Init() now takes ptr to Buffer to initialiase.
Change Buf_Destroy() to return ptr to string when not freed.
Remove large number of casts to (Byte) and (Byte *) - 'Byte' is 'char' here.
Buf_AddByte[s] guarantees that the data is 0 termininated, so never add '\0'.
Keep 'count' not 'left' and 'inPtr', code is simplier with only one update.
Fix fallou, no functional change.
 1.23 20-Dec-2008  dsl A lot of code assumes that the pointer returned by Buf_GetAll() is malloced.
Replace Buf_Discard() with Buf_Empty() since the former might leave the
'outPtr != buffer' and the only caller wanted all the data discared.
Remove 'outPtr' now that it always equals 'buffer'.
The assumption about Buf_GetAll()is now guaranteed by design.
 1.22 06-Oct-2008  joerg Don't use emalloc and friends directly, but call them consistently
bmake_malloc and friends. Implement them via macros for the native case
and provide fallback implementations otherwise. Avoid polluting the
namespace by not defining enomem globally. Don't bother to provide
strdup and strndup, they were only used for the estrdup and estrndup
comapt code.

This addresses the presence of emalloc in system libraries on A/UX and
resulted strange issues as reported by Timothy E. Larson.
 1.21 15-Feb-2008  christos back all changes out until I fix it properly.
 1.20 14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.19 08-Aug-2005  christos From Max Okumoto:
- Remove casts to NULL.
- Remove space between cast and object.
 1.18 05-Aug-2005  christos More KNF cleanups from Max Okumoto
 1.17 25-Jul-2005  christos Whitespace KNF cleanup from Max Okumoto
 1.16 16-Feb-2005  christos PR/29203, PR/29204: Max Okumoto: KNF changes to make [no functional changes]
 1.15 07-May-2004  ross Simplify build, no functional changes.

Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().

It's now possible to build make on some hosts with: cc *.c */*.c
 1.14 07-Aug-2003  agc branches: 1.14.2;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.13 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.12 15-Sep-1999  mycroft Nuke Buf_{G,Ung}etByte{,s}(), since they aren't used, and make BufExpand do
power-of-2 allocation.
 1.11 28-Sep-1997  lukem wrap #include <sys/cdefs.h>, __RCSID(...) stuff in #ifndef MAKE_BOOTSTRAP
 1.10 01-Jul-1997  christos Add WARNS=1
RCSID police
 1.9 31-Dec-1996  christos Use only integral types in procedure arguments.
 1.8 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.7 29-Mar-1996  jtc branches: 1.7.4;
Added erealloc() function that calls enomem() if the allocation fails
(this is like the existing emalloc() function). Changed all realloc()
calls to erealloc().
 1.6 14-Jun-1995  christos - $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.5 06-Jun-1994  jtc Fixes from Christos Zoulas, who used purify, objectcenter and testcenter
to find memory leaks and illegal memory accesses.
 1.4 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.3 13-Jan-1994  jtc Include appropriate header files to bring prototypes into scope.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7.4.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.14.2.1 10-May-2004  tron Pull up revision 1.15 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.24.8.1 23-May-2012  yamt sync with head.
 1.50 28-Apr-2024  rillig make: don't reallocate memory after evaluating an expression

When an expression is evaluated, the resulting text is short-lived in
almost all cases. In particular, the compaction neither affects the
target names nor the global variable values, which are the prime
candidates for permanent memory usage.
 1.49 19-Dec-2023  rillig make: clean up comments

No binary change, except for line numbers in assertions.
 1.48 01-Jun-2023  rillig make: shorten function names, clean up comments

No functional change.
 1.47 08-Jan-2022  rillig make: inline Buf_Clear

No functional change.
 1.46 15-Dec-2021  rillig make: remove redundant comments for multiple-inclusion guards
 1.45 15-Dec-2021  rillig make: prevent memory leaks from buffers

The warning about unused function results would have prevented the
memory leak that was fixed in cond.c 1.303 from 2021-12-13.
 1.44 28-Nov-2021  rillig make: move duplicate function Buf_AddFlag to buf.c

It is used only for debug output, therefore performance doesn't matter.

No functional change.
 1.43 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.42 30-Jan-2021  rillig make(1): inline Buf_Len
 1.41 30-Jan-2021  rillig make(1): remove __predict_false

The effect (at least on x86_64) is so minimal that it is not worth
cluttering the code.
 1.40 30-Jan-2021  rillig make(1): inline Buf_GetAll
 1.39 30-Jan-2021  rillig make(1): split Buf_Destroy into Buf_Done and Buf_DoneData

In all cases except one, the boolean argument to Buf_Destroy was
constant. Removing that argument by splitting the function into two
separate functions makes the intention clearer on the call site. It
also removes the possibility for using the return value of Buf_Done,
which would have made no sense.

The function Buf_Done now pairs with Buf_Init, just as in HashTable and
Lst.

Even though Buf_Done is essentially a no-op, it is kept as a function,
both for symmetry with Buf_Init and for clearing the Buffer members
after use (this will be done only in CLEANUP mode, in a follow-up
commit).
 1.38 28-Dec-2020  rillig make(1): rename Buf_Expand_1 to Buf_Expand
 1.37 06-Dec-2020  rillig make(1): indent buf.h with tabs instead of spaces
 1.36 10-Nov-2020  rillig make(1): use consistent definition for MAKE_INLINE
 1.35 07-Nov-2020  rillig make(1): make API of Buf_Init simpler

In most cases, the caller doesn't want to specify the exact number of
preallocated bytes.
 1.34 27-Sep-2020  rillig make(1): in the Buffer functions, rename bp to buf

It's not necessary to emphasize on the pointerness of the variable since
that's obvious from the context.
 1.33 27-Sep-2020  rillig make(1): rename Buf_Size to Buf_Len

The new name better matches the field name Buffer.len as well as the
variables around the calls to this function.
 1.32 27-Sep-2020  rillig make(1): prefer positive array index in Buf_AddByte

Ideally the condition for allocating more memory would have been
(old_len + 2 > bp->cap) since that's the actually intended wording. But
GCC 5 neglected to generate good code for that on x86_64, so be it.
 1.31 27-Sep-2020  rillig make(1): rename Buffer fields

It was confusing to have a function Buf_Size that returns buf->count
even though there is also buf->size.
 1.30 27-Sep-2020  rillig make(1): replace direct access to Buffer fields with inline function

This way, renaming the fields of the buffer is restricted to only buf.h
and buf.c.
 1.29 13-Sep-2020  rillig make(1): fix position of MAKE_ATTR_UNUSED in inline functions

The attribute needs to be before the return type, otherwise GCC 5
complains that Hash_GetValue is defined but not used, when compiling
with USER_CPPFLAGS=-Dinline=. The other functions don't get any
warnings. It's probably because Hash_GetValue is the only inline
function that returns a pointer.
 1.28 01-Sep-2020  rillig make(1): clean up documentation in buf.h, and redundant include files
 1.27 31-Aug-2020  rillig make(1): improve documentation for Buffer fields
 1.26 25-Aug-2020  rillig make(1): allow make to be compiled in C90 mode

Since the inline functions are the only C99 feature used by now, setting
USER_CFLAGS='-std=c90 -ansi -Dinline=' is enough for compiling make with
a C90 compiler.
 1.25 13-Aug-2020  rillig make(1): convert Buf_AddByte to inline function

This lets the compiler decide whether to actually inline the code (which
it does). It also provides better type safety and avoids a few
underscores and parentheses in the code.
 1.24 13-Aug-2020  rillig make(1): remove type alias Byte = char

This alias was only actually used in very few places, and changing it to
unsigned char or any other type would not be possible without generating
lots of compile-time errors. Therefore there was no abstraction, only
unnecessary complexity.
 1.23 08-Aug-2020  rillig make(1): remove trailing Z from buffer functions

This Z had been useful during the migration from int to size_t. This
migration is finished, at least for the Buffer type, so the Z is no
longer necessary.
 1.22 01-Aug-2020  rillig make(1): switch Buffer size from int to size_t

This change helps to make the various integer types compatible and is a
preparational step for setting WARNS=6 in the Makefile.

The documentation of buf.c has been cleaned up and condensed since it
was mostly redundant, and some statements were even slightly wrong.

All code changes are covered by the existing unit tests, except for the
few lines in for.c around for_var_len. These changes have been reviewed
thoroughly and manually, like all the others in this commit.

Those buffer functions that deal with sizes have been renamed by
appending a Z, to make sure that no function call was accidentally
forgotten. They will be renamed back in a follow-up commit.

As usual, the scope of a few affected variables has been reduced, and
some variables had to be split since they had been incorrectly merged
before.

The order of the arguments to Buf_AddBytes has changed from (mem_len,
mem) to (mem, mem_len), in order to make it consistent with the
functions from the C standard library, such as snprintf.
 1.21 26-Jul-2020  rillig make(1): add Buffer functions for common tasks

Adding a string or a substring to a buffer are common tasks when handling
variables. There is no need to spell out the strlen call or the pointer
subtraction at every call site.

Subtracting pointers results in a ptrdiff_t, which would have to be
converted to an int in each case for WARNS=6. Having this conversion in a
single place keeps the code clean.
 1.20 26-Jul-2020  rillig make(1): add Buf_AddInt to make the calling code simpler
 1.19 31-May-2017  maya Don't prefix include guards by _, suggested by riastradh
 1.18 31-May-2017  maya The previous change might actually be less generic.
prepend by _MAKE, to be sure.
 1.17 24-Apr-2012  sjg Var* are generally very liberal with memory, with the expectation
that none of it persists for long.
This isn't always true - for example a long running .for loop.

Buf_DestroyCompact() is used by Var_Subst(), rather than Buf_Destroy().
If it looks like we can save BUF_COMPACT_LIMIT (128) or more bytes,
call realloc. This can reduce memory consumption by about 20%
Setting BUF_COMPACT_LIMIT to 0 dissables this.
 1.16 17-Jan-2009  dsl branches: 1.16.8;
__predict_false() isn't defined if we aren't netbsd, stub out.
 1.15 17-Jan-2009  dsl Change 'Buffer' so that it is the actual struct, not a pointer to it.
Saves having to malloc/free a fixed size structure.
Buf_Init() now takes ptr to Buffer to initialiase.
Change Buf_Destroy() to return ptr to string when not freed.
Remove large number of casts to (Byte) and (Byte *) - 'Byte' is 'char' here.
Buf_AddByte[s] guarantees that the data is 0 termininated, so never add '\0'.
Keep 'count' not 'left' and 'inPtr', code is simplier with only one update.
Fix fallou, no functional change.
 1.14 20-Dec-2008  dsl A lot of code assumes that the pointer returned by Buf_GetAll() is malloced.
Replace Buf_Discard() with Buf_Empty() since the former might leave the
'outPtr != buffer' and the only caller wanted all the data discared.
Remove 'outPtr' now that it always equals 'buffer'.
The assumption about Buf_GetAll()is now guaranteed by design.
 1.13 22-Nov-2008  dsl Convert Buf_AddByte(0 to a more normal do { ... } while (0) form.
 1.12 15-Feb-2008  christos back all changes out until I fix it properly.
 1.11 14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.10 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.9 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.8 15-Sep-1999  mycroft Nuke Buf_{G,Ung}etByte{,s}(), since they aren't used, and make BufExpand do
power-of-2 allocation.
 1.7 31-Dec-1996  christos Use only integral types in procedure arguments.
 1.6 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.5 14-Jun-1995  christos branches: 1.5.6;
- $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.4 06-Jun-1994  jtc Fixes from Christos Zoulas, who used purify, objectcenter and testcenter
to find memory leaks and illegal memory accesses.
 1.3 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.6.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.16.8.1 23-May-2012  yamt sync with head.
 1.268 06-Jul-2025  rillig make: clean up
 1.267 13-Jun-2025  rillig make: add on-demand inter-process stack traces

When debugging a build that heavily uses nested calls to sub-makes, the
chain of calls is useful to quickly assess the situation. If explicitly
requested, include the actions from any parent processes in the stack
traces.

Reviewed by: sjg
 1.266 18-May-2025  rillig make: rename variables, remove now-redundant comments
 1.265 03-May-2025  rillig make: miscellaneous cleanups
 1.264 22-Apr-2025  rillig make: clean up

Replace 'unsigned int' with simply 'unsigned'.

In compat.c, skipping whitespace is not needed, as the loop above
already skips it.

In job.c, remove the unused header <sys/file.h>.

Inline the TMPPAT macro, as it is only needed in a single place.
 1.263 22-Apr-2025  rillig make: move struct Job from job.h to job.c

The content of this struct is an implementation detail, and other parts
of make only need to access very few parts of it.
 1.262 19-Jan-2025  rillig make: fix code coverage counts

See tests/usr.bin/gcov/t_gcov.sh.
 1.261 20-Jul-2024  rillig make: don't run erroneous commands in compat mode

When there is a parse or evaluation error in an expression that becomes
part of the command, don't run that command, as the result of the failed
evaluation typically contains garbage characters. Skip the remaining
commands from that target as well, as they may depend on the erroneous
command.
 1.260 11-Jul-2024  sjg Compat_RunCommand use tempfile if cmd too big

Extract the logic recently added to Cmd_Exec to handle
long commands via temp file to Cmd_Argv,
so it can also be leveraged by Compat_RunCommand

Reviewed by: christos
 1.259 15-Jun-2024  rillig branches: 1.259.2;
make: clean up collection of context information for error messages
 1.258 02-Jun-2024  rillig make: sync VarEvalMode constant names with their debug log names
 1.257 25-May-2024  rillig make: fix memory leak for command strings
 1.256 25-May-2024  rillig make: minimize local variables around a vfork call

Passing all relevant values as arguments allows to remove the 'volatile'
qualifiers.
 1.255 20-Apr-2024  rillig make: provide more context information for parse/evaluate errors
 1.254 10-Mar-2024  sjg make: record exit status in GNode

SetErrorVars can now set .ERROR_EXIT which allows
a .ERROR target to ignore the case of .ERROR_EXIT == 6
which means failure happened elsewhere.

Reviewed by:
 1.253 01-Mar-2024  sjg make: export target scope values

Pass target scope to Var_ReexportVars so that a target process
will see the correct values in its env.
We must then mark any Global scope variable as unexported
so targets without local value get the Global one.
 1.252 05-Jan-2024  rillig make: miscellaneous cleanups
 1.251 26-Dec-2023  sjg Move fflush to a point to catch all cases.
 1.250 26-Dec-2023  sjg make: fix order of output in compat mode

Ensure that make's output is correctly ordered with the output of the
target's commands, even when the output does not go to a terminal.

Reviewed by: rillig
 1.249 24-Dec-2023  sjg Compat_RunCommand call Shell_Init is shellPath is NULL

Since .SHELL is potentially used in compat mode as well,
the man page description should not imply it is only used in jobs mode.

Remove path="sh" from shell-sh unit-test - and it would have detected
this bug.

Reviewed by: rillig
 1.248 19-Dec-2023  rillig make: clean up comments

No binary change, except for line numbers in assertions.
 1.247 04-May-2023  sjg Compat_RunCommand mark bp volatile

gcc 4.8.5 (NetBSD 7.2) gets upset about bp.
 1.246 18-Mar-2023  sjg make: handle .PHONY consitently on interrupt

JobDeleteTarget skips .PHONY targets
CompatDeleteTarget should do the same

This addresses https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=269663
 1.245 14-Feb-2023  rillig make: clean up calls to Var_Subst

None of the calls to Var_Subst used the return value, and the return
value was always VPR_OK.

No functional change.
 1.244 17-Jan-2023  christos Accept whitespace between command specifiers @+- like gmake does. New binutils
does this.
 1.243 07-Dec-2022  rillig make: clean up comments
 1.242 10-Oct-2022  rillig make: change return type of unlink_file back to int

As unlink_file is a wrapper around unlink, use the same encoding for the
possible return values as in the wrapped function. This consistency is
more important than expressing all possible return values in the return
type 'bool'.

https://mail-index.netbsd.org/tech-toolchain/2022/10/06/msg004155.html

No functional change.
 1.241 17-Aug-2022  rillig make: fix exit status for '-q' (since 1994)
 1.240 07-May-2022  rillig make: allow to randomize build order of targets

In complex dependency structures, when a build fails, a probable cause
is a missing dependency declaration between some files. In compat mode,
the build order is deterministic, in jobs mode, it is somewhat
deterministic. To explore more edge cases, add the line ".MAKE.MODE +=
randomize-targets" somewhere in the makefile.

Fixes PR bin/45226 by riastradh. Reviewed by christos.
 1.239 07-May-2022  rillig make: rename Compat_Run to Compat_MakeAll

No functional change.
 1.238 22-Jan-2022  rillig make: add missing newline after "cannot continue" message

It was wrong of Parse_File to output an unfinished line and hope for
some other code to finish it. As demonstrated in the test, PrintOnError
did not do that in the case of additional debug output.

To keep the overall behavior as close as possible to before, the other
callers of PrintOnError now have to pass the newline themselves. Passing
strings that start with newlines but don't end with them looked
suspicious anyway.
 1.237 08-Jan-2022  rillig make: remove redundant braces

No binary change, except for assertion line numbers.
 1.236 07-Jan-2022  rillig make: rename and inline Targ_Precious

No functional change.
 1.235 27-Dec-2021  rillig make: remove unnecessary words from command line options

Several years ago, the command line options were individual global
variables. The global variable could therefore not be named 'silent'
since that would have conflicted with local variables of the same name.
After moving the global variable to the namespace 'struct CmdOpts',
there is no conflict anymore.

There doesn't seem to be any risk of naming collisions for the names
'touch' and 'query'.

No functional change.
 1.234 27-Dec-2021  rillig make: rename eunlink to unlink_file

The name eunlink suggested a relation with the similarly named functions
emalloc or esnprintf, but that was misleading. Instead, unlink_file
works like unlink, except that it refuses to remove an empty directory.

No functional change.
 1.233 15-Dec-2021  rillig make: amend leftover cleanups from the previous commits

No functional change.
 1.232 15-Dec-2021  rillig make: format comments according to /usr/share/misc/style

Assisted by indent(1), with manual corrections due to its many remaining
bugs.

No functional change.
 1.231 15-Dec-2021  rillig make: use consistent indentation for statements and continuations

No binary change, except for line numbers in assertions in suff.c.
 1.230 15-Dec-2021  rillig make: change return type of Compat_RunCommand from int to bool

The documentation was wrong before since status was not restricted to
only 0 or 1.

No functional change.
 1.229 28-Nov-2021  rillig make: fix a few lint warnings about type mismatch in enum comparisons

These warnings were triggered with the lint flag '-e', which enables
additional checks on enums. This check would have detected the type
mismatch from the previous commit.

The check has a few strange warnings though, complaining about
initialization of 'unsigned long' with 'unsigned long', so don't enable
it for the official builds.

No functional change.
 1.228 28-Nov-2021  rillig make: convert GNodeFlags from enum into bit-fields

Now that Enum_ToString is implemented for each type separately, it's
easy to convert them to bit-fields. This gets rid of the magic numbers
12 for CYCLE and 13 for DONECYCLE that left a suspicious gap in the
numbers. This gap was not needed since the code didn't make use of the
relative ordering of the enum constants.

The effects of this conversion are fewer capital letters in the code,
smaller scope for the GNode flags, and clearer code especially when
setting a flag back to false.

One strange thing is that GCC 10.3.0 doesn't optimize GNodeFlags_IsNone
to an single bitmasking instruction, at least on x86_64. Instead it
generates a testb instruction for each of the flags, even loading bit 8
separately from the others. Clang 12.0.1 knows this optimization
though and generates the obvious sequence of movzwl, testl, jz.

No functional change.
 1.227 27-Apr-2021  christos add const
 1.226 04-Apr-2021  rillig make: rename a few functions to be more descriptive

No functional change.
 1.225 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.224 05-Feb-2021  rillig make: in the Var_ functions, move the scope to the front

This change provides for a more natural reading order in the code.
Placing the scope first makes it immediately clear in which context the
remaining parameters are interpreted.

No functional change.
 1.223 04-Feb-2021  rillig make: rename context and ctxt to scope

This continues the previous commit, in which VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE were renamed.

Renaming the variable 'ctxt' was trivial since that word is used nowhere
else. In the comments though, each occurrence of the word 'context' had
to be checked individually since the word 'context' was not only used
for referring to a variable scope. It is also used to distinguish
different situations where characters are escaped in a certain way
('parsing context') and in a few other expressions.
 1.222 02-Feb-2021  rillig make: when exiting due to an error, print graph information

The code now does what the manual page has been promising since at least
1993.
 1.221 01-Feb-2021  rillig make: always use vfork, never fork

Before compat.c 1.217, job.c 1.390 and main.c 1.504 from 2020-12-27, the
exported make variables were exported from each freshly forked child
process. There was no practical difference though between exporting the
variables from the parent process or the child process since these two
processes share the same address space, except that the forked process
is very limited in what it may actually do. This limitation was
violated on a regular basis.

When an exported variable referred to a variable that used the :sh
variable modifier, this led to a fork from within vfork, which is not
allowed. Since 2020-12-27, exporting the variables is done from the
main process, which prevents this situation from ever occurring.

Since that day, there is no need anymore to distinguish between vfork
and fork, which removes any need for the macro.
 1.220 19-Jan-2021  rillig make(1): remove do-not-format markers from comments

These markers had been used inconsistently. Furthermore the source code
had not been formatted automatically before 2020 at all, otherwise there
wouldn't have been any trailing whitespace left.
 1.219 10-Jan-2021  rillig make(1): consistently use boolean expressions in conditions

Most of the make code already followed the style of explicitly writing
(ptr != NULL) instead of the shorter (ptr) in conditions.

The remaining 50 instances have been found by an experimental,
unpublished check in lint(1) that treats bool expressions as
incompatible to any other scalar type, just as in Java, C#, Pascal and
several other languages.

The only unsafe operation on Boolean that is left over is (flags &
FLAG), for an enum implementing a bit set. If Boolean is an ordinary
integer type (the default), some high bits may get lost. But if Boolean
is the same as _Bool (by compiling with -DUSE_C99_BOOLEAN), C99 6.3.1.2
defines that a conversion from any scalar to the type _Bool acts as a
comparison to 0, which cannot lose any bits.
 1.218 30-Dec-2020  rillig make(1): format multi-line comments
 1.217 27-Dec-2020  rillig make(1): re-export variables from the actual make process

Since make uses vfork if available, re-exporting the variables happens
in the address space of the main process anyway, so there is no point in
mentioning anything about "our client process" anywhere.
 1.216 20-Dec-2020  rillig make(1): omit linear search for command in Compat_RunCommand
 1.215 13-Dec-2020  rillig make(1): fix .ERROR_TARGET in compat -k mode (since 2010-04-07)
 1.214 13-Dec-2020  rillig make(1): document variable expansion in the .END node
 1.213 13-Dec-2020  christos fix comment
 1.212 13-Dec-2020  rillig make(1): add comments for strange error handling in Compat_Run
 1.211 13-Dec-2020  rillig make(1): extract InitSignals from Compat_Run
 1.210 13-Dec-2020  rillig make(1): extract MakeBeginNode from Compat_Run

The comment "execute the commands" had once been correct but not
anymore. Since a few years, not only the commands of the .BEGIN and
.END nodes are executed, instead the nodes are made as usual, including
their dependencies.
 1.209 13-Dec-2020  rillig make(1): extract UseShell from Compat_RunCommand
 1.208 12-Dec-2020  rillig make(1): rename Var_ExportVars to Var_ReexportVars
 1.207 12-Dec-2020  rillig make(1): remove const from function parameters

These have been left-overs from refactoring, when these pieces were
extracted to separate functions.
 1.206 12-Dec-2020  rillig make(1): inline Targ_Ignore and Targ_Silent

Each of these functions was only used 2 times, and each of these calls
used a different part of the whole expression.
 1.205 10-Dec-2020  rillig make(1): split JobFlags into separate fields

Having all these flags in a single bitmask makes it harder to see where
exactly they can possibly be used since their state could also be
modified using the unsuspicious job->flags = 0. Using individual names
just leaves the single memset, and that is only used during
initialization.
 1.204 07-Dec-2020  rillig make(1): fix wrong exit status for multiple failed main targets
 1.203 07-Dec-2020  rillig make(1): add test for wrong exit status 0 after failed targets with -k
 1.202 07-Dec-2020  rillig make(1): merge local variables in Compat_Run
 1.201 07-Dec-2020  rillig make(1): clean up Compat_Run

Now that errors in the main targets and in their dependencies have the
same effect on the .END node and its dependencies, the two variables can
be merged.
 1.200 07-Dec-2020  rillig make(1): don't make .END if the main targets already failed

This only applies to -k mode. By default, make exits earlier and skips
the .END node as well if an error occurs.
 1.199 07-Dec-2020  rillig make(1): fix exit status in -k mode if a dependency fails

Whether in -k mode or not, the exit status tells whether all requested
targets were made or not. If a dependency could not be made, the main
target was not made as well, therefore the exit status must be nonzero
in such a case.

This part of the code lacked proper unit tests until today. The unit
test deptgt-end-fail.mk is compatible with make>=2003 at least, allowing
to compare the output over time.

In 2003, in the ok-ok-ok-ok case, "Making all from all-dep." was printed
twice in a row, for whatever reason ... (40 minutes later) ... If I had
just made the two commands for 'all' and '.END' more distinguishable.
Back in 2003, the local variables for .END had not been initialized,
instead the .END node was run with the local variables of the last
preceding node. In this case, that node was 'all', therefore ${.TARGET}
had obviously expanded to 'all'.

Somewhere in 2004, the shell commands were no longer run with the -e
flag, which resulted in the "exit status $?" line to be printed in cases
that had stopped early before.

Somewhere in 2005, the local variables for the .END node had been fixed.
The variable ${.TARGET} now had the value '.END', just as expected. In
addition, the dependencies for the .END node were made, although without
getting their proper local variables. This resulted in the output
"Making out of nothing" instead of the expected "Making end-dep out of
nothing".

Still in 2005, in the test case "all=ok all-dep=ok end=ok end-dep=ERR",
the error code of the failed 'end-dep' was first reported as "*** Error
code 1 (continuing)". To compensate for this improvement, a new bug had
been introduced. The test case "all=ok all-dep=ok end=ERR end-dep=ERR"
had properly exited with status 1 on 2005-01-01, but on 2006-01-01 it
exited with status 0, thereby ignoring errors in the .END node.

Somewhere in 2008, some of the error messages (but not all) were
directed to stderr instead of stdout. The actual output stayed the same
though.

Somewhere in 2011, the dependency of the .END node got its own local
variables, and ${.TARGET} now expanded to 'end-dep', as expected.

Somewhere in 2016, the two empty lines between the "*** Error code 1
(continuing)" and the "Stop." got compressed into a single empty line.

On 2020-12-07 (that is, today), the exit status 1 has been restored in
the error cases, after it had been wrong for at least 14 years.
 1.198 06-Dec-2020  rillig make(1): refactor Compat_Run to show the error condition more clearly

This refactoring allows to gradually change the conditions for the
"Stop." error message, to demonstrate which cases are affected by each
tiny change.
 1.197 06-Dec-2020  rillig make(1): refactor error handling in Compat_Run

This is in preparation for the upcoming bug fixes.
 1.196 28-Nov-2020  rillig make(1): reduce pointer indirection for GNode.implicitParents
 1.195 28-Nov-2020  rillig make(1): reduce pointer indirection for GNode.cohorts
 1.194 28-Nov-2020  rillig make(1): reduce memory allocation for GNode.parents and GNode.children
 1.193 28-Nov-2020  rillig make(1): remove pointer indirection from GNode.commands

Just to save a few memory allocations. No noticeable effect on the
performance though.
 1.192 24-Nov-2020  rillig make(1): fix error handling for .BEGIN dependency in -k mode
 1.191 24-Nov-2020  rillig make(1): fix error handling for dependency of .END in -k mode

Fix one bug, find 4 new ones. All these bugs have been around since
2005-05-08, when dependencies on the .BEGIN, .END and .INTERRUPT nodes
were implemented. Before that, checking gn->made == ERROR was
appropriate, but adding the dependencies made ABORTED a new possible
error value from Compat_Make.
 1.190 24-Nov-2020  rillig make(1): document the enum GNodeMade

Given only the state names and their individual documentation, it is
hard to see the full picture. To make this easier, provide typical
examples of the ways that a GNode takes through these states.
 1.189 24-Nov-2020  rillig make(1): move documentation about the result of Compat_Make
 1.188 24-Nov-2020  rillig make(1): fix missing "Stop." after failed .END node in -k mode
 1.187 23-Nov-2020  rillig make(1): use comparisons in boolean expressions

The generated code stays exactly the same.
 1.186 23-Nov-2020  rillig make(1): indent compat.c with tabs instead of spaces
 1.185 23-Nov-2020  rillig make(1): split Compat_Make into smaller functions
 1.184 23-Nov-2020  rillig make(1): extract DebugFailedTarget from Compat_RunCommand
 1.183 15-Nov-2020  rillig make(1): clean up coding style in compat, parse, suff
 1.182 14-Nov-2020  rillig make(1): clean up Job_Touch

Several more outdated comments were removed. To compensate for that,
several new comments mark places where errors are not properly
propagated.
 1.181 08-Nov-2020  rillig make(1): rename Make_OODate to GNode_IsOODate

It doesn't matter which of the make modules is in charge of determining
whether a node is out-of-date. Therefore, remove the module name from
the function name.
 1.180 08-Nov-2020  rillig make(1): rename Make_TimeStamp to GNode_UpdateYoungestChild
 1.179 07-Nov-2020  rillig make(1): clean up Compat_Make
 1.178 07-Nov-2020  rillig make(1): clean up Compat_RunCommand
 1.177 07-Nov-2020  rillig make(1): replace switch with if-else chain in Compat_RunCommand
 1.176 07-Nov-2020  rillig make(1): omit redundant bitwise or in Compat_Make
 1.175 07-Nov-2020  rillig make(1): clean up code stylistically

* Replace character literal 0 with '\0'.
* Replace pointer literal 0 with NULL.
* Remove redundant parentheses.
* Parentheses in multi-line conditions are not redundant at the
beginning of a line.
* Replace a few !ptr with ptr == NULL.
* Replace a few ptr with ptr != NULL.
* Replace (expr & mask) == 0 with !(expr & mask).
* Remove redundant braces for blocks in cases where the generated code
stays the same. (Assertions further down in the code would get
different line numbers.)
* Rename parameters in CondParser_String to reflect the data flow.
* Replace #ifdef notdef with #if 0.

The generated code stays exactly the same, at least with GCC 5.5.0 on
NetBSD 8.0 amd64 using the default configuration.
 1.174 02-Nov-2020  rillig make(1): clean up CompatDeleteTarget and CompatInterrupt
 1.173 01-Nov-2020  rillig make(1): negate NoExecute to GNode_ShouldExecute
 1.172 31-Oct-2020  rillig make(1): remove unused code from needshell

Since usr.bin/xinstall no longer uses this code, there is no need to
keep the second parameter.
 1.171 31-Oct-2020  rillig make(1): do not look up local variables like .TARGET anywhere else

Nobody defines a global variable named .TARGET since that would have
many unpredictable effects, applying to all targets at once.

Nobody defines an environment variable named .TARGET since that's
against the naming conventions for environment variables and would have
the same effect.

Because of this, there is no point looking up the variables that are
local to a GNode anywhere else. This means they cannot come from the
environment and thus their value doesn't need to be freed after use,
which makes the code simpler.

The newly added accessor functions in make.h refer to external
functions, but since that header is not used anywhere outside of
usr.bin/make, it doesn't matter. Between 2020-08-25 and 2020-10-30,
that header had been referenced by usr.bin/xinstall.
 1.170 30-Oct-2020  rillig make(1): change char * to void * in Var_Value

The only purpose of the parameter freeIt is to free the memory
associated with the return value. To do this, no pointer arithmetic is
needed. Therefore, change to a void pointer, to catch accidental use of
that pointer.
 1.169 26-Oct-2020  rillig make(1): group the command line options and arguments

By having a single struct that holds all command line options and
arguments, it is easy to see in the code when such a command line
argument is modified. It also cleans up the namespace since the command
line options don't follow a common naming style. Having them in a
struct also means that there is a single place for putting the
documentation, not two as before.

The struct also suggests to extract the initialization code out of main,
which is still too large, having more than 400 lines of code and
covering far too many topics.
 1.168 24-Oct-2020  rillig make(1): clean up code style in compat.c
 1.167 23-Oct-2020  rillig make(1): rename GNode.cmgn to youngestChild

The name is longer than before but also clearer.
 1.166 18-Oct-2020  rillig make(1): replace execError with execDie

All calls to this function were followed by _exit(1).
 1.165 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.164 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.163 05-Oct-2020  rillig make(1): clean up compat.c

Only cosmetic changes, no change of functionality.
 1.162 03-Oct-2020  rillig make(1): clean up #include sections
 1.161 01-Oct-2020  rillig make(1): remove redundant function prototypes
 1.160 01-Oct-2020  rillig make(1): add note about "..." with duplicate shell commands
 1.159 28-Sep-2020  rillig make(1): replace += 1 with ++ and -= 1 with --

Just for visual consistency. The generated code stays exactly the same.
 1.158 28-Sep-2020  rillig make(1): make debug logging simpler

This avoids referring to the debug_file variable in many places where
this implementation detail is not necessary.
 1.157 28-Sep-2020  rillig make(1): make debugging code shorter
 1.156 27-Sep-2020  rillig make(1): normalize whitespace in source code

There is no more space tab. Either only tabs or only spaces or tabs
followed by spaces, but not spaces followed by tabs.
 1.155 27-Sep-2020  rillig make(1): inline Lst_ForEachUntil in Compat_Make

This avoids the extra local function and a few conversions to void
pointers, to gain additional type safety.

The code in Compat_RunCommand does not modify gn->commands structurally,
therefore it does not need the extra complexity of Lst_ForEachUntil. It
does have access to a list node to exactly this list. This list node is
only used to set the command to NULL after processing it, not for
removing the node from the list.
 1.154 27-Sep-2020  rillig make(1): rename local variable in MakeNodes

By convention, list nodes are named ln to distinguish them from GNodes,
which are called gn.
 1.153 27-Sep-2020  rillig make(1): make parameter of Compat_RunCommand const
 1.152 26-Sep-2020  rillig make(1): inline Lst_ForEachUntil in Compat_Make
 1.151 26-Sep-2020  rillig make(1): clean up API for finding and creating GNodes

The previous API had complicated rules for the cases in which the single
function returned NULL or what it did. The flags for that function were
confusing since passing TARG_NOHASH would create a new node even though
TARG_CREATE was not included in that bit mask.

Splitting the function into 3 separate functions avoids this confusion.
It also reveals several places where the complicated API led to
unreachable code. Such code has been removed.
 1.150 24-Sep-2020  rillig make(1): rename Lst_ForEach to Lst_ForEachUntil

Since the callback function returns a terminating condition, this is not
really a foreach loop.

Many of the calls to Lst_ForEachUntil don't make use of the terminating
condition, and several don't modify the list structurally, which means
they don't need this complicated implementation.

In a follow-up commit, Lst_ForEach will be added back with a much
simpler implementation that iterates over the list naively, without a
terminating condition and without taking the iteration state from
Lst_Open/Lst_Next/Lst_Close into account. The migration to this simpler
implementation will be done step by step since each callback function
needs to be examined closely.
 1.149 23-Sep-2020  rillig make(1): fix assertion failure in -j mode with .END node

There had been two separate global variables for the .END node, and in
parallel mode, only the one in jobs.c was initialized.

The code in JobRun heads over to Compat_Make without calling Compat_Run
first, which left the variable ENDNode uninitialized.
 1.148 22-Sep-2020  rillig make(1): prepare Var_Subst for proper error handling

Returning a VarParseResult instead of a string makes it possible to let
the error bubble up, until it reaches the main expression.
 1.147 22-Sep-2020  rillig make(1): use fine-grained type names for lists and their nodes

This is only intended to help the human reader. There is no additional
type safety yet.
 1.146 21-Sep-2020  rillig make(1): add specific typedefs for lists

These typedefs are only intended to help human readers, they do not
provide any type-safety. They also make the pointers explicit, which
had been hidden before by the typedef for Lst and LstNode. Typing a few
'*' is less work than finding out which of the many types are pointers
and which aren't.

In meta.c, the variable "ln" served two completely different purposes,
which have been split again. Register allocation is the job of the
compiler, not of the human source code reader.
 1.145 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.144 13-Sep-2020  rillig make(1): reduce indentation in Compat_RunCommand

The while (1) had been there since the initial import on 1993-03-21, and
in all that time there had never been a good reason for having it.
 1.143 12-Sep-2020  rillig make(1): fix prototype of Compat_Make
 1.142 12-Sep-2020  rillig make(1): fix name and prototype of Compat_RunCommand

By convention, exported identifiers are written with underscore.

The prototype of an exported function must not use void * just because
it is used in Lst_ForEach. This is an implementation detail and must
remain so.
 1.141 12-Sep-2020  rillig make(1): fix inconsistent code indentation
 1.140 11-Sep-2020  rillig make(1): add wrappers around ctype.h functions

This avoids casting the argument to unsigned char, and to cast the
result of toupper/tolower back to char.
 1.139 30-Aug-2020  rillig make(1): remove unreachable code from CompatRunCommand

At the point where Str_Words is called, the string contains no
meta-characters. This means that the parameter "expand" in Str_Words is
never looked at. This in turn means that this parameter can be set to
FALSE, thereby making it impossible that Str_Words returns NULL.
 1.138 30-Aug-2020  rillig make(1): replace brk_string with Str_Words

The API is much simpler, and there is less detail that is exposed by
default and fewer punctuation to type on the caller's side. To see that
there is some memory to be freed, one would have to look into the
struct. Having part of the return value as the actual return value and
the rest in output parameters was unnecessarily asymmetrical.
 1.137 30-Aug-2020  rillig make(1): rename GNode.iParents to implicitParents

The i alone was too ambiguous. It could have meant ignore, implicit,
interactive, and probably many more.
 1.136 30-Aug-2020  rillig make(1): rename Lst_Memeber to Lst_FindDatum

The new name nicely aligns with Lst_Find and Lst_FindFrom.
 1.135 29-Aug-2020  rillig make(1): fix assertion failure for .SUFFIXES in archives

This occurred in the posix1.mk test, even though it is disabled in
unit-tests. But in tests/usr.bin/make it still runs. There, it should
have produced an "expected failure" but crashed instead.

The archive-suffix test is the stripped-down version of the posix1 test.
 1.134 29-Aug-2020  rillig make(1): clean up documentation for CompatInterrupt and Compat_Run
 1.133 29-Aug-2020  rillig make(1): add another Boolean variant to check during development
 1.132 28-Aug-2020  rillig make(1): remove trailing 'S' from names of Lst functions

The migration from null-passing Lst functions to argument-checking Lst
functions is completed.

There were 2 surprises: The targets list may be NULL, and in Dir_AddDir,
the path may be NULL. The latter case is especially surprising since
that function turns into an almost-nop in that case. This is another
case where probably 2 independent functions have been squeezed into a
single function. This may be improved in a follow-up commit.

All other lists were fine. They were always defined and thus didn't
need much work.
 1.131 27-Aug-2020  rillig make(1): migrate Lst_IsEmpty to Lst_IsEmptyS
 1.130 27-Aug-2020  rillig make(1): migrate Lst_ForEach to Lst_ForEachS

Most lists are always valid. Only the "targets" variable may be null in
some cases, probably.
 1.129 23-Aug-2020  rillig make(1): make compat.c ready for WARNS=6
 1.128 23-Aug-2020  rillig make(1): make brk_string return size_t for the number of words
 1.127 23-Aug-2020  rillig make(1): handle special case of a list containing null pointers

GNode.commands is the only place in make where a list can contain null
pointers. That's unexpected, and memory management in CompatRunCommand
looks suspicous enough to warrant extensive documentation.
 1.126 22-Aug-2020  rillig make(1): clean up headers

Remove redundant headers that are already included by "make.h".
Make <assert.h> available to all compilation units that use "make.h".
 1.125 22-Aug-2020  rillig make(1): replace segmentation fault with failed assertion

To reproduce: ./make -r -C unit-tests -f sh-dots.mk -j1

Without -j1, the test succeeds.
 1.124 22-Aug-2020  rillig make(1): require argument of Lst_Member to be non-null

Since the lists don't contain null pointers, it doesn't make sense to
search for a null pointer. All calls but one already had obviously
non-null arguments. The one remaining call using targ->suff has been
guarded for now.

The code for Lst_Member became much simpler than before. Partly because
the old code had an extra condition for circular lists, which are not
used by make.
 1.123 22-Aug-2020  rillig make(1): convert Lst_Enqueue and Lst_Dequeue to nonnull variants

Except for once instance in parse.c, the usage pattern for Lst_Dequeue
was to first test whether the list is empty. This pattern allowed the
implementation of Lst_Dequeue to become simpler since the null check is
not needed anymore.

The calls to Lst_Enqueue never pass an invalid list or a null pointer,
therefore making them strict was trivial.
 1.122 22-Aug-2020  rillig make(1): replace "(void)Lst_AtEnd" with stricter "Lst_AppendS"

This change ensures that there is actually something added to the list.
Lst_AtEnd had silently skipped the addition if the list was invalid
(null pointer), which was not intended in these cases. The "(void)" is
assumed to mean "I know that this cannot fail", while it could also mean
"I don't care whether something actually happened".

Running "./build.sh -j6 tools" still succeeds after this change,
therefore chances are very low that this change breaks anything. If
there is any change, it's an obvious assertion failure. There is no
silent change in behavior though.
 1.121 22-Aug-2020  rillig make(1): remove constant variable

The variable "local" had been TRUE for at least the last 28 years.

No change in binary size, as expected.
 1.120 22-Aug-2020  rillig make(1): remove form feeds in the code
 1.119 21-Aug-2020  rillig make(1): make list library code stricter

Up to now, the list library didn't distinguish between programming
mistakes (violations of invariants, illegal parameter values) and
actually interesting situations like "element not found in list".

The current code contains many branches for conditions that are neither
exercised by the unit tests nor by real-world usage. There is no point
in keeping this unnecessary code.

The list functions will be migrated from their lenient variants to the
stricter variants in small parts, each function getting the S suffix
when it is made strict, to avoid any confusion about how strict a
particular function is. When all functions have been migrated, they
will be renamed back to their original names.

While here, the comments of the functions are cleaned up since they
mention irrelevant implementation details in the API comments, as well
as "side effects" that are really main effects.
 1.118 01-Aug-2020  rillig make(1): use consistent indentation in source code

Tabs for multiples of 8, then spaces.

The usage string has been kept as-is since the spaces there are
indentional and do influence the output.
 1.117 01-Aug-2020  rillig make(1): avoid calls to free(3) in the common case of a NULL pointer
 1.116 01-Aug-2020  rillig make(1): let Var_Value return a const char *

The return value must not be modified anyway, so let the compiler check
this for free.
 1.115 28-Jul-2020  rillig make(1): remove dead code from Var_Subst

The first parameter from Var_Subst had been a literal NULL in all cases.
These have been fixed using this command:

sed -i 's|Var_Subst(NULL, |Var_Subst(|' *.c

The one remaining case was not found because the "NULL," was followed by
a line break instead of a space.

The removed code probably wouldn't have worked as expected anyway.
Expanding a single variable to a literal string would have led to
unexpected behavior for cases like ${VAR:M${pattern}}, in case pattern
would contain an unescaped ':' itself.
 1.114 19-Jul-2020  rillig make(1): rename Varf_Flags to VarEvalFlags

In var.c there are lots of different flag types. To make any accidental
mixture obvious, each flag group gets its own prefix.

The only flag group that is visible outside of var.c is concerned with
evaluating variables, therefore the "e", which replaces the former "f"
that probably just meant "flag".
 1.113 03-Jul-2020  rillig make(1): remove trailing whitespace
 1.112 03-Jul-2020  rillig make(1): remove redundant parentheses around return values
 1.111 02-Jul-2020  rillig make(1): remove useless parameter from Var_Set

The enum corresponding to this int parameter is only defined in var.c,
which makes it impractical for the outside to set this parameter to
anything but 0.

On x86_64, this reduces the size of the resulting executable by 5 kB.
 1.110 19-Jan-2020  riastradh Reimplement make(1) meta mode without filemon(4).
 1.109 19-Dec-2019  maxv Revert the filemon removal in bmake, as pointed out by maya we do care
about not introducing divergence with FreeBSD, and the cost of unused
is acceptable here.
 1.108 18-Dec-2019  maxv Retire filemon, discussed on tech-kern@.
 1.107 20-Jul-2017  sjg branches: 1.107.4;
Make compat.c handle SIGINT etc more like job.c

If there is a running child, pass the signal on, and
wait for it to exit before we self-terminate.

Reviewed by: christos
 1.106 26-Aug-2016  dholland Add a .DELETE_ON_ERROR: magic target that causes *failed* targets as
well as *interrupted* targets to be deleted. The name and behavior of
the variable matches gmake.

Also fix a glitch in newline output on error in compat mode that I
discovered while doing it.

Closes PR 51376.
 1.105 12-May-2016  sjg Propagate errors from filemon.

If we encounter errors producing a .meta file,
we should not consider the target completed successfully.
 1.104 18-Feb-2016  christos Collapse the 3 boolean parameter to 1 flags parameter. No functional change.
 1.103 17-Jan-2016  christos remove free NULL checks (Tilman Sauerbeck)
 1.102 09-Jan-2016  christos Preserve $$ in := assignments..

FOO=\$$CRAP
BAR:=${FOO}

all:
echo ${FOO}
echo ${BAR}
 1.101 11-Oct-2015  sjg Add Boolean wantit to Var_Parse and Var_Subst

wantit will be FALSE when we are just consuming to discard
in which case we skip "expensive" things like Cmd_Exec.

Reviewed by: christos
 1.100 19-Jun-2015  christos make needshell customizable, so that xinstall can use it.
 1.99 19-Jun-2015  christos create needshell so we don't scan the string multiple times.
 1.98 19-Jun-2015  mlelstv Adjust metachar handling to previous behaviour:
- space and tab are no shell metachars, remove them from generic
metachar function
- add space and tab as to-be-quoted characters for :Q modifier
- add = and : as characters that require command handling by the shell
 1.97 17-Jun-2015  christos Centralize the "is a meta char" test, instead of using two different arrays.
 1.96 07-Sep-2014  joerg Revert all make changes except the unit tests to the state of three
weeks ago. Individual changes can be reapplied after review.
 1.95 23-Aug-2014  christos PR/46096: Jarmo Jaakkola: fix many problems with dependencies (PR 49086)

Quite extensive rewrite of the Suff module. Some ripple effects into
Parse and Targ modules too.

Dependency searches in general were made to honor explicit rules so
implicit and explicit sources are no longer applied on targets that
do not invoke a transformation rule.

Archive member dependency search was rewritten. Explicit rules now
work properly and $(.TARGET) is set correctly. POSIX semantics for
lib(member.o) and .s1.a rules are supported.

.SUFFIXES list maintenance was rewritten so that scanning of existing
rules works when suffixes are added and that clearing the suffix list
removes single suffix rules too. Transformation rule nodes are now
mixed with regular nodes so they are available as regular targets too
if needed (especially after the known suffixes are cleared).

The .NULL target was documented in the manual page, especially to
warn against using it when a single suffix rule would work.
A deprecation warning was also added to the manual and make also
warns the user if it encounters .NULL.

Search for suffix rules no longer allows the explicit dependencies
to override the selected transformation rule. A check is made in
the search that the transformation that would be tried does not
already exist in the chain. This prevents getting stuck in an infinite
loop under specific circumstances. Local variables are now set
before node's children are expanded so dynamic sources work in
multi-stage transformations. Make_HandleUse() no longer expands
the added children for transformation nodes, preventing triple
expansion and allowing the Suff module to properly postpone their
expansion until proper values are set for the local variables.

Directory prefix is no longer removed from $(.PREFIX) if the target
is found via directory search.

The last rule defined is now used instead of the first one (POSIX
requirement) in case a rule is defined multiple times. Everything
defined in the first instance is undone, but things added "globally"
are honored. To implement this, each node tracks attribute bits
which have been set by special targets (global) instead of special
sources (local). They also track dependencies that were added by
a rule with commands (local) instead of rule with no commands (global).

New attribute, OP_FROM_SYS_MK is introduced. It is set on all targets
found in system makefiles so that they are not eligible to become
the main target. We cannot just set OP_NOTMAIN because it is one of
the attributes inherited from transformation and .USE rules and would
make any eligible target that uses a built-in inference rule ineligible.

The $(.IMPSRC) local variable now works like in gmake: it is set to
the first prerequisite for explicit rules. For implicit rules it
is still the implied source.

The manual page is improved regarding the fixed features. Test cases
for the fixed problems are added.

Other improvements in the Suff module include:
- better debug messages for transformation rule search (length of
the chain is now visualized by indentation)
- Suff structures are created, destroyed and moved around by a set
of maintenance functions so their reference counts are easier
to track (this also gets rid of a lot of code duplication)
- some unreasonably long functions were split into smaller ones
- many local variables had their names changed to describe their
purpose instead of their type
 1.94 03-Jan-2014  sjg Treat '~' as a meta char requiring a shell.
Patch from Steve McIntyre 93sam at debian.org

Reviewed by: christos
 1.93 02-Sep-2013  sjg Do not apply shellErrFlag unless errCheck is true.
 1.92 05-Jul-2013  sjg If commandShell hasErrCtl is true, set shellErrFlag for use by
CompatRunCommand() so that behavior in jobs and compat mode
remains consistent.
 1.91 25-Jan-2013  sjg Remove Check_Cwd - it is no longer needed.
 1.90 07-Oct-2012  sjg Treat empty commands same as jobs mode
 1.89 10-Jun-2012  wiz branches: 1.89.2;
Remove a __dead for an undead function (clang errors out otherwise).
 1.88 05-Jun-2012  sjg kill(2) is more appropriate and more portable than raise(3)
 1.87 05-Jun-2012  sjg Re-raising SIGINT etc, after running .INTERRUPT
provides much more reliable shutdown on some systems.
Based on CompatInterrupt in FreeBSD's make.
 1.86 30-May-2012  sjg An empty command is quietly ignored in jobs mode, but causes a failure
in compat mode. Just skip it.
 1.85 15-May-2012  seanb - Use _exit() instead of exit() in signal handler since
the latter isn't signal safe.
 1.84 16-Sep-2011  joerg branches: 1.84.2;
Use __dead consistently. If it doesn't exist, define it away.
 1.83 14-Aug-2011  christos - remove gcc-4.5 warnings
- simplify job printing code
- document non-literal format strings
 1.82 25-Nov-2010  christos Instead of keeping around the mtime of the youngest child, keep a pointer
to it, so that we can print it when we do the out of date determination.
 1.81 13-Sep-2010  sjg Add meta.c which implements "meta" mode for make.
In this mode, a .meta file is created for each target, capturing
the expanded commands used, any command output, and if filemon(9)
is available, a record of system calls which are of interest.
Not enabled unless USE_META=yes is set when building make.
Also, if FILEMON_H exists, meta.c will be compiled to use filemon(9).
 1.80 07-Aug-2010  sjg wait[pid]() is called in several places.
If we encounter an error and run the .ERROR target, we may
reap a pid which jobs is waiting for. Ensure that we
cleanup so that make isn't left waiting for an already
deceased child.
 1.79 03-Jun-2010  sjg We have required sigaction() for quite a while.
Use bmake_signal() - a wrapper around sigaction()
rather than signal() to ensure that signals are handled
consistently.
 1.78 23-Apr-2010  sjg On darwin at least, vfork() fails in child of vfork().
It probably shouldn't work anyway, so avoid this.
We use the macro vFork() - a function seems to cause problems
and is unnecessary overhead.
 1.77 07-Apr-2010  sjg Add:

.error "message"
.warning "message"
based on FreeBSD implementation.
add .info while were at it.

.ERROR: a target to run on error.
We pass the failing GNode to PrintOnError so it can set
.ERROR_TARGET.

.MAKE.MAKEFILE_PREFERENCE
As a means to control make's list of prefered makefile names.
(Default: "makefile Makefile")

.MAKE.DEPENDFILE
Names the file to read dependencies from
(Default ".depend")

.MAKE.MODE
Processed after all makefiles are read.
Can put make into "compat" mode (more to come).

Fix:

compat.c: Error code should not be sent to debug_file.
Make_DoAllVar: use DONE_ALLSRC to avoid processing a node multiple times.
ReadMakefile: we can simply use doing_depend to control setting MAKEFILE.
 1.76 22-Feb-2009  dholland Use pid_t for the result of fork and wait. PR 38031 from Ryan Stutsman.
 1.75 23-Jan-2009  dsl branches: 1.75.2;
Change 'ClientData' to 'void *' so that relevant parameters can
be made 'const void *'.
 1.74 16-Jan-2009  dsl Debug print improvements.
 1.73 19-Dec-2008  christos if brk_string failed, use the shell.
 1.72 13-Dec-2008  dsl Use NULL instead of -1 cast to the relavant type (usually via NIL).
This was a suggestion from christos - so blame him if there is a deep
reason for using -1 :-)
 1.71 15-Feb-2008  christos back all changes out until I fix it properly.
 1.70 14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.69 19-Jan-2008  sjg Implement -dl (aka LOUD) to override '@' at the start of script lines.
Based on supplied patch.

PR: 37202
 1.68 05-Oct-2007  sjg Add the ability to .export variables to the environment.
 1.67 05-Apr-2007  christos branches: 1.67.4;
kill clobbered warning from Tobias Nygren
 1.66 17-Nov-2006  dsl branches: 1.66.2; 1.66.4;
A rather large rototil in the way the parallel make code schedules jobs.
This gives a considerable speedup in the processing of .WAIT and .ORDER.
Both .WAIT and .ORDER stop both the commands of the node, and its dependant
nodes being built until the LH nodes are complete.
.WAIT only applies to the dependency line on which it appears, whereas
.ORDER applies globally between the two nodes.
In both cases dependant nodes can be built because other targets need them.
make now processes the target list left to right, scheduling child nodes
as they are needed to make other nodes (instead of attempting to generate
a bottom-up dependency graph at the start). This means that 'make -j1'
will tend to build in the same order as a non-parallel make.
Note that:
all: x y
x: a .WAIT b
y: b .WAIT a
does not generate a dependency loop.
But
x: y
.ORDER y x
does (unless something elswhere causes 'y' to be built).
 1.65 27-Oct-2006  dsl Since 'ClientData' is 'void *', nuke almost all the (ClientData) casts.
 1.64 22-Oct-2006  christos sprinkle volatile.
 1.63 15-Oct-2006  dsl Output all debug trace output through 'debug_file' defaulting to 'stdout'.
(Almost all the debug output went there, but some went to stderr.)
Split the parsing of -d (debug flags) out into its own routine.
Allow the output filename to be changed by specifying -dF<file> to create
a log file, or -dF+<file> to append to it. <file> may be stdout or stderr.
Also change so that -d-<flags> acts on <flags> locally but doesn't copy
them to MAKEFLAGS so they aren't inherited by child makes.
I'm not 100% happy with the command line syntax for the above, so they are
currently undocumented.
 1.62 09-Oct-2006  apb In a non-native build, always use a shell to execute commands. This may
be necessary in a weird cross-build environment. Previously, if the
command looked simple enough, we would try to exec it directly.

OK sjg, christos
 1.61 22-Apr-2006  christos Coverity CID 530: Don't leak the argument vector.
 1.60 08-Aug-2005  christos From Max Okumoto:
- Remove casts to NULL.
- Remove space between cast and object.
 1.59 25-Jul-2005  christos Whitespace KNF cleanup from Max Okumoto
 1.58 08-May-2005  christos Don't complain that we cannot make .END.
 1.57 08-May-2005  christos Now that dependencies in .BEGIN, .END, and .INTERRUPT work, allow them.
 1.56 16-Feb-2005  christos PR/29203, PR/29204: Max Okumoto: KNF changes to make [no functional changes]
 1.55 01-Jul-2004  jmc Add some checks for gcc around a few function declarations and note the
unused variables. Also fix a few other warnings that PR#22118 shows when
trying to compile bmake on non-NetBSD hosts
 1.54 07-May-2004  sjg Remove use of sh -e when running in compat mode.
Its not posix compliant and serves very little purpose.
With this change compat and jobs modes are consistent wrt how
they treat each line of a script.

Add support for the '+' command line prefix as required by posix.
Lines prefixed with '+' are executed even when -n is given.
[Actually posix says they should also be done for -q and -t]

PR:
Reviewed by: jmc
 1.53 07-May-2004  ross Simplify build, no functional changes.

Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().

It's now possible to build make on some hosts with: cc *.c */*.c
 1.52 10-Sep-2003  jmmv branches: 1.52.2;
Add the 'e' debug flag (i.e., '-d e'): when enabled, show the "target
failed" and "command failed" messages added recently. These introduce
too much noise when debugging some kind of problems, specially in pkgsrc.
 1.51 09-Sep-2003  lukem when displaying the 'Failed command:', collapse runs of whitespace in the
command to a single space. suggested by David Laight in private mail.
 1.50 08-Sep-2003  lukem don't free cmdStart too early, as cmd points somewhere in there and we
may want cmd for error messages.
should fix [bin/22705] from itojun@
 1.49 02-Sep-2003  lukem Also display failed target. Given
printf "all:\n\ttrue\n\t@false\n" | make -f -
the error output now looks like:
*** Failed target: all
*** Failed command: false
*** Error code 1
instead of just
*** Error code 1

XXX: add this support for make -j builds.
 1.48 02-Sep-2003  lukem display the command that failed.
this is useful if the command-line had been suppressed.
 1.47 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.46 01-Aug-2003  sjg Allow .SHELL: to control the shell used by compat mode too.
Add a shell spec for ksh - a nice portable posix shell.
Document .SHELL:
 1.45 14-Jul-2003  christos Pass WARNS=3
 1.44 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.43 27-Apr-2002  bjh21 Rather than hardcoding "/bin/sh", use _PATH_BSHELL. To allow bootstrapping,
provide a default for this in pathnames.h, and only include <paths.h> ifndef
MAKE_BOOTSTRAP.
 1.42 21-Mar-2002  christos don't print extra newlines on errors.
 1.41 14-Mar-2002  pk JobExec(): don't use Punt() in the child; it can't possibly DTRT, and will also
mess up the parents variables.

Instead, use execError() for all error paths in the child code.
 1.40 07-Feb-2002  pk When making a node which is the source of both a .MADE target and a
normal target (the latter dependency being the reason why it's made),
the .MADE parent should not be put on the `toBeMade' list again (in
Make_Update()) since it was already put on it in Make_ExpandUse().
Doing so would cause the rules for the .MADE target to be executed
(at least) twice, and also mess up the unmade children count of _its_
parent, resulting in spurious graph cylce detection.

To achieve this, make sure the unmade children count of the .MADE target
is set to zero before enqueueing it on the `toBeMade' list in
Make_ExpandUse(). Then, in Make_Update(), check if the parent has the
.MADE attribute before diddling with the queue.

For the same reason the status of a node must not be set to UPTODATE
unconditionally in compat mode, since that will prevent the node from
being built even if it is the source of a normal target. Instead,
check both its state and the type of the parent to decide whether to
continue on behalf of the current parent.
 1.39 04-Feb-2002  christos Remove OP_NOSUFF, fix OP_MADE in compat mode [from pk], and make the OP_MADE
comment reflect reality.
 1.38 03-Feb-2002  pk Don't bother to apply suffix rules to find sources for a target marked
as .MADE.
 1.37 27-Jan-2002  reinoud Fix major bug in make(1) ... due to shadowing of the dotLast path used for
the .DOTLAST primitive by a boolean variable with the same name, this whole
mechanism was broken ... it doesn't save much stat calls but it was wrong.

Thanks to Jason Thorpe for the other shadow-variable fixing patches he
made.
 1.36 16-Oct-2001  sjg Don't ignore errors during .END processing.

PR: 14267
Reviewed: christos
 1.35 12-Jun-2001  sjg Add 4th arg (flags) to Var_Set so that VarLoopExpand can tell it not
to export interator variables when using context VAR_CMD.

Reviewed: christos
 1.34 01-Jun-2001  sjg A number of semi-related changes.
1. make -dx turns on DEBUG_SHELL which causes sh -x to be used where
possible.
2. PrintOnError() is now called when make is stopping due to an error.
This routine reports the curdir and the value of any variables listed
in MAKE_PRINT_VAR_ON_ERROR.
3. Variables set via command line, are propagated to child-makes via
MAKEFLAGS. This behaviour appears to be necessary for POSIX (according
to the GNU folk anyway).
4. Do not reset MAKEFILE when reading ".depend" as this rather eliminates the
usefulness of ${MAKEFILE}.
5. Added ${.newline} as a simple means of being able to include \n in the
result of a :@ loop expansion.
6. Set ${MAKE_VERSION} if defined. Need to come up with a useful value.

Reviewed: christos
 1.33 29-May-2001  christos better error messages on exec* failures. From Simon Burge.
 1.32 06-Apr-2001  wiz Negative exit code cleanup: Replace exit(-x) with exit(x).
As seen on tech-userlevel.
 1.31 01-Jan-2001  sommerfeld Delete forceSerial; just use compatMake for that.
Add -N flag to *really* not execute any commands (useful when using
the -d flags to debug usr/src/Makefile)
Document -N
Update documentation of -n to mention that it still executes commands
for targets marked .MAKE so that the -N/-n distinction is clear.
 1.30 20-Apr-2000  sjg Changes to make MAKEOBJDIRPREFIX useful.

Firstly, we ignore getenv("PWD") if MAKEOBJDIRPREFIX is set so that we always
get the same value for .CURDIR regardless of how make was invoked.

Second, when executing a command we check if it is ${.MAKE} or ${.MAKE:T}
without a preceeding chdir, if so we insert a chdir(${.CURDIR}) so that
the Makefile will be found by the child make. Note that this behaviour is
dissabled if MAKEOBJDIRPREFIX is not set or if NOCHECKMAKECHDIR is set.
See the comments in main.c for more detail.

With these two changes, one can successfully build usr/src using MAKEOBJDIRPREFIX
allowing the src to be mounted from a CD-ROM.
 1.29 21-Jan-2000  mycroft Nuke `extern int errno;' in code we compile with -Wstrict-prototypes. We get
the correct definition from errno.h.
 1.28 16-Sep-1999  mycroft Fix a bug in the previous. In the `compat' case, we don't actually use the
list of target nodes returned by Make_ExpandUse(). We have to search the
cohorts explicitly while iterating through the tree. So, tweak CompatMake()
to do this.
 1.27 24-Mar-1999  sommerfe branches: 1.27.2;
report a sensible error if wait() fails.
 1.26 11-Nov-1998  christos This patch fixes the problem introduced in the previous commit where
parents would be get remade, even if children were not really updated
by the commands executed for them. It also makes all the children have
the real modification time set if possible, so it should fix some other
timing weirdnesses...

- collapse childMade and make fields into flags and convert them to bits
CHILDMADE and REMAKE
- introduce FORCE flag that gets set in all the parents of a child that
has no sources and does not exist.
- set oodate if the FORCE flag is set, and not if CHILDMADE
- centralize the RECHECK into Make_Recheck() and use this in make.c and compat.c
- use Make_TimeStamp for all child -> parent timestamp propagations
 1.25 01-Nov-1998  itohy Reduced memory leaks.
I found some more leaks, but are not in inside of iterations.
 1.24 26-Mar-1998  christos PR/5210: Hauke Fath: make core dumps with .SHELL
Unfortunately this revealed a deeper problem with the brk_string code.
To fix it:
- remove sharing of the buffer between brk_string invocations
- change the semantics of brk_string so that the argument array
starts with 0, and return the buffer where the strings are
stored
 1.23 31-Dec-1997  thorpej Change an exit() to _exit(), so that it's safe for vfork().
 1.22 28-Sep-1997  lukem branches: 1.22.2;
wrap #include <sys/cdefs.h>, __RCSID(...) stuff in #ifndef MAKE_BOOTSTRAP
 1.21 01-Jul-1997  christos Add WARNS=1
RCSID police
 1.20 07-May-1997  mycroft Ignore `-t' when the .MAKE attribute is set.
 1.19 06-May-1997  mycroft Make sure `-n' is actually disabled for targets with the .MAKE attribute.
 1.18 28-Mar-1997  christos Make sure that the children of nodes that are marked .MADE, are marked
UPTODATE and their timestamps are consistent.
 1.17 23-Mar-1997  christos Locate all the children of a node marked as MADE.
 1.16 10-Mar-1997  christos Add a .MADE directive to indicated that the children of a target are
up-to-date, even when they are not. This is to simulate our current
make install behavior with proper dependencies.
 1.15 20-Feb-1997  christos Reported by cgd: fix .USE directive problems:
1. ${.*} variables did not get expanded in dependencies.
2. expanded ${.*} variables in .USE dependencies can cause tree
restructuring; handle it.
3. in compat mode, expand .USE before evaluating the list of targets,
instead of doing .USE expansions on demand, because they can cause
tree restructuring.
 1.14 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.13 22-Nov-1995  christos branches: 1.13.4;
Updates for POSIX/SVR4 compiling:

arch.c: Don't require ranlib stuff. Not everybody has it.
dir.c: SunOS-4 != Solaris; change #ifdef sun to #if sun && !__svr4__
job.c, compat.c: Don't use 'union wait', use int and the W*() macros.
main.c: Check for uname() == -1; some unames return > 0...
util.c, job.c: Add signal() with BSD semantics for svr4, don't use bsd
sigmask and friends.
 1.12 02-Nov-1995  christos Minor:
- ${.PREFIX} should never contain a full pathname
- Fixed gcc -Wall warnings
Major:
- compatMake is now FALSE. This means that we are now running in
full pmake mode:
* rules on dependency lines can be executed in parallel and or
out of sequence:

foo: bar baz

can fire the rule for baz before the rule for bar is fired.
To enforce bar to be fired before baz, another rule needs to be
added. [bar: baz]
* adjacent shell commands in a target are now executed by a single
invocation of the shell, not one invocation of the shell per line
(compatMake can be turned off using the -B flag)
- The -j flag now works... I.e. make -j 4 will fork up to four jobs in
parallel when it can. The target name is printed before each burst
of output caused by the target execution as '--- target ---', when j > 1
- I have changed all the Makefiles so that they work with make -j N, and
I have tested the whole netbsd by:
'make -j 4 cleandir; make -j 4 depend; make -j 4; make -j 4 install'
- I have not compiled or tested this version of make with -DREMOTE.
 1.11 27-Sep-1995  jtc Update lseek() constants:
L_SET -> SEEK_SET
And add off_t cast to offset argument.
 1.10 14-Jun-1995  christos - $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.9 25-Nov-1994  christos Don't remove targets when the -n flag is given and make is interrupted.
(From Keith Bostic)
 1.8 16-Jun-1994  jtc Christos' fix for quoting variable extraction properly.
 1.7 06-Jun-1994  jtc Fixes from Christos Zoulas, who used purify, objectcenter and testcenter
to find memory leaks and illegal memory accesses.
 1.6 07-Mar-1994  cgd kill some warnings, from Christos.
 1.5 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.4 13-Jan-1994  jtc Include appropriate header files to bring prototypes into scope.
 1.3 01-Aug-1993  mycroft Add RCS identifiers.
 1.2 21-Mar-1993  cgd after 0.2.2 "stable" patches applied
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.13.4.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.22.2.1 08-May-1998  mycroft Sync with trunk, per request of christos.
 1.27.2.1 23-Jan-2000  he Pull up revision 1.29 (requested by mycroft):
Always do the errno indirection hack, so that non-threaded
libraries get the right errno value when linked with -lpthread.
This means "always include <errno.h> and never declare errno
yourself".
 1.52.2.2 10-May-2004  tron Pull up revision 1.54 (requested by sjg in ticket #282):
Remove use of sh -e when running in compat mode.
Its not posix compliant and serves very little purpose.
With this change compat and jobs modes are consistent wrt how
they treat each line of a script.
Add support for the '+' command line prefix as required by posix.
Lines prefixed with '+' are executed even when -n is given.
[Actually posix says they should also be done for -q and -t]
PR:
Reviewed by: jmc
 1.52.2.1 10-May-2004  tron Pull up revision 1.53 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.66.4.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.66.2.1 05-Jun-2007  bouyer Apply patch (requested by tron in ticket #696):
usr.bin/make/compat.c patch
usr.bin/make/cond.c patch
usr.bin/make/dir.c patch
usr.bin/make/for.c patch
usr.bin/make/main.c patch
usr.bin/make/make.1 patch
usr.bin/make/make.c patch
usr.bin/make/make.h patch
usr.bin/make/nonints.h patch
usr.bin/make/parse.c patch
usr.bin/make/str.c patch
usr.bin/make/targ.c patch
usr.bin/make/util.c patch
usr.bin/make/var.c patch

Synchronize make(1) with HEAD branch to increase perfomance and
improve stability.
 1.67.4.2 23-Mar-2008  matt sync with HEAD
 1.67.4.1 06-Nov-2007  matt sync with HEAD
 1.75.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.84.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.84.2.2 30-Oct-2012  yamt sync with head
 1.84.2.1 23-May-2012  yamt sync with head.
 1.89.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.89.2.2 25-Feb-2013  tls resync with head
 1.89.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.107.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.259.2.1 02-Aug-2025  perseant Sync with HEAD
 1.378 06-Jul-2025  rillig make: complain about unfinished escape sequences or string literals
 1.377 06-Jul-2025  rillig make: improve debug log message for 'exists' function

The previous wording came from a time where the return type of
FuncExists was a string; this wording neither matches the current
implementation nor is it understandable without knowing the code.
 1.376 06-Jul-2025  rillig make: clean up
 1.375 29-Jun-2025  rillig make: if a condition is erroneous, skip the whole .if/.endif
 1.374 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.373 22-Apr-2025  rillig make: clean up

Replace 'unsigned int' with simply 'unsigned'.

In compat.c, skipping whitespace is not needed, as the loop above
already skips it.

In job.c, remove the unused header <sys/file.h>.

Inline the TMPPAT macro, as it is only needed in a single place.
 1.372 10-Apr-2025  rillig make: remove redundant error counter when parsing a condition
 1.371 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.370 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.369 07-Aug-2024  rillig make: in erroneous conditions, report the non-expanded text

In a condition, when a function call expression is missing its closing
parenthesis, there's no point in having the expanded argument text in
the error message.

When parsing a bare word in a condition, the trailing space was included
in that word, which was inconsistent, as the leading space was not
included either. Removing the trailing space from the word reduces the
cases where a multiple-inclusion guard steps in, but only in an edge
case that is irrelevant in practice.
 1.368 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.367 06-Aug-2024  rillig make: add details to error messages about missing ')'
 1.366 06-Jul-2024  rillig make: error out on conditions containing the operators '&' and '|'

These abbreviated variants of the '&&' and '||' operators were never
documented, so error out in non-lint mode as well.
 1.365 02-Jun-2024  rillig branches: 1.365.2;
make: sync VarEvalMode constant names with their debug log names
 1.364 25-May-2024  rillig make: fix a few more memory leaks
 1.363 23-Apr-2024  rillig make: clean up comments, code and tests
 1.362 07-Feb-2024  rillig make: remove redundant comments

No functional change.
 1.361 21-Jan-2024  rillig make: refactor CondParser_Term to be inlinable

No functional change.
 1.360 21-Jan-2024  rillig make: clean up parsing of conditions

No functional change.
 1.359 29-Dec-2023  rillig make: clean up comments

No binary change, except for line numbers in assertions.
 1.358 29-Dec-2023  rillig make: simplify memory allocation for string buffers

In edge cases and short-lived buffers, the initial buffer size is
irrelevant, so use the default.

No functional change.
 1.357 19-Dec-2023  rillig make: clean up comments

No binary change, except for line numbers in assertions.
 1.356 17-Dec-2023  rillig make: clean up names of local variables

No binary change.
 1.355 19-Nov-2023  rillig make: replace 'variable expression' with 'expression' in comments

No binary change.
 1.354 11-Aug-2023  rillig make: clean up multiple-inclusion guards

No functional change.
 1.353 23-Jun-2023  rillig make: clean up variable and function names

No functional change.
 1.352 23-Jun-2023  rillig make: warn about malformed patterns in ':M', ':N' and '.if make(...)'

These patterns shouldn't occur in practice, as their results are tricky
to predict. Generate a warning for now, and maybe an error later.

Reviewed by sjg@.
 1.351 21-Jun-2023  sjg Allow guard targets to use variables.

I commonly use __${.PARSEDIR:tA}__ where a unique guard
is needed, __${.PARSEDIR}__ is also useful in many cases.

Combination of patch from rillig and mine
 1.350 20-Jun-2023  rillig make: allow targets to be used as multiple-inclusion guards

This style is used by FreeBSD, among others.
 1.349 19-Jun-2023  rillig make: add tests for full code coverage of multiple-inclusion guards
 1.348 19-Jun-2023  rillig make: clean up code for skipping files with multiple-inclusion guard

No functional change.
 1.347 19-Jun-2023  rillig make: if a makefile is protected by a guard, only include it once

"looks reasonable" sjg@
 1.346 16-Jun-2023  rillig make: remove parameter names from function declarations

No binary change.
 1.345 01-Jun-2023  rillig make: shorten function names, clean up comments

No functional change.
 1.344 14-Feb-2023  rillig make: reduce complexity of evaluating expressions

No functional change.
 1.343 14-Feb-2023  rillig make: don't interpret the return value of Var_Parse

The return value of Var_Parse is largely redundant to the returned
string. The idea behind the type VarParseResult was to migrate all call
sites to checking this return value instead of the returned string, but
that hasn't happened. Instead, the additional type only added more
complexity.

There was a single place where that return value was actually used, when
parsing conditions. And even in that case, ignoring the VarParseResult
added back an error message that previously hid bugs, in the test
cond-token-plain.mk.

Even though these error messages are redundant in the other tests, they
don't hurt as they don't happen often.
 1.342 24-Sep-2022  rillig make: clean up tracking of depth of nested .if directives

The variable cond_min_depth was redundant. It was only accessed while
parsing the makefiles. Merging it into struct IncludedFile removes the
possible confusion between cond_min_depth and including_cond_min_depth.

No functional change.
 1.341 24-Sep-2022  rillig make: fix variable and function names relating to .if nesting

The previous names were confusing since they suggested that cond_depth
instead of cond_min_depth would be saved and restored.

No functional change.
 1.340 24-Sep-2022  rillig make: move Cond_save_depth above Cond_restore_depth

This puts the functions into chronological order, as saving happens
before restoring.

No functional change.
 1.339 24-Sep-2022  rillig make: use assertion for internal error condition

When the nesting level of conditionals is restored to an unreasonably
high value, the error message "0 open conditionals" doesn't make sense.
 1.338 23-Sep-2022  sjg Cond_reset_depth just use cond_min_depth

To avoid errors from unclosed conditionals on .break
it is sufficient to just set cond_depth = cond_min_depth.

Patch from rillig
 1.337 08-Sep-2022  rillig make: list comparison operators in declaration order

This allows a tiny optimization in the switch statement.

No functional change.
 1.336 04-Sep-2022  rillig make: add more details to error message for numeric comparison

Before:
String comparison operator must be either == or !=

After:
Comparison with '>=' requires both operands 'no' and '10' to be numeric

Noticed by martin@ in pkgsrc/textproc/py-pygments.
 1.335 02-Sep-2022  sjg make: add .break to terminate .for loop early

When .break is encountered within a .for loop
it causes immediate termination.

Outside of a .for loop .break causes a parse error.

Reviewed by: christos
 1.334 15-Apr-2022  rillig tests/make: adjust expectations to actual behavior

The bug in deptgt-silent-jobs.mk has been fixed, the debug logging for
comparing conditions and for deleting global variables has changed
intentionally.
 1.333 03-Mar-2022  rillig make: improve comments about parsing and evaluating conditions

No binary change.
 1.332 03-Mar-2022  rillig make: improve local variable name in ParseWord in conditions

That function not only parses function arguments but also bare words, so
the name argBuf didn't match anymore.

No binary change.
 1.331 03-Mar-2022  rillig make: make debug logging for comparisons less technical
 1.330 11-Feb-2022  rillig make: simplify control flow in CondParser_Comparison

No functional change.
 1.329 09-Feb-2022  rillig make: fix mistakes, spelling and typos in comments and manual page

No binary change for -DNDEBUG.
 1.328 09-Feb-2022  rillig make: clean up variable names

No binary change.
 1.327 29-Jan-2022  rillig make: rename labels in CondParser_Leaf

No binary change.
 1.326 15-Jan-2022  rillig make: replace Var_Value with Var_Exists where applicable

The latter function already existed in 1993, no idea why it was not
used.

No functional change.
 1.325 14-Jan-2022  rillig make: inline EvalBare

No functional change.
 1.324 07-Jan-2022  rillig make: clean up function argument names and comments

No binary change except for assertion line numbers.
 1.323 07-Jan-2022  rillig make: remove redundant initializer in CondParser_ComparisonOrLeaf

No binary change.
 1.322 02-Jan-2022  rillig make: clean up nitpicks

In ParseWord, the expressions '*p' and 'ch' are the same.

In ParseDependencyTargetWord, clean up a wordy comment and join two
conditions.

In the test cond-token-number, clarify that make doesn't convert from
hex to decimal but only from hex to internal representation.

No functional change.
 1.321 30-Dec-2021  rillig tests/make: demonstrate edge case that evaluates an expression twice
 1.320 30-Dec-2021  rillig make: remove redundant code from CondParser_ComparisonOrLeaf

No functional change.
 1.319 30-Dec-2021  rillig make: split ParseWord into the actual ParseWord and ParseFuncArg

Combining two similar but fundamentally different parsing tasks in a
single function only increased the complexity, of the implementation as
well as the call sites.

The code makes it obvious now that a function argument is a bare word
surrounded by parentheses.

The special case of an empty word is only needed for the function
argument, it cannot occur in a bare word. The code for that has been
moved to the caller. Such an empty word not only occurs for 'defined()'
but also for 'defined(${:U})'.

No functional change.
 1.318 30-Dec-2021  rillig make: make ParseWord in condition parser simpler

Merge the two return values (bool, string) into a single return value.
As before, the caller cannot observe the difference between a parse
error and an empty word, both are handled in the same way.

In CondParser_ComparisonOrLeaf, the word cannot be empty since the
calling function CondParser_Token already handles all cases that could
lead to an empty word.

No functional change.
 1.317 30-Dec-2021  rillig make: internally return false for irrelevant leaves in conditions

The result of irrelevant leaves is effectively ignored by CondParser_And
and CondParser_Or. Use the 'doEval &&' pattern to make the code
consistent with CondParser_Comparison and CondParser_FuncCall.

No functional change.
 1.316 29-Dec-2021  rillig make: in irrelevant function calls in conditions, return false

When a condition contains an irrelevant function call, it doesn't matter
whether the function call evaluates to true or to false, it will be
discarded anyway by either CondParser_And or CondParser_Or.

Returning false instead of true makes the code simpler, plus it is more
common to return false for irrelevant results.

No functional change.
 1.315 29-Dec-2021  rillig make: use simpler return type for ParseWord in conditions

No functional change.
 1.314 29-Dec-2021  rillig make: replace table for function lookup in conditions with simple code

The code for looking up the function from the table forced the compiler
to use a specific memory layout. Replacing the table with explicit code
provides the compiler more opportunities to optimize the code. Another
side effect is that there are fewer pointer operations.

Previously, is_token checked that the character after the word does not
continue the word, this is now done separately since for the function
lookup, this check was unnecessary. The newly added skip_string
provides a higher abstraction level, it is no longer necessary to pass
the string length as a separate, redundant parameter.

No functional change.
 1.313 29-Dec-2021  rillig make: clean up condition parser

No functional change.
 1.312 29-Dec-2021  rillig make: merge duplicate types CondEvalResult and CondResult

No binary change.
 1.311 29-Dec-2021  rillig make: merge duplicate enum constants for CondEvalResult and CondResult

No binary change.
 1.310 29-Dec-2021  rillig make: remove redundant parameter for evaluating conditions

No functional change.
 1.309 29-Dec-2021  rillig make: merge types CondResult and CondEvalResult

No functional change.
 1.308 27-Dec-2021  rillig make: rename local variables to be simpler

No binary change.
 1.307 27-Dec-2021  rillig make: clean up comments
 1.306 15-Dec-2021  rillig make: format comments according to /usr/share/misc/style

Assisted by indent(1), with manual corrections due to its many remaining
bugs.

No functional change.
 1.305 15-Dec-2021  rillig make: use consistent indentation for statements and continuations

No binary change, except for line numbers in assertions in suff.c.
 1.304 13-Dec-2021  rillig make: condense CondParser_ComparisonOp

No functional change.
 1.303 13-Dec-2021  rillig make: fix memory leak when parsing '.if ${expr}' (since 2004-04-13)

$ (
echo 'VAR=value'
perl -e 'printf(".if \${VAR}\n.endif\n" x 5000);';
echo 'all:'
printf '\t%s\n' \
'@pid=$$$$; \' \
'ppid=$$(ps -o ppid -p "$$pid" | sed 1d); \' \
'ps -o vsz,rsz -p $$ppid | sed 1d'
) > leak-cond2.mk

$ make-2004.04.08.07.24.26 -r -f leak-cond.mk
2668
$ make-2004.04.13.16.06.23 -r -f leak-cond.mk
3964

$ echo $(((3964 - 2668) * 1000 / 5000))
259

This 259 is close enough to the 256 from Buf_Init in CondParser_Leaf.
 1.302 12-Dec-2021  rillig tests/make: refine comments for parsing and evaluating conditions
 1.301 12-Dec-2021  rillig make: rename ParseFuncArg to ParseWord, update comments

No functional change.
 1.300 12-Dec-2021  rillig make: merge duplicate code in CondParser_FuncCall

No functional change.
 1.299 12-Dec-2021  rillig make: generate more specific error message on malformed conditional
 1.298 11-Dec-2021  rillig make: remove dead code in CondParser_FuncCall

The return value (size_t)-1 was only used by the function 'empty', which
moved to CondParser_FuncCallEmpty.

No functional change.
 1.297 11-Dec-2021  rillig make: remove unused function parameter in conditional handling

No functional change.
 1.296 11-Dec-2021  rillig make: clean up CondParser_FuncCallEmpty

No functional change.
 1.295 11-Dec-2021  rillig make: inline ParseEmptyArg into CondParser_FuncCallEmpty

No functional change.
 1.294 11-Dec-2021  rillig make: simplify evaluation of function 'empty'

No functional change.
 1.293 11-Dec-2021  rillig make: merge duplicate code in ParseEmptyArg

No functional change.
 1.292 11-Dec-2021  rillig make: use proper return type for ParseEmptyArg

Now that ParseEmptyArg is no longer bound to have the same prototype as
ParseFuncArg, it can use a more appropriate return type instead of
encoding everything in a size_t.

Since ParseEmptyArg never returned 0, that code path was unused. It was
only used for all other functions.

No functional change.
 1.291 11-Dec-2021  rillig make: remove unused arguments from CondParser_FuncCallEmpty

No functional change.
 1.290 11-Dec-2021  rillig make: separate handling of 'empty' and the other functions

No functional change.
 1.289 10-Dec-2021  rillig make: merge duplicate code in parsing conditions

No functional change.
 1.288 10-Dec-2021  rillig make: remove recursion from CondParser_And

No functional change intended. Before cond.c 1.286 from today, there
would have been the functional change that in malformed conditions, the
extra expression would not be evaluated. Now that CondParser_Token is
always called with doEval == false, there is no change in behavior to be
expected.
 1.287 10-Dec-2021  rillig make: do not expand operator token in CondParser_Or

At the point where CondParser_Or calls CondParser_Token, there was a
previous call to CondParser_And. Due to this, the next token is already
stored in par->curr, and the parameter doEval is ignored.

Changing the argument from doEval to false makes the code similar to the
corresponding code in CondParser_And.

No functional change.
 1.286 10-Dec-2021  rillig make: do not evaluate misplaced expressions in malformed conditions

This change only affects the behavior for parse errors. Syntactically
well-formed conditions work exactly as before.
 1.285 10-Dec-2021  rillig make: simplify parsing of '||' in conditions

Previously, the grammar said 'Or -> Or || And', while the code looked
more like 'Or -> And || Or'. Make the code look like the grammar and
keep track of the resulting value of the condition explicitly.

No functional change intended.
 1.284 09-Dec-2021  rillig make: revert previous commit to CondParser_Or

Even though the unit tests for make cover a lot of cases, they don't
cover all cases. After the previous commit, the NetBSD build failed
with:

bsd.sys.mk line 247: \
Malformed conditional (!defined(NOPIE) && \
(!defined(LDSTATIC) || ${LDSTATIC} != "-static"))
 1.283 09-Dec-2021  rillig make: avoid recursion in CondParser_Or

Previously, a long chain of '1 || 1 || 1 || 1 || ...' led to a deep
recursion. Furhermore, the code didn't match the grammar on superficial
reading: the grammar said "or || and", the code said "and || or".

No functional change.
 1.282 09-Dec-2021  rillig make: remove period from end of error messages and warnings

The majority of the existing error messages and warnings does not
include a period at the end. Follow this style consistently.
 1.281 05-Dec-2021  rillig make: fix comments
 1.280 26-Sep-2021  rillig make: fix lint warning on i386

cond.c(800): warning: argument #3 is converted from 'unsigned char' to
'unsigned int' due to prototype [259]
 1.279 21-Sep-2021  rillig make: reduce relocations, thereby reducing .text size

No functional change.
 1.278 21-Sep-2021  rillig make: reduce relocations and thereby .text size, make opname const

No functional change.
 1.277 21-Sep-2021  rillig make: rename and invert CondParser.lhsStrict to leftUnquotedOK

The new name is easier to grasp than the rather abstract word 'strict'.

No functional change.
 1.276 21-Sep-2021  rillig make: do not allow unquoted 'left == right' after modifier ':?'

Having a static variable for state that clearly belongs in the parser
looked suspicious, and indeed it was wrong.

When the distinction between .if conditions and expressions of the form
${condition:?:} was added in cond.c 1.68 from 2015-05-05, a new unit
test was added, but it didn't cover this edge case. At that time, the
state of the condition parser consisted of a few global variables
instead of a separate data type, as would have been appropriate for
parsing nested conditions.
 1.275 21-Sep-2021  rillig make: remove unnecessary negation from CondParser_StringExpr

No functional change.
 1.274 21-Sep-2021  rillig make: remove unnecessary const from parameters

These were leftovers from earlier refactorings, when extracting code to
separate functions.

No functional change.
 1.273 21-Sep-2021  rillig make: fix out-of-bounds memory read (since previous commit)
 1.272 21-Sep-2021  rillig make: reduce indentation in CondParser_FuncCall

No functional change.
 1.271 21-Sep-2021  rillig make: fix documentation about operator associativity in conditions
 1.270 29-Jul-2021  rillig make: in TryParseNumber, reset errno as late as possible

No functional change.
 1.269 21-Jun-2021  rillig make: fix grammar in error message for malformed conditional
 1.268 21-Jun-2021  rillig make: clean up comments in cond.c
 1.267 11-Jun-2021  rillig make: inline strcmp when parsing conditions

GCC 10 does not do that even though it could easily.

No functional change.
 1.266 11-Jun-2021  rillig make: clean up function names and documentation for conditions

No functional change.
 1.265 11-Jun-2021  rillig make: rename If_Eval to EvalBare

No functional change.
 1.264 11-Jun-2021  rillig make: move parsing of function calls out of CondParser_LeafToken

The grammar above the parsing code says that a Leaf has nothing to do
with function calls, so don't mix these in the actual code.

No functional change.
 1.263 11-Jun-2021  rillig make: improve function names for parsing conditions

No functional change.
 1.262 19-Apr-2021  rillig make: do not complain when skipping the condition 'no >= 10'

Seen in external/bsd/tmux when building with Clang. See
varmod-ifelse.mk for the detailed story.
 1.261 04-Apr-2021  rillig make: convert VarEvalFlags back into an enum, but not a bit-set

As was apparent in VarEvalFlags_ToString, a bit-set was not the best
data type since most of the flags were not freely combinable. The two
flags that could be combined were keepDollar and keepUndef, but even
these have distinguished names in the debug log.

The downside of struct bit-fields is that they need extra helper
functions in C90 (see nonints.h). Exchange these for a few helper
functions in var.c, to keep the code outside var.c simple.

No functional change.
 1.260 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.259 15-Mar-2021  rillig make: replace enum bit-field with struct bit-field for VarEvalFlags

This makes the code easier to read, especially in var.c. It also makes
debugging sessions easier since some debuggers don't show enum
bit-fields symbolically as soon as more than one bit is set.

The code outside var.c is basically unchanged, except that instead of
passing the individual flags, there are 4 predefined evaluation modes.
These suffice for all practical use cases. Only in the implementation
deep inside var.c, the value of the flags keepDollar and keepUndef
differs.

There is no way of passing the struct to EnumFlags_ToString, which means
the ToString function has to be spelled out explicitly. This allows for
fine-tuning the representation in the debug log, to reduce the amount of
uppercae letters.

No functional change.
 1.258 15-Mar-2021  rillig make: rename VARE_NONE to VARE_PARSE_ONLY

The name 'NONE' described the bit pattern, which was not useful to
understand its meaning. Omitting VARE_WANTRES only parses the
expression, without evaluating any part of it.

No functional change, not even in debug mode since Enum_FlagsToString
always returns "none" for all-bits-unset.
 1.257 22-Feb-2021  rillig make: remove freestanding freeIt variables

These variables all belong to a string variable. Connect them using
FStr, which reduces the number of variables to keep track of.

No functional change.
 1.256 05-Feb-2021  rillig make: in the Var_ functions, move the scope to the front

This change provides for a more natural reading order in the code.
Placing the scope first makes it immediately clear in which context the
remaining parameters are interpreted.

No functional change.
 1.255 04-Feb-2021  rillig make: rename some VAR constants to SCOPE

The word "context" does not fit perfectly to the variables that are
associate with a GNode, as the context is usually something from the
outside and the variables are more like properties inherent to the
GNode.

The term "global context" fits even less. Since the thing where
variables are looked up is commonly named a scope, use that term
instead.

This commit only renames the global variables VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE, plus a few very closely related comments. These are:

GNode.vars (because of line breaks)
GNode_Free (dito)
varname-make_print_var_on_error.mk
varname-make_print_var_on_error-jobs.mk

The debug message in Var_Stats is left as-is since there is no unit test
for it yet.

The other renamings (variable names "context", "ctxt", as well as
further comments) will be done in a follow-up commit.
 1.254 30-Jan-2021  rillig make(1): split Buf_Destroy into Buf_Done and Buf_DoneData

In all cases except one, the boolean argument to Buf_Destroy was
constant. Removing that argument by splitting the function into two
separate functions makes the intention clearer on the call site. It
also removes the possibility for using the return value of Buf_Done,
which would have made no sense.

The function Buf_Done now pairs with Buf_Init, just as in HashTable and
Lst.

Even though Buf_Done is essentially a no-op, it is kept as a function,
both for symmetry with Buf_Init and for clearing the Buffer members
after use (this will be done only in CLEANUP mode, in a follow-up
commit).
 1.253 22-Jan-2021  rillig make(1): remove "warning" from missing closing parenthesis

This only affects the diagnostics for parse errors that involve a
missing closing parenthesis. Whether or not this is a parse error is
still the same.

It may look redundant to pass both the CondParser and the parsing
position pp to the functions, but that's necessary since during parsing,
not every code path updates the main parsing position immediately.
 1.252 21-Jan-2021  rillig make(1): replace warning + error with just an error in conditionals

Before, there was a "warning" for comparing strings using '<', which was
wrong. That warning was then followed by an error, after parsing the
whole conditional. This was only because it was easier to implement.

Replace the warning with an actual error. This only affects
conditionals in .if lines, the conditionals in the :? modifier such as
${"A" < "B":?smaller:greater} still print 2 errors.
 1.251 21-Jan-2021  rillig make(1): fix debug output for comparison operators in conditionals

This produces fewer warnings than before, but these were edge cases that
probably didn't matter in practice. The "Malformaed conditional" is
still generated, the set of accepted conditionals is still the same.
 1.250 21-Jan-2021  rillig make(1): document wrong debug output in evaluation of conditionals
 1.249 21-Jan-2021  rillig make(1): reformat CondParser_StringExpr
 1.248 21-Jan-2021  rillig make(1): extract CondParser_StringExpr from CondParser_String
 1.247 21-Jan-2021  rillig make(1): demonstrate parse error without error message in conditional
 1.246 21-Jan-2021  rillig make(1): make CondParser_String simpler

No functional change.
 1.245 21-Jan-2021  rillig make(1): fix Coverity annotation

FStr is not an allocated data type.
 1.244 19-Jan-2021  rillig make(1): extract DetermineKindOfConditional from Cond_EvalLine
 1.243 19-Jan-2021  rillig make(1): remove struct If from evaluation of conditionals

The variant of the .if directive can be stored in the CondParser
directly, instead of pointing to a struct If.

The type CondParser may have to be renamed since the condition is not
only parsed, it is evaluated as well.

No functional change.
 1.242 19-Jan-2021  rillig make(1): remove do-not-format markers from comments

These markers had been used inconsistently. Furthermore the source code
had not been formatted automatically before 2020 at all, otherwise there
wouldn't have been any trailing whitespace left.
 1.241 19-Jan-2021  rillig make(1): distinguish between tokens and results in conditionals

No functional change.
 1.240 19-Jan-2021  rillig make(1): update references to the renamed CondParser functions
 1.239 19-Jan-2021  rillig make(1): condense code for parsing and evaluating conditionals
 1.238 19-Jan-2021  rillig make(1): add error handling for edge case in malformed conditions
 1.237 19-Jan-2021  rillig make(1): fix possible return values for CondParser_Term

The invalid return values didn't do any harm since CondParser_Factor and
CondParser_Expr passed them through, and CondParser_Eval carefully
checks for TOK_TRUE or TOK_FALSE and treats everything else as an error.

No change in observable behavior since there is no debug logging in that
part of the code.
 1.236 19-Jan-2021  rillig make(1): demonstrate wrong return value in CondParser_Term
 1.235 10-Jan-2021  rillig make(1): consistently use boolean expressions in conditions

Most of the make code already followed the style of explicitly writing
(ptr != NULL) instead of the shorter (ptr) in conditions.

The remaining 50 instances have been found by an experimental,
unpublished check in lint(1) that treats bool expressions as
incompatible to any other scalar type, just as in Java, C#, Pascal and
several other languages.

The only unsafe operation on Boolean that is left over is (flags &
FLAG), for an enum implementing a bit set. If Boolean is an ordinary
integer type (the default), some high bits may get lost. But if Boolean
is the same as _Bool (by compiling with -DUSE_C99_BOOLEAN), C99 6.3.1.2
defines that a conversion from any scalar to the type _Bool acts as a
comparison to 0, which cannot lose any bits.
 1.234 09-Jan-2021  rillig make(1): fix lint warnings
 1.233 30-Dec-2020  rillig make(1): format multi-line comments
 1.232 27-Dec-2020  rillig make(1): clean up VarParseResult constants

The many constants were invented because at that time I didn't quite
understand the actual outcomes of Var_Parse that need to be
distinguished. There are only a few:

(1) Errors, whether they are parse errors, or evaluation errors or
undefined variables. The old constants VPR_PARSE_MSG and
VPR_UNDEF_MSG are merged into VPR_ERR.

(2) Undefined expressions in a situation in which they are allowed.
Previously the documentation for VPR_UNDEF_SILENT talked about
undefined expressions in situations where they were not allowed.
That case is fully covered by VPR_ERR instead.

(3) Errors that are silently ignored. These are probably bugs.

(4) Everything went fine, the expression has a defined value.
 1.231 23-Dec-2020  rillig make(1): rename CmdOpts.lint to strict

When running lint(1) on the code, it defines the preprocessor macro
"lint" to 1, which generated a syntax error in the declaration "Boolean
lint", as that became "Boolean 1".
 1.230 20-Dec-2020  rillig make(1): change return type of Var_Value to FStr
 1.229 20-Dec-2020  rillig make(1): return FStr from Var_Parse

This reduces the number of variable declarations at the call sites.
 1.228 20-Dec-2020  rillig make(1): clean up memory handling in CondParser_String
 1.227 20-Dec-2020  rillig make(1): clean up memory handling in CondParser_String
 1.226 14-Dec-2020  rillig make(1): error out on .else with extraneous text
 1.225 14-Dec-2020  rillig make(1): error out if an '.endif' contains extraneous text
 1.224 14-Dec-2020  rillig make(1): make structure of the code in Cond_EvalLine clearer
 1.223 14-Dec-2020  rillig make(1): don't pretend to expand CondParser_Eval

At that point, the variable expression has already been expanded. To
avoid the impression that the token might be relevant, pass FALSE
instead of TRUE. No change of behavior.
 1.222 12-Dec-2020  rillig make(1): remove const from function parameters

These have been left-overs from refactoring, when these pieces were
extracted to separate functions.
 1.221 05-Dec-2020  rillig make(1): remove redundant assignments
 1.220 29-Nov-2020  rillig make(1): reduce memory allocation for dirSearchPath
 1.219 28-Nov-2020  rillig make(1): reduce memory allocation for CmdOpts.create
 1.218 28-Nov-2020  rillig make(1): remove pointer indirection from GNode.commands

Just to save a few memory allocations. No noticeable effect on the
performance though.
 1.217 23-Nov-2020  rillig make(1): use properly typed comparisons in boolean contexts
 1.216 23-Nov-2020  rillig make(1): align end-of-line comments with tabs
 1.215 23-Nov-2020  rillig make(1): indent cond.c with tabs instead of spaces
 1.214 13-Nov-2020  rillig make(1): in lint mode, check for ".else <cond>"
 1.213 13-Nov-2020  rillig make(1): use bitset for IfState

Previously, the individual IfStates contained redundant information,
which was apparent in the documentation. This led to expressions like
(state > ELSE_ACTIVE) that are hard to read since the reader has to look
up the order of the enum.

To avoid this, the state of an '.if' block is now encoded using a bitset,
encoding the properties of each state directly. This replaces the
previous (state > ELSE_ACTIVE) with !(state & IFS_ACTIVE), which is
easier to understand.

No change in behavior.
 1.212 13-Nov-2020  rillig make(1): replace large switch with if-else in Cond_EvalLine
 1.211 13-Nov-2020  rillig make(1): move the comment about ".else <cond>" to the correct place
 1.210 12-Nov-2020  rillig make(1): improve readability of IfState documentation

The words "None" and "One" looked and sounded too similar.
 1.209 12-Nov-2020  rillig make(1): rename local variable in Cond_EvalLine

A variable called line is not supposed to be a moving target, that's what
the name p is reserved for.
 1.208 12-Nov-2020  rillig make(1): remove complicated code to find the definition for plain .if
 1.207 12-Nov-2020  rillig make(1): document IfState in more detail
 1.206 12-Nov-2020  rillig make(1): clean up Cond_EvalLine

The constant MAXIF was not a maximum but an initial capacity. Inline it
to remove the misleading name. Likewise, MAXIF_BUMP was an unnecessary
and wrong name.

Rename the enum since it only describes a single state, not multiple.

Rename the stack of states since it describes multiple states, not one.

Add markers where to add the missing error messages for unknown
directives or extraneous cond, such as in ".else cond" or ".endif cond".
 1.205 11-Nov-2020  rillig make(1): document non-obvious special case in EvalNotEmpty
 1.204 11-Nov-2020  rillig make(1): add test to cover the If_Eval call in EvalNotEmpty
 1.203 10-Nov-2020  rillig make(1): remove unreachable code from CondParser_String

The code that has been removed was not reachable from after the Var_Parse
call. All branches after the Var_Parse are either freed properly or
return the expanded value.
 1.202 10-Nov-2020  rillig make(1): fix error message when parsing unknown .if (since 2005-05-01)
 1.201 10-Nov-2020  rillig make(1): add tests for parsing conditionals, document a parsing bug
 1.200 10-Nov-2020  rillig make(1): document ParseEmptyArg
 1.199 10-Nov-2020  rillig make(1): remove unnecessary NULL marker from functions list

Comparing the pointer works equally well and uses less memory.
 1.198 09-Nov-2020  rillig make(1): document handling of '#' and '\n' in conditionals
 1.197 08-Nov-2020  rillig make(1): in lint mode, only allow '&&' and '||', not '&' and '|'

These variants of the condition operators are neither documented in the
manual page nor are they used in practice.
 1.196 08-Nov-2020  rillig make(1): extract CondParser_Func from CondParser_LeafToken
 1.195 08-Nov-2020  rillig make(1): inline strchr call in CondParser_LeafToken
 1.194 08-Nov-2020  rillig make(1): rename CondParser_Func to CondParser_LeafToken

The previous name was misleading since the function did not only parse
function call expressions.
 1.193 08-Nov-2020  rillig make(1): fix type mismatch between int and Token
 1.192 08-Nov-2020  rillig make(1): improve local variable name in EvalNotEmpty
 1.191 08-Nov-2020  rillig make(1): improve variable names in EvalNotEmpty

In a unary expression, there is no left-hand side.
 1.190 08-Nov-2020  rillig make(1): rename local variable in CondParser_String
 1.189 08-Nov-2020  rillig make(1): clean up TryParseNumber in conditions

More descriptive variable names, more appropriate literals for
comparisons, one task per paragraph of code.
 1.188 08-Nov-2020  rillig make(1): clean up FuncExists
 1.187 08-Nov-2020  rillig make(1): clean up code related to VarEvalFlags

Mention VARE_WANTRES before VARE_UNDEFERR since the latter depends on
the former.

In ApplyModifier_Assign, VARE_KEEP_DOLLAR doesn't have to be removed
from eflags since ParseModifierPart does this already.

In EvalUndefined, testing for VARE_WANTRES is redundant if VARE_UNDEFERR
is already set.
 1.186 08-Nov-2020  rillig make(1): clean up VarEvalFlags in the calls to Var_Parse and Var_Subst

There are only 3 flags, and some combinations don't even make sense.

VARE_UNDEFERR only makes sense if combined with VARE_WANTRES. If the
latter is not set, the variable expressions are only parsed, without
asking whether they are defined or not. Therefore, VARE_UNDEFERR cannot
have any effect in that case.

VARE_KEEP_DOLLAR is actively ignored by ParseModifierPart. In cases
where VARE_WANTRES is not set, this means that VARE_NONE can be passed,
which is easier to grasp than any bitset operations. This also gets rid
of a few type casts from enum to unsigned int that were necessary to
pass WARNS=6.
 1.185 07-Nov-2020  rillig make(1): clean up CondParser_Comparison
 1.184 07-Nov-2020  rillig make(1): reword condition in CondParser_String

The parentheses were confusing for human readers.

The compiler doesn't really care about the wording of the condition, GCC
5 on amd64 generates non-obvious but nice code anyway, replacing the
logical or with a logical and.
 1.183 07-Nov-2020  rillig make(1): fix type mismatch between Boolean and Token

Even though the C boolean and Token are encoded the same, the code should
still distinguish them, for the benefit of human readers.
 1.182 07-Nov-2020  rillig make(1): fix type mismatch in If_Eval

No practical consequences since TOK_FALSE == 0 and TOK_TRUE == 1.
 1.181 07-Nov-2020  rillig make(1): add test for parse error in function defined()
 1.180 07-Nov-2020  rillig make(1): add test for parse error in condition using empty()
 1.179 07-Nov-2020  rillig make(1): make API of Buf_Init simpler

In most cases, the caller doesn't want to specify the exact number of
preallocated bytes.
 1.178 07-Nov-2020  rillig make(1): clean up code stylistically

* Replace character literal 0 with '\0'.
* Replace pointer literal 0 with NULL.
* Remove redundant parentheses.
* Parentheses in multi-line conditions are not redundant at the
beginning of a line.
* Replace a few !ptr with ptr == NULL.
* Replace a few ptr with ptr != NULL.
* Replace (expr & mask) == 0 with !(expr & mask).
* Remove redundant braces for blocks in cases where the generated code
stays the same. (Assertions further down in the code would get
different line numbers.)
* Rename parameters in CondParser_String to reflect the data flow.
* Replace #ifdef notdef with #if 0.

The generated code stays exactly the same, at least with GCC 5.5.0 on
NetBSD 8.0 amd64 using the default configuration.
 1.177 06-Nov-2020  rillig make(1): merge duplicate code for skipping horizontal whitespace
 1.176 06-Nov-2020  rillig make(1): fix tests directive-ifmake and varcmd with custom boolean

When make is compiled with -DUSE_UCHAR_BOOLEAN, these tests failed.
Merge duplicate code and don't depend on the actual value of TRUE when
evaluating conditions.
 1.175 05-Nov-2020  rillig make(1): remove redundant parentheses from sizeof operator

The parentheses are only needed if the argument is a type, not an
expression.
 1.174 02-Nov-2020  rillig make(1): remove word "Ptr" from variable names

Whether or not a variable is a pointer is obvious from the context.
Since the introduction of function prototypes in C90, this information
is checked by the compiler and no longer needs to be encoded in the
variable names.
 1.173 30-Oct-2020  rillig make(1): change char * to void * in Var_Value

The only purpose of the parameter freeIt is to free the memory
associated with the return value. To do this, no pointer arithmetic is
needed. Therefore, change to a void pointer, to catch accidental use of
that pointer.
 1.172 30-Oct-2020  rillig make(1): clean up is_separator
 1.171 30-Oct-2020  rillig make(1): fix parse error in string literal in conditional

The string literal "${VAR} " had produced a "Malformed conditional", at
least since 2003. (That's the oldest make I have available for testing.)
Strange that nobody else noticed that in the last 17 years.
 1.170 30-Oct-2020  rillig make(1): rename VAR_CMD to VAR_CMDLINE

Since make has to do with both the command line and child commands, the
former name was confusing.
 1.169 26-Oct-2020  rillig make(1): group the command line options and arguments

By having a single struct that holds all command line options and
arguments, it is easy to see in the code when such a command line
argument is modified. It also cleans up the namespace since the command
line options don't follow a common naming style. Having them in a
struct also means that there is a single place for putting the
documentation, not two as before.

The struct also suggests to extract the initialization code out of main,
which is still too large, having more than 400 lines of code and
covering far too many topics.
 1.168 24-Oct-2020  rillig make(1): clean up comments in cond.c
 1.167 23-Oct-2020  rillig make(1): negate OP_NOP and rename it to GNode_IsTarget
 1.166 23-Oct-2020  rillig make(1): inline CondFindStrMatch into FuncMake
 1.165 22-Oct-2020  rillig make(1): remove redundant type casts

This mainly affects the void pointers in callback functions for lists.
These had been necessary once when the parameter type was still
ClientData instead of void pointer.
 1.164 18-Oct-2020  rillig make(1): add tags to enum types

This allows IDEs to offer better type information than "anonymous enum".
 1.163 17-Oct-2020  rillig make(1): fix indentation
 1.162 05-Oct-2020  rillig make(1): make cond.c ready for WARNS=6, part 2
 1.161 05-Oct-2020  rillig make(1): make cond.c ready for WARNS=6
 1.160 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.159 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.158 05-Oct-2020  rillig make(1): fix test for .ifndef when compiled with -DUSE_UCHAR_BOOLEAN

In that compilation variant, TRUE is defined to 255, to see whether all
boolean expressions evaluate to either 1 or 0. The field If.doNot in
cond.c doesn't do this since it uses the actual value of TRUE.
Therefore, change the evaluation slightly to also handle this case.
 1.157 03-Oct-2020  rillig make(1): use consistent pattern for parsing whitespace

The pp and cpp in the function names stand for "parsing position" and
"const parsing position".
 1.156 01-Oct-2020  rillig make(1): remove redundant function prototypes
 1.155 28-Sep-2020  rillig make(1): replace += 1 with ++ and -= 1 with --

Just for visual consistency. The generated code stays exactly the same.
 1.154 28-Sep-2020  rillig make(1): make debugging code shorter
 1.153 27-Sep-2020  rillig make(1): normalize whitespace in source code

There is no more space tab. Either only tabs or only spaces or tabs
followed by spaces, but not spaces followed by tabs.
 1.152 26-Sep-2020  rillig make(1): clean up API for finding and creating GNodes

The previous API had complicated rules for the cases in which the single
function returned NULL or what it did. The flags for that function were
confusing since passing TARG_NOHASH would create a new node even though
TARG_CREATE was not included in that bit mask.

Splitting the function into 3 separate functions avoids this confusion.
It also reveals several places where the complicated API led to
unreachable code. Such code has been removed.
 1.151 25-Sep-2020  rillig make(1): rename variables cp2 to be more expressive
 1.150 25-Sep-2020  rillig make(1): add tags to some of the unnamed structs

The tags prevent the structs from accidentally becoming compatible
types.

While here, remove a few typedefs for structs that are single-purpose,
since there is no point in abstracting from the actual representation of
these types.
 1.149 25-Sep-2020  rillig make(1): rename local variables in ParseFuncArg
 1.148 22-Sep-2020  rillig make(1): rename VarParseErrors to VarParseResult

The name VPE_OK was confusing since it was not an error at all.
 1.147 14-Sep-2020  rillig make(1): fix coverity annotation for CondParser_String

It had been broken since 2020-09-08, when CondLexer (now CondParser) was
added.
 1.146 13-Sep-2020  rillig make(1): suppress wrong "Malformed conditional" for undefined variables

This only has an effect in lint mode right now.
 1.145 13-Sep-2020  rillig make(1): prepare Var_Parse for proper error handling and reporting

Right now, Var_Parse swallows many errors during parsing and evaluation.
Ideally, these errors should propagate from the deeply nested
expressions where they occur up to the top-level expressions. When such
an error occurs, the depending expressions should not be evaluated any
further. They may still be parsed, but side effects should be
minimized.

The goal is to prevent incomplete expressions like the "xy}" in
moderrs.exp:106 from being evaluated and eventually passed to the shell
for execution. This expression is a left-over from a parse error in the
mod-t-parse target in moderrs.mk:154.

This commit is a first step in analyzing and verifying the current state
of affairs. The modelling in VarParseErrors already looks complicated
but is expected to closely match reality.
 1.144 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.143 13-Sep-2020  rillig make(1): fix parameter type of CondEvalExpression
 1.142 13-Sep-2020  rillig make(1): clean up API for evaluating conditions

There was no need to make struct If publicly visible.

There was no need to have parameters in the public API that were passed
the same constants all the time.

The former function names had not been distinctive.
 1.141 12-Sep-2020  rillig make(1): rename Var_ParsePP back to Var_Parse

The migration to the "parsing position" pointer has been done.
 1.140 12-Sep-2020  rillig make(1): migrate CondParser_String to Var_ParsePP
 1.139 12-Sep-2020  rillig make(1): use correct character literals in TryParseNumber
 1.138 12-Sep-2020  rillig make(1): clean up code in CondParser_String

The two parts of the for loop were not related in any way, which made
the code more confusing than necessary.
 1.137 12-Sep-2020  rillig make(1): fix inconsistent code indentation
 1.136 12-Sep-2020  rillig make(1): inline local variable in Cond_Eval
 1.135 12-Sep-2020  rillig make(1): fix wording of parse error in conditionals

The word "should" is not appropriate for situations that eventually lead
to a parse error.
 1.134 11-Sep-2020  rillig make(1): add wrappers around ctype.h functions

This avoids casting the argument to unsigned char, and to cast the
result of toupper/tolower back to char.
 1.133 11-Sep-2020  rillig make(1): split EvalComparison into smaller functions
 1.132 11-Sep-2020  rillig make(1): clean up code for evaluating conditions
 1.131 11-Sep-2020  rillig make(1): extract EvalNotEmpty from CondParser_Comparison
 1.130 11-Sep-2020  rillig make(1): split CondParser_Comparison into 2 parts
 1.129 11-Sep-2020  rillig make(1): document CondParser_Comparison
 1.128 11-Sep-2020  rillig make(1): add tests for really strange edge cases in conditions
 1.127 11-Sep-2020  rillig make(1): reorder parameters of condition parsing functions

First the subject, then the options, then the output parameters.
 1.126 11-Sep-2020  rillig make(1): reduce code size in CondParser_Eval
 1.125 11-Sep-2020  rillig make(1): use consistent naming scheme for condition parsing functions
 1.124 11-Sep-2020  rillig make(1): rename CondGetString to CondParser_String

This describes the function's effect more accurately. The verb "get" is
not commonly associated to having side effects.
 1.123 11-Sep-2020  rillig make(1): replace *par->p with par->p[0]

It's a few characters more code than before but can be read strictly
from left to right, which was not possible before.
 1.122 11-Sep-2020  rillig make(1): rename CondParser.condExpr to p

The prefix "cond" was needed when this struct field was a global
variable. The main name "expr" was not precise enough since this code is
about parsing a condition, not an expression.

During parsing, this variable does not contain the whole expression but
a pointer to the remaining part of the condition, therefore the name
"expr" had been confusing.
 1.121 11-Sep-2020  rillig make(1): rename CondLexer to CondParser

The name CondLexer was wrong since this type is about parsing conditions
that can be arbitrarily nested.
 1.120 10-Sep-2020  rillig make(1): reduce code size in CondGetString

The pattern is now the usual "test the character, then increment the
pointer", throughout the whole function.
 1.119 10-Sep-2020  rillig make(1): skip redundant condExpr-- in CondGetString
 1.118 10-Sep-2020  rillig make(1): reduce code size for parsing the || or && operators

On x86_64, accessing [0] generates less code than [1].
 1.117 08-Sep-2020  rillig make(1): clean up comments in cond.c
 1.116 08-Sep-2020  rillig make(1): add CondLexer_SkipWhitespace
 1.115 08-Sep-2020  rillig make(1): rename CondLexer.condPushBack to curr

This variable has some context information from the struct now,
therefore its name can be shorter.
 1.114 08-Sep-2020  rillig make(1): group the condition parsing state into a struct

Instead of having 3 global variables, the struct clearly communicates
that the 3 variables belong together. During debugging, it's easy to
just "p *lex" instead of remembering the names of the 3 former global
variables.

Converting the global variables into a local variable makes it
immediately clear that the functions in this file operate on this
struct. Keeping the global variables in mind is more difficult. Having
a local variable also gets rid of the 3 sv_* variables in
Cond_EvalExpression, which were also a sign that these "global
variables" were not that global at all.

This commit only contains the minimal code changes for converting the
variables into a local struct. It was tempting to add functions like
CondLexer_SkipWhitespace, but this is better left for a follow-up
commit.
 1.113 08-Sep-2020  rillig make(1): in CondGetString, replace repeated Buf_Add with Buf_AddStr
 1.112 04-Sep-2020  rillig make(1): rename local functions for parsing conditions

The word "get" implies a cheap operation without side effects. Parsing
instead has lots of side effects, even if it's only that the parsing
position is updated.
 1.111 04-Sep-2020  rillig make(1): migrate get_mpt_arg to Var_ParsePP

This part is covered well by the unit tests. When I forgot to decrement
the linePtr, several of them failed reliably.
 1.110 04-Sep-2020  rillig make(1): migrate Var_Parse in CondGetArg to Var_ParsePP
 1.109 03-Sep-2020  rillig make(1): document use of magic values in CondDoEmpty
 1.108 03-Sep-2020  rillig make(1): update documentation for Cond_EvalExpression and Cond_Eval
 1.107 03-Sep-2020  rillig make(1): make parameter of Cond_Eval and Cond_EvalExpression const
 1.106 29-Aug-2020  rillig make(1): trust that Var_Parse never returns NULL

That function is quite long, but all its return paths lead either to the
expanded variable expression, or to var_Error or varNoError.
 1.105 29-Aug-2020  rillig make(1): rename Lst_FindB back to Lst_Find

The migration from "comparison function" to "match function" is done,
the "B" in the names is no longer needed.
 1.104 29-Aug-2020  rillig make(1): start replacing Lst_Find with Lst_FindB

Lst_Find is called with a "comparison" function that returns the integer
0 if the desired node is found. This leads to confusion since there are
so many different return value conventions for int, such as 0/1 for
mimicking false/true, -1/0 as in close(2), and the sign as in strcmp(3).
This API is much easier to understand if the "comparison" function is
not called a comparison function (since that is too close to strcmp),
but a "match" function that just returns a boolean.

In Lst_FindFromB, the node argument may be null. This deviates from the
other Lst functions, which require Lst and LstNode to generally be
non-null. In this case it is useful though to make the calling code
simpler.

In arch.c, this makes a lot of the previous documentation redundant.

In cond.c, the documentation is reduced a little bit since it had
already been cleaned up before. It also removes the strange negation
from CondFindStrMatch.

In dir.c, the documentation collapses as well.

In main.c, separating the ReadMakefile function from the callbacks for
Lst_FindB allows the former to get back its natural function signature,
with proper types and no unused parameters.

To catch any accidental mistakes during the migration from Lst_Find to
Lst_FindB, the code can be compiled with -DUSE_DOUBLE_BOOLEAN, which
will complain about incompatible function pointer types.
 1.103 28-Aug-2020  rillig make(1): remove trailing 'S' from names of Lst functions

The migration from null-passing Lst functions to argument-checking Lst
functions is completed.

There were 2 surprises: The targets list may be NULL, and in Dir_AddDir,
the path may be NULL. The latter case is especially surprising since
that function turns into an almost-nop in that case. This is another
case where probably 2 independent functions have been squeezed into a
single function. This may be improved in a follow-up commit.

All other lists were fine. They were always defined and thus didn't
need much work.
 1.102 28-Aug-2020  rillig make(1): migrate Lst_Find to Lst_FindS
 1.101 27-Aug-2020  rillig make(1): migrate Lst_IsEmpty to Lst_IsEmptyS
 1.100 23-Aug-2020  rillig make(1): reverse order of the Lst_Find parameters

The other callbacks all have (function, param), only the Lst_Find had
(param, function), which was inconsistent.
 1.99 22-Aug-2020  rillig make(1): clean up headers

Remove redundant headers that are already included by "make.h".
Make <assert.h> available to all compilation units that use "make.h".
 1.98 20-Aug-2020  rillig make(1): move complicated boolean expression out of the function call

It's easier to inspect in a debugger this way.
 1.97 20-Aug-2020  rillig make(1): fix type of string length variables
 1.96 20-Aug-2020  rillig make(1): fix wrong or outdated comments
 1.95 13-Aug-2020  rillig make(1): fix type mismatch in compare_expression

This was caught by a simple "typedef double Boolean" in sprite.h.

If only there were a C compiler with "strict" mode, where pointers,
numbers and booleans were separate and unassignable data types, this
copy-and-paste typo would have been caught much earlier.
 1.94 13-Aug-2020  rillig make(1): fix type of local variable in CondGetString

When the Boolean type from sprite.h is replaced with C99's standard bool
type, the chained assignment leads to the following compile error with
GCC 5:

cond.c:404:5: error: suggest parentheses around assignment used as truth
value [-Werror=parentheses]
*quoted = qt = *condExpr == '"' ? 1 : 0;

Changing the type of qt from int to bool fixes this.
 1.93 09-Aug-2020  rillig make(1): format the source code consistently, at least per file

Some files use 4 spaces per indentation level, others use 8. At least
for the few files from this commit, they use a consistent style
throughout each file now.

In Cond_Eval, the #define has changed into an enum since the identifiers
need not be visible to the C preprocessor.
 1.92 08-Aug-2020  rillig make(1): remove trailing Z from buffer functions

This Z had been useful during the migration from int to size_t. This
migration is finished, at least for the Buffer type, so the Z is no
longer necessary.
 1.91 08-Aug-2020  rillig make(1): mark condition strings as constant
 1.90 08-Aug-2020  rillig make(1): remove redundant documentation from cond.c

Many of the functions in cond.c are so small that it's faster to read
their code instead of a large block of documentation.

There are other functions that actually need a detailed description.
These have been left as-is.
 1.89 08-Aug-2020  rillig make(1): remove redundant function prototypes from cond.c
 1.88 03-Aug-2020  rillig make(1): no declaration-after-statement anymore

NetBSD make is intended to be maximally portable, therefore it uses only
C89. This was not declared in the Makefile before.

There are still a few places in parse.c and metachar.c that use
end-of-line comments. These will be fixed in a follow-up commit.
 1.87 01-Aug-2020  rillig make(1): switch Buffer size from int to size_t

This change helps to make the various integer types compatible and is a
preparational step for setting WARNS=6 in the Makefile.

The documentation of buf.c has been cleaned up and condensed since it
was mostly redundant, and some statements were even slightly wrong.

All code changes are covered by the existing unit tests, except for the
few lines in for.c around for_var_len. These changes have been reviewed
thoroughly and manually, like all the others in this commit.

Those buffer functions that deal with sizes have been renamed by
appending a Z, to make sure that no function call was accidentally
forgotten. They will be renamed back in a follow-up commit.

As usual, the scope of a few affected variables has been reduced, and
some variables had to be split since they had been incorrectly merged
before.

The order of the arguments to Buf_AddBytes has changed from (mem_len,
mem) to (mem, mem_len), in order to make it consistent with the
functions from the C standard library, such as snprintf.
 1.86 01-Aug-2020  rillig make(1): use enum for return values of Cond_Eval and friends
 1.85 01-Aug-2020  rillig make(1): use consistent indentation in source code

Tabs for multiples of 8, then spaces.

The usage string has been kept as-is since the spaces there are
indentional and do influence the output.
 1.84 01-Aug-2020  rillig make(1): avoid calls to free(3) in the common case of a NULL pointer
 1.83 01-Aug-2020  rillig make(1): make CondDoDefined simpler
 1.82 26-Jul-2020  rillig make(1): make return value of Var_Parse constant

This return value is not supposed to be modified since it can be a string
literal. The modifiable part is returned via freePtr, but only for
freeing, not for actually modifying anything.
 1.81 19-Jul-2020  rillig make(1): clean up unnecessary snprintf and multi-line function calls
 1.80 19-Jul-2020  rillig make(1): rename Varf_Flags to VarEvalFlags

In var.c there are lots of different flag types. To make any accidental
mixture obvious, each flag group gets its own prefix.

The only flag group that is visible outside of var.c is concerned with
evaluating variables, therefore the "e", which replaces the former "f"
that probably just meant "flag".
 1.79 09-Jul-2020  sjg compare_expression: return after fetch lhs and rhs if !doEval

Otherwise we end up throwing warings/errors for valid
conditionals due to not expanding variables fully.

Add tests to catch this.

Reviewed by: rillig
 1.78 03-Jul-2020  rillig make(1): remove trailing whitespace
 1.77 03-Jul-2020  rillig make(1): remove redundant parentheses around return values
 1.76 28-Jun-2020  rillig make(1): fix evaluation of unreachable conditions

Since 2015-10-11, make had evaluated unreachable conditions even though
the manual page said it didn't.
 1.75 16-Apr-2017  riastradh Replace dead conditional by assert.

CID 975995
 1.74 18-Feb-2016  christos branches: 1.74.2; 1.74.4;
Collapse the 3 boolean parameter to 1 flags parameter. No functional change.
 1.73 17-Jan-2016  christos remove free NULL checks (Tilman Sauerbeck)
 1.72 09-Jan-2016  christos Preserve $$ in := assignments..

FOO=\$$CRAP
BAR:=${FOO}

all:
echo ${FOO}
echo ${BAR}
 1.71 02-Dec-2015  sjg Fix evaluation of defined(FOO) and ${FOO} > 0
add a unit-test to catch it.
 1.70 30-Nov-2015  sjg Avoid accessing beyond end of empty string.

Detected by Address Sanitizer - dim at FreeBSD.org
 1.69 11-Oct-2015  sjg Add Boolean wantit to Var_Parse and Var_Subst

wantit will be FALSE when we are just consuming to discard
in which case we skip "expensive" things like Cmd_Exec.

Reviewed by: christos
 1.68 05-May-2015  sjg When evaluating condtionals from .if we want to require
that the lhs is a variable reference, a number or a quoted string.
This helps avoid subtle bugs caused by typos.

When conditionals are being evaluated during variable expansion
we cannot be as strict becuase lhs will already have been expanded.

We therefor pass a boolean to Cond_EvalExpression to tell it how
lhs should be treated.

Add unit-tests/cond2.mk to test the above

Reviewed by: christos, joerg
 1.67 03-Nov-2012  christos off-by-one
 1.66 03-Nov-2012  pgoyette Fix build break due to signed/unsigned comparison
 1.65 03-Nov-2012  sjg Allow cond_state[] to grow.
The need is rare, but real.

Reviewed by: christos
 1.64 12-Jun-2012  joerg branches: 1.64.2;
Replace __dead, __unused and the various printf format attributes
with versions prefixed by MAKE_ATTR_* to avoid modifying the
implementation namespace. Make sure they are available in all places
using nonints.h to fix bootstrap on Linux.
 1.63 21-May-2012  sjg In meta mode, level 0 can legitimately see > 64 nested .if's
 1.62 29-Mar-2011  sjg branches: 1.62.4;
CondDoExists: Avoid use after free()
 1.61 13-Feb-2011  sjg Mark unused args.
 1.60 06-Nov-2009  dsl branches: 1.60.2;
Change enum values so that TOK_FALSE is 0 and TOK_TRUE is 1.
Use this fact to remove loads of ? : clauses.
 1.59 30-Jan-2009  dsl Rename all the members of 'enum Token' to TOK_FOO.
Makes it rather more obvious wherethey belong - especially since
two of them were 'True' and 'False' (and not 1 and 0 either).
 1.58 30-Jan-2009  dsl Treat .ifdef ${foo} as .if defined(${foo}) not .if "${foo}" != "".
(and similarly for the other .ifxxx).
Do comparison against "" or 0 for .if "foo" and .if <numeric> directly
instead of faking up the operator string.
Rename error: to done: and use it for more exit paths.
Elucidate and correct some comments.

Fixes problems with makefiles that do:
.for var in var_1 var_2
.ifdef ${var}
...
which used to check whether var_1 was defined - because the .ifdef saw the
literal var_1, not a variable expansion due to the way .for loop variables
were substituted.
 1.57 29-Jan-2009  enami Avoid infinite loop.
 1.56 28-Jan-2009  dsl Allow for () in the argument to .ifdef et al.
Save/restore current values of global data across expression evaluation
to give ${foo:? ...} a change of working inside another .if.
 1.55 23-Jan-2009  dsl Sprinkle some const.
In particular for Lst_Find() and Lst_FindFrom().
Remove some unneeded casts and some now-undeeded UNCONST().
 1.54 23-Jan-2009  dsl Change 'ClientData' to 'void *' so that relevant parameters can
be made 'const void *'.
 1.53 23-Jan-2009  dsl There is no point in saving the last character of a NUL-terminated
string in order to overwrite with a NUL, then restore the original value!
Remove and simplify the CondDoFoo() functions.
 1.52 18-Jan-2009  dsl Revert previous - cause grief with .ifdef (foo)
Instead return False for exists(), defined(), make() etc when the
argument has length zero.
 1.51 18-Jan-2009  dsl Only terminate a conditional function argument on ')' if we expect the
argument to be exclosed in (...).
'.if exists()' is parsed as '.ifdef exists()' and the ')' must not be
left over at the end.
I have no idea why any of my recent changes have affected this.
But pkgsrc/mk/compiler/gcc.mk (line 488) does .if exists(${FCPATH})
even though FCPATH is only set when the file exists.
 1.50 17-Jan-2009  dsl Change 'Buffer' so that it is the actual struct, not a pointer to it.
Saves having to malloc/free a fixed size structure.
Buf_Init() now takes ptr to Buffer to initialiase.
Change Buf_Destroy() to return ptr to string when not freed.
Remove large number of casts to (Byte) and (Byte *) - 'Byte' is 'char' here.
Buf_AddByte[s] guarantees that the data is 0 termininated, so never add '\0'.
Keep 'count' not 'left' and 'inPtr', code is simplier with only one update.
Fix fallou, no functional change.
 1.49 13-Dec-2008  dsl Use NULL instead of -1 cast to the relavant type (usually via NIL).
This was a suggestion from christos - so blame him if there is a deep
reason for using -1 :-)
 1.48 29-Nov-2008  dsl Before deciding to use the default function in a .if, check whether the
token that follows the argument might be '==' or '!='.
If so then treat as a string comparison instead.
Fixes bin/15233 and bin/30967 provided some whitespace is present.
".if A==A" remains a check for defined(A==A) since make places no
restrictions on the names of variables!
 1.47 29-Nov-2008  dsl Common up parsing .if defined() make() exists() target() commands() and empty()
Add a check for the '(' following the function name, if absent then treat
as if the function name is unknown - usually leading to a syntax error.
No other functional changes intended.
 1.46 23-Nov-2008  dsl Do a string compare if the rh argument doesn't completely convert to a number
(instead of silently ignoring the chars that failed to convert).
Use strtoul() instead of homebrew copy.
Only use strtod() if strtoul() fails because the value is too large or
contains '.', 'e' or 'E'.
Do a compare for strings that start '-' or '+' as well as digits.
 1.45 22-Nov-2008  dsl Fix conversion of hex numerics in comparisons.
Broken by a fix from christos 14 years ago.
 1.44 22-Nov-2008  dsl Move two great chunks of code out of a switch statement and into
separate functions.
No functional change.
 1.43 22-Nov-2008  dsl If there is a syntax error in a .if expression then ignore the entire
conditional block (ie down to the matching .endif) instead of passing
the input line back to the normal parsing code.
Do the same if the maximum .if nesting (64 levels) is breached.
 1.42 29-Oct-2008  sjg If Parse_Error is called after curFile is invalid, set it to a dummy
to avoid seg-fault. Also the NULL filename will cause ParseVErrorInternal
to skip trying to report file and line number info.

If CondToken is called outside the context of a .if etc, variables in
the expression being parsed will already be expanded, so allow for
an unqouted number to jump us back into the compare logic.
This allows ${${SomeNumber:U42} > 0:?True:False} to work anywhere.

Job_Finish should process postCommands if it has commands or children.
 1.41 15-Feb-2008  christos back all changes out until I fix it properly.
 1.40 14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.39 07-Feb-2008  joerg Print the complain about random stuff after empty only once.
 1.38 06-Feb-2008  joerg Warn for constructs like
.if empty xxx(foo)
which are interpreted as
.if empty(foo)
or
.if empty (foo)

This is based on rillig's commit to pkgsrc/devel/bmake, but doesn't warn
for the third case. Discussed with sjg.
 1.37 04-Feb-2007  dsl branches: 1.37.4;
Add code to ensure that .if/.endif are correctly nested with .for/.endfor
and also include files don't have mismatched .if/.endif
It has been suggested that make used to have this test, but I can't
remember removing any code that might have performed it.
 1.36 02-Dec-2006  dsl Simplify the code that processes .if lines.
It doesn't need a two-dimensional array to remember the states of .if lines.
It would be even simpler if we didn't try to detect .else and .elif lines
that follow .else lines.
Unfortunately this isn't the code that is stupendously slow...
 1.35 27-Oct-2006  dsl branches: 1.35.2;
Since 'ClientData' is 'void *', nuke almost all the (ClientData) casts.
 1.34 15-Oct-2006  dsl Output all debug trace output through 'debug_file' defaulting to 'stdout'.
(Almost all the debug output went there, but some went to stderr.)
Split the parsing of -d (debug flags) out into its own routine.
Allow the output filename to be changed by specifying -dF<file> to create
a log file, or -dF+<file> to append to it. <file> may be stdout or stderr.
Also change so that -d-<flags> acts on <flags> locally but doesn't copy
them to MAKEFLAGS so they aren't inherited by child makes.
I'm not 100% happy with the command line syntax for the above, so they are
currently undocumented.
 1.33 28-Jul-2006  sjg Add debug output for CondDoExists() - the results can be surprising.
 1.32 22-Apr-2006  christos Coverity CID 526: Check for condTop < 0 where we decrement it, not later
when the damage is already done.
 1.31 02-Apr-2006  christos Remove bogus debugging code I accidentally committed.
 1.30 31-Mar-2006  christos Add some coverity allocation comments, and change the way the allocator
functions work. When they allocate storage that needs to be freed, instead
of setting a boolean, set the pointer to be freed. Plug some more memory
leaks found by inspection.
 1.29 08-Aug-2005  christos From Max Okumoto:
- Remove casts to NULL.
- Remove space between cast and object.
 1.28 25-Jul-2005  christos Whitespace KNF cleanup from Max Okumoto
 1.27 02-Jun-2005  lukem appease gcc -Wuninitialized
 1.26 01-Mar-2005  christos When parsing conditional tokens, make sure that the token is followed by
a non-alpha character, so that .elsefoo is not parsed as .else leading
to confusion later.
 1.25 16-Feb-2005  christos PR/29203, PR/29204: Max Okumoto: KNF changes to make [no functional changes]
 1.24 07-May-2004  ross Simplify build, no functional changes.

Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().

It's now possible to build make on some hosts with: cc *.c */*.c
 1.23 13-Apr-2004  sjg Allow "string" and "${varspec}" on lhs of conditionals.
This makes it possible to use expressions like
${("${LIST:Msomething"}):?present:absent}
it also makes treatment of lhs and rhs more consistent, and
makes CondToken easier to read.

Update unit-test/cond1 to test new features.
 1.22 08-Apr-2004  sjg Revised patch for catching extraneous .else's
We actually need to tack condTop and skipIfLevel.
Bump MAXIF while here.
Enhance the unit-test for conditionals to exercise more code.

PR: 24420
 1.21 08-Apr-2004  sjg Back out previous patch for now.
Breaks bsd.obj.mk
 1.20 08-Apr-2004  sjg Add check for extraneous .else's - based on patch from Arne H. Juul
in PR/24420.
Add a unit-test for conditionals.
Also in the unit-test makefile strip any .CURDIR in output.

PR: 24420
 1.19 06-Jan-2004  sjg branches: 1.19.2;
Handle more complex conditional expressions.
CondCvtArg now returns NULL if it consumed all input, or a pointer
to any left overs.
 1.18 06-Sep-2003  sjg Make empty() consider an undefined variable as empty,
rather than throw a syntax error.
 1.17 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.16 14-Jul-2003  christos Pass WARNS=3
 1.15 17-Apr-2003  sjg math.h is not needed and including it introduces uncessary dependencies
on some systems.

PR: 21204
 1.14 30-Dec-2002  sjg Treat an unquoted '#' as end of line when parsing conditionals.
This ensures that comments are ok at the end of line.

PR: 19596
Reviewed by: christos
 1.13 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.12 14-Jan-2001  christos Provide a new .if commands(<target>) primitive that returns true if the
target has commands associated with it.
 1.11 18-Sep-1998  christos Fix conditional variable expression parsing (reported by cgd)
 1.10 01-Apr-1998  christos Add conditional variable evaluation from Alistair Crooks.
 1.9 28-Sep-1997  lukem branches: 1.9.2;
wrap #include <sys/cdefs.h>, __RCSID(...) stuff in #ifndef MAKE_BOOTSTRAP
 1.8 01-Jul-1997  christos Add WARNS=1
RCSID police
 1.7 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.6 14-Jun-1995  christos branches: 1.6.6;
- $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.5 06-Jun-1994  jtc Fixes from Christos Zoulas, who used purify, objectcenter and testcenter
to find memory leaks and illegal memory accesses.
 1.4 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.3 13-Jan-1994  jtc Include appropriate header files to bring prototypes into scope.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.6.6.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.9.2.1 08-May-1998  mycroft Sync with trunk, per request of christos.
 1.19.2.5 10-May-2004  tron Pull up revision 1.24 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.19.2.4 10-May-2004  tron Pull up revision 1.23 (requested by sjg in ticket #282):
Allow "string" and "${varspec}" on lhs of conditionals.
This makes it possible to use expressions like
${("${LIST:Msomething"}):?present:absent}
it also makes treatment of lhs and rhs more consistent, and
makes CondToken easier to read.
Update unit-test/cond1 to test new features.
 1.19.2.3 10-May-2004  tron Pull up revision 1.22 (requested by sjg in ticket #282):
Revised patch for catching extraneous .else's
We actually need to tack condTop and skipIfLevel.
Bump MAXIF while here.
Enhance the unit-test for conditionals to exercise more code.
PR: 24420
 1.19.2.2 10-May-2004  tron Pull up revision 1.21 (requested by sjg in ticket #282):
Back out previous patch for now.
Breaks bsd.obj.mk
 1.19.2.1 10-May-2004  tron Pull up revision 1.20 (requested by sjg in ticket #282):
Add check for extraneous .else's - based on patch from Arne H. Juul
in PR/24420.
Add a unit-test for conditionals.
Also in the unit-test makefile strip any .CURDIR in output.
PR: 24420
 1.35.2.2 05-Jun-2007  bouyer Apply patch (requested by tron in ticket #696):
usr.bin/make/compat.c patch
usr.bin/make/cond.c patch
usr.bin/make/dir.c patch
usr.bin/make/for.c patch
usr.bin/make/main.c patch
usr.bin/make/make.1 patch
usr.bin/make/make.c patch
usr.bin/make/make.h patch
usr.bin/make/nonints.h patch
usr.bin/make/parse.c patch
usr.bin/make/str.c patch
usr.bin/make/targ.c patch
usr.bin/make/util.c patch
usr.bin/make/var.c patch

Synchronize make(1) with HEAD branch to increase perfomance and
improve stability.
 1.35.2.1 20-Dec-2006  bouyer branches: 1.35.2.1.2;
Pull up following revision(s) (requested by dsl in ticket #285):
usr.bin/make/cond.c: revision 1.36
usr.bin/make/parse.c: revision 1.121-1.124
usr.bin/make/make.h: revision 1.65
usr.bin/make/targ.c: revision 1.46
usr.bin/make/main.c: revision 1.138-1.139
Simplify the code that processes .if lines.
It doesn't need a two-dimensional array to remember the states of .if lines.
It would be even simpler if we didn't try to detect .else and .elif lines
that follow .else lines.
Unfortunately this isn't the code that is stupendously slow...
Unknot this code slightly by avoiding 'break/return; else' and by putting
the short parts of some conditionals first.
First step towards speeding up the parsing of makefiles (esp. the unwanted
parts of .if clauses).
There should be no changes to the logic.
There really is no point calling estrdup() to get a copy of the makefile name
into every 'gnode' (aka target), instead just copy a pointer to the string
and avoid freeing the original name when we close the file.
I can't imagine any makefile set where this gives a larger footprint!
Add anewline to the end of the error message output when the debug log
file cannot be opened.
Put the big block of code that was common to ParseDoInclude() and
ParseTraditionalInclude() into a separate routine.
Fix the 'use after free' and 'free on item not malloced' that got added
to ParseTraditionalInclude() in Feb 2006 (rev 1.111).
Kill the 'PTR' struct and put both its members into IFile.
Remove the parameter from ParseEOF(), 1 of the 3 calls passed the wrong value!
Fortunately another test stopped anything nasty happening, we'll use that
test instead.
Revert part of a recent commit.
ParseEOF() shouldn't close the original file.
Some minor changes:
- Only test 'printVars' once.
Has side effect of not trying to find the 'main' target for '-V varname'.
- Only reap the single child process in Cmd_Exec(),
I think this is for 'xx != cmd' so probobably no other children should exist.
- Don't read and parse .depend if '-r' and '-V varname' are set.
I suspect that .depend shouldn't affect the output of any -V command...
 1.35.2.1.2.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.37.4.1 23-Mar-2008  matt sync with HEAD
 1.60.2.1 17-Feb-2011  bouyer Sync with HEAD
 1.62.4.3 16-Jan-2013  yamt sync with (a bit old) head
 1.62.4.2 30-Oct-2012  yamt sync with head
 1.62.4.1 23-May-2012  yamt sync with head.
 1.64.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.74.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.74.2.1 26-Apr-2017  pgoyette Sync with HEAD
 1.365.2.1 02-Aug-2025  perseant Sync with HEAD
 1.29 07-Feb-2024  rillig make: remove unneeded conditional-compilation toggles

The toggles INCLUDES, LIBRARIES, POSIX, SYSVINCLUDE, SYSVVARSUB,
GMAKEEXPORT and SUNSHCMD are no longer needed, they were unconditionally
set.

The toggle NO_REGEX was configurable from the command line, but
disabling it would result in various error messages about the unknown
':C' modifier.

OK sjg@.
 1.28 11-Dec-2020  rillig make(1): fix documentation of POSIX configuration

Empty commands are always allowed, whether in POSIX mode or not.
 1.27 11-Dec-2020  rillig make(1): remove DEFMAXLOCAL and DEFMAXJOBS

These have been hard-wired all the time. The word LOCAL doesn't make
sense anymore since the code for running jobs remotely has gone.
 1.26 29-Nov-2020  rillig make(1): use space instead of tab for preprocessor directives
 1.25 19-Oct-2020  rillig make(1): clean up headers, no functional change
 1.24 18-Oct-2020  rillig make(1): remove USE_IOVEC

When a system call in a child process failed, there was no guarantee
that the error message would be written completely. Using writev
correctly is harder than building the string in a buffer and then
writing it in the traditional way.

According to POSIX 2004, using memory allocation or even calling
write(2) from the child process invokes undefined behavior. The
remaining code from make has done all this for several years now,
successfully, therefore adding one more of that won't hurt.

Make still tries to write the error message atomically by passing the
whole buffer at once to write(2), just as in the previous writev(2)
implementation.
 1.23 27-Sep-2020  rillig make(1): fix punctuation and add paragraphs in config.h comments
 1.22 01-Sep-2020  rillig make(1): mark LIBSUFF and RECHECK as independent build options
 1.21 31-Mar-2012  christos Add a gmake inspired export command
 1.20 14-Oct-2007  apb branches: 1.20.28;
Make it easier for the build environment (such as a configure script)
to override the default shell:

* Rename _BASENAME_DEFSHELL to DEFSHELL_CUSTOM, because it's no longer
always a basename, it might be a full path;
* Rename DEFSHELL to DEFSHELL_INDEX, because it's actually an index into
an array;
* Provide symbolic names for the possible values if DEFSHELL_INDEX;
* Document how the build environment may set DEFSHELL_INDEX or
DEFSHELL_CUSTOM to choose the default shell;
* Move the fallback definition of DEFSHELL_INDEX from config.h to job.c,
because it's used only in job.c.

Discussed with sjg.
 1.19 09-Oct-2006  apb branches: 1.19.8;
Allow make(1) to be built with something other than "sh" as the
shell. To use this, build with -D_PATH_DEFSHELLDIR=\"/path/to/dir\"
-D_BASENAME_DEFSHELL=\"shell\".

* Change the order of entries in shells[]. Now DEFSHELL defaults to 0,
and shells[0] describes the default shell. This will be "sh" in the
usual case.

* If _BASENAME_DEFSHELL is defined, insert an additional entry above
"sh" in the shells[] array, making this new entry shells[0]. The
new entry is assumed to refer to an sh-compatible shell with a
non-standard name. (Tested using _PATH_DEFSHELLDIR="/usr/pkg/bin" and
_BASENAME_DEFSHELL="bash".)

* In the shells[] entry for "sh", test defined(MAKE_NATIVE) &&
defined(__NetBSD__) to decide whether we can use the "q" flag.

OK sjg, christos
 1.18 09-Oct-2006  dsl Rip out the code for not 'USE_PGRP', I can't imagine it being useful!
My guess is that it is compat code for before the pgrp stuff was added.
 1.17 07-May-2004  ross Simplify build, no functional changes.

Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().

It's now possible to build make on some hosts with: cc *.c */*.c
 1.16 07-Aug-2003  agc branches: 1.16.2;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.15 01-Aug-2003  sjg Allow .SHELL: to control the shell used by compat mode too.
Add a shell spec for ksh - a nice portable posix shell.
Document .SHELL:
 1.14 16-Jan-2002  tv Bleh, make the conditional work *correctly* this time (...teaches me not to
try distilling down parenthesized booleans without caffeine).
 1.13 16-Jan-2002  tv Fix typo in previous.
 1.12 16-Jan-2002  tv Don't look at archive timestamps if MAKE_BOOTSTRAP is set. (I'm not
entirely sure that this is useful *at all* these days, since it's been
turned off for ELF since ELF was brought in....)
 1.11 29-May-2001  christos better error messages on exec* failures. From Simon Burge.
 1.10 03-May-1999  christos Define USE_PGRP so that we send signals to our job's process group instead
of only pid.
 1.9 26-Sep-1997  christos PR/4140: David A. Holland: use svr4 style archives for ELF environments
 1.8 26-Apr-1997  mellon Don't look at archive information on platforms that run ELF binaries
 1.7 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.6 28-May-1996  christos - Move -D flags from Makefile to config.h and explain what they do. Add
-Wall -Wno-unused to CFLAGS. Add new define SYSVVARSUB to enable SysV
style variable substitutions and enable them.
- Add SunOS style command substitutions via SUNSHCMD
- Fix core dump with '{variable = value'
 1.5 04-Feb-1996  christos branches: 1.5.4;
Support SVR4 style archives.
 1.4 14-Jun-1995  christos - $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.3 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.4.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.16.2.1 10-May-2004  tron Pull up revision 1.17 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.19.8.1 06-Nov-2007  matt sync with HEAD
 1.20.28.1 17-Apr-2012  yamt sync with head
 1.297 12-Jun-2025  rillig make: use a common style for unexpected error messages

In enomem, report the actual error instead of a fixed ENOMEM.
 1.296 11-Apr-2025  rillig make: convert more messages to the "file:123" format
 1.295 07-Jul-2024  rillig make: only generate code for cleanup functions in CLEANUP mode
 1.294 31-May-2024  rillig branches: 1.294.2;
make: clean up API for iterating over hash tables
 1.293 25-May-2024  rillig make: fix some more memory leaks
 1.292 25-May-2024  rillig make: fix a few more memory leaks
 1.291 24-May-2024  rillig make: remove trailing whitespace
 1.290 20-May-2024  sjg make: cleanup style in FindFile

Since we removed the last check for isinclude,
restore to the previous indentation etc.

No functional change.
 1.289 20-May-2024  sjg Allow .include <> to search .CURDIR last

libc at least appears to depend on this.
 1.288 19-May-2024  sjg make: use separate function to include makefiles.

Have Dir_FindFile and Dir_FindInclude call FindFile with a
bool flag to indicate whether .CURDIR should be be searched at all.
 1.287 19-May-2024  sjg Dir_FindFile treat sysIncPath and defSysIncPath as special

Rather than play games with adding .DOTLAST and then having to
exclude that from .SYSPATH, just have Dir_FindFile check if
path is sysIncPath or defSysIncPath and behave as if .DOTLAST seen
and also skip the final search of .CURDIR.

Fix Dir_SetSYSPATH to use defSysIncPath if sysIncPath is empty.
 1.286 29-Dec-2023  rillig make: fix declared types of list nodes

No functional change.
 1.285 19-Dec-2023  rillig make: clean up comments

No binary change, except for line numbers in assertions.
 1.284 17-Dec-2023  rillig make: clean up names of local variables

No binary change.
 1.283 21-Sep-2023  rillig make: remove obsolete comments, clean up comments and identifiers

No binary change, except for the line numbers in assertions.
 1.282 23-Jun-2023  rillig make: warn about malformed patterns in ':M', ':N' and '.if make(...)'

These patterns shouldn't occur in practice, as their results are tricky
to predict. Generate a warning for now, and maybe an error later.

Reviewed by sjg@.
 1.281 22-Jun-2023  rillig make: clean up comments related to pattern matching
 1.280 24-Jan-2023  sjg make: .SYSPATH: to add dirs to sysIncPath

.SYSPATH: with no sources will clear sysIncPath
otherwise sources are added

Reviewed by: rillig
 1.279 07-May-2022  rillig make: fix grammar in comment of DirFindDot
 1.278 04-Feb-2022  rillig make: use unsigned int for line numbers everywhere

Previously, some line numbers were stored as signed int while others
were stored as size_t. Since line numbers are never negative, use an
unsigned type. Since the maximum file size for makefiles is 1 GB (see
loadfile), unsigned int is large enough even on 64-bit platforms.

Using a single data types reduces the number of type conversions. Using
unsigned int improves compatibility with C90 (printf %u instead of %zu),
which is needed by bmake, which is derived from usr.bin/make.

No functional change.
 1.277 30-Jan-2022  christos Make the GNode lineno unsigned to fix lint warning in var.c calling
PrintLocation()
 1.276 15-Dec-2021  rillig make: use consistent indentation for statements and continuations

No binary change, except for line numbers in assertions in suff.c.
 1.275 28-Nov-2021  rillig make: eliminate CachedStatsFlags

Having two boolean flags as parameters should be easier to understand
than bit manipulations. The variable names now match more directly.

No functional change.
 1.274 28-Nov-2021  rillig make: convert GNodeFlags from enum into bit-fields

Now that Enum_ToString is implemented for each type separately, it's
easy to convert them to bit-fields. This gets rid of the magic numbers
12 for CYCLE and 13 for DONECYCLE that left a suspicious gap in the
numbers. This gap was not needed since the code didn't make use of the
relative ordering of the enum constants.

The effects of this conversion are fewer capital letters in the code,
smaller scope for the GNode flags, and clearer code especially when
setting a flag back to false.

One strange thing is that GCC 10.3.0 doesn't optimize GNodeFlags_IsNone
to an single bitmasking instruction, at least on x86_64. Instead it
generates a testb instruction for each of the flags, even loading bit 8
separately from the others. Clang 12.0.1 knows this optimization
though and generates the obvious sequence of movzwl, testl, jz.

No functional change.
 1.273 21-Sep-2021  rillig make: remove unnecessary const from parameters

These were leftovers from earlier refactorings, when extracting code to
separate functions.

No functional change.
 1.272 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.271 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.270 05-Feb-2021  rillig make: add const to SearchPath_Print
 1.269 05-Feb-2021  rillig make: add shortcut Global_Delete for deleting a global variable
 1.268 04-Feb-2021  rillig make: rename some VAR constants to SCOPE

The word "context" does not fit perfectly to the variables that are
associate with a GNode, as the context is usually something from the
outside and the variables are more like properties inherent to the
GNode.

The term "global context" fits even less. Since the thing where
variables are looked up is commonly named a scope, use that term
instead.

This commit only renames the global variables VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE, plus a few very closely related comments. These are:

GNode.vars (because of line breaks)
GNode_Free (dito)
varname-make_print_var_on_error.mk
varname-make_print_var_on_error-jobs.mk

The debug message in Var_Stats is left as-is since there is no unit test
for it yet.

The other renamings (variable names "context", "ctxt", as well as
further comments) will be done in a follow-up commit.
 1.267 03-Feb-2021  rillig make: replace Global_AppendExpand with Global_Append

All callers with a variable name that is guaranteed to not contain a
dollar sign have been converted to call Global_Append instead of the
previous Global_AppendExpand. After that, Global_AppendExpand was
unused, therefore it was effectively just renamed.
 1.266 03-Feb-2021  rillig make: use shortcut functions Global_SetExpand and Global_AppendExpand

There are many places where global variables are set or appended to. To
reduce clutter and code size, encode the VAR_GLOBAL in the function
name.

The word Expand in the function names says that the variable name is
expanded. In most of the cases, this is not necessary, but there are no
corresponding functions Global_Set or Global_Append yet.

Encoding the information whether the name is expanded or not in the
function name will make inconsistencies obvious in future manual code
reviews. Letting the compiler check this by using different types for
unexpanded and expanded variable names is probably not worth the effort.
There are still a few bugs to be fixed, such as in SetVar, which expands
the variable name twice in a row.
 1.265 30-Jan-2021  rillig make(1): split Buf_Destroy into Buf_Done and Buf_DoneData

In all cases except one, the boolean argument to Buf_Destroy was
constant. Removing that argument by splitting the function into two
separate functions makes the intention clearer on the call site. It
also removes the possibility for using the return value of Buf_Done,
which would have made no sense.

The function Buf_Done now pairs with Buf_Init, just as in HashTable and
Lst.

Even though Buf_Done is essentially a no-op, it is kept as a function,
both for symmetry with Buf_Init and for clearing the Buffer members
after use (this will be done only in CLEANUP mode, in a follow-up
commit).
 1.264 24-Jan-2021  rillig make(1): convert SearchPath to struct

This prepares for making dotLast a simple struct member instead of a
fake CachedDir, which is easier to understand.
 1.263 23-Jan-2021  rillig make(1): split Dir_FindFile into separate functions
 1.262 23-Jan-2021  rillig make(1): remove the remaining beasts from the comments
 1.261 23-Jan-2021  rillig make(1): extend comments in dir.c
 1.260 23-Jan-2021  rillig make(1): rename Dir_AddDir, reorder parameters of SearchPath_ToFlags
 1.259 23-Jan-2021  rillig make(1): extract SearchPath_ExpandMiddle from SearchPath_Expand
 1.258 23-Jan-2021  rillig make(1): split local variable in SearchPath_Expand
 1.257 23-Jan-2021  rillig make(1): rename parameter of SearchPath_Expand
 1.256 23-Jan-2021  rillig make(1): rename Dir_Expand to SearchPath_Expand

The main subject of this function is the search path. In this search
path the pattern is expanded.
 1.255 10-Jan-2021  rillig make(1): consistently use boolean expressions in conditions

Most of the make code already followed the style of explicitly writing
(ptr != NULL) instead of the shorter (ptr) in conditions.

The remaining 50 instances have been found by an experimental,
unpublished check in lint(1) that treats bool expressions as
incompatible to any other scalar type, just as in Java, C#, Pascal and
several other languages.

The only unsafe operation on Boolean that is left over is (flags &
FLAG), for an enum implementing a bit set. If Boolean is an ordinary
integer type (the default), some high bits may get lost. But if Boolean
is the same as _Bool (by compiling with -DUSE_C99_BOOLEAN), C99 6.3.1.2
defines that a conversion from any scalar to the type _Bool acts as a
comparison to 0, which cannot lose any bits.
 1.254 30-Dec-2020  rillig make(1): format multi-line comments
 1.253 27-Dec-2020  rillig make(1): exit 2 on technical errors

This allows the -q option to distinguish errors from out-of-date
targets. Granted, it's an edge case but it should be solved
consistently anyway.

The majority of cases in which make exits with exit status 1, even in -q
mode, is when there are parse errors. These have been kept as-is for
now as they affect many of the unit tests.

The technical errors, on the other hand, occur so rarely that it's hard
to write reliable tests for them that fail consistently on all platforms
supported by make.
 1.252 13-Dec-2020  rillig make(1): add str_basename to reduce duplicate code

The function basename from POSIX has a few unfortunate properties, it is
allowed to return a pointer to static memory. This is too unreliable,
therefore this trivial own implementation.
 1.251 06-Dec-2020  rillig make(1): remove comment decoration
 1.250 06-Dec-2020  rillig make(1): inline macros for debug logging

No changes to the resulting binary, except for the line numbers in
assertions.
 1.249 04-Dec-2020  rillig make(1): use consistent variable names for list nodes
 1.248 04-Dec-2020  rillig make(1): use fixed format for debug output of the directory cache

The previous output format had a %-20s conversion specifier. This
produced different output depending on the length of the pathname, which
was too difficult to normalize. By moving the directory name to the
end, it is no longer necessary to fill up any space, and the numbers are
always aligned properly.

As a result, 3 of the unit tests no longer need any special
postprocessing of their output.
 1.247 01-Dec-2020  rillig make(1): rename local variable in Dir_SetPATH

The variable name should reflect the close relationship to the .DOTLAST
keyword that can be used in search paths.
 1.246 01-Dec-2020  rillig make(1): remove Dir_InitDir

The function name had been too ambiguous since it didn't mention the
particular directory that was initialized. Instead of that function,
Dir_InitCur is called directly from main_Init.

The pseudo CachedDir entry ".DOTLAST" is initialized at the very
beginning. The observable behavior is unchanged since this a
memory-only object with no connection to the file system.
 1.245 30-Nov-2020  rillig make(1): clean up variable names in Dir_FindFile

The special path entry is called .DOTLAST, therefore the local variable
should have the same name.

A variable named 'base' must not point to the slash of a pathname. It
may only point to the character after the slash, everything else is
confusing, even if it's only for a brief moment.
 1.244 30-Nov-2020  rillig make(1): document difference between 'cur' and 'dot'
 1.243 30-Nov-2020  rillig make(1): fix memory leak for lstat cache in -DCLEANUP mode
 1.242 29-Nov-2020  rillig make(1): initialize global variables in dir.c

Calling CachedDir_Assign requires that the variable be initialized. On
most systems, NULL is represented as all-zero bits already. This change
is only for the few other systems.

Add some comments explaining the implementation of Dir_AddDir since that
is tricky to read from the code alone.
 1.241 29-Nov-2020  rillig make(1): clean up memory management for CachedDirs

Previously, the reference count for a newly created CacheDir had been
set to 1 in CacheNewDir. This was wrong because at that point, the
object had not been referenced by any nonlocal variable. The reference
count is no longer incremented at this point.

All callers of CacheNewDir either append the newly created CachedDir to
a SearchPath via Lst_Append and CachedDir_Ref, or they assign it to a
global variable via CachedDir_Assign.

Since the reference count is no longer wrongly incremented, it does not
need to be decremented more than necessary in Dir_End. To keep the code
simple and maintainable, all assignments to global variables are now
handled by CachedDir_Assign. Adding a CachedDir to a list is still done
manually via Lst_Append, and the corresponding code for decrementing is
in SearchPath_Clean and SearchPath_Free. These details may be cleaned
up in a follow-up commit.

As a result, when OpenDirs_Done is called in the unit tests, the list of
open directories is empty. It had been non-empty in a single unit test
before (dep-wildcards.mk), as a result of calling Dir_Expand.

The additional debug logging for the reference counting is not enabled
by default since it contains memory addresses, which makes the output
dependent on the memory allocator.

The function CachedDir_Destroy has been merged into CachedDir_Undef,
which had only been used in Dir_End before. The new name emphasizes
that it corresponds to CachedDir_Ref.
 1.240 29-Nov-2020  rillig make(1): fix the reference count of dotLast going negative

The memory management for dotLast is quite simple. It is initialized
exactly once main_Init > Init_Objdir > Dir_InitDir and freed exactly
once in main_CleanUp > Dir_End. Previously, dotLast was not freed at all.

The first call to CachedDir_Unref decremented the refCount to 0 but
didn't free anything. Next, CachedDir_Destroy was called, which
decremented the reference count to -1, therefore skipping the actual
freeing. This was probably an implementation mistake.

Since Dir_End is called at the very end of main_CleanUp, no code
accesses dotLast after it has been freed.
 1.239 29-Nov-2020  rillig make(1): move CachedDir_Destroy up to the related functions
 1.238 29-Nov-2020  rillig make(1): extract CachedDir_Free0 from CachedDir_Destroy
 1.237 29-Nov-2020  rillig make(1): remove wrong comment in Dir_InitCur

In a makefile with repeated ".CURDIR=." lines, Dir_AddDir is called with
a NULL path, once per line. Since the path is NULL, the search for
OpenDirs_Find is skipped and the directory is always read from disk.
The freshly read directory has a refCount of 1, and the refCount never
raises above 2.

In Dir_InitCur, the directory of the previous .CURDIR has a refCount of
2, which is decremented twice and then freed. After this, the new
directory is placed in the global 'cur', after incrementing its refCount
to 2.

It still seems wrong that the refCount of 'cur' is 2 instead of 1, but
it works well.
 1.236 29-Nov-2020  rillig make(1): add debug logging for OpenDirs_Done
 1.235 29-Nov-2020  rillig make(1): extract CacheNewDir from Dir_AddDir

Change the debug output for directories that are not found.
 1.234 29-Nov-2020  rillig make(1): make documentation of CachedDir.refCount more precise
 1.233 29-Nov-2020  rillig make(1): add debug logging for reference counting of CachedDir
 1.232 29-Nov-2020  rillig make(1): normalize order of declarations in dir.c
 1.231 29-Nov-2020  rillig make(1): remove comment about returning const

The callers modify the reference count of the CachedDir, therefore it
must be modifiable.
 1.230 29-Nov-2020  rillig make(1): rename Dir_Destroy to CachedDir_Destroy

It is no longer exported by the Dir module.
 1.229 29-Nov-2020  rillig make(1): unexport CachedDir internals
 1.228 29-Nov-2020  rillig make(1): reduce memory allocation for dirSearchPath
 1.227 28-Nov-2020  rillig make(1): reduce memory allocation in OpenDirs
 1.226 28-Nov-2020  rillig make(1): replace void pointer in Dir_Destroy with proper pointer
 1.225 28-Nov-2020  rillig make(1): replace Dir_Destroy with SearchPath_Free

The function Dir_Destroy is an implementation detail of the cached
directories, and it should not be exported to the other modules. The
search paths, on the other hand, are the high-level API that may be used
by the other modules, as the concept of search paths is documented in
the manual page.
 1.224 28-Nov-2020  rillig make(1): rename some Dir functions to SearchPath

These functions have the search path as their main subject.
 1.223 28-Nov-2020  rillig make(1): reduce pointer indirection for GNode.implicitParents
 1.222 23-Nov-2020  rillig make(1): use comparisons in boolean expressions

The generated code stays exactly the same.
 1.221 23-Nov-2020  rillig make(1): indent remaining functions in dir.c with tabs
 1.220 23-Nov-2020  rillig make(1): extract ResolveMovedDepends from ResolveFullName
 1.219 23-Nov-2020  rillig make(1): extract ResolveFullName from Dir_UpdateMTime
 1.218 23-Nov-2020  rillig make(1): in Dir_Expand, don't re-use local variables

While here, add a few remarks from a previous attempt at flattening
the function.
 1.217 23-Nov-2020  rillig make(1): update the deactivated code in Dir_FindFile

While here, reduce the scope of the variable ln.
 1.216 23-Nov-2020  rillig make(1): indent Dir_Expand with tabs instead of spaces
 1.215 23-Nov-2020  rillig make(1): flatten Dir_Expand

While here, leave comments in all places where unexpected edge cases
might have hidden.
 1.214 23-Nov-2020  rillig make(1): use properly typed comparisons in boolean contexts
 1.213 23-Nov-2020  rillig make(1): align end-of-line comments with tabs
 1.212 23-Nov-2020  rillig make(1): indent dir.c using tabs instead of spaces

Except for Dir_Expand and Dir_UpdateMTime, which are nested too deeply
to use tabs right now. They first have to be split into separate
functions.
 1.211 23-Nov-2020  rillig make(1): migrate CachedDir.files from HashTable to HashSet
 1.210 14-Nov-2020  rillig make(1): replace a few HashTable_CreateEntry with HashTable_Set

Instead of HashTable_CreateEntry and HashEntry_Set, several places just
need the HashEntry for storing a value in it. This makes the calling
code simpler to understand.

These parts of the code are already hard enough to understand since they
are about memory management and aliasing. Having a too detailed API for
the HashTable only distracts from these topics.
 1.209 14-Nov-2020  rillig make(1): inline local variable in Dir_UpdateMTime

Now that the signature of cached_stats is cleaned up, the line is short
enough to contain the whole condition.
 1.208 14-Nov-2020  rillig make(1): remove redundant struct make_stat

In the cache for stat(2) and lstat(2), only one of the two timestamps
was ever used. To prevent a result from stat(2) leaking into the cache
for lstat(2), there have been two completely separate caches all the
time. Using different fields in the struct was therefore unnecessary.

By removing the redundant field, the internal struct in the cache is the
same as the external struct. This makes one of them redundant, thus
struct make_stat has been renamed to cached_stat, which better describes
its purpose, and the internal struct cache_st has been removed.

Just as before, the cache prevents any direct access to its internal
data. When passing it to the caller, it is copied.

Just as before, the field names of struct cached_stat cannot correspond
to those from struct stat, since the latter are often defined as macros.
Therefore they are prefixed with cst instead of st.

The redundancy had been added on 2020-06-05.
 1.207 14-Nov-2020  rillig make(1): remove redundant parameter from cached_stats

The hash table for the cached data depends only on the passed flags,
therefore the caller does not need to know about their existence.
 1.206 14-Nov-2020  rillig make(1): clean up cached_stats

No functional change.
 1.205 14-Nov-2020  rillig make(1): clarify what 'recently' means in the comments in dir.c
 1.204 14-Nov-2020  rillig make(1): fix typo in comments

This typo may have been influenced by all the '$' in the code.
 1.203 14-Nov-2020  rillig make(1): flatten Dir_InitCur
 1.202 08-Nov-2020  rillig make(1): document inefficient cache lookup in DirMatchFiles
 1.201 08-Nov-2020  rillig make(1): change return type of Dir_MTime to void

Only some callers actually needed the updated time, and because of the
many branches, it was difficult to see that the return value was indeed
gn->mtime all the time.
 1.200 08-Nov-2020  rillig make(1): change return type of Arch_MTime to void

This makes it easier to prove that Dir_MTime always returns gn->mtime,
without looking at the implementation of Arch_UpdateMTime.
 1.199 08-Nov-2020  rillig make(1): change return type of Arch_MemberMTime to void

This makes it easier to prove that Dir_MTime always returns gn->mtime,
without looking at the implementation of Arch_UpdateMemberMTime.
 1.198 07-Nov-2020  rillig make(1): use proper enum constant instead of 0 for CachedStatsFlags
 1.197 07-Nov-2020  rillig make(1): make API of Buf_Init simpler

In most cases, the caller doesn't want to specify the exact number of
preallocated bytes.
 1.196 07-Nov-2020  rillig make(1): clean up code stylistically

* Replace character literal 0 with '\0'.
* Replace pointer literal 0 with NULL.
* Remove redundant parentheses.
* Parentheses in multi-line conditions are not redundant at the
beginning of a line.
* Replace a few !ptr with ptr == NULL.
* Replace a few ptr with ptr != NULL.
* Replace (expr & mask) == 0 with !(expr & mask).
* Remove redundant braces for blocks in cases where the generated code
stays the same. (Assertions further down in the code would get
different line numbers.)
* Rename parameters in CondParser_String to reflect the data flow.
* Replace #ifdef notdef with #if 0.

The generated code stays exactly the same, at least with GCC 5.5.0 on
NetBSD 8.0 amd64 using the default configuration.
 1.195 06-Nov-2020  rillig make(1): rename Arch_MemMTime to Arch_MemberMTime

The abbreviation Mem was ambiguous, it could have meant memory as well.
 1.194 05-Nov-2020  rillig make(1): remove redundant parentheses from sizeof operator

The parentheses are only needed if the argument is a type, not an
expression.
 1.193 31-Oct-2020  rillig make(1): remove dead code for filename expansion using curly braces

Any string containing curly braces is already handled in the very first
if statement.
 1.192 30-Oct-2020  rillig make(1): fix indentation in source code
 1.191 27-Oct-2020  rillig make(1): rewrap and reword the large comment for directory caching

Hashing the directories is not a problem at all, it's the caching that
makes things complicated.
 1.190 26-Oct-2020  rillig make(1): remove "Results: none" from the documentation of void functions
 1.189 25-Oct-2020  rillig make(1): add GNode_Path to access the path of a GNode
 1.188 25-Oct-2020  rillig make(1): rename hash functions to identify the type name

This makes it easier to spot mismatches between the function name and
its first parameter, although the compiler should already catch most of
them. Except for void pointers.
 1.187 25-Oct-2020  rillig make(1): replace Dir_CopyDir with Dir_CopyDirSearchPath

Callback functions for the Lst functions do not belong in the public API
of a module.
 1.186 25-Oct-2020  rillig make(1): clean up Dir_HasWildcards
 1.185 25-Oct-2020  rillig make(1): clean up DirLookupSubdir and DirLookupAbs

As with cp2, the variable names p1 and p2 are not expressive.
 1.184 25-Oct-2020  rillig make(1): omit trailing space in debug output for expanding file patterns
 1.183 25-Oct-2020  rillig make(1): clean up documentation of DirExpandInt, rename it

The code in that function is so trivial that there is no point in
writing this much redundant documentation.
 1.182 25-Oct-2020  rillig make(1): document pattern matching edge case in DirMatchFiles
 1.181 25-Oct-2020  rillig make(1): refactor DirMatchFiles

Split the conditions since the comment only applies to one of them.
Use local variables for common subexpressions.
 1.180 25-Oct-2020  rillig make(1): clean up documentation of DirExpandCurly and Dir_Expand
 1.179 25-Oct-2020  rillig make(1): document that the SearchPath of Dir_FindFile may be NULL
 1.178 25-Oct-2020  rillig make(1): remove unused parameter from DirFindDot
 1.177 25-Oct-2020  rillig make(1): rename parameter of DirLookup

The DirLookup functions work on "name", which may be a complete path,
and on "base" or "cp", which is the basename of the file. Don't use
"name" for the basename, since that would be confusing.
 1.176 25-Oct-2020  rillig make(1): remove unused parameters from DirLookup
 1.175 25-Oct-2020  rillig make(1): only define OpenDirs_Done if necessary
 1.174 24-Oct-2020  rillig make(1): remove UNCONST from Dir_Expand

That code is called so seldom that one more memory allocation doesn't
hurt. It needs a wildcard character in a dependency declaration, which
is rare in practice; see dep-wildcards.mk for an example.
 1.173 24-Oct-2020  rillig make(1): inline DirFindName
 1.172 22-Oct-2020  rillig make(1): remove redundant type casts

This mainly affects the void pointers in callback functions for lists.
These had been necessary once when the parameter type was still
ClientData instead of void pointer.
 1.171 19-Oct-2020  rillig make(1): inline simple Lst getters

The function call variant takes more screen space than the direct field
access. Having an abstract API is usually a good idea, in this case of
simple read-only member access it makes the code more difficult to read.

LstNode_Set has been kept as a function since it is not a read-only
accessor function.
 1.170 18-Oct-2020  rillig make(1): add tags to enum types

This allows IDEs to offer better type information than "anonymous enum".
 1.169 18-Oct-2020  rillig make(1): replace Lst_Open with simple iteration in Dir_SetPATH
 1.168 18-Oct-2020  rillig make(1): replace Lst_Open with simple iteration in Dir_FindFile
 1.167 18-Oct-2020  rillig make(1): rename Lst_Init to Lst_New

For the other types such as HashTable and Buffer, the Init function does
not allocate the memory for the structure itself, it only fills it.
 1.166 18-Oct-2020  rillig make(1): rename HashEntry.name to key
 1.165 18-Oct-2020  rillig make(1): remove underscore from Hash_Table and Hash_Entry

For consistency with the other type names, such as GNodeListNode.
 1.164 18-Oct-2020  rillig make(1): make API for iterating over hash tables simpler
 1.163 17-Oct-2020  rillig make(1): normalize initialization and cleanup of the modules
 1.162 17-Oct-2020  rillig make(1): fix indentation
 1.161 05-Oct-2020  rillig make(1): remove pathname limit for Dir_FindHereOrAbove

While trying to compile the code with GCC's -Wformat-truncation, the
snprintf calls felt quite complicated. The function Dir_FindHereOrAbove
is not in a bottleneck execution path, therefore it doesn't hurt to
dynamically allocate the memory instead of using size-limited stack
memory.
 1.160 05-Oct-2020  rillig make(1): make dir.c, for.c and hash.c ready for WARNS=6

Some types have changed from int to unsigned int, size_t or time_t.

The variable i in hash.c has been kept as int since it counts down to
-1, which generates efficient machine code, at least on x86_64.
 1.159 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.158 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.157 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.156 03-Oct-2020  rillig make(1): clean up #include sections
 1.155 02-Oct-2020  rillig make(1): use hash table for looking up open directories by name

As long as there are less than 20 open directories, it's perfectly fine
to use a doubly-linked list for name lookup. A singly linked list or
even an array list would have been better, but anyway.

When the number of directories rises above 1000, which happens with
dirdeps.mk, linear list lookup becomes too expensive, especially since
each list entry is compared using a strcmp call, in a callback function
that is not inlined.

Using a hash table is much more efficient than linear lookup. While
here, abstract all operations regarding the openDirectories list into a
new data type that provides a simple and straight-forward API. This
strongly typed API is especially important since the current
implementation of the list and hash table is weakly typed, using void *
for the actual data, and StringList and CachedDirList refer to the
exactly same type, they just have different names to help the human
readers but don't provide any type safety.
 1.154 01-Oct-2020  rillig make(1): remove redundant function prototypes
 1.153 28-Sep-2020  rillig make(1): replace += 1 with ++ and -= 1 with --

Just for visual consistency. The generated code stays exactly the same.
 1.152 28-Sep-2020  rillig make(1): make debug logging simpler

This avoids referring to the debug_file variable in many places where
this implementation detail is not necessary.
 1.151 28-Sep-2020  rillig make(1): make debugging code shorter
 1.150 27-Sep-2020  rillig make(1): improve documentation of CachedDir and Dir_AddDir
 1.149 27-Sep-2020  rillig make(1): normalize whitespace in source code

There is no more space tab. Either only tabs or only spaces or tabs
followed by spaces, but not spaces followed by tabs.
 1.148 26-Sep-2020  rillig make(1): inline and remove LstNode_Prev and LstNode_Next

These functions made the code larger than necessary. The prev and next
fields are published intentionally since navigating in a doubly-linked
list is simple to do and there is no need to wrap this in a layer of
function calls, not even syntactically. (On the execution level, the
function calls had been inlined anyway.)
 1.147 25-Sep-2020  rillig make(1): replace a few calls to Lst_Open with simple loops

This avoids relying on the internal iterator of the list, which is
supposed to be removed in the near future.
 1.146 24-Sep-2020  rillig make(1): inline Lst_ForEach for debugging output in search paths
 1.145 24-Sep-2020  rillig make(1): rename Lst_ForEach to Lst_ForEachUntil

Since the callback function returns a terminating condition, this is not
really a foreach loop.

Many of the calls to Lst_ForEachUntil don't make use of the terminating
condition, and several don't modify the list structurally, which means
they don't need this complicated implementation.

In a follow-up commit, Lst_ForEach will be added back with a much
simpler implementation that iterates over the list naively, without a
terminating condition and without taking the iteration state from
Lst_Open/Lst_Next/Lst_Close into account. The migration to this simpler
implementation will be done step by step since each callback function
needs to be examined closely.
 1.144 22-Sep-2020  rillig make(1): use fine-grained type names for lists and their nodes

This is only intended to help the human reader. There is no additional
type safety yet.
 1.143 22-Sep-2020  rillig make(1): rename type Path to CachedDir

The word "path" is commonly used either as an abbreviation for pathname
(a string consisting of several directory or file names) or as an
abbreviation for search path (a list of directory names used for
searching files), but not for a single directory.
 1.142 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.141 12-Sep-2020  rillig make(1): fix assertion failure in Dir_Destroy in -DCLEANUP mode

When the openDirectories path list is cleaned up, each path from it is
first dequeued and then freed via Dir_Destroy. At this point, the path
is no longer in openDirectories, which triggered an assertion in
Lst_Remove, called by Dir_Destroy.
 1.140 12-Sep-2020  rillig make(1): fix indentation in dir.c
 1.139 12-Sep-2020  rillig make(1): rename local variable in Dir_FindFile

The name "cp" is not appropriate for a variable containing the basename
of a path.
 1.138 11-Sep-2020  rillig make(1): replace *a->b with a->b[0]

This allows the code to be read strictly from left to right. In most
places this style was already used.
 1.137 07-Sep-2020  rillig make(1): document that nested braces work as expected now
 1.136 05-Sep-2020  rillig make(1): remove initial size argument from Hash_InitTable

In all but one case this argument was set to auto-detect anyway. The
one case where it was set was not worth keeping this complicated API.
 1.135 02-Sep-2020  rillig make(1): fix cached_stat for files with st_mtime 0
 1.134 02-Sep-2020  rillig make(1): fix aliasing problem in cached_stat from the previous commit

When the struct stat was used for both calling the actual stat and for
returning the result, no copying was needed. This also had the side
effect that for the first call of cached_stat, the returned struct stat
included all the fields properly filled in, and on later calls, these
fields were all zeroed out.

These two variables are separate now, thus the fields need to be copied
explicitly. There are no existing unit tests for this, but ./build.sh
failed reliably.
 1.133 02-Sep-2020  rillig make(1): reduce number of stat fields returned by cached_stat

Only st_mtime and st_mode are actually filled, the remaining fields had
been set to zero. To prevent these from ever being accessed, a custom
struct make_stat replaces the previously used struct stat.

The fields in struct make_stat are intentionally named different from
the fields in struct stat because NetBSD and some other operating
systems define st_mtime as a macro, and that would not work in a field
declaration.
 1.132 02-Sep-2020  rillig make(1): use proper types in API of cached_stat and cached_lstat
 1.131 02-Sep-2020  rillig make(1): use Hash API from dir.c

When the Hash struct fields are renamed the next time, this should not
influence any code outside hash.h and hash.c.
 1.130 01-Sep-2020  rillig make(1): rename Hash_Table fields

Back in the 1980s it made sense to have the type information encoded in
the variable names. At the time when make was imported into the NetBSD
tree (1993-03-21), the functions did indeed not have prototypes, they
only had return types. The void type was already invented at that time.
Since the compiler could not verify the types of function parameters, it
made perfect sense to have each variable tell whether it was a pointer
or not.

Since ISO C90 this is no longer necessary since the compiler checks
this. The variable names can now focus on the application level and
their high-level meaning, expressing the relationship to other
variables instead of encoding redundant type information.
 1.129 01-Sep-2020  rillig make(1): improve variable names and data types in Dir_FindHereOrAbove
 1.128 01-Sep-2020  rillig make(1): make data types in Dir_HasWildcards more precise
 1.127 30-Aug-2020  rillig make(1): rename GNode.iParents to implicitParents

The i alone was too ambiguous. It could have meant ignore, implicit,
interactive, and probably many more.
 1.126 30-Aug-2020  rillig make(1): rename Lst_Datum to LstNode_Datum
 1.125 30-Aug-2020  rillig make(1): rename Lst_Memeber to Lst_FindDatum

The new name nicely aligns with Lst_Find and Lst_FindFrom.
 1.124 29-Aug-2020  rillig make(1): clean up comments in dir.c
 1.123 29-Aug-2020  rillig make(1): rename LstNode functions to match their type
 1.122 29-Aug-2020  rillig make(1): rename Lst_FindB back to Lst_Find

The migration from "comparison function" to "match function" is done,
the "B" in the names is no longer needed.
 1.121 29-Aug-2020  rillig make(1): start replacing Lst_Find with Lst_FindB

Lst_Find is called with a "comparison" function that returns the integer
0 if the desired node is found. This leads to confusion since there are
so many different return value conventions for int, such as 0/1 for
mimicking false/true, -1/0 as in close(2), and the sign as in strcmp(3).
This API is much easier to understand if the "comparison" function is
not called a comparison function (since that is too close to strcmp),
but a "match" function that just returns a boolean.

In Lst_FindFromB, the node argument may be null. This deviates from the
other Lst functions, which require Lst and LstNode to generally be
non-null. In this case it is useful though to make the calling code
simpler.

In arch.c, this makes a lot of the previous documentation redundant.

In cond.c, the documentation is reduced a little bit since it had
already been cleaned up before. It also removes the strange negation
from CondFindStrMatch.

In dir.c, the documentation collapses as well.

In main.c, separating the ReadMakefile function from the callbacks for
Lst_FindB allows the former to get back its natural function signature,
with proper types and no unused parameters.

To catch any accidental mistakes during the migration from Lst_Find to
Lst_FindB, the code can be compiled with -DUSE_DOUBLE_BOOLEAN, which
will complain about incompatible function pointer types.
 1.120 28-Aug-2020  rillig make(1): clean up Dir_AddDir

Extract the null check for path to the top level. This has the
side-effect of only incrementing dotLast.refCount if that entry is
actually used.

Reduce the indentation of the code by returning early from the simple
branches.
 1.119 28-Aug-2020  rillig make(1): remove trailing 'S' from names of Lst functions

The migration from null-passing Lst functions to argument-checking Lst
functions is completed.

There were 2 surprises: The targets list may be NULL, and in Dir_AddDir,
the path may be NULL. The latter case is especially surprising since
that function turns into an almost-nop in that case. This is another
case where probably 2 independent functions have been squeezed into a
single function. This may be improved in a follow-up commit.

All other lists were fine. They were always defined and thus didn't
need much work.
 1.118 28-Aug-2020  rillig make(1): migrate Lst_Find to Lst_FindS
 1.117 28-Aug-2020  rillig make(1): remove unused reference to Lst_Last
 1.116 28-Aug-2020  rillig make(1): migrate Lst_First to Lst_FirstS
 1.115 27-Aug-2020  rillig make(1): migrate Lst_IsEmpty to Lst_IsEmptyS
 1.114 27-Aug-2020  rillig make(1): migrate Lst_Succ to Lst_SuccS
 1.113 27-Aug-2020  rillig make(1): migrate Lst_ForEach to Lst_ForEachS

Most lists are always valid. Only the "targets" variable may be null in
some cases, probably.
 1.112 27-Aug-2020  rillig make(1): migrate remaining code from Lst_Open to Lst_OpenS
 1.111 26-Aug-2020  rillig make(1): add stricter variants for remaining Lst functions

In most cases the Lst functions are only called when the arguments are
indeed valid. It's not guaranteed though, therefore each function call
needs to be analyzed and converted individually.

While here, remove a few statements that were only useful when the Lst
functions handled circular lists.
 1.110 23-Aug-2020  rillig make(1): reverse order of the Lst_Find parameters

The other callbacks all have (function, param), only the Lst_Find had
(param, function), which was inconsistent.
 1.109 22-Aug-2020  rillig make(1): migrate Lst_AtFront to Lst_PrependS

This makes Lst_AtFront unused, as well as LstInsertBefore.
 1.108 22-Aug-2020  rillig make(1): replace Lst_Duplicate with Lst_CopyS

Lst_Duplicate would have passed through any null pointer, which was not
needed for make. It was the last function that used Lst_AtEnd, which in
turn was the last function that used LstInsertAfter. As a result, these
two functions have been removed.
 1.107 22-Aug-2020  rillig make(1): use Lst_OpenS in Dir_SetPATH

Since dirSearchPath is initialized in Dir_Init, opening the list can
never fail.
 1.106 22-Aug-2020  rillig make(1): fix indentation
 1.105 22-Aug-2020  rillig make(1): extract percentage calculation out of Dir_PrintDirectories
 1.104 22-Aug-2020  rillig make(1): require argument of Lst_Member to be non-null

Since the lists don't contain null pointers, it doesn't make sense to
search for a null pointer. All calls but one already had obviously
non-null arguments. The one remaining call using targ->suff has been
guarded for now.

The code for Lst_Member became much simpler than before. Partly because
the old code had an extra condition for circular lists, which are not
used by make.
 1.103 22-Aug-2020  rillig make(1): replace Lst_Datum with non-null guaranteeing Lst_DatumS
 1.102 22-Aug-2020  rillig make(1): convert Lst_Enqueue and Lst_Dequeue to nonnull variants

Except for once instance in parse.c, the usage pattern for Lst_Dequeue
was to first test whether the list is empty. This pattern allowed the
implementation of Lst_Dequeue to become simpler since the null check is
not needed anymore.

The calls to Lst_Enqueue never pass an invalid list or a null pointer,
therefore making them strict was trivial.
 1.101 22-Aug-2020  rillig make(1): remove wrong comment for Dir_Init

Neither the list nor the hash table modules have anything to do with
opening directories.
 1.100 22-Aug-2020  rillig make(1): replace "(void)Lst_AtEnd" with stricter "Lst_AppendS"

This change ensures that there is actually something added to the list.
Lst_AtEnd had silently skipped the addition if the list was invalid
(null pointer), which was not intended in these cases. The "(void)" is
assumed to mean "I know that this cannot fail", while it could also mean
"I don't care whether something actually happened".

Running "./build.sh -j6 tools" still succeeds after this change,
therefore chances are very low that this change breaks anything. If
there is any change, it's an obvious assertion failure. There is no
silent change in behavior though.
 1.99 22-Aug-2020  rillig make(1): add Lst_Append to add an item at the end of the list

The previous variant of using a special case of Lst_InsertAfter was
unnecessarily complicated. Linked lists are a very basic data
structure, and there is no need to overcomplicate things by introducing
unnecessary conditions and branches.
 1.98 22-Aug-2020  rillig make(1): remove unused return value for DirMatchFiles
 1.97 22-Aug-2020  rillig make(1): split Dir_Init into two functions

There's just no point in having a function consisting of a big
if-then-else.
 1.96 21-Aug-2020  rillig make(1): use stricter list API for sequential access

In several places, it just doesn't make sense to have a null pointer
when a list is expected.

In the existing unit tests, the list passed to Lst_Open is always valid,
but that's not a guarantee for real-world usage. Therefore, Lst_Open
has been left for now, and Lst_OpenS is only the preferred alternative
to it.
 1.95 21-Aug-2020  rillig make(1): assert correct usage of the Lst_Open API

All calls to Lst_Next are properly protected by Lst_Open, so there is no
possible assertion failure here.
 1.94 21-Aug-2020  rillig make(1): make list library code stricter

Up to now, the list library didn't distinguish between programming
mistakes (violations of invariants, illegal parameter values) and
actually interesting situations like "element not found in list".

The current code contains many branches for conditions that are neither
exercised by the unit tests nor by real-world usage. There is no point
in keeping this unnecessary code.

The list functions will be migrated from their lenient variants to the
stricter variants in small parts, each function getting the S suffix
when it is made strict, to avoid any confusion about how strict a
particular function is. When all functions have been migrated, they
will be renamed back to their original names.

While here, the comments of the functions are cleaned up since they
mention irrelevant implementation details in the API comments, as well
as "side effects" that are really main effects.
 1.93 21-Aug-2020  rillig make(1): remove unused code for circular lists

The list library had probably been imported from a general-purpose
library that also supported circular lists. These are not used by make
though.

After replacing Lst_Init(FALSE) with Lst_Init(), only a single call to
Lst_Init remained with a non-constant argument, and that was in
Lst_Concat, which was to be expected.
 1.92 13-Aug-2020  rillig make(1): clean up debug logging in dir.c

In C90, the variadic macro argument __VA_ARGS__ is not known, therefore
fall back to the forms listing the number of actual printf arguments.
 1.91 13-Aug-2020  rillig make(1): avoid negated conditions in DirExpandCurly
 1.90 13-Aug-2020  rillig make(1): clean up DirExpandCurly

Now that nested curly braces work as expected and are covered by unit
tests, the debug log is no longer necessary.
 1.89 13-Aug-2020  rillig make(1): use enum instead of #define for cached_stats
 1.88 12-Aug-2020  rillig make(1): make Dir_MakeFlags simpler

This avoids unnecessary string allocations, especially for long lists.

There is no unit test to cover this code. Since this is an obscure,
undocumented part of make, I wasn't able to come up with a unit test.
Therefore I resorted to write a separate testing program to verify the
expected results.

$ cat <<'EOF' >dir_test.c
#include <stdio.h>

#include "make.h"
#include "dir.h"

int main(int argc, char **argv)
{
int i;
Lst lst;
char *flags;

lst = Lst_Init(FALSE);
for (i = 1; i < argc; i++)
Dir_AddDir(lst, argv[i]);
flags = Dir_MakeFlags("-I", lst);

printf("%s\n", flags);
free(flags);
return 0;
}
EOF

# Needs some trivial patches to Makefile and main.c
$ make PROG=dir_test EXTRA_SRCS=dir_test.c EXTRA_CPPFLAGS=-DNO_MAIN \
COPTS.main.c=-Wno-unused-function NOMAN=1

$ ./dir_test a b c

$ mkdir a b c
$ ./dir_test a b c
-Ia -Ib -Ic
$ rmdir a b c
 1.87 10-Aug-2020  rillig make(1): replace str_concat with str_concat2 and str_concat3

The new functions have a simpler interface, and str_concat3 is even more
general-purpose, since the middle string is no longer required to be
exactly of length 1.
 1.86 10-Aug-2020  rillig make(1): fix parameter name of str_concat

The previous documentation mentioned Str_Concat, but str_concat has been
written in lowercase for years. The "flags" are not flags since they
cannot be combined, not even when they are written in hex.
 1.85 09-Aug-2020  rillig make(1): format the source code consistently, at least per file

Some files use 4 spaces per indentation level, others use 8. At least
for the few files from this commit, they use a consistent style
throughout each file now.

In Cond_Eval, the #define has changed into an enum since the identifiers
need not be visible to the C preprocessor.
 1.84 03-Aug-2020  rillig make(1): no declaration-after-statement anymore

NetBSD make is intended to be maximally portable, therefore it uses only
C89. This was not declared in the Makefile before.

There are still a few places in parse.c and metachar.c that use
end-of-line comments. These will be fixed in a follow-up commit.
 1.83 01-Aug-2020  rillig make(1): use consistent indentation in source code

Tabs for multiples of 8, then spaces.

The usage string has been kept as-is since the spaces there are
indentional and do influence the output.
 1.82 31-Jul-2020  rillig make(1): document another instance of undefined behavior

The UNCONST macro is really terrible.

This segmentation fault can be forced by setting _PATH_DEFSYSMK in
pathnames.h to "./sys*.mk" or any other string that has a slash and a
wildcard to the right of the slash.
 1.81 31-Jul-2020  rillig make(1): fix regression and add test for empty brace expansion

This had been broken in r1.80 of dir.c, a few minutes ago.
 1.80 31-Jul-2020  rillig make(1): refactor DirExpandCurly

Separating the low-level parts into small functions reduces the need for
summarizing comments between the code lines.

Using a consistent naming scheme for the variables and expressive names
makes the code easier to understand. The number of variables has
increased from 7 to 11, their clearer names compensate for that, plus
the fact that they come in triples (x, x_end, x_len). Placing the
variables into appropriate registers and eliminating memory access is
left as an exercise to the compiler.
 1.79 31-Jul-2020  rillig make(1): fix parsing of nested braces in dependency lines

Before, make could not parse {{thi,fou}r,fif}teen properly. It did
correctly split up the outer brace into "" + "{thi,fou}r,fif" + "teen",
but then, when expanding the inner braces, it interpreted the first
comma already as a separator, even though this comma was enclosed in
another set of braces.

This resulted in the wrong expansion "{thiteen", which produced the
error message. The next word "fouteen" was produced since the parser
stopped at the next closing brace. After this, parsing continued after
the closing brace, producing "rteen". Finally, the last expansion was
the correct "fifteen".
 1.78 31-Jul-2020  rillig make(1): trying to understand how DirExpandCurly works
 1.77 31-Jul-2020  rillig make(1): prefer memcpy over strncpy in DirExpandCurly

strncpy has unnecessary overhead when the source memory is already
guaranteed to contain no '\0'.
 1.76 03-Jul-2020  rillig make(1): remove trailing whitespace
 1.75 03-Jul-2020  rillig make(1): remove redundant parentheses around return values
 1.74 05-Jun-2020  sjg cached_stats: do not conflate stat and lstat

While make uses lstat quite rarely, it does so for reason.
Avoid confusing the results.

Reviewed by: christos
 1.73 12-Jul-2018  christos Fix previous: cached_stats() returning < 0 means that the file is not found,
not that it was found in the cache, and centralize reporting.
 1.72 12-Jul-2018  reinoud Remove duplicate code in make(1)'s dir.c.

When the cached_stats() code was added, some old logic stayed around that
implements the cached_stats() too.
 1.71 16-Apr-2017  riastradh branches: 1.71.10; 1.71.12;
Plug memory leaks in Dir_FindFile.

CID 978364
 1.70 16-Apr-2017  riastradh Use, don't kludge, MAKE_ATTR_UNUSED.

CID 1300234
CID 1300237
CID 1300238
CID 1300245
CID 1300255
CID 1300267
CID 1300284
 1.69 31-Jan-2017  sjg Partially initialize Dir before MainParseArgs can be called.

The rest can be done once curdir is finalized.
 1.68 07-Jun-2016  sjg branches: 1.68.2; 1.68.4;
Extend the mtimes cache used by dir.c so it can be used by others.

We store both st_mtime and st_mode, since some callers care about the
later.

Reviewed by: christos
 1.67 05-Mar-2013  christos Add a .STALE special target that gets invoked when dependency files contain
stail entries.
 1.66 05-Mar-2013  christos Keep track of the location where a dependency is defined, so we can report
about it.
 1.65 12-Jun-2012  joerg branches: 1.65.2;
Replace __dead, __unused and the various printf format attributes
with versions prefixed by MAKE_ATTR_* to avoid modifying the
implementation namespace. Make sure they are available in all places
using nonints.h to fix bootstrap on Linux.
 1.64 07-Apr-2012  christos Remove recheck hackery that caused extra stats, and explicitly ask for
recheck when needed. Before it used to be the case that we could only
use the cached entry once. Once the cached entry was used, we removed
it from the cache. Now it is kept forever.
 1.63 05-Mar-2011  sjg branches: 1.63.4;
Treat some/dir/ the same as some/dir/.
 1.62 27-Nov-2010  sjg When a source file moves, make will ignore the stale dependency,
but if the file in question is one that needs to be compiled (.c or .cc),
it still hands the bogus name to the compiler.

If Dir_MTime() cannot find such a file (gn->iParents is not empty),
see if the basename can be found via .PATH, and if so set gn->path to
the found file. This prevents the stale path being given to the
compiler.

In meta_oodate(), if a referenced file no longer exists, consider the
target out-of-date.

Also, if meta_oodate() decides a target is out-of-date, and it
it uses .OODATE in its commands, we need .OODATE recomputed.
Undo our call to Make_DoAllVar() so that the call from Make_OODate()
will do the right thing.
 1.61 24-Jan-2009  dsl Don't cast 'time_t' to 'void *' and back it will lose precision.
 1.60 23-Jan-2009  dsl Sprinkle some const.
In particular for Lst_Find() and Lst_FindFrom().
Remove some unneeded casts and some now-undeeded UNCONST().
 1.59 23-Jan-2009  dsl Change 'ClientData' to 'void *' so that relevant parameters can
be made 'const void *'.
 1.58 28-Dec-2008  christos if mtime == 0, make it 1 because the code expects 0 time to mean that the
file does not exist
 1.57 13-Dec-2008  dsl Use NULL instead of -1 cast to the relavant type (usually via NIL).
This was a suggestion from christos - so blame him if there is a deep
reason for using -1 :-)
 1.56 06-Oct-2008  joerg Don't use emalloc and friends directly, but call them consistently
bmake_malloc and friends. Implement them via macros for the native case
and provide fallback implementations otherwise. Avoid polluting the
namespace by not defining enomem globally. Don't bother to provide
strdup and strndup, they were only used for the estrdup and estrndup
comapt code.

This addresses the presence of emalloc in system libraries on A/UX and
resulted strange issues as reported by Timothy E. Larson.
 1.55 15-Feb-2008  christos back all changes out until I fix it properly.
 1.54 14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.53 01-Jan-2007  dsl Remove 'else' after 'return', and similar whitspace changes.
Extra debug on where files are actually found.
 1.52 16-Dec-2006  dsl Fix a comment that has been wrong since rev 1.1, minor layout fix.
 1.51 27-Oct-2006  dsl branches: 1.51.2; 1.51.4;
Since 'ClientData' is 'void *', nuke almost all the (ClientData) casts.
 1.50 15-Oct-2006  dsl Output all debug trace output through 'debug_file' defaulting to 'stdout'.
(Almost all the debug output went there, but some went to stderr.)
Split the parsing of -d (debug flags) out into its own routine.
Allow the output filename to be changed by specifying -dF<file> to create
a log file, or -dF+<file> to append to it. <file> may be stdout or stderr.
Also change so that -d-<flags> acts on <flags> locally but doesn't copy
them to MAKEFLAGS so they aren't inherited by child makes.
I'm not 100% happy with the command line syntax for the above, so they are
currently undocumented.
 1.49 22-Apr-2006  christos Coverity CID 528: Avoid NULL deref.
 1.48 08-Aug-2005  christos From Max Okumoto:
- Remove casts to NULL.
- Remove space between cast and object.
 1.47 05-Aug-2005  christos More KNF cleanups from Max Okumoto
 1.46 25-Jul-2005  christos Whitespace KNF cleanup from Max Okumoto
 1.45 16-Feb-2005  christos PR/29203, PR/29204: Max Okumoto: KNF changes to make [no functional changes]
 1.44 29-Dec-2004  christos Dir_MTime did not search for a file using the correct parh; i.e. it was
ignoring suffix-specific path search. So if a node was marked .MADE,
then suffix rules would not be applied to it, and we would look for
the file only in the default path, not the suffix-specific path.

XXX: Now that we looked for the suffix, we can save it in the GNode,
but we don't do this yet.
 1.43 01-Jul-2004  jmc Change to use __unused instead and provide a compat definition in make.h if
not already defined from cdefs.h
 1.42 01-Jul-2004  jmc Add some checks for gcc around a few function declarations and note the
unused variables. Also fix a few other warnings that PR#22118 shows when
trying to compile bmake on non-NetBSD hosts
 1.41 07-May-2004  ross Simplify build, no functional changes.

Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().

It's now possible to build make on some hosts with: cc *.c */*.c
 1.40 03-Feb-2004  chuck branches: 1.40.2;
add parent directory search for make as discussed on tech-toolchain.
- new dir.c function: Dir_FindHereOrAbove:
Search for a path in the current directory and then all the directories
above it in turn until the path is found or we reach the root ("/").
- add hooks to use it in main.c for -m and syspath (compiled in
_PATH_DEFSYSPATH and $MAKESYSPATH).
- updated man page
 1.39 11-Jan-2004  dsl Change DEBUG(DIR) traces to indent subsequent filenames instead of
generating very long lines (basically changes "..." into " ...\n ").
 1.38 09-Sep-2003  drochner Remove some code which makes file lookup rely on the fact that
the first two directory entries are "." and "..".
This behaviour is not required by applicable standards, and
actually not provided by "coda".
Now we get the "." and ".." into the per-directiry hash tables,
but this should not hurt.
 1.37 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.36 14-Jul-2003  christos Pass WARNS=3
 1.35 26-Nov-2002  sjg Whenever we update .PATH, set the variable ${.PATH} to reflect the
search list that will be used. Thus 'dot' and 'cur' will appear in
${.PATH} either at the start or end depending on .DOTLAST even though
they are not strictly in dirSearchPath.

When .CURDIR is assigned to - re-set the 'cur' Path.

Finally, when checking subdirs, look in 'dot' and 'cur' (first or last
depending on .DOTLAST) just as we do in other situations.
 1.34 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.33 03-Feb-2002  pk Resurrect revision 1.23: no need to stat .PHONY targets.
 1.32 31-Jan-2002  pk Fix the bug addressed in revision 1.27 properly. Analysis of the problem
(see also PR#15179):

When looking up names which directory components (i.e. having slashes,
except when of the form `./name'), FindFile()/DirLookup() first looks
the final filename component in the cache for each directory on the search
path and then proceeds to match the prefixed directory components by
comparing them to the trailing directory components of the the search
path being probed.

This is not correct. When looking for `bar/target' in a path `.../src/foo',
you want it to come up with `.../src/foo/bar/target' (if it exists). There's
no point in comparing the the `bar' prefix on the target to the `foo' suffix
on the search path. Indeed, this will cause a false match if those prefix
and suffix components are actually equal and search path itself also has a
file called `target'. For example, looking for `foo/target' in `.../src/foo'
will spuriously match `.../src/foo/target', not `.../src/foo/foo/target'.

This last bug prompted the change in dir.c, rev 1.27, which happens
to partially workaround it by avoiding the above matching code in the
case of the `curdir' search path entry (at the cost of incurring an
exorbitant amount of cache misses). The situation is unchanged however,
when processing other entries on the search path (e.g. those other than
`dot' and `cur').

Drop the prefix matching code in DirLookup() entirely and use DirFindDot()
and DirLookup() only for names without proper directory components (i.e.
`target' and `./target). Otherwise, non-absolute names are dealt with by
DirLookupSubdir(), while absolute names can be checked for an exact match
of the directory components prefix against the directories on the current
search path. This allows for the use of the file cache to check the
existence of the file and additionally, provides a shortcut out of
Dir_FindFile() if we have the prefix match but not a cache entry (this
is especially beneficial for searches in .CURDIR when it's not equal
to `dot').
 1.31 27-Jan-2002  reinoud Fix major bug in make(1) ... due to shadowing of the dotLast path used for
the .DOTLAST primitive by a boolean variable with the same name, this whole
mechanism was broken ... it doesn't save much stat calls but it was wrong.

Thanks to Jason Thorpe for the other shadow-variable fixing patches he
made.
 1.30 26-Jan-2002  christos Don't bother to lookup for files in `.' that start with a `/'. Cuts in the
number of NAMI's from 1344 -> 830 in a full build of /usr/src/usr.bin/make.
 1.29 18-Jan-2002  pk In Dir_FindFile() add a missing Lst_Close() and move another one to the
proper place.
 1.28 12-Nov-2001  tv Redo the hashtable for "." if .OBJDIR changes.
 1.27 11-Nov-2001  tv Fix long-standing bug where, if an objdir exists, searching the .PATH for a
file will strip any leading path on the filename when searching ${.CURDIR}.

This bug manifested itself more prominently with xsrc/xfree/xc/lib/GL/GL,
since we now always search ${.CURDIR} as an alternative to ${.OBJDIR}
(PR bin/14499).
 1.26 16-Apr-2000  christos Don't core-dump when the current working directory is not readable
 1.25 25-Nov-1999  mrg back out rev 1.23 (don't stat PHONY targets). it broken the libcrypto
build by causing everything to be remade everytime. this fixes PR#8419.
 1.24 15-Sep-1999  mycroft branches: 1.24.4;
Don't bother iterating through all the data structures to free(3) everything
right before exiting.
(The code is still present, `#ifdef CLEANUP', in case someone needs it...)
 1.23 15-Sep-1999  mycroft Fix another case where we stat(2)ed .PHONY targets.
 1.22 12-Jul-1999  thorpej Correct an inverse initialization of a variable, which caused all .PATHs
to be treated as .DOTLAST.
 1.21 11-Jul-1999  thorpej Add a mechanism for specifying that ${.CURDIR} will be searched last
in the presence of .PATH directives by specifying:

.PATH: .DOTLAST

This will be used to fixup the build system to work with both crypto-us
and crypto-intl sub-trees.

Make(1) changes by Christos Zoulas, after much badgering by me :-)
 1.20 28-Sep-1997  lukem wrap #include <sys/cdefs.h>, __RCSID(...) stuff in #ifndef MAKE_BOOTSTRAP
 1.19 01-Jul-1997  christos Add WARNS=1
RCSID police
 1.18 09-May-1997  christos Change the way curdir is handled [this started at the previous version]...
Instead of adding it in .PATH, handle it specially the same way as "." is
handled.
 1.17 08-May-1997  gwr Add the new .NOPATH feature which can be used to disable .PATH search
for particular targets, i.e. .depend, objects, etc. (from Christos).
 1.16 06-May-1997  mycroft Don't do a VPATH or .PATH search for .PHONY targets. (From Christos.)
 1.15 02-May-1997  christos Make used to add every directory where it found files in the search path.
I.e. if you had a line in your Makefile:
../foo.o: foo.c
`..' would be added in the search path. The addition of such paths has
been now disabled. If a pathname contains a slash, then the directory
where such a file is found is not added to the search path. Of course
this eliminates most (all?) use of this function.
 1.14 29-Mar-1997  christos Don't disable wildcards completely; they are used by other Makefiles.
 1.13 27-Mar-1997  christos - Disable globbing for targets/dependencies when POSIX is defined.
- Fix globbing so that patterns that don't have a matching number of [] or {}
don't get expanded. (before the [ case got expanded to nothing!) This is
disabled.
 1.12 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.11 13-Aug-1996  christos Add estrdup(), a checked version of strdup and use it.
 1.10 04-Feb-1996  christos branches: 1.10.4;
fix pr/1421 and pr/1997
 1.9 22-Nov-1995  christos Updates for POSIX/SVR4 compiling:

arch.c: Don't require ranlib stuff. Not everybody has it.
dir.c: SunOS-4 != Solaris; change #ifdef sun to #if sun && !__svr4__
job.c, compat.c: Don't use 'union wait', use int and the W*() macros.
main.c: Check for uname() == -1; some unames return > 0...
util.c, job.c: Add signal() with BSD semantics for svr4, don't use bsd
sigmask and friends.
 1.8 14-Jun-1995  christos - $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.7 24-Dec-1994  cgd a few casts, for peace and quiet.
 1.6 06-Jun-1994  jtc Fixes from Christos Zoulas, who used purify, objectcenter and testcenter
to find memory leaks and illegal memory accesses.
 1.5 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.4 13-Jan-1994  jtc Include appropriate header files to bring prototypes into scope.
 1.3 08-Dec-1993  jtc Update to use <dirent.h>.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.10.4.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.24.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.40.2.1 10-May-2004  tron Pull up revision 1.41 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.51.4.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.51.2.1 05-Jun-2007  bouyer Apply patch (requested by tron in ticket #696):
usr.bin/make/compat.c patch
usr.bin/make/cond.c patch
usr.bin/make/dir.c patch
usr.bin/make/for.c patch
usr.bin/make/main.c patch
usr.bin/make/make.1 patch
usr.bin/make/make.c patch
usr.bin/make/make.h patch
usr.bin/make/nonints.h patch
usr.bin/make/parse.c patch
usr.bin/make/str.c patch
usr.bin/make/targ.c patch
usr.bin/make/util.c patch
usr.bin/make/var.c patch

Synchronize make(1) with HEAD branch to increase perfomance and
improve stability.
 1.63.4.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.63.4.2 30-Oct-2012  yamt sync with head
 1.63.4.1 17-Apr-2012  yamt sync with head
 1.65.2.1 23-Jun-2013  tls resync from head
 1.68.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.68.2.2 26-Apr-2017  pgoyette Sync with HEAD
 1.68.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.71.12.1 10-Jun-2019  christos Sync with HEAD
 1.71.10.1 28-Jul-2018  pgoyette Sync with HEAD
 1.294.2.1 02-Aug-2025  perseant Sync with HEAD
 1.49 07-Jul-2024  rillig make: only generate code for cleanup functions in CLEANUP mode
 1.48 19-May-2024  sjg branches: 1.48.2;
make: use separate function to include makefiles.

Have Dir_FindFile and Dir_FindInclude call FindFile with a
bool flag to indicate whether .CURDIR should be be searched at all.
 1.47 24-Jan-2023  sjg make: .SYSPATH: to add dirs to sysIncPath

.SYSPATH: with no sources will clear sysIncPath
otherwise sources are added

Reviewed by: rillig
 1.46 15-Dec-2021  rillig make: remove redundant comments for multiple-inclusion guards
 1.45 15-Dec-2021  rillig make: mark several functions whose result must be used

Suggested by sjg, to catch more bugs like the memory leak in cond.c
1.303 from 2021-12-13.

No binary change.
 1.44 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.43 05-Feb-2021  rillig make: add const to SearchPath_Print
 1.42 23-Jan-2021  rillig make(1): rename Dir_AddDir, reorder parameters of SearchPath_ToFlags
 1.41 23-Jan-2021  rillig make(1): rename Dir_Expand to SearchPath_Expand

The main subject of this function is the search path. In this search
path the pattern is expanded.
 1.40 01-Dec-2020  rillig make(1): remove Dir_InitDir

The function name had been too ambiguous since it didn't mention the
particular directory that was initialized. Instead of that function,
Dir_InitCur is called directly from main_Init.

The pseudo CachedDir entry ".DOTLAST" is initialized at the very
beginning. The observable behavior is unchanged since this a
memory-only object with no connection to the file system.
 1.39 29-Nov-2020  rillig make(1): use space instead of tab for preprocessor directives
 1.38 29-Nov-2020  rillig make(1): unexport CachedDir internals
 1.37 28-Nov-2020  rillig make(1): replace Dir_Destroy with SearchPath_Free

The function Dir_Destroy is an implementation detail of the cached
directories, and it should not be exported to the other modules. The
search paths, on the other hand, are the high-level API that may be used
by the other modules, as the concept of search paths is documented in
the manual page.
 1.36 28-Nov-2020  rillig make(1): rename some Dir functions to SearchPath

These functions have the search path as their main subject.
 1.35 23-Nov-2020  rillig make(1): migrate CachedDir.files from HashTable to HashSet
 1.34 14-Nov-2020  rillig make(1): remove redundant struct make_stat

In the cache for stat(2) and lstat(2), only one of the two timestamps
was ever used. To prevent a result from stat(2) leaking into the cache
for lstat(2), there have been two completely separate caches all the
time. Using different fields in the struct was therefore unnecessary.

By removing the redundant field, the internal struct in the cache is the
same as the external struct. This makes one of them redundant, thus
struct make_stat has been renamed to cached_stat, which better describes
its purpose, and the internal struct cache_st has been removed.

Just as before, the cache prevents any direct access to its internal
data. When passing it to the caller, it is copied.

Just as before, the field names of struct cached_stat cannot correspond
to those from struct stat, since the latter are often defined as macros.
Therefore they are prefixed with cst instead of st.

The redundancy had been added on 2020-06-05.
 1.33 08-Nov-2020  rillig make(1): change return type of Dir_MTime to void

Only some callers actually needed the updated time, and because of the
many branches, it was difficult to see that the return value was indeed
gn->mtime all the time.
 1.32 25-Oct-2020  rillig make(1): replace Dir_CopyDir with Dir_CopyDirSearchPath

Callback functions for the Lst functions do not belong in the public API
of a module.
 1.31 19-Oct-2020  rillig make(1): clean up headers, no functional change
 1.30 18-Oct-2020  rillig make(1): remove underscore from Hash_Table and Hash_Entry

For consistency with the other type names, such as GNodeListNode.
 1.29 05-Oct-2020  rillig make(1): remove pathname limit for Dir_FindHereOrAbove

While trying to compile the code with GCC's -Wformat-truncation, the
snprintf calls felt quite complicated. The function Dir_FindHereOrAbove
is not in a bottleneck execution path, therefore it doesn't hurt to
dynamically allocate the memory instead of using size-limited stack
memory.
 1.28 05-Oct-2020  rillig make(1): make dir.c, for.c and hash.c ready for WARNS=6

Some types have changed from int to unsigned int, size_t or time_t.

The variable i in hash.c has been kept as int since it counts down to
-1, which generates efficient machine code, at least on x86_64.
 1.27 27-Sep-2020  rillig make(1): improve documentation of CachedDir and Dir_AddDir
 1.26 27-Sep-2020  rillig make(1): normalize whitespace in source code

There is no more space tab. Either only tabs or only spaces or tabs
followed by spaces, but not spaces followed by tabs.
 1.25 22-Sep-2020  rillig make(1): use fine-grained type names for lists and their nodes

This is only intended to help the human reader. There is no additional
type safety yet.
 1.24 22-Sep-2020  rillig make(1): rename type Path to CachedDir

The word "path" is commonly used either as an abbreviation for pathname
(a string consisting of several directory or file names) or as an
abbreviation for search path (a list of directory names used for
searching files), but not for a single directory.
 1.23 02-Sep-2020  rillig make(1): reduce number of stat fields returned by cached_stat

Only st_mtime and st_mode are actually filled, the remaining fields had
been set to zero. To prevent these from ever being accessed, a custom
struct make_stat replaces the previously used struct stat.

The fields in struct make_stat are intentionally named different from
the fields in struct stat because NetBSD and some other operating
systems define st_mtime as a macro, and that would not work in a field
declaration.
 1.22 01-Sep-2020  rillig make(1): improve variable names and data types in Dir_FindHereOrAbove
 1.21 01-Sep-2020  rillig make(1): make data types in Dir_HasWildcards more precise
 1.20 22-Aug-2020  rillig make(1): clean up headers

Remove redundant headers that are already included by "make.h".
Make <assert.h> available to all compilation units that use "make.h".
 1.19 22-Aug-2020  rillig make(1): split Dir_Init into two functions

There's just no point in having a function consisting of a big
if-then-else.
 1.18 31-May-2017  maya Don't prefix include guards by _, suggested by riastradh
 1.17 31-May-2017  maya The previous change might actually be less generic.
prepend by _MAKE, to be sure.
 1.16 31-May-2017  maya Use less generic include guards
 1.15 07-Apr-2012  christos Remove recheck hackery that caused extra stats, and explicitly ask for
recheck when needed. Before it used to be the case that we could only
use the cached entry once. Once the cached entry was used, we removed
it from the cache. Now it is kept forever.
 1.14 23-Jan-2009  dsl branches: 1.14.8;
Change 'ClientData' to 'void *' so that relevant parameters can
be made 'const void *'.
 1.13 15-Feb-2008  christos back all changes out until I fix it properly.
 1.12 14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.11 03-Feb-2004  chuck add parent directory search for make as discussed on tech-toolchain.
- new dir.c function: Dir_FindHereOrAbove:
Search for a path in the current directory and then all the directories
above it in turn until the path is found or we reach the root ("/").
- add hooks to use it in main.c for -m and syspath (compiled in
_PATH_DEFSYSPATH and $MAKESYSPATH).
- updated man page
 1.10 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.9 14-Jul-2003  christos Pass WARNS=3
 1.8 26-Nov-2002  sjg Whenever we update .PATH, set the variable ${.PATH} to reflect the
search list that will be used. Thus 'dot' and 'cur' will appear in
${.PATH} either at the start or end depending on .DOTLAST even though
they are not strictly in dirSearchPath.

When .CURDIR is assigned to - re-set the 'cur' Path.

Finally, when checking subdirs, look in 'dot' and 'cur' (first or last
depending on .DOTLAST) just as we do in other situations.
 1.7 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.6 12-Nov-2001  tv Redo the hashtable for "." if .OBJDIR changes.
 1.5 08-May-1997  gwr Add the new .NOPATH feature which can be used to disable .PATH search
for particular targets, i.e. .depend, objects, etc. (from Christos).
 1.4 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.3 14-Jun-1995  christos branches: 1.3.6;
- $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.2 06-Jun-1994  jtc Fixes from Christos Zoulas, who used purify, objectcenter and testcenter
to find memory leaks and illegal memory accesses.
 1.1 05-Mar-1994  cgd branches: 1.1.1;
fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.1.1.1 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.3.6.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.14.8.1 17-Apr-2012  yamt sync with head
 1.48.2.1 02-Aug-2025  perseant Sync with HEAD
 1.16 28-Nov-2021  rillig make: replace bloated bit-set-to-string code with simple code

It was a nice idea to implement a bit-set using an enum type and have a
generic ToString function for them. In the end, the implementation
involved really heavy preprocessor magic and was probably difficult to
understand. Replace all the code with a few bits of straight-forward
preprocessor magic that can be readily understood by just looking 5
lines around, instead of digging through 130 lines of lengthy macro
definitions.

Curiously, this reduces the binary size even though the 3 ToString
functions now have a few lines of duplicate code and there are more
explicit function calls.

The ToString functions are only seldom used, so the additional memory
allocation is acceptable.

No functional change.
 1.15 02-Feb-2021  rillig make: remove overengineered Enum_ValueToString

For printing the status of a GNode, there was already made_name (now
renamed to GNodeMade_Name), which prints user-friendly text instead of
the bare enum constant names.

To do this change confidently, I first had to demonstrate that the
output really affects something other than just the word "UNMADE". There
had not been a test for that case before, and the test immediately
discovered a bug in the -dg2 and -dg3 options. This bug is one of the
oldest in make, dating back to at least 1993.
 1.14 09-Jan-2021  rillig make(1): fix lint warnings
 1.13 30-Dec-2020  rillig make(1): format multi-line comments
 1.12 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.11 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.10 03-Oct-2020  rillig make(1): clean up #include sections
 1.9 03-Oct-2020  rillig make(1): fix indentation of code for printing enum values
 1.8 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.7 12-Sep-2020  rillig make(1): fix inconsistent code indentation
 1.6 01-Sep-2020  rillig make(1): improve documentation for enum.c and enum.h
 1.5 28-Aug-2020  rillig make(1): fix build errors for USER_CPPFLAGS=-DNDEBUG

The functions LstIsValid and LstNodeIsValid are only used in assertions.

Without the always-false assertion, Enum_ValueToString could have
returned undefined behavior.
 1.4 24-Aug-2020  rillig make(1): in debug mode, print GNode details in symbols

A string like OP_DEPENDS|OP_OPTIONAL|OP_PRECIOUS is much easier to read
and understand than the bit pattern 00000089.

The implementation in enum.h looks really bloated and ugly, but using
this API is as simple and natural as possible. That's the trade-off.

In enum.h, I thought about choosing the numbers in the macros such that
it is always possible to combine two of them in order to reach an
arbitrary number, because of the "part1, part2" in the ENUM__SPEC macro.
The powers of 2 are not these numbers, as 7 cannot be expressed as the
sum of two of them. Neither are the fibonacci numbers since 12 cannot
be expressed as the sum of 2 fibonacci numbers. I tried to find a
general pattern to generate these minimal 2-sum numbers, but failed.
 1.3 09-Aug-2020  rillig make(1): clean up indentation, includes, add documentation
 1.2 08-Aug-2020  rillig make(1): fix CRLF line endings in newly added files
 1.1 08-Aug-2020  rillig make(1): add more detailed debug logging for variable modifiers

Before a modifier is applied to a variable, it is not yet parsed,
therefore it is only possible to log a rough estimate of the modifier.
But after applying it, the parsing position has advanced, and the full
modifier can be logged.

In addition, to fully understand how the modifiers work, it's not enough
to just know the variable names and values, there are also some flags
that influence how the modifiers behave. The most influential is
VARE_WANTRES.

Thanks to sjg for the extensive review and valuable feedback on the
first drafts.
 1.20 28-Nov-2021  rillig make: replace bloated bit-set-to-string code with simple code

It was a nice idea to implement a bit-set using an enum type and have a
generic ToString function for them. In the end, the implementation
involved really heavy preprocessor magic and was probably difficult to
understand. Replace all the code with a few bits of straight-forward
preprocessor magic that can be readily understood by just looking 5
lines around, instead of digging through 130 lines of lengthy macro
definitions.

Curiously, this reduces the binary size even though the 3 ToString
functions now have a few lines of duplicate code and there are more
explicit function calls.

The ToString functions are only seldom used, so the additional memory
allocation is acceptable.

No functional change.
 1.19 15-Mar-2021  rillig make: clean up header for runtime type information for enums

An enum with 32 bits would lead to signed integer overflow anyway, so
that definition is not worth keeping even if it works on typical
2-complement platforms.

The definitions for 2, 4 and 8 enum have been unused for several months
now.

No functional change.
 1.18 02-Feb-2021  rillig make: remove unused INTERNAL flag

It had been used for cached_realpaths, until this variable had its type
changed from GNode to HashTable in main.c 1.469 from 2020-11-14.
 1.17 02-Feb-2021  rillig make: remove overengineered Enum_ValueToString

For printing the status of a GNode, there was already made_name (now
renamed to GNodeMade_Name), which prints user-friendly text instead of
the bare enum constant names.

To do this change confidently, I first had to demonstrate that the
output really affects something other than just the word "UNMADE". There
had not been a test for that case before, and the test immediately
discovered a bug in the -dg2 and -dg3 options. This bug is one of the
oldest in make, dating back to at least 1993.
 1.16 30-Jan-2021  rillig make(1): fix lint warning about empty declarations
 1.15 30-Jan-2021  rillig make(1): reduce boilerplate for printing bit sets in debug mode

No functional change.
 1.14 30-Dec-2020  rillig make(1): format multi-line comments
 1.13 28-Dec-2020  rillig make(1): replace global preserveUndefined with VARE_KEEP_UNDEF

Controlling the expansion of variable expressions using a global
variable and a VARE flag was inconsistent.

Converting the global variable into a flag had to prerequisites:

1. The unintended duplicate variable assignment had to be fixed, as
done in parse.c 1.520 from 2020-12-27. Without this fix, it would have
been necessary to add more flags to Var_Exists and Var_SetWithFlags, and
this would have become too complex.

2. There had to be a unit test demonstrating that VARE_KEEP_DOLLAR only
applies to the top-level expression and is not passed to the
subexpressions, while VARE_KEEP_UNDEF applies to all subexpressions as
well. This test is in var-op-expand.mk 1.10 from 2020-12-28, at least
for the ':@word@' modifier. In ParseModifierPartSubst, VARE_KEEP_UNDEF
is not passed down either, in the same way.
 1.12 25-Sep-2020  rillig make(1): add tags to some of the unnamed structs

The tags prevent the structs from accidentally becoming compatible
types.

While here, remove a few typedefs for structs that are single-purpose,
since there is no point in abstracting from the actual representation of
these types.
 1.11 22-Sep-2020  rillig make(1): move VAR_JUNK and VAR_KEEP away from VarFlags

These two flags have nothing to do with a variable. They are only used
while evaluating a variable expression.

While here, rename the flags and make their documentation more precise.
 1.10 12-Sep-2020  rillig make(1): fix inconsistent code indentation
 1.9 01-Sep-2020  rillig make(1): improve documentation for enum.c and enum.h
 1.8 25-Aug-2020  rillig make(1): distinguish enum flags and values in debugging mode

When printing an enum value in debugging mode, distinguish between
bitsets containing flags and ordinary enums that just contain different
values.

Make the macros in enum.h more uniform. Provide a simple scheme for
defining the run-time type information of enums whose number of values
is a number with more than 2 bits set in the binary representation.
This case was not obvious before, and it was pure luck that the current
interesting enum types only had 3, 10 or 32 different values.

The type with the 32 different values actually only has 31 significant
bits since the enum constant OP_OPMASK is only used when querying the
enum, not for defining or describing the possible values. For this
reason, it was unavoidable to refactor the rtti macros, to support even
this case.
 1.7 24-Aug-2020  rillig make(1): in debug mode, print GNode details in symbols

A string like OP_DEPENDS|OP_OPTIONAL|OP_PRECIOUS is much easier to read
and understand than the bit pattern 00000089.

The implementation in enum.h looks really bloated and ugly, but using
this API is as simple and natural as possible. That's the trade-off.

In enum.h, I thought about choosing the numbers in the macros such that
it is always possible to combine two of them in order to reach an
arbitrary number, because of the "part1, part2" in the ENUM__SPEC macro.
The powers of 2 are not these numbers, as 7 cannot be expressed as the
sum of two of them. Neither are the fibonacci numbers since 12 cannot
be expressed as the sum of 2 fibonacci numbers. I tried to find a
general pattern to generate these minimal 2-sum numbers, but failed.
 1.6 23-Aug-2020  rillig make(1): fix assertion failure in debug output for read-only variables
 1.5 09-Aug-2020  rillig make(1): clean up indentation, includes, add documentation
 1.4 09-Aug-2020  rillig make(1): use fixed-size arrays for Enum_ToString

Declaring the ToStringSize as "static const size_t" made it an ordinary
integer expression. To avoid variable length arrays, the commonly
accepted way is to declare the length as an enum constant, as that is
considered an integer constant expression, which in turn makes the
declaration a fixed-size array.
 1.3 09-Aug-2020  christos Fix build; gcc does not like VLA's, so hard code the boundary
Use c99 initializers
 1.2 08-Aug-2020  rillig make(1): fix CRLF line endings in newly added files
 1.1 08-Aug-2020  rillig make(1): add more detailed debug logging for variable modifiers

Before a modifier is applied to a variable, it is not yet parsed,
therefore it is only possible to log a rough estimate of the modifier.
But after applying it, the parsing position has advanced, and the full
modifier can be logged.

In addition, to fully understand how the modifiers work, it's not enough
to just know the variable names and values, there are also some flags
that influence how the modifiers behave. The most influential is
VARE_WANTRES.

Thanks to sjg for the extensive review and valuable feedback on the
first drafts.
 1.2 19-Jan-2020  riastradh Per sjg's suggestion, split filemon API into separate back ends.

By default we use the ktrace back end, but the /dev/filemon back end
is available as a compile-time option, by setting USE_FILEMON=dev in
make. sjg raised concerns about ktrace performance and would like to
continue using /dev/filemon on FreeBSD (which has seen more
maintenance kernel-side) without forking make.
 1.1 19-Jan-2020  riastradh Reimplement make(1) meta mode without filemon(4).
 1.2 19-Jan-2020  riastradh Per sjg's suggestion, split filemon API into separate back ends.

By default we use the ktrace back end, but the /dev/filemon back end
is available as a compile-time option, by setting USE_FILEMON=dev in
make. sjg raised concerns about ktrace performance and would like to
continue using /dev/filemon on FreeBSD (which has seen more
maintenance kernel-side) without forking make.
 1.1 19-Jan-2020  riastradh Reimplement make(1) meta mode without filemon(4).
 1.186 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.185 22-Apr-2025  rillig make: clean up

Replace 'unsigned int' with simply 'unsigned'.

In compat.c, skipping whitespace is not needed, as the loop above
already skips it.

In job.c, remove the unused header <sys/file.h>.

Inline the TMPPAT macro, as it is only needed in a single place.
 1.184 11-Apr-2025  rillig make: condense code for parsing variable names in .for loops
 1.183 30-Mar-2025  rillig make: if there is an error in the items of a .for loop, don't iterate
 1.182 07-Jun-2024  rillig branches: 1.182.2;
make: remove redundant shortcut for building the .for loop body

The function NeedsEscapes was not optimized enough by GCC 10 to be worth
the extra code.
 1.181 02-Jun-2024  rillig make: sync VarEvalMode constant names with their debug log names
 1.180 25-May-2024  rillig make: fix a few more memory leaks
 1.179 01-Apr-2024  rillig make: remove unreachable code in handling .for loops
 1.178 21-Jan-2024  rillig make: clean up redundant 'const' from automatic variables

No binary change.
 1.177 19-Nov-2023  rillig make: replace 'variable expression' with 'expression' in comments

No binary change.
 1.176 01-Jun-2023  rillig make: add more details to debug logging of .for loops
 1.175 01-Jun-2023  rillig make: shorten function names, clean up comments

No functional change.
 1.174 09-May-2023  rillig make: skip syntactically wrong .for loops

When a .for loop cannot be interpreted correctly, for example when there
are no iteration variables or the number of words doesn't match the
iteration variables, skip the body of the .for loop instead of
interpreting it once.
 1.173 08-May-2023  rillig make: disallow characters like '$' in variable names in .for loops

Fixes PR 53146.
 1.172 08-May-2023  rillig make: fix parsing of unusual line continuations in .for loops
 1.171 14-Feb-2023  rillig make: clean up calls to Var_Subst

None of the calls to Var_Subst used the return value, and the return
value was always VPR_OK.

No functional change.
 1.170 03-Sep-2022  rillig make: clean up handling of .break in .for loops

Move For_Break further up, as the functions in that file are sorted from
small to big. The cast from size_t to unsigned int is required by lint.

In parse.c, move the code into a separate function to keep
ParseDirective small. Its only job is to parse the directive and then
delegate to another function doing the actual work.

In the manual page, remove empty lines.

In the test, ensure that .break stops processing of the .for loop
immediately; anything after the .break is not processed anymore.
Replace ':=' with '=', as there is no need to evaluate '$i' early.
Check the expected value in the .mk file instead of the .exp file, to
keep the reading scope as small as possible.
 1.169 02-Sep-2022  sjg make: add .break to terminate .for loop early

When .break is encountered within a .for loop
it causes immediate termination.

Outside of a .for loop .break causes a parse error.

Reviewed by: christos
 1.168 12-Jun-2022  rillig make: document ExprLen, which is part of a .for loop

No binary change
 1.167 04-Feb-2022  rillig make: use unsigned int for line numbers everywhere

Previously, some line numbers were stored as signed int while others
were stored as size_t. Since line numbers are never negative, use an
unsigned type. Since the maximum file size for makefiles is 1 GB (see
loadfile), unsigned int is large enough even on 64-bit platforms.

Using a single data types reduces the number of type conversions. Using
unsigned int improves compatibility with C90 (printf %u instead of %zu),
which is needed by bmake, which is derived from usr.bin/make.

No functional change.
 1.166 27-Jan-2022  rillig make: clean up AddEscape for building the body of a .for loop

Adding 1 + len bytes but only incrementing the pointer by len bytes
looked suspicious, so use the same expression in both places.

No functional change.
 1.165 09-Jan-2022  rillig make: extract low-level character operations into utility function

Suggested by nia.
https://mail-index.netbsd.org/source-changes-d/2022/01/09/msg013564.html

No functional change.
 1.164 09-Jan-2022  rillig make: fix crash for newline in .for value in -dp mode (since yesterday)
 1.163 09-Jan-2022  rillig make: fix use-after-free in -dp mode (since yesterday)

In a .for loop that contains an unclosed .if directive,
Cond_restore_depth generates an error message. If stack traces are
enabled using the option '-dp', the details of the .for loop are added
to the stack trace, but at that point, the ForLoop had already been
freed. To reproduce:

make-2022.01.09.00.33.57 -r -f unit-tests/directive-for.mk -dp
 1.162 09-Jan-2022  rillig make: remove redundant parameter from ForLoop_SubstVarLong

The buffer of a .for loop is always either empty or ends with '\n'. A
variable name consists of arbitrary non-whitespace characters.
Therefore a variable name can never reach the end of the buffer.

No functional change.
 1.161 08-Jan-2022  rillig make: add details about .for loop variables to stack traces

The stack traces are enabled with the debug logging option '-dp'.
 1.160 08-Jan-2022  rillig make: fix reported line numbers of continuation lines (since 2002)

Previously, multi-line directives like '.info' or '.error' reported the
line number of their last line instead of their first line, which is
more usual. This also affected the debug log from '-dp'.
 1.159 08-Jan-2022  rillig make: inline Buf_Clear

No functional change.
 1.158 07-Jan-2022  rillig make: clean up structure of For_Eval

Put related decisions on the same indentation level, remove unnecessary
negation, keep the code for the '.for' directive together.

No functional change.
 1.157 07-Jan-2022  rillig make: clean up handling of .for loops

Sort ForLoop members in natural reading order.

Remove redundant condition in ForLoop_ParseItems; at that point, the
number of variables is non-zero.

Rename Buf_AddEscaped since that function is not part of the Buffer API,
it is specific to .for loops.

No functional change.
 1.156 07-Jan-2022  rillig make: eliminate file-scope variable forLevel

No functional change.
 1.155 07-Jan-2022  rillig make: use simpler code for handling .for loops

Since the body of a .for loop is scanned from start to end, there is no
need to remember the length of a variable name.

Using memcmp for comparing the variable name was probably overkill since
the variable names are usually very short, so rather compare them byte
by byte.

No functional change.
 1.154 02-Jan-2022  rillig make: clean up handling of .for loops and .include directives

No functional change.
 1.153 02-Jan-2022  rillig make: in .for loops, pass the body to be filled as parameter

This is a preparation for cleaning up the code for loading and parsing
files, especially the part for including other files and for .for loops.

No functional change.
 1.152 01-Jan-2022  rillig make: remove unused parameter from Parse_PushInput

The parameter readMore was never NULL.

No functional change.
 1.151 15-Dec-2021  rillig make: format comments according to /usr/share/misc/style

Assisted by indent(1), with manual corrections due to its many remaining
bugs.

No functional change.
 1.150 12-Dec-2021  rillig make: rename Parse_SetInput to Parse_PushInput

The word 'set' sounded too much like it would replace the current file,
but instead the file is pushed to the stack, and the previous file is
continued later.

No functional change.
 1.149 12-Dec-2021  rillig make: rename ForLoop.sub_next to nextItem

This matches the naming style of the other ForLoop members.

No functional change.
 1.148 05-Dec-2021  rillig make: inline Str_Words into .for loop handling

This saves one memory allocation and a bit of copying, per .for loop.

No functional change.
 1.147 02-Sep-2021  rillig make: rename for_var_len to ExprLen

The text ${VAR} is not a variable, it's a variable expression.

No functional change.
 1.146 02-Sep-2021  rillig make: inline strchr call, make ForLoop_SubstBody clearer

In ForLoop_SubstBody, GCC already merged the common subexpressions p[1]
and p[-1], but that was difficult to see for humans as well.

No functional change.
 1.145 01-Sep-2021  rillig make: remove optimization for single-letter .for variables

Most .for loops have a single iteration variable. For these loops, the
difference between the optimized and the unoptimized versions of the
code is negligible.

Remove the optimization since the comment for explaining it was almost
larger than the code itself.
 1.144 25-Jun-2021  rillig make: prevent newline injection in .for loops

When a value of a .for loop contained a literal newline, such as from
the expression ${.newline}, that newline was passed verbatim to the
"expanded current body" of the .for loop. There it was interpreted as a
literal newline, which ended the current line and started a new one.
This resulted in several syntax errors.

In cases like these, print a more precise error message.
 1.143 24-Jun-2021  rillig make: sprinkle const
 1.142 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.141 04-Feb-2021  rillig make: rename some VAR constants to SCOPE

The word "context" does not fit perfectly to the variables that are
associate with a GNode, as the context is usually something from the
outside and the variables are more like properties inherent to the
GNode.

The term "global context" fits even less. Since the thing where
variables are looked up is commonly named a scope, use that term
instead.

This commit only renames the global variables VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE, plus a few very closely related comments. These are:

GNode.vars (because of line breaks)
GNode_Free (dito)
varname-make_print_var_on_error.mk
varname-make_print_var_on_error-jobs.mk

The debug message in Var_Stats is left as-is since there is no unit test
for it yet.

The other renamings (variable names "context", "ctxt", as well as
further comments) will be done in a follow-up commit.
 1.140 01-Feb-2021  rillig make(1): clean up variable names and comments in .for loop code
 1.139 30-Jan-2021  rillig make(1): split Buf_Destroy into Buf_Done and Buf_DoneData

In all cases except one, the boolean argument to Buf_Destroy was
constant. Removing that argument by splitting the function into two
separate functions makes the intention clearer on the call site. It
also removes the possibility for using the return value of Buf_Done,
which would have made no sense.

The function Buf_Done now pairs with Buf_Init, just as in HashTable and
Lst.

Even though Buf_Done is essentially a no-op, it is kept as a function,
both for symmetry with Buf_Init and for clearing the Buffer members
after use (this will be done only in CLEANUP mode, in a follow-up
commit).
 1.138 25-Jan-2021  rillig make(1): split For_Eval into separate functions
 1.137 25-Jan-2021  rillig make(1): extract ForLoop_New to separate function
 1.136 25-Jan-2021  rillig make(1): rename struct For to struct ForLoop

This removes the ambiguity whether For_Free is meant to be a
module-exported function or a local function associate with that struct.
Rename the affected functions as well.
 1.135 19-Jan-2021  rillig make(1): remove do-not-format markers from comments

These markers had been used inconsistently. Furthermore the source code
had not been formatted automatically before 2020 at all, otherwise there
wouldn't have been any trailing whitespace left.
 1.134 10-Jan-2021  rillig make(1): consistently use boolean expressions in conditions

Most of the make code already followed the style of explicitly writing
(ptr != NULL) instead of the shorter (ptr) in conditions.

The remaining 50 instances have been found by an experimental,
unpublished check in lint(1) that treats bool expressions as
incompatible to any other scalar type, just as in Java, C#, Pascal and
several other languages.

The only unsafe operation on Boolean that is left over is (flags &
FLAG), for an enum implementing a bit set. If Boolean is an ordinary
integer type (the default), some high bits may get lost. But if Boolean
is the same as _Bool (by compiling with -DUSE_C99_BOOLEAN), C99 6.3.1.2
defines that a conversion from any scalar to the type _Bool acts as a
comparison to 0, which cannot lose any bits.
 1.133 09-Jan-2021  rillig make(1): fix lint warnings
 1.132 31-Dec-2020  rillig make(1): fix undefined behavior in SubstVarLong

A memcmp implementation that would check the start and end pointers
first would have detected this possible out-of-bounds memory read.
 1.131 31-Dec-2020  rillig make(1): make control flow in SubstVarLong of .for loops more obvious
 1.130 31-Dec-2020  rillig make(1): clean up SubstVarShort in .for loops

This function does not need to advance the parsing position, which
removes duplicate code.
 1.129 31-Dec-2020  rillig make(1): move detailed comment to ForSubstBody
 1.128 31-Dec-2020  rillig make(1): extract ForSubstBody from ForReadMore

This leaves ForReadMore with the single responsibility of interfacing
with ReadMoreProc in Parse_SetInput.
 1.127 31-Dec-2020  rillig make(1): rename ech to endc

Focusing on the "end" is more important than on the data type "ch".
 1.126 31-Dec-2020  rillig make(1): inline variable in ForReadMore

This variable was intended to help the compilers produce efficient code
by avoiding a duplicate memory read. As it turned out, GCC 5.5 doesn't
need this help, and probably newer compilers don't need it either. Well
done, GCC, keeping track of the memory locations even if the pointer to
it changes in the middle.
 1.125 31-Dec-2020  rillig make(1): clean up ForReadMore

After the previous clean up in for.c 1.123 from 2020-12-30, GCC 5.5 did
not inline the function SubstVarLong anymore since it was now called
from 2 places. GCC didn't notice that the function call was essentially
the same since in differed only in the end character.

By combining the cases for ${V} and $(V), the code becomes even shorter
than before, while still being understandable.
 1.124 31-Dec-2020  rillig make(1): simplify termination condition for .for loop

At this point, the number of iteration items is always a multiple of the
number of iteration variables, which makes any addition more complicated
than absolutely necessary.
 1.123 30-Dec-2020  rillig make(1): improve .for loop documentation, clean up ForReadMore

The comma expression in ForReadMore may be a nice trick, but it's not as
easy to read as a simple if-then-else chain. Test for '{' before '('
since BSD makefiles use braces by convention.
 1.122 30-Dec-2020  rillig make(1): format multi-line comments
 1.121 27-Dec-2020  rillig make(1): add error handling for .for loop items

Right now, Var_Subst always returns VPR_OK, even if there had been parse
errors or evaluation errors. If that is no longer true, the errors will
be reported properly.
 1.120 19-Dec-2020  rillig make(1): improve comments for .for loops
 1.119 19-Dec-2020  rillig make(1): rename ForIterate to ForReadMore
 1.118 15-Dec-2020  rillig make(1): indent for.c using tabs instead of spaces
 1.117 13-Dec-2020  rillig make(1): replace %zu with %u in printf calls

This is needed to compile bmake with GCC 2.8.1 on SunOS 5.9.

To support ancient systems like this, the whole code of usr.bin/make is
supposed to use only ISO C90 features, except for filemon, which is not
used on these systems.
 1.116 12-Dec-2020  rillig make(1): remove const from function parameters

These have been left-overs from refactoring, when these pieces were
extracted to separate functions.
 1.115 07-Nov-2020  rillig make(1): clean up Buf_AddEscaped in .for loops

All this dance of determining the needed escape characters before
iterating, saving them upfront, evaluating them later using complicated
boolean expressions was not necessary at all. All that is needed is a
simple NeedsEscapes, called at just the right time.
 1.114 07-Nov-2020  rillig make(1): make API of Buf_Init simpler

In most cases, the caller doesn't want to specify the exact number of
preallocated bytes.
 1.113 07-Nov-2020  rillig make(1): clean up code stylistically

* Replace character literal 0 with '\0'.
* Replace pointer literal 0 with NULL.
* Remove redundant parentheses.
* Parentheses in multi-line conditions are not redundant at the
beginning of a line.
* Replace a few !ptr with ptr == NULL.
* Replace a few ptr with ptr != NULL.
* Replace (expr & mask) == 0 with !(expr & mask).
* Remove redundant braces for blocks in cases where the generated code
stays the same. (Assertions further down in the code would get
different line numbers.)
* Rename parameters in CondParser_String to reflect the data flow.
* Replace #ifdef notdef with #if 0.

The generated code stays exactly the same, at least with GCC 5.5.0 on
NetBSD 8.0 amd64 using the default configuration.
 1.112 31-Oct-2020  rillig make(1): format #include directives consistently
 1.111 26-Oct-2020  rillig make(1): remove stray closing brace from comment
 1.110 26-Oct-2020  rillig make(1): clean up variable substitution in .for loops

The variable name cmd_cp was not really helpful for understanding the
code.
 1.109 26-Oct-2020  rillig make(1): use consistent variable names in for.c
 1.108 25-Oct-2020  rillig make(1): clean up comments in .for handling
 1.107 25-Oct-2020  rillig make(1): use complete words in error message for .for loop
 1.106 25-Oct-2020  rillig make(1): extract code to see if a directive is a .for or .endfor
 1.105 25-Oct-2020  rillig make(1): rename local variable in For_Eval
 1.104 25-Oct-2020  rillig make(1): test funny character in .for variable names
 1.103 25-Oct-2020  rillig make(1): reduce memory allocation in .for loops

It was not necessary to allocate a new buffer for each iteration of the
.for loop.
 1.102 25-Oct-2020  rillig make(1): use Words instead of Vector for the .for items

This makes memory management a bit simpler and also more efficient.
 1.101 25-Oct-2020  rillig make(1): remove unnecessary type ForVar

Now that the escaping information is computed just-in-time, the item of
a .for loops is a simple string with no additional information.
Therefore, unwrap the struct.
 1.100 25-Oct-2020  rillig make(1): compute escaping flags for .for values when needed

Before, they were computed when parsing the .for line, which was
unnecessarily early.
 1.99 25-Oct-2020  rillig make(1): extract GetEscapes from For_Eval
 1.98 25-Oct-2020  rillig make(1): extract SubstVarShort from ForIterate
 1.97 25-Oct-2020  rillig make(1): extract SubstVarLong from ForIterate
 1.96 25-Oct-2020  rillig make(1): use Vector instead of strlist_t for expanding .for loops

strlist_t combines a string with an unsigned int. This unsigned int had
been the string length for variables and the escaping flags for values.
This is another case of using generic types where specific types would
give more guidance to the reader.

Defining the types ForVar and ForItem expresses the involved concepts
more directly.

This is the last use of strlist_t, which will be removed in a follow-up
commit.
 1.95 25-Oct-2020  rillig make(1): clean up code for handling .for loops
 1.94 18-Oct-2020  rillig make(1): add tags to enum types

This allows IDEs to offer better type information than "anonymous enum".
 1.93 05-Oct-2020  rillig make(1): make dir.c, for.c and hash.c ready for WARNS=6

Some types have changed from int to unsigned int, size_t or time_t.

The variable i in hash.c has been kept as int since it counts down to
-1, which generates efficient machine code, at least on x86_64.
 1.92 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.91 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.90 03-Oct-2020  rillig make(1): use consistent pattern for parsing whitespace

The pp and cpp in the function names stand for "parsing position" and
"const parsing position".
 1.89 28-Sep-2020  rillig make(1): make debugging code shorter
 1.88 27-Sep-2020  rillig make(1): normalize whitespace in source code

There is no more space tab. Either only tabs or only spaces or tabs
followed by spaces, but not spaces followed by tabs.
 1.87 27-Sep-2020  rillig make(1): rename Buf_Size to Buf_Len

The new name better matches the field name Buffer.len as well as the
variables around the calls to this function.
 1.86 25-Sep-2020  rillig make(1): add tags to some of the unnamed structs

The tags prevent the structs from accidentally becoming compatible
types.

While here, remove a few typedefs for structs that are single-purpose,
since there is no point in abstracting from the actual representation of
these types.
 1.85 22-Sep-2020  rillig make(1): prepare Var_Subst for proper error handling

Returning a VarParseResult instead of a string makes it possible to let
the error bubble up, until it reaches the main expression.
 1.84 14-Sep-2020  rillig make(1): inline character constants in var.c

This removes a level of indirection, and the macro names were quite
similar in appearance as well. The macros may have been used by people
whose editors don't recognize C string and character literals when
navigating to the corresponding brace or parenthesis. These editors had
already been confused before this commit since there are also string
literals with unbalanced parentheses, and there are far fewer
compensating comments such as /*{*/ or /*)*/ in the code. In fact, the
only such comment that is left over was in for.c.

This way, there is now a single consistent way of writing these
character literals, which is without macros or comments, since that is
the simplest form.
 1.83 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.82 12-Sep-2020  rillig make(1): fix inconsistent code indentation
 1.81 12-Sep-2020  rillig make(1): use proper return type for For_Accum
 1.80 12-Sep-2020  rillig make(1): update the comment about .for loops to match the code
 1.79 11-Sep-2020  rillig make(1): add wrappers around ctype.h functions

This avoids casting the argument to unsigned char, and to cast the
result of toupper/tolower back to char.
 1.78 07-Sep-2020  rillig make(1): save a strlen call in ForIterate
 1.77 07-Sep-2020  rillig make(1): constify local variables in ForIterate
 1.76 07-Sep-2020  rillig make(1): split local variable in ForIterate
 1.75 07-Sep-2020  rillig make(1): convert ForEscapes from #define to enum
 1.74 07-Sep-2020  rillig make(1): add local variable for escapes to for_substitute

Just for debugging. No change in code size.
 1.73 06-Sep-2020  rillig make(1): add const to For_Eval and For_Accum
 1.72 06-Sep-2020  rillig make(1): clean up For_Eval

* Reduce scope of local variables.
* Remove unnecessary null character test before positive isspace call.
 1.71 06-Sep-2020  rillig make(1): properly initialize For structure in For_Eval

Initializing a Buffer or a strlist_t with zero-valued bytes only works
by conincidence, but because it would be the correct way. In the code
path "missing `in' in for", that zero-filled Buffer is freed using
Buf_Destroy, which could have invoked undefined behavior.
 1.70 06-Sep-2020  rillig make(1): improve documentation in For_Eval
 1.69 06-Sep-2020  rillig make(1): fix type of For.short_var
 1.68 04-Sep-2020  rillig make(1): unexport For_Iterate

By convention, exported functions have an underscore, and static
functions don't.
 1.67 30-Aug-2020  rillig make(1): replace brk_string with Str_Words

The API is much simpler, and there is less detail that is exposed by
default and fewer punctuation to type on the caller's side. To see that
there is some memory to be freed, one would have to look into the
struct. Having part of the return value as the actual return value and
the rest in output parameters was unnecessarily asymmetrical.
 1.66 29-Aug-2020  rillig make(1): remove duplicate code for allocation a substring
 1.65 23-Aug-2020  rillig make(1): make brk_string return size_t for the number of words
 1.64 22-Aug-2020  rillig make(1): clean up headers

Remove redundant headers that are already included by "make.h".
Make <assert.h> available to all compilation units that use "make.h".
 1.63 09-Aug-2020  rillig make(1): format the source code consistently, at least per file

Some files use 4 spaces per indentation level, others use 8. At least
for the few files from this commit, they use a consistent style
throughout each file now.

In Cond_Eval, the #define has changed into an enum since the identifiers
need not be visible to the C preprocessor.
 1.62 08-Aug-2020  rillig make(1): remove trailing Z from buffer functions

This Z had been useful during the migration from int to size_t. This
migration is finished, at least for the Buffer type, so the Z is no
longer necessary.
 1.61 03-Aug-2020  rillig make(1): no declaration-after-statement anymore

NetBSD make is intended to be maximally portable, therefore it uses only
C89. This was not declared in the Makefile before.

There are still a few places in parse.c and metachar.c that use
end-of-line comments. These will be fixed in a follow-up commit.
 1.60 02-Aug-2020  rillig make(1): move and condense comment for For_Run

It was simply wrong that calling For_Run had "Side Effects: None".
 1.59 01-Aug-2020  rillig make(1): switch Buffer size from int to size_t

This change helps to make the various integer types compatible and is a
preparational step for setting WARNS=6 in the Makefile.

The documentation of buf.c has been cleaned up and condensed since it
was mostly redundant, and some statements were even slightly wrong.

All code changes are covered by the existing unit tests, except for the
few lines in for.c around for_var_len. These changes have been reviewed
thoroughly and manually, like all the others in this commit.

Those buffer functions that deal with sizes have been renamed by
appending a Z, to make sure that no function call was accidentally
forgotten. They will be renamed back in a follow-up commit.

As usual, the scope of a few affected variables has been reduced, and
some variables had to be split since they had been incorrectly merged
before.

The order of the arguments to Buf_AddBytes has changed from (mem_len,
mem) to (mem, mem_len), in order to make it consistent with the
functions from the C standard library, such as snprintf.
 1.58 01-Aug-2020  rillig make(1): use consistent indentation in source code

Tabs for multiples of 8, then spaces.

The usage string has been kept as-is since the spaces there are
indentional and do influence the output.
 1.57 28-Jul-2020  rillig make(1): remove unnecessary struct tag

Identifiers starting with an underscore and an uppercase letter are
reserved for the C implementation.
 1.56 28-Jul-2020  rillig make(1): remove dead code from Var_Subst

The first parameter from Var_Subst had been a literal NULL in all cases.
These have been fixed using this command:

sed -i 's|Var_Subst(NULL, |Var_Subst(|' *.c

The one remaining case was not found because the "NULL," was followed by
a line break instead of a space.

The removed code probably wouldn't have worked as expected anyway.
Expanding a single variable to a literal string would have led to
unexpected behavior for cases like ${VAR:M${pattern}}, in case pattern
would contain an unescaped ':' itself.
 1.55 19-Jul-2020  rillig make(1): rename Varf_Flags to VarEvalFlags

In var.c there are lots of different flag types. To make any accidental
mixture obvious, each flag group gets its own prefix.

The only flag group that is visible outside of var.c is concerned with
evaluating variables, therefore the "e", which replaces the former "f"
that probably just meant "flag".
 1.54 03-Jul-2020  rillig make(1): remove trailing whitespace
 1.53 16-Apr-2017  riastradh Clarify that assignment is for effect, not truth of value.

CID 977502
 1.52 18-Feb-2016  christos branches: 1.52.2; 1.52.4;
Collapse the 3 boolean parameter to 1 flags parameter. No functional change.
 1.51 09-Jan-2016  christos Preserve $$ in := assignments..

FOO=\$$CRAP
BAR:=${FOO}

all:
echo ${FOO}
echo ${BAR}
 1.50 11-Oct-2015  sjg Add Boolean wantit to Var_Parse and Var_Subst

wantit will be FALSE when we are just consuming to discard
in which case we skip "expensive" things like Cmd_Exec.

Reviewed by: christos
 1.49 03-Jun-2012  sjg Handle "quoted strings" as items in a .for list
 1.48 25-Dec-2010  dholland branches: 1.48.6;
Begin cleanup of the make parser: separate out the logic for reading files
from the parsing goo. This will now use mmap for reading if it works and
fall back to read only for pipes and such. Step 1 of a cleanup program
proposed without objection on tech-toolchain.
 1.47 06-Feb-2010  dholland Improve the error message that results when you have a multi-variable .for
and the substitution list doesn't divide evenly.
 1.46 17-Jan-2009  dsl Change 'Buffer' so that it is the actual struct, not a pointer to it.
Saves having to malloc/free a fixed size structure.
Buf_Init() now takes ptr to Buffer to initialiase.
Change Buf_Destroy() to return ptr to string when not freed.
Remove large number of casts to (Byte) and (Byte *) - 'Byte' is 'char' here.
Buf_AddByte[s] guarantees that the data is 0 termininated, so never add '\0'.
Keep 'count' not 'left' and 'inPtr', code is simplier with only one update.
Fix fallou, no functional change.
 1.45 14-Jan-2009  dsl Contrary to my previous thoughts, .for loop variable values do contain
variable references - eg ${.TARGET} since that can't be expanded earlier.
Also the variable gets re-expanded before modifiers are applied.
All this means that we do need to let :U expand variables and must not
just escape $.
 1.44 13-Jan-2009  dsl When substituting .for control variables (as ${:U...}) escape '$' and '\'
as well as ':' and '}' or ')'.
The parameters have just been expanded (and will be expanded again) later
so don't need expanding as part of the :U process.
Seems to fix pkgsrc breakage at line 34 of bsd.pkginstall.mk doing:
.for i in ${PKG_USERS}
_PKG_VARS.pkginstall+= PKG_UID.${u} PKG_GECOS.${u} PKG_HOME.${u} PKG_SHELL.${u}
.endfor
when PKG_USERS = ${AVAHI_USER}:${AVAHI_GROUP}::Avahi\ user:/nonexistent
(set at line 41 of the ahavi Makefile)
I really dont think the above has the desired effect!
 1.43 11-Jan-2009  dsl Instead of stashing the body of every iteration of a .for loop, pass
Parse_SetInput() the name of a function to get the loop data blocks.
This should only be a change to the program logic.
 1.42 10-Jan-2009  dsl When substituting .for control variables any } or ) that matches the
${ or $( must be \ escaped.
Should fix some pkgsrc issues - eg 'clean' in print/gv.
 1.41 29-Dec-2008  dsl Count both () and {} when looking for the end of a :M pattern.
In particular inside .if empty(...) it was only counting ().
In reality this needs further changes.
This may well fix recent pkgsrc breakage.
 1.40 21-Dec-2008  dsl Only escape ':' in the outer level of .for variable substitution.
XXX: like elsewhere this code just counts {( against })
 1.39 21-Dec-2008  dsl Change the way .for variables are substituted.
Instead of doing a full substitution giving plain text, just replace the
variable part with something that will expand to the required text - leaving
any modifiers for the later evaluation of the input line.
This stops .for being used as an 'eval' (previously you could generate .if etc)
and also means it is still a variable expansion - which some other parts need
to work in the expected fashion.
 1.38 20-Dec-2008  dsl Add functions for processing extendable arrays of pointers to strings.
Use for the .for variables and substution items - changing the latter from
make's all conquering lst.lib functions.
Being able to index everything makes the code simpler.
No functional changes intended.
 1.37 20-Dec-2008  dsl Set the .for loop control variables in reverse order to avoid faffing.
 1.36 13-Dec-2008  dsl Use NULL instead of -1 cast to the relavant type (usually via NIL).
This was a suggestion from christos - so blame him if there is a deep
reason for using -1 :-)
 1.35 01-Dec-2008  dsl Correct some comments.
 1.34 01-Dec-2008  christos fix off-by-one allocation. functional change intended...
 1.33 30-Nov-2008  dsl Simplify somewhat the code that parses .for lines.
Use malloc to allocate space for teh strings (instead of a buf structure)
to make it mossible to not leak the associated memory (leak not fixed!).
No functional change intended.
 1.32 29-Nov-2008  dsl Split For_Eval() into two functions.
For_Eval() is now only called for the first line of a .for.
For_Accum() is called for the subsequent lines.
Stops any problems with forLevel being left invalid after an error.
Use a return value of -1 from For_Eval() to mean 'skip input line' to stop
a .for line with a syntax error being reparsed by make.
 1.31 22-Nov-2008  dsl Convert ADDWORD() to do { ... } while (0)
 1.30 06-Oct-2008  joerg Don't use emalloc and friends directly, but call them consistently
bmake_malloc and friends. Implement them via macros for the native case
and provide fallback implementations otherwise. Avoid polluting the
namespace by not defining enomem globally. Don't bother to provide
strdup and strndup, they were only used for the estrdup and estrndup
comapt code.

This addresses the presence of emalloc in system libraries on A/UX and
resulted strange issues as reported by Timothy E. Larson.
 1.29 26-May-2008  christos PR/38756: dominik: make dumps core on invalid makefile
 1.28 15-Feb-2008  christos branches: 1.28.4; 1.28.6;
back all changes out until I fix it properly.
 1.27 14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.26 01-Jan-2007  dsl Remove 'else' after 'return', and similar whitspace changes.
Extra debug on where files are actually found.
 1.25 16-Dec-2006  dsl Use open/read/close instead of stdio for makefiles.
Commons up the code for reading files and buffers, and allows a further
change where we don't copy the data out of the buffer when generating 'lines.
This will speed up makefile parsing (esp .if clauses).
 1.24 27-Oct-2006  dsl branches: 1.24.2; 1.24.4;
Since 'ClientData' is 'void *', nuke almost all the (ClientData) casts.
 1.23 15-Oct-2006  dsl Output all debug trace output through 'debug_file' defaulting to 'stdout'.
(Almost all the debug output went there, but some went to stderr.)
Split the parsing of -d (debug flags) out into its own routine.
Allow the output filename to be changed by specifying -dF<file> to create
a log file, or -dF+<file> to append to it. <file> may be stdout or stderr.
Also change so that -d-<flags> acts on <flags> locally but doesn't copy
them to MAKEFLAGS so they aren't inherited by child makes.
I'm not 100% happy with the command line syntax for the above, so they are
currently undocumented.
 1.22 09-Aug-2005  christos Add typedefs for DuplicateProc and FreeProc from Max Okumoto.
 1.21 08-Aug-2005  christos From Max Okumoto:
- Remove casts to NULL.
- Remove space between cast and object.
 1.20 05-Aug-2005  christos More KNF cleanups from Max Okumoto
 1.19 25-Jul-2005  christos Whitespace KNF cleanup from Max Okumoto
 1.18 16-Feb-2005  christos PR/29203, PR/29204: Max Okumoto: KNF changes to make [no functional changes]
 1.17 07-May-2004  ross Simplify build, no functional changes.

Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().

It's now possible to build make on some hosts with: cc *.c */*.c
 1.16 06-Mar-2004  enami branches: 1.16.2;
Print useful line number on error while executing .for directive.
 1.15 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.14 14-Jul-2003  christos Pass WARNS=3
 1.13 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.12 12-Mar-2002  christos PR/15888: Jarkko Teppo: Problems building on HP/UX
1. Compensate for h-pox assert brain damage where it gets confused by the
string in: assert(!memcmp(foo, "in", 2)); I miss the h-pox broken compiler,
I had not had to work around it for years.
2. Oh, finally h-pox has random() and utimes(). We don't need our own anymore.
 1.11 12-Jun-2001  sjg Add 4th arg (flags) to Var_Set so that VarLoopExpand can tell it not
to export interator variables when using context VAR_CMD.

Reviewed: christos
 1.10 06-Jun-2000  mycroft Roll back my for-expansion changes. Doing this right is just too hard to be
worth it.
 1.9 01-Jun-2000  mycroft Create a `for' context, and substitute iteration variable from it using the
normal Var_Parse() path. This allows :R, etc. to work on iteration variables.
 1.8 18-Apr-2000  simonb branches: 1.8.2;
Buf_GetAll() takes an int *, not a size_t *.

Build failure on alpha reported by Tim Rightnour on current-users.
 1.7 16-Apr-2000  christos PR/9899: David A. Holland: multi-variable .for constructs in make
 1.6 28-Sep-1997  lukem wrap #include <sys/cdefs.h>, __RCSID(...) stuff in #ifndef MAKE_BOOTSTRAP
 1.5 01-Jul-1997  christos Add WARNS=1
RCSID police
 1.4 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.3 14-Jun-1995  christos branches: 1.3.6;
- $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.2 06-Jun-1994  jtc Fixes from Christos Zoulas, who used purify, objectcenter and testcenter
to find memory leaks and illegal memory accesses.
 1.1 05-Mar-1994  cgd branches: 1.1.1;
fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.1.1.1 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.3.6.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.8.2.1 23-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.16.2.1 10-May-2004  tron Pull up revision 1.17 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.24.4.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.24.2.1 05-Jun-2007  bouyer Apply patch (requested by tron in ticket #696):
usr.bin/make/compat.c patch
usr.bin/make/cond.c patch
usr.bin/make/dir.c patch
usr.bin/make/for.c patch
usr.bin/make/main.c patch
usr.bin/make/make.1 patch
usr.bin/make/make.c patch
usr.bin/make/make.h patch
usr.bin/make/nonints.h patch
usr.bin/make/parse.c patch
usr.bin/make/str.c patch
usr.bin/make/targ.c patch
usr.bin/make/util.c patch
usr.bin/make/var.c patch

Synchronize make(1) with HEAD branch to increase perfomance and
improve stability.
 1.28.6.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.28.4.1 04-Jun-2008  yamt sync with head
 1.48.6.1 30-Oct-2012  yamt sync with head
 1.52.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.52.2.1 26-Apr-2017  pgoyette Sync with HEAD
 1.182.2.1 02-Aug-2025  perseant Sync with HEAD
 1.80 22-Apr-2025  rillig make: clean up

Replace 'unsigned int' with simply 'unsigned'.

In compat.c, skipping whitespace is not needed, as the loop above
already skips it.

In job.c, remove the unused header <sys/file.h>.

Inline the TMPPAT macro, as it is only needed in a single place.
 1.79 07-Jul-2024  rillig make: don't track hash table chain lengths during lookup

The chain lengths are only used for debugging purposes, so avoid the
extra cost at each lookup. Instead, calculate the maximum chain length
only when it is actually requested in -dh mode.

The reported number changes slightly: Before, it was the length of the
chain that was actually traversed to find an entry, up to that entry,
now it is the length of the largest chain in the table, no matter if it
was actually accessed or not.
 1.78 05-Jun-2024  rillig branches: 1.78.2;
make: sync comments with reality
 1.77 31-May-2024  rillig make: simplify expression in iteration over hash tables
 1.76 31-May-2024  rillig make: clean up API for iterating over hash tables
 1.75 24-May-2024  rillig make: remove dead code from HashTable_DeleteEntry
 1.74 19-Dec-2023  rillig make: clean up comments

No binary change, except for line numbers in assertions.
 1.73 17-Dec-2023  rillig make: clean up names of local variables

No binary change.
 1.72 09-Feb-2022  rillig make: fix mistakes, spelling and typos in comments and manual page

No binary change for -DNDEBUG.
 1.71 27-Jan-2022  rillig make: merge duplicate code for finding an entry in a hash table

No functional change.
 1.70 27-Jan-2022  rillig make: replace HashEntry_KeyEquals with strncmp

No functional change.
 1.69 27-Dec-2021  rillig make: replace __func__ with actual strings

Make is supposed to be C90-compatible, and __func__ is from C99.

No functional change.
 1.68 15-Dec-2021  rillig make: use consistent indentation for statements and continuations

No binary change, except for line numbers in assertions in suff.c.
 1.67 15-Dec-2021  rillig make: change return type of HashTable_Set to void

None of the callers needs the HashEntry for further manipulation.

No functional change.
 1.66 07-Dec-2021  rillig make: inline HashIter_Init

It is only used in non-critical code paths, but the generated code gets
smaller by inlining.

No functional change.
 1.65 12-Sep-2021  rillig make: fix build for DEBUG_HASH_LOOKUP
 1.64 11-Apr-2021  rillig make: avoid allocating memory for simple variable names

The main change is in ParseVarname, where a Buffer is replaced with the
newly introduced LazyBuf. LazyBuf is inspired by
https://golang.org/src/path/path.go.

In CanonicalVarname, the pre-comparison of the first letter of the
variable name is no longer necessary. GCC 9 optimizes a fixed-length
memcmp so well that the code can finally be written to target human
readers, leaving the optimization to the compiler.
 1.63 03-Apr-2021  rillig make: backport to C90

In the past few months I had accidentally used C99 features in the make
code. According to tools/README, tools that are used in the build
system should restrict themselves to C90.

This allows make to build with GCC's options "-pedantic
-Wno-system-headers -Dinline= -Wno-error=cast-qual".

I didn't notice anyone actively complaining though, I just wanted to see
how much work this backporting would be. The identifier __func__ is
still used, as in other tools.

No functional change.
 1.62 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.61 01-Feb-2021  rillig make: clean up comments in hash.c
 1.60 30-Dec-2020  rillig make(1): format multi-line comments
 1.59 15-Dec-2020  rillig make(1): clean up hash function for HashTable

Expressing a multiplication as a bit shifts and subtraction is the job
of the compiler. For humans, a multiplication is easier to read.
 1.58 23-Nov-2020  rillig make(1): use tabs for indentation in hash.h and hash.c
 1.57 14-Nov-2020  rillig make(1): replace a few HashTable_CreateEntry with HashTable_Set

Instead of HashTable_CreateEntry and HashEntry_Set, several places just
need the HashEntry for storing a value in it. This makes the calling
code simpler to understand.

These parts of the code are already hard enough to understand since they
are about memory management and aliasing. Having a too detailed API for
the HashTable only distracts from these topics.
 1.56 05-Nov-2020  rillig make(1): remove redundant parentheses from sizeof operator

The parentheses are only needed if the argument is a type, not an
expression.
 1.55 25-Oct-2020  rillig make(1): print hash in debug log with fixed width

This way all the keys are nicely aligned in the debug log.
 1.54 25-Oct-2020  rillig make(1): rename hash functions to identify the type name

This makes it easier to spot mismatches between the function name and
its first parameter, although the compiler should already catch most of
them. Except for void pointers.
 1.53 25-Oct-2020  rillig make(1): clean up comments in hash.c
 1.52 25-Oct-2020  rillig make(1): clean up hash table functions
 1.51 25-Oct-2020  rillig make(1): refactor Hash_DeleteTable
 1.50 25-Oct-2020  rillig make(1): refactor Hash_InitTable

First prepare all the data, then initialize the fields in declaration
order.
 1.49 25-Oct-2020  rillig make(1): clean up RebuildTable for hash tables

The previous code used ++ and -- a lot, it also reused variables a lot
for different purposes.
 1.48 25-Oct-2020  rillig make(1): reduce amount of string hashing

In pkgsrc, running "bmake show-all" in pkgtools/pkglint called the hash
function 249130 times before, and only 115502 times after.

Still, a single call to Var_Set hashes the same string 3 times.
 1.47 18-Oct-2020  rillig make(1): rename HashEntry.name to key
 1.46 18-Oct-2020  rillig make(1): remove underscore from Hash_Table and Hash_Entry

For consistency with the other type names, such as GNodeListNode.
 1.45 18-Oct-2020  rillig make(1): make API for iterating over hash tables simpler
 1.44 05-Oct-2020  rillig make(1): make dir.c, for.c and hash.c ready for WARNS=6

Some types have changed from int to unsigned int, size_t or time_t.

The variable i in hash.c has been kept as int since it counts down to
-1, which generates efficient machine code, at least on x86_64.
 1.43 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.42 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.41 04-Oct-2020  rillig make(1): merge duplicate code in Hash_FindEntry and Hash_CreateEntry
 1.40 04-Oct-2020  rillig make(1): avoid forward declaration for RebuildTable
 1.39 04-Oct-2020  rillig make(1): remove dead code from Hash_FindEntry

All callers pass a properly initialized table.
 1.38 03-Oct-2020  rillig make(1): replace strcpy with memcpy in Hash_CreateEntry

The string length is already known, no need to recalculate it.
 1.37 03-Oct-2020  rillig make(1): remove unnecessary code from Hash_DeleteEntry

This function is only called 2 times, and both callers pass valid
arguments.
 1.36 03-Oct-2020  rillig make(1): clean up hash table implementation

Having the hash function potentially redefined is a bit too much
flexibility. If actually needed, this should be done using a patch, not
using the C preprocessor.

Converting the macro to a function made the control flow easier to
understand. It also revealed that the variable p was unnecessary in
both Hash_FindEntry and Hash_CreateEntry.
 1.35 28-Sep-2020  rillig make(1): make debugging code shorter
 1.34 27-Sep-2020  rillig make(1): normalize whitespace in source code

There is no more space tab. Either only tabs or only spaces or tabs
followed by spaces, but not spaces followed by tabs.
 1.33 26-Sep-2020  rillig make(1): add Hash_FindValue, for direct access to hash table data
 1.32 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.31 05-Sep-2020  rillig make(1): remove initial size argument from Hash_InitTable

In all but one case this argument was set to auto-detect anyway. The
one case where it was set was not worth keeping this complicated API.
 1.30 05-Sep-2020  rillig make(1): make Hash_Table independent from -funsigned-char

This only makes a difference for Hash_Table keys outside the ASCII
character set, and these are barely used in practice, if at all.

The effects of this change can only be seen in debug mode, when printing
the full contents of the variable namespaces. In this output, the order
of the entries might change.

All other use cases stay the same as before.
 1.29 01-Sep-2020  rillig make(1): rename Hash_Table fields

Back in the 1980s it made sense to have the type information encoded in
the variable names. At the time when make was imported into the NetBSD
tree (1993-03-21), the functions did indeed not have prototypes, they
only had return types. The void type was already invented at that time.
Since the compiler could not verify the types of function parameters, it
made perfect sense to have each variable tell whether it was a pointer
or not.

Since ISO C90 this is no longer necessary since the compiler checks
this. The variable names can now focus on the application level and
their high-level meaning, expressing the relationship to other
variables instead of encoding redundant type information.
 1.28 28-Aug-2020  rillig make(1): remove redundant comments from hash.c
 1.27 26-Aug-2020  rillig make(1): remove header sprite.h

Make is independent of the Sprite operating system.
 1.26 01-Aug-2020  rillig make(1): use consistent indentation in source code

Tabs for multiples of 8, then spaces.

The usage string has been kept as-is since the spaces there are
indentional and do influence the output.
 1.25 20-Jul-2020  sjg Make DEBUG_HASH less of a fire-hose.

Reporting keys on every lookup is overkill unless
playing with a new HASH, so wrap in #ifdef DEBUG_HASH_LOOKUP
Also add some stats at the end so we can see
final size and max chain length - maxchain is a better
variable name than maxlen.
 1.24 19-Jul-2020  riastradh Nix trailing whitespace.
 1.23 18-Jul-2020  sjg Add -dh for DEBUG_HASH

Allow tracking of max chain length, to see how well the hash
tables are working.
Pull the actual hash operation into a marco so it can be
easily changed - for experimenting.

The current hash, is pretty good.

Reviewed by: christos
 1.22 03-Jul-2020  rillig make(1): add Hash_ForEach to avoid duplicate code
 1.21 03-Jul-2020  rillig make(1): remove redundant parentheses around return values
 1.20 14-Nov-2013  sjg Don't SEGV when Hash_Table is uninitialized
 1.19 24-Jan-2009  dsl branches: 1.19.8; 1.19.14;
Don't cast 'time_t' to 'void *' and back it will lose precision.
 1.18 13-Dec-2008  dsl Use NULL instead of -1 cast to the relavant type (usually via NIL).
This was a suggestion from christos - so blame him if there is a deep
reason for using -1 :-)
 1.17 06-Oct-2008  joerg Don't use emalloc and friends directly, but call them consistently
bmake_malloc and friends. Implement them via macros for the native case
and provide fallback implementations otherwise. Avoid polluting the
namespace by not defining enomem globally. Don't bother to provide
strdup and strndup, they were only used for the estrdup and estrndup
comapt code.

This addresses the presence of emalloc in system libraries on A/UX and
resulted strange issues as reported by Timothy E. Larson.
 1.16 04-Aug-2005  christos remove unnecessary casts to void * functions (Max Okumoto)
 1.15 25-Jul-2005  christos Whitespace KNF cleanup from Max Okumoto
 1.14 16-Feb-2005  christos PR/29203, PR/29204: Max Okumoto: KNF changes to make [no functional changes]
 1.13 07-May-2004  ross Simplify build, no functional changes.

Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().

It's now possible to build make on some hosts with: cc *.c */*.c
 1.12 07-Aug-2003  agc branches: 1.12.2;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.11 14-Jul-2003  christos Pass WARNS=3
 1.10 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.9 11-Jun-2000  mycroft Use a lower threshold for rebuilding hash tables.
 1.8 28-Sep-1997  lukem branches: 1.8.10;
wrap #include <sys/cdefs.h>, __RCSID(...) stuff in #ifndef MAKE_BOOTSTRAP
 1.7 01-Jul-1997  christos Add WARNS=1
RCSID police
 1.6 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.5 14-Jun-1995  christos branches: 1.5.6;
- $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.4 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.3 13-Jan-1994  jtc Include appropriate header files to bring prototypes into scope.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.6.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.8.10.1 23-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.12.2.1 10-May-2004  tron Pull up revision 1.13 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.19.14.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.19.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.78.2.1 02-Aug-2025  perseant Sync with HEAD
 1.52 22-Apr-2025  rillig make: clean up

Replace 'unsigned int' with simply 'unsigned'.

In compat.c, skipping whitespace is not needed, as the loop above
already skips it.

In job.c, remove the unused header <sys/file.h>.

Inline the TMPPAT macro, as it is only needed in a single place.
 1.51 07-Jul-2024  rillig make: don't track hash table chain lengths during lookup

The chain lengths are only used for debugging purposes, so avoid the
extra cost at each lookup. Instead, calculate the maximum chain length
only when it is actually requested in -dh mode.

The reported number changes slightly: Before, it was the length of the
chain that was actually traversed to find an entry, up to that entry,
now it is the length of the largest chain in the table, no matter if it
was actually accessed or not.
 1.50 01-Jun-2024  rillig branches: 1.50.2;
make: require return value of HashIter_Next to be used

This would have prevented an endless loop in
purge_relative_cached_realpaths.
 1.49 31-May-2024  rillig make: clean up API for iterating over hash tables
 1.48 19-Dec-2023  rillig make: clean up comments

No binary change, except for line numbers in assertions.
 1.47 17-Dec-2023  rillig make: clean up names of local variables

No binary change.
 1.46 31-Jan-2022  rillig make: remove redundant declaration of HashIter_Init

Since hash.h 1.41 from 2021-12-07.

No binary change.
 1.45 15-Dec-2021  rillig make: format comments according to /usr/share/misc/style

Assisted by indent(1), with manual corrections due to its many remaining
bugs.

No functional change.
 1.44 15-Dec-2021  rillig make: remove redundant comments for multiple-inclusion guards
 1.43 15-Dec-2021  rillig make: change return type of HashTable_Set to void

None of the callers needs the HashEntry for further manipulation.

No functional change.
 1.42 15-Dec-2021  rillig make: mark several functions whose result must be used

Suggested by sjg, to catch more bugs like the memory leak in cond.c
1.303 from 2021-12-13.

No binary change.
 1.41 07-Dec-2021  rillig make: inline HashIter_Init

It is only used in non-critical code paths, but the generated code gets
smaller by inlining.

No functional change.
 1.40 11-Apr-2021  rillig make: avoid allocating memory for simple variable names

The main change is in ParseVarname, where a Buffer is replaced with the
newly introduced LazyBuf. LazyBuf is inspired by
https://golang.org/src/path/path.go.

In CanonicalVarname, the pre-comparison of the first letter of the
variable name is no longer necessary. GCC 9 optimizes a fixed-length
memcmp so well that the code can finally be written to target human
readers, leaving the optimization to the compiler.
 1.39 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.38 15-Dec-2020  rillig make(1): indent hash.h and make_malloc.h with tabs instead of spaces
 1.37 29-Nov-2020  rillig make(1): use space instead of tab for preprocessor directives
 1.36 23-Nov-2020  rillig make(1): migrate CachedDir.files from HashTable to HashSet
 1.35 23-Nov-2020  rillig make(1): add HashSet type

This makes the code for handling suffixes simpler since it doesn't need
the clumsy API of HashTable_CreateEntry anymore.
 1.34 23-Nov-2020  rillig make(1): use tabs for indentation in hash.h and hash.c
 1.33 14-Nov-2020  rillig make(1): replace a few HashTable_CreateEntry with HashTable_Set

Instead of HashTable_CreateEntry and HashEntry_Set, several places just
need the HashEntry for storing a value in it. This makes the calling
code simpler to understand.

These parts of the code are already hard enough to understand since they
are about memory management and aliasing. Having a too detailed API for
the HashTable only distracts from these topics.
 1.32 10-Nov-2020  rillig make(1): use consistent definition for MAKE_INLINE
 1.31 25-Oct-2020  rillig make(1): rename hash functions to identify the type name

This makes it easier to spot mismatches between the function name and
its first parameter, although the compiler should already catch most of
them. Except for void pointers.
 1.30 25-Oct-2020  rillig make(1): reduce amount of string hashing

In pkgsrc, running "bmake show-all" in pkgtools/pkglint called the hash
function 249130 times before, and only 115502 times after.

Still, a single call to Var_Set hashes the same string 3 times.
 1.29 18-Oct-2020  rillig make(1): rename HashEntry.name to key
 1.28 18-Oct-2020  rillig make(1): remove underscore from Hash_Table and Hash_Entry

For consistency with the other type names, such as GNodeListNode.
 1.27 18-Oct-2020  rillig make(1): make API for iterating over hash tables simpler
 1.26 05-Oct-2020  rillig make(1): make dir.c, for.c and hash.c ready for WARNS=6

Some types have changed from int to unsigned int, size_t or time_t.

The variable i in hash.c has been kept as int since it counts down to
-1, which generates efficient machine code, at least on x86_64.
 1.25 27-Sep-2020  rillig make(1): normalize whitespace in source code

There is no more space tab. Either only tabs or only spaces or tabs
followed by spaces, but not spaces followed by tabs.
 1.24 26-Sep-2020  rillig make(1): add Hash_FindValue, for direct access to hash table data
 1.23 13-Sep-2020  rillig make(1): fix position of MAKE_ATTR_UNUSED in inline functions

The attribute needs to be before the return type, otherwise GCC 5
complains that Hash_GetValue is defined but not used, when compiling
with USER_CPPFLAGS=-Dinline=. The other functions don't get any
warnings. It's probably because Hash_GetValue is the only inline
function that returns a pointer.
 1.22 05-Sep-2020  rillig make(1): remove initial size argument from Hash_InitTable

In all but one case this argument was set to auto-detect anyway. The
one case where it was set was not worth keeping this complicated API.
 1.21 01-Sep-2020  rillig make(1): rename Hash_Table fields

Back in the 1980s it made sense to have the type information encoded in
the variable names. At the time when make was imported into the NetBSD
tree (1993-03-21), the functions did indeed not have prototypes, they
only had return types. The void type was already invented at that time.
Since the compiler could not verify the types of function parameters, it
made perfect sense to have each variable tell whether it was a pointer
or not.

Since ISO C90 this is no longer necessary since the compiler checks
this. The variable names can now focus on the application level and
their high-level meaning, expressing the relationship to other
variables instead of encoding redundant type information.
 1.20 01-Sep-2020  rillig make(1): replace Hash_Table macros with inline functions
 1.19 29-Aug-2020  rillig make(1): merge duplicate code for bmake_strldup
 1.18 13-Aug-2020  rillig make(1): follow naming conventions for multiple-inclusion guards

This avoids undefined behavior.
 1.17 06-Aug-2020  rillig make(1): remove unused macro Hash_Size
 1.16 01-Aug-2020  rillig make(1): use consistent indentation in source code

Tabs for multiples of 8, then spaces.

The usage string has been kept as-is since the spaces there are
indentional and do influence the output.
 1.15 20-Jul-2020  sjg Make DEBUG_HASH less of a fire-hose.

Reporting keys on every lookup is overkill unless
playing with a new HASH, so wrap in #ifdef DEBUG_HASH_LOOKUP
Also add some stats at the end so we can see
final size and max chain length - maxchain is a better
variable name than maxlen.
 1.14 18-Jul-2020  sjg Add -dh for DEBUG_HASH

Allow tracking of max chain length, to see how well the hash
tables are working.
Pull the actual hash operation into a marco so it can be
easily changed - for experimenting.

The current hash, is pretty good.

Reviewed by: christos
 1.13 03-Jul-2020  rillig make(1): add Hash_ForEach to avoid duplicate code
 1.12 31-May-2017  maya Use less generic include guards
 1.11 07-Jun-2016  sjg Extend the mtimes cache used by dir.c so it can be used by others.

We store both st_mtime and st_mode, since some callers care about the
later.

Reviewed by: christos
 1.10 24-Jan-2009  dsl Don't cast 'time_t' to 'void *' and back it will lose precision.
 1.9 23-Jan-2009  dsl Change 'ClientData' to 'void *' so that relevant parameters can
be made 'const void *'.
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.7 14-Jul-2003  christos Pass WARNS=3
 1.6 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.5 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.4 14-Jun-1995  christos branches: 1.4.6;
- $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.3 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.6.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.50.2.1 02-Aug-2025  perseant Sync with HEAD
 1.519 04-Aug-2025  sjg Always pass valid length to meta_job_output.
 1.518 03-Aug-2025  sjg make: ensure output captured in meta file is accurate

In CollectOutput() a newline before the end of job->outBuf
results in a short write to stdout, but meta_job_output()
was recording the entire string in the meta file, so on
next call the left overs would be duplicated in the meta file.

Pass a length to meta_job_output() if it should only report part of
the data in meta file.
 1.517 06-Jul-2025  rillig make: clean up
 1.516 13-Jun-2025  rillig make: do not discard empty lines in the output of a command
 1.515 13-Jun-2025  rillig make: add job prefix if necessary in non-default filtered mode
 1.514 13-Jun-2025  rillig make: omit redundant call to strlen during output of a parallel job
 1.513 13-Jun-2025  rillig make: add on-demand inter-process stack traces

When debugging a build that heavily uses nested calls to sub-makes, the
chain of calls is useful to quickly assess the situation. If explicitly
requested, include the actions from any parent processes in the stack
traces.

Reviewed by: sjg
 1.512 12-Jun-2025  rillig make: use a common style for unexpected error messages

In enomem, report the actual error instead of a fixed ENOMEM.
 1.511 18-May-2025  rillig make: clean up building the shell commands in parallel mode
 1.510 18-May-2025  rillig make: clean up an error message and a debug message

When adding a .WAIT dependency, use the common format "target: source"
instead of the unusual "source -> target".
 1.509 18-May-2025  rillig make: rename variables, remove now-redundant comments
 1.508 18-May-2025  rillig make: remove redundant comments, summarize a few others
 1.507 17-May-2025  rillig make: remove timeout for polling in parallel mode

Job_CatchOutput is always called in a loop with nothing else being done
meanwhile, and it wakes up as soon as a child process exits. So instead
of checking every 5 seconds, just wait indefinitely.
 1.506 10-May-2025  rillig make: rename token pool variables to be more descriptive
 1.505 09-May-2025  rillig make: unify debug messages for parallel mode

Always print the process status in hex, with a leading "0x", to avoid
confusion for status 127f, which looks suspiciously decimal.

Prefix all process IDs with "pid", to be able to filter them easily.

Omit trailing whitespace when printing a command.
 1.504 09-May-2025  rillig make: move ContinueJobs further up, to eliminate a forward declaration

Reword a debug log message from "Restarting" to "Continuing", as the
child process is not started again from the beginning.
 1.503 09-May-2025  rillig make: error out if writing to an internal pipe fails

The write end of the childExitJob pipe is synchronous, therefore, there
is no EAGAIN to be expected. Writing to the pipe is expected to succeed,
so error out noticeably.
 1.502 09-May-2025  rillig make: clean up constant names and function names
 1.501 09-May-2025  rillig make: replace magic numbers in job debug log with descriptive names
 1.500 03-May-2025  rillig make: miscellaneous cleanups
 1.499 03-May-2025  rillig make: use uniform debug log messages for the token pool
 1.498 02-May-2025  rillig make: in the debug log, replace magic numbers with identifiers
 1.497 23-Apr-2025  rillig make: prevent overly large values for the -j option

A comment previously suggested to clip the number of parallel jobs to
PIPE_BUF, but that would have been wrong, as PIPE_BUF is not the maximum
capacity of a pipe, but rather the maximum number of bytes that are
guaranteed to be written to the pipe atomically.

Previously, the output end of the token pool pipe was blocking, which
meant that the "errno == EAGAIN" branches were unreachable. Now that the
pipe is nonblocking, they would be reachable. When setting up the token
pool, writing to a full pipe indicates too many parallel jobs requested,
and is thus rejected. At any later point in time, writing to a full pipe
indicates an internal error, as each sub-make is supposed to only return
as many tokens as it previously took from the pool. Therefore, error out
in these situations.
 1.496 22-Apr-2025  rillig make: clean up

Replace 'unsigned int' with simply 'unsigned'.

In compat.c, skipping whitespace is not needed, as the loop above
already skips it.

In job.c, remove the unused header <sys/file.h>.

Inline the TMPPAT macro, as it is only needed in a single place.
 1.495 22-Apr-2025  rillig make: group the code for handling the job token pool
 1.494 22-Apr-2025  rillig make: remove no-op code

Whitespace is already skipped in the loop above.

When no jobs are running, there is no need to wait for one.
 1.493 22-Apr-2025  rillig make: move struct Job from job.h to job.c

The content of this struct is an implementation detail, and other parts
of make only need to access very few parts of it.
 1.492 12-Apr-2025  rillig make: clean up job and output handling
 1.491 12-Apr-2025  rillig make: before exiting after a build error, wait for the jobs to finish
 1.490 11-Apr-2025  rillig make: convert more messages to the "file:123" format
 1.489 08-Mar-2025  rillig make: re-add cast for pid_t -1

POSIX only specifies that pid_t is an arithmetic type, it doesn't even
have to be an integer type. Just in case a platform defines pid_t as an
unsigned integer type, avoid a compiler warning about passing a negative
constant to an unsigned target type.

Such a platform is probably rare, as Job.pid is declared as int, not
pid_t, so there would be more compiler warnings of this kind on such a
platform.
 1.488 07-Mar-2025  rillig make: prevent SIGPIPE for child processes in parallel mode

Starting with job.c 1.198 from 2020-06-19, when one branch of a parallel
build failed, make exited immediately without waiting until the child
processes from the other branches had finished. As a consequence, the
child processes faced a SIGPIPE when they tried to write to stdout.

The call to Job_Wait is taken straight from Fatal, where it used to be
called before the "die silently" execution path was introduced in 2020.
 1.487 07-Mar-2025  rillig make: clean up comments and code for parallel mode

Most of the comments didn't help understand the code.

The Finish function was named way too soft for what it does, which is to
exit without cleaning up properly. Since it was used only once, inline
it. The code from that function causes jobs to be terminated early when
an unrelated target has failed, resulting in partially written files,
due to SIGPIPE.
 1.486 24-Feb-2025  rillig make: on interrupt in parallel mode, reliably remove the targets

Previously, when make was interrupted in parallel mode, it first removed
the current job's target and then forwarded the signal to the child
process. This left a little gap in which the child process had the
chance of recreating the target, leading to incomplete, often zero-sized
target files.

Now first forward the signal to the child process, then wait for the
child process to finish, and finally remove the target file.
 1.485 19-Jan-2025  rillig make: fix code coverage counts

See tests/usr.bin/gcov/t_gcov.sh.
 1.484 03-Jan-2025  rillig make: clean up job handling
 1.483 22-Jul-2024  rillig make: remove dead code
 1.482 22-Jul-2024  rillig make: fix exit status for error in .BEGIN/.END prerequisite
 1.481 20-Jul-2024  rillig make: don't run erroneous commands in parallel mode
 1.480 07-Jul-2024  rillig make: only generate code for cleanup functions in CLEANUP mode
 1.479 05-Jul-2024  rillig make: reduce lint-specific comments about ARGSUSED
 1.478 28-Jun-2024  rillig branches: 1.478.2;
make: reduce usage of the UNCONST hack
 1.477 25-Jun-2024  rillig make: fix invalid-free for custom shell definitions

Don't try to free a pointer that is taken from the middle of a string,
in this case a shell specification.
 1.476 15-Jun-2024  rillig make: clean up collection of context information for error messages
 1.475 02-Jun-2024  rillig make: sync VarEvalMode constant names with their debug log names
 1.474 25-May-2024  rillig make: replace magic numbers with POSIX FILENO constants

No binary change.
 1.473 25-May-2024  rillig make: fix memory leak for command strings
 1.472 25-May-2024  rillig make: fix some more memory leaks
 1.471 07-May-2024  sjg make: all command line overrides go in .MAKEOVERRIDES

Not all variables that start with '.' are internals,
and unless they are explicitly flagged as internal should go
into .MAKEOVERRIDES

Update varname-dot-makeoverrides to check this.

Also avoid using SCOPE_CMDLINE when ReadOnly will do.
 1.470 27-Apr-2024  rillig make: clean up, test .NOPATH

Trim down the comments in the archive module, as they mainly repeated
the code. Trim down the binary code size in the archive module, as it
is rarely used.

In Var_Parse, delay two variable assignments until they are actually
needed.
 1.469 26-Apr-2024  rillig make: in parallel mode, print the directory in which a job failed

When multiple targets run in parallel, the "stopped in" line may be
several lines away from the "Failed target" line, making them hard to
correlate.
 1.468 20-Apr-2024  rillig make: provide more context information for parse/evaluate errors
 1.467 10-Mar-2024  sjg make: record exit status in GNode

SetErrorVars can now set .ERROR_EXIT which allows
a .ERROR target to ignore the case of .ERROR_EXIT == 6
which means failure happened elsewhere.

Reviewed by:
 1.466 01-Mar-2024  sjg make: export target scope values

Pass target scope to Var_ReexportVars so that a target process
will see the correct values in its env.
We must then mark any Global scope variable as unexported
so targets without local value get the Global one.
 1.465 07-Jan-2024  rillig make: clean up comments, constify shell name
 1.464 07-Jan-2024  sjg make: more consistent error messages

Move %s: progname from Job_CheckCommands to Fatal
to avoid is being repeated when Job_CheckCommands is passed Error.

This means some errors from var also report progname (and level)
which is useful.

Reviewed by: rillig
 1.463 05-Jan-2024  rillig make: miscellaneous cleanups
 1.462 29-Dec-2023  rillig make: clean up comments

No binary change, except for line numbers in assertions.
 1.461 19-Dec-2023  rillig make: clean up comments

No binary change, except for line numbers in assertions.
 1.460 17-Dec-2023  rillig make: clean up names of local variables

No binary change.
 1.459 15-Feb-2023  rillig make: inline macros for variable names

The variable name '.MAKEOVERRIDES' was already used in the non-macro
form.

No binary change.
 1.458 14-Feb-2023  rillig make: clean up calls to Var_Subst

None of the calls to Var_Subst used the return value, and the return
value was always VPR_OK.

No functional change.
 1.457 17-Jan-2023  christos Accept whitespace between command specifiers @+- like gmake does. New binutils
does this.
 1.456 10-Oct-2022  rillig make: change return type of unlink_file back to int

As unlink_file is a wrapper around unlink, use the same encoding for the
possible return values as in the wrapped function. This consistency is
more important than expressing all possible return values in the return
type 'bool'.

https://mail-index.netbsd.org/tech-toolchain/2022/10/06/msg004155.html

No functional change.
 1.455 03-Sep-2022  rillig make: untangle output handling in jobs mode, remove redundant braces

No functional change.
 1.454 03-Sep-2022  rillig make: fix handling of null bytes in the output in jobs mode

The test job-output-null failed occasionally, depending on the exact
timing of the child's write and make's read.
 1.453 07-May-2022  rillig make: rename Compat_Run to Compat_MakeAll

No functional change.
 1.452 12-Feb-2022  rillig make: fix echoing of command with '-' in silent target in jobs mode

Since job.c 1.83 from 2003-12-20, the command had been echoed even if
the target had the attribute '.SILENT'.

In sh-flags.exp, each removed 'echo' command is below a target name
matching the pattern 'opt-?j????-tgt-??s-cmd-?i?', which means that the
target was marked as silent, either through a global '.SILENT'
declaration or the command line option '-s' or the attribute '.SILENT'
on the target.

Reported by Alan Barrett in PR#45356.
 1.451 04-Feb-2022  rillig make: use unsigned int for line numbers everywhere

Previously, some line numbers were stored as signed int while others
were stored as size_t. Since line numbers are never negative, use an
unsigned type. Since the maximum file size for makefiles is 1 GB (see
loadfile), unsigned int is large enough even on 64-bit platforms.

Using a single data types reduces the number of type conversions. Using
unsigned int improves compatibility with C90 (printf %u instead of %zu),
which is needed by bmake, which is derived from usr.bin/make.

No functional change.
 1.450 30-Jan-2022  christos Make the GNode lineno unsigned to fix lint warning in var.c calling
PrintLocation()
 1.449 22-Jan-2022  rillig make: add missing newline after "cannot continue" message

It was wrong of Parse_File to output an unfinished line and hope for
some other code to finish it. As demonstrated in the test, PrintOnError
did not do that in the case of additional debug output.

To keep the overall behavior as close as possible to before, the other
callers of PrintOnError now have to pass the newline themselves. Passing
strings that start with newlines but don't end with them looked
suspicious anyway.
 1.448 08-Jan-2022  rillig make: remove redundant braces

No binary change, except for assertion line numbers.
 1.447 07-Jan-2022  rillig make: rename and inline Targ_Precious

No functional change.
 1.446 07-Jan-2022  rillig make: reduce code for initializing error handling in shell

No functional change.
 1.445 27-Dec-2021  rillig make: remove unnecessary words from command line options

Several years ago, the command line options were individual global
variables. The global variable could therefore not be named 'silent'
since that would have conflicted with local variables of the same name.
After moving the global variable to the namespace 'struct CmdOpts',
there is no conflict anymore.

There doesn't seem to be any risk of naming collisions for the names
'touch' and 'query'.

No functional change.
 1.444 27-Dec-2021  rillig make: rename eunlink to unlink_file

The name eunlink suggested a relation with the similarly named functions
emalloc or esnprintf, but that was misleading. Instead, unlink_file
works like unlink, except that it refuses to remove an empty directory.

No functional change.
 1.443 15-Dec-2021  rillig make: format comments according to /usr/share/misc/style

Assisted by indent(1), with manual corrections due to its many remaining
bugs.

No functional change.
 1.442 15-Dec-2021  rillig make: use consistent indentation for statements and continuations

No binary change, except for line numbers in assertions in suff.c.
 1.441 15-Dec-2021  rillig make: change return type of Compat_RunCommand from int to bool

The documentation was wrong before since status was not restricted to
only 0 or 1.

No functional change.
 1.440 28-Nov-2021  rillig make: convert GNodeFlags from enum into bit-fields

Now that Enum_ToString is implemented for each type separately, it's
easy to convert them to bit-fields. This gets rid of the magic numbers
12 for CYCLE and 13 for DONECYCLE that left a suspicious gap in the
numbers. This gap was not needed since the code didn't make use of the
relative ordering of the enum constants.

The effects of this conversion are fewer capital letters in the code,
smaller scope for the GNode flags, and clearer code especially when
setting a flag back to false.

One strange thing is that GCC 10.3.0 doesn't optimize GNodeFlags_IsNone
to an single bitmasking instruction, at least on x86_64. Instead it
generates a testb instruction for each of the flags, even loading bit 8
separately from the others. Clang 12.0.1 knows this optimization
though and generates the obvious sequence of movzwl, testl, jz.

No functional change.
 1.439 28-Nov-2021  rillig make: eliminate common subexpressions in DebugFailedJob

No functional change.
 1.438 28-Nov-2021  rillig make: fix memory leak in jobs mode with -de (since today)
 1.437 28-Nov-2021  rillig make: with the option -de in jobs mode, output expanded commands

This helps tracking down the actual cause of build failures in build
systems like NetBSD's build.sh that use highly abstracted commands that
are mainly defined in terms of variables.
 1.436 24-Oct-2021  sjg Do not ignore write failures.

We should not ignore failure to write to cmdFILE,
meta files and filemon.

Reviewed by: rillig
 1.435 16-Jun-2021  rillig make: fix error handling in jobs mode

By using the same error handling code as in the branch for non-empty
commands, the behavior is the same again as before 2021-01-29.
 1.434 16-Jun-2021  rillig make: extract commands-ok check from JobWriteShellCommands

This piece of code did not match the function name and thus could not
reasonably be expected in that function.

In job.c 1.399 from 2021-01-29 I missed exactly this little detail when
I added code to skip the apparently unnecessary creation of empty shell
files. The code I added only handled the happy case, not the case where
the target could not be made.

That code path then differed, leading to a much more verbose error
message than before.

before:
don't know how to make ../missing/no-such.o. Stop

after:
don't know how to make ../missing/no-such.o. Stop
...
`../missing/no-such.o' was not built (made BEINGMADE, ...)!
`muck' was not built (made DEFERRED, type OP_DEPENDS|...)!
`muck' has .ORDER dependency against build-all (made DEFERRED, ...)

Thanks to sjg for finding and reproducing this unintended change of
behavior.
 1.433 16-Jun-2021  rillig make: clean up comment for JobStart

The parameter 'flags' was renamed in job.c 1.354 from 2020-12-10 without
adjusting the documentation.

The parameter 'previous' was removed in job.c 1.108 from 2006-03-12,
also without adjusting the documentation of JobStart.

No functional change.
 1.432 27-Apr-2021  rillig make: use consistent variable names, types and braces in DebugFailedJob

No functional change.
 1.431 27-Apr-2021  rillig make: remove stray space in -de output in jobs mode

In compat mode, having a space in this place makes sense to align the
target name with the command. In jobs mode, since each command is
listed in a separate line, there is no need for the double space.
 1.430 27-Apr-2021  christos Print -de error information when running multiple jobs

Problem and patch description from https://reviews.freebsd.org/D29647:

When running `make -de` (without any -j flag) bmake prints which command
failed. However, when using the -j flag the -de flag is ignored. This can
make it rather difficult to determine which command failed in an very
parallel build (especially when combined with the -s flag to avoid
ridiculously large logfiles). For single-threaded builds we can combine
-s with -de to get the failed command but this does not work with -jN
(even with -j1). This patch prints the failed shell script with -de in the
multiple jobs mode as well.

From Alexander Richardson @ FreeBSD
 1.429 16-Apr-2021  rillig make: use distinct wording for writing to the shell commands file

The word 'write' now means to write to the file that holds the shell
commands to be run later.

The word 'print' is now used exclusively for handling the output of the
child commands and printing them to make's stdout.

No functional change.
 1.428 16-Apr-2021  rillig make: align name of jobs_table_dump to the other functions
 1.427 15-Apr-2021  rillig make: remove type name for the abort status in job handling
 1.426 15-Apr-2021  rillig make: rename PrintOutput to PrintFilteredOutput to avoid confusion

In the default configuration, the function PrintOutput did nothing.
Only if the shell has defined an output filter, something happens at
all.
 1.425 15-Apr-2021  rillig make: document two previously unknown bugs in job mode
 1.424 04-Apr-2021  rillig make: rename a few functions to be more descriptive

No functional change.
 1.423 04-Apr-2021  rillig make: rename ambiguous functions

These two functions have counterparts that include the word 'Do' in
their name, which is confusing.

No functional change.
 1.422 03-Apr-2021  rillig make: backport to C90

In the past few months I had accidentally used C99 features in the make
code. According to tools/README, tools that are used in the build
system should restrict themselves to C90.

This allows make to build with GCC's options "-pedantic
-Wno-system-headers -Dinline= -Wno-error=cast-qual".

I didn't notice anyone actively complaining though, I just wanted to see
how much work this backporting would be. The identifier __func__ is
still used, as in other tools.

No functional change.
 1.421 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.420 05-Feb-2021  sjg Job_TempFile: unlink while signals blocked
 1.419 05-Feb-2021  sjg Avoid strdup in mkTempFile

Require caller to pass a buffer and size if they
want the tempfile not unlinked.

Add Job_TempFile to handle blocking signals around
call to mkTempFile, so that meta_open_filemon can use it
in jobs mode.
 1.418 05-Feb-2021  rillig make: remove unnecessary assignment in Job_Start, clean up comments
 1.417 05-Feb-2021  rillig make: in the Var_ functions, move the scope to the front

This change provides for a more natural reading order in the code.
Placing the scope first makes it immediately clear in which context the
remaining parameters are interpreted.

No functional change.
 1.416 04-Feb-2021  rillig make: rename some VAR constants to SCOPE

The word "context" does not fit perfectly to the variables that are
associate with a GNode, as the context is usually something from the
outside and the variables are more like properties inherent to the
GNode.

The term "global context" fits even less. Since the thing where
variables are looked up is commonly named a scope, use that term
instead.

This commit only renames the global variables VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE, plus a few very closely related comments. These are:

GNode.vars (because of line breaks)
GNode_Free (dito)
varname-make_print_var_on_error.mk
varname-make_print_var_on_error-jobs.mk

The debug message in Var_Stats is left as-is since there is no unit test
for it yet.

The other renamings (variable names "context", "ctxt", as well as
further comments) will be done in a follow-up commit.
 1.415 03-Feb-2021  rillig make: replace Global_AppendExpand with Global_Append

All callers with a variable name that is guaranteed to not contain a
dollar sign have been converted to call Global_Append instead of the
previous Global_AppendExpand. After that, Global_AppendExpand was
unused, therefore it was effectively just renamed.
 1.414 03-Feb-2021  rillig make: replace Global_SetExpand with Global_Set for constant names
 1.413 03-Feb-2021  rillig make: use shortcut functions Global_SetExpand and Global_AppendExpand

There are many places where global variables are set or appended to. To
reduce clutter and code size, encode the VAR_GLOBAL in the function
name.

The word Expand in the function names says that the variable name is
expanded. In most of the cases, this is not necessary, but there are no
corresponding functions Global_Set or Global_Append yet.

Encoding the information whether the name is expanded or not in the
function name will make inconsistencies obvious in future manual code
reviews. Letting the compiler check this by using different types for
unexpanded and expanded variable names is probably not worth the effort.
There are still a few bugs to be fixed, such as in SetVar, which expands
the variable name twice in a row.
 1.412 01-Feb-2021  rillig make: indent preprocessor directives consistently

As seen in share/misc/style.
 1.411 01-Feb-2021  rillig make: always use vfork, never fork

Before compat.c 1.217, job.c 1.390 and main.c 1.504 from 2020-12-27, the
exported make variables were exported from each freshly forked child
process. There was no practical difference though between exporting the
variables from the parent process or the child process since these two
processes share the same address space, except that the forked process
is very limited in what it may actually do. This limitation was
violated on a regular basis.

When an exported variable referred to a variable that used the :sh
variable modifier, this led to a fork from within vfork, which is not
allowed. Since 2020-12-27, exporting the variables is done from the
main process, which prevents this situation from ever occurring.

Since that day, there is no need anymore to distinguish between vfork
and fork, which removes any need for the macro.
 1.410 01-Feb-2021  rillig make: remove unused Lst_Destroy

The code in job.c that seemed to use it is inside an '#if 0' block.
 1.409 01-Feb-2021  rillig make: clean up Job_CatchOutput

The switch statement was unnecessarily long since every branch needed to
be terminated with a break or with a comment explaining that it didn't
fall through to the next case label.
 1.408 01-Feb-2021  rillig make: rename fd-related variables in job.c

In job.c 1.330 from 2020-11-28 I had renamed them because of naming
collisions. At at time I apparently didn't know exactly what these
variables were used for since their new names were incorrect and
misleading. Try better names this time.
 1.407 01-Feb-2021  rillig make: clean up job.c

There used to be a time when Job_Init only ran the commands of the
special .BEGIN target, but that's several years ago.

The 'becomes' for echoTmpl was confusing since it referred to a time
where echoTmpl shared the same memory location as errOn, which was
really confusing since echoTmpl, as the name says, is a printf template
while errOn is a plain string. All this confusion, just to save 4 or 8
bytes of memory, was not worth it.

Since shellArgv is only used for freeing it and no code is supposed to
ever interpret that memory, rename the variable.
 1.406 01-Feb-2021  sjg Use sig_atomic_t for caught_sigchld
 1.405 31-Jan-2021  sjg Reduce unnecessary calls to waitpid

Set a flag when we catch SIGCHLD and
don't call waitpid if it is not set.
Clear it when we call waitpid.
 1.404 30-Jan-2021  rillig make(1): clean up JobWriteShellCommands
 1.403 30-Jan-2021  rillig make(1): clean up comments in JobSaveCommands and JobStart
 1.402 29-Jan-2021  rillig make(1): explain seemingly redundant condition in jobs mode
 1.401 29-Jan-2021  rillig make(1): remove unnecessary fflush for empty shell files

If nothing is done to any file, there is no need to flush stdout. Move
the call to each of the remaining branches, except for -t mode, where
Job_Touch already takes care of everything.
 1.400 29-Jan-2021  rillig make(1): rename JobOpenTmpFile to JobWriteShellCommands

The old name didn't reflect that the function not only opens the
temporary file for writing but also actually writes the shell commands
to that file.
 1.399 29-Jan-2021  rillig make(1): do not create empty shell files in jobs mode

In a chain of dependencies such as "all: build; build: do-build", the
intermediate targets do not have any commands. In jobs mode,
nevertheless, an empty file was created and fed to the shell. This was
unnecessary. See jobs-empty-commands.mk.

The case of the special command line "...", which was suggested on
current-users, is not optimized since it doesn't occur in practice.

Suggested by Mateusz Guzik on current-users:
https://mail-index.netbsd.org/current-users/2021/01/26/msg040215.html
 1.398 19-Jan-2021  rillig make(1): remove do-not-format markers from comments

These markers had been used inconsistently. Furthermore the source code
had not been formatted automatically before 2020 at all, otherwise there
wouldn't have been any trailing whitespace left.
 1.397 10-Jan-2021  rillig make(1): make a few more bool expressions more precise

The previous version of lint(1) from a few hours ago didn't catch all
occurrences. And even the current one doesn't catch everything.
Function arguments and return types still need some work. The "return
quietly" from shouldDieQuietly still implicitly converts from int to
_Bool.

No functional change.
 1.396 10-Jan-2021  rillig make(1): consistently use boolean expressions in conditions

Most of the make code already followed the style of explicitly writing
(ptr != NULL) instead of the shorter (ptr) in conditions.

The remaining 50 instances have been found by an experimental,
unpublished check in lint(1) that treats bool expressions as
incompatible to any other scalar type, just as in Java, C#, Pascal and
several other languages.

The only unsafe operation on Boolean that is left over is (flags &
FLAG), for an enum implementing a bit set. If Boolean is an ordinary
integer type (the default), some high bits may get lost. But if Boolean
is the same as _Bool (by compiling with -DUSE_C99_BOOLEAN), C99 6.3.1.2
defines that a conversion from any scalar to the type _Bool acts as a
comparison to 0, which cannot lose any bits.
 1.395 09-Jan-2021  rillig make(1): fix lint warnings
 1.394 08-Jan-2021  sjg Ensure PrintOnError always reports 'stopped in' on first call.

We may still suppress the rest of the noise if shouldDieQuietly
says to, but the 'stopped in' output is too important to lose.
Avoid repeating it though in the same process.

For the case of aborting due to failure detected elsewhere,
exit 6 so we have a clue.

PR: 55578
Reviewed by:
 1.393 08-Jan-2021  sjg Set wantToken when none available.

PR: 53285
Reviewed by: gson
 1.392 02-Jan-2021  rillig make(1): add a few remarks to JobOutput

That function is not used in practice. Still, there are a lot of subtle
details that can get wrong in that code.
 1.391 30-Dec-2020  rillig make(1): format multi-line comments
 1.390 27-Dec-2020  rillig make(1): re-export variables from the actual make process

Since make uses vfork if available, re-exporting the variables happens
in the address space of the main process anyway, so there is no point in
mentioning anything about "our client process" anywhere.
 1.389 20-Dec-2020  rillig make(1): omit linear search for command in Compat_RunCommand
 1.388 15-Dec-2020  rillig make(1): format function definitions consistently
 1.387 13-Dec-2020  rillig make(1): add str_basename to reduce duplicate code

The function basename from POSIX has a few unfortunate properties, it is
allowed to return a pointer to static memory. This is too unreliable,
therefore this trivial own implementation.
 1.386 13-Dec-2020  rillig make(1): replace *line with line[0]

Since a line is not an iterator and since the expression *line typically
means "the current element", not "the first character", replacing *line
with line[0] more directly expresses the idea of accessing the first
character of a string.
 1.385 12-Dec-2020  rillig make(1): rename Var_ExportVars to Var_ReexportVars
 1.384 12-Dec-2020  rillig make(1): clean up comments around JobPrintSpecials
 1.383 12-Dec-2020  rillig make(1): rename ParseRunOptions to ParseCommandFlags
 1.382 12-Dec-2020  rillig make(1): extract ShellWriter_ErrOn from JobPrintCommand

It had been conceptually wrong to modify cmdFlags.echo just to suppress
echoing while enabling error checking.

Now the code in JobPrintCommand speaks for itself and no longer needs
any comments. The few lines at the end have the sole purpose of
restoring the default state (echo + errChk) in the shell file.
 1.381 12-Dec-2020  rillig make(1): fix typo in comment of JobPrintCommand
 1.380 12-Dec-2020  rillig make(1): make Job_Touch simpler
 1.379 12-Dec-2020  rillig make(1): split JobFinishDone into smaller functions
 1.378 12-Dec-2020  rillig make(1): extract JobFinishDone from JobFinish
 1.377 12-Dec-2020  rillig make(1): clean up comments in JobFinish
 1.376 12-Dec-2020  rillig make(1): inline ShellWriter_PrintCmd

The parameter name escCmd was wrong for the call in JobPrintCommand.
 1.375 12-Dec-2020  rillig make(1): rename Shell.exitFlag to errFlag

Now its name matches the user-visible .SHELL parameter again, reducing a
tiny bit of that mapping chaos.
 1.374 12-Dec-2020  rillig make(1): move Job.xtraced to ShellWriter

This flag was placed wrong in the Job since it is only necessary as long
as the shell commands are written to the shell file.

Resetting it in JobStart and JobExec was completely misguided since that
is far away from writing the shell commands; this should have been done
in JobPrintCommands instead.

The status of this flag doesn't need to be printed in debugging mode
since it is controlled by a single command line option (-dx) and does
not interact with all the other switches.
 1.373 12-Dec-2020  rillig make(1): in jobs mode, extract echo control into separate functions

This removes the clutter from the code that calls these functions. That
code is still complicated enough since it modifies variables it
shouldn't.
 1.372 12-Dec-2020  rillig make(1): make printing of shell commands independent from the job
 1.371 12-Dec-2020  rillig make(1): in jobs mode, extract writing of shell commands

Right now, the test sh-flags.mk demonstrates many variants to configure
echoing of the shell commands (-s, .SILENT, '@'), error handling (-i,
.IGNORE, '-') and whether the commands are run (-n, -N, .MAKE,
.RECURSIVE, '+').

Even more variants are possible by configuring the shell to have error
control. None of the built-in shell definitions has error control, so
it is unlikely that anybody uses them, but who knows.

Being able to configure these details at 3 levels is good, but what
makes all this really hard to understand is that some of these switches
interact in non-obvious ways. For example, in jobs mode, a single
command can change job->ignerr (in JobPrintSpecialsEchoCtl), which will
affect all further commands of that job.

The goal of this refactoring is to make the code easier to understand by
making the switches on the job level constant and by moving all
modifications to them to the ShellWriter.
 1.370 12-Dec-2020  rillig make(1): remove const from function parameters

These have been left-overs from refactoring, when these pieces were
extracted to separate functions.
 1.369 12-Dec-2020  rillig make(1): inline Targ_Ignore and Targ_Silent

Each of these functions was only used 2 times, and each of these calls
used a different part of the whole expression.
 1.368 11-Dec-2020  rillig make(1): mark strange code that calls exit(signo)

In other places, the exit status of make is carefully chosen to be 0
(success), 1 (did not make everything), 2 (other error). Using a signal
number is not guaranteed to be consistent among operating systems and is
therefore a weird choice.
 1.367 11-Dec-2020  rillig make(1): document why runIgnImpl is used in jobs mode
 1.366 11-Dec-2020  rillig make(1): rename shell flags in struct Shell

The previous name 'echo' was too unspecific, given that the other fields
in the same struct are called echoOff, echoOn, echoTmpl.
 1.365 11-Dec-2020  rillig make(1): clean up comments for struct Shell
 1.364 10-Dec-2020  rillig make(1): name Shell fields consistently

They are all templates with a single %s placeholder, so embed this
unambiguously in the variable name. The previous variable names didn't
provide any clue that echoCmd, execIgnore and errExit had a lot in
common.
 1.363 10-Dec-2020  rillig make(1): clean up JobPrintCommand

The local variable 'cmd' had been used for both the unexpanded and the
expanded command. This in turn had required the parameter to be
non-const.
 1.362 10-Dec-2020  rillig make(1): eliminate global variable numCommands

It had only been used in a very small scope. The elimination of
Lst_ForEach made it easy to turn this global variable into a local
variable.
 1.361 10-Dec-2020  rillig make(1): extract JobOpenTmpFile from JobStart
 1.360 10-Dec-2020  rillig make(1): rename RunFlags to CommandFlags

Flags of similar names are also available in CmdOpts (global command
line options) and Job. The new name CommandFlags emphasizes that these
flags apply to the smallest scope possible, which is a single command,
as opposed to the whole GNode/Job.
 1.359 10-Dec-2020  rillig make(1): split Job.errOffOrExecIgnore into separate fields

Like errOnOrEcho, these two fields were completely unrelated. One of
them expected a %s placeholder, the other didn't.
 1.358 10-Dec-2020  rillig make(1): split Job.errOnOrEcho into separate fields

They have never been related. Furthermore, Job.errOn is really tricky
to reach at all. To do that, one has to define a custom shell and set
hasErrCtl=true. The manual page has an example for that, but it's
probably not use in practice, just like the possibility to use the C
shell for all commands.
 1.357 10-Dec-2020  rillig make(1): negate Job.silent to echo

This gets rid of a few explicit negations and an implicit negation in
the variable name.
 1.356 10-Dec-2020  rillig make(1): unpack struct JobFlags

The job flags are only used individually.
 1.355 10-Dec-2020  rillig make(1): rename commandShell to shell

The word 'command' was not necessary for understanding the variable.
 1.354 10-Dec-2020  rillig make(1): split JobFlags into separate fields

Having all these flags in a single bitmask makes it harder to see where
exactly they can possibly be used since their state could also be
modified using the unsuspicious job->flags = 0. Using individual names
just leaves the single memset, and that is only used during
initialization.
 1.353 10-Dec-2020  rillig make(1): in JobStart, negate 'noExec' to 'run'
 1.352 10-Dec-2020  rillig make(1): fix theoretical type mismatch for Job_Touch
 1.351 08-Dec-2020  rillig make(1): in jobs mode, invert local variable noSpecials to run
 1.350 08-Dec-2020  rillig make(1): negate RunFlags.silent to become RunFlags.echo

This reduces the number of negations in the code.
 1.349 08-Dec-2020  rillig make(1): move flags errOff into RunFlags.ignerr
 1.348 08-Dec-2020  rillig make(1): move flag runAlways into RunFlags
 1.347 08-Dec-2020  rillig make(1): move flag shutUp into struct RunFlags

Running a command is controlled by several flags. Instead of passing
them around individually, it's easier to have them grouped.
 1.346 08-Dec-2020  rillig make(1): split JobPrintSpecials into manageable pieces
 1.345 08-Dec-2020  rillig make(1): extract JobPrintSpecials from JobPrintCommand
 1.344 08-Dec-2020  rillig make(1): extract InitShellNameAndPath from Shell_Init

This gets rid of the ugly "else #endif".
 1.343 07-Dec-2020  rillig make(1): clean up debug logging
 1.342 07-Dec-2020  rillig make(1): replace signal handling macros with local functions
 1.341 07-Dec-2020  rillig make(1): indent job.c with tabs instead of spaces
 1.340 07-Dec-2020  rillig make(1): remove duplicate code for job output
 1.339 07-Dec-2020  rillig make(1): replace macro MESSAGE with local function

The first parameter of the macro was always stdout, and there was no
apparent reason to pass anything else there.

Let the compiler decide whether to inline this or not, it's not
time-critical.
 1.338 06-Dec-2020  rillig make(1): remove comment decoration
 1.337 05-Dec-2020  rillig make(1): remove redundant assignments
 1.336 05-Dec-2020  rillig make(1): remove unused parameter from JobOutput
 1.335 04-Dec-2020  rillig make(1): use consistent variable names for list nodes
 1.334 29-Nov-2020  rillig make(1): use space instead of tab for preprocessor directives
 1.333 28-Nov-2020  rillig make(1): reduce memory allocation for GNode.parents and GNode.children
 1.332 28-Nov-2020  rillig make(1): remove pointer indirection from GNode.commands

Just to save a few memory allocations. No noticeable effect on the
performance though.
 1.331 28-Nov-2020  rillig make(1): rename conflicting global variables called 'error'

When compiling make in all-in-one mode, these variable names conflict.
They could have been merged into a single variable, but that would have
required to make it a global variable for the other modules as well.
The parse module has a similar variable called 'fatals'. All these can
possibly be merged into a single variable, but not now.
 1.330 28-Nov-2020  rillig make(1): rename global variables in job.c

When compiling make in all-in-one mode, the variable name nfds conflicts
with the local variable name nfds in meta_compat_parent.

The variable name jobfds was misleading. It has nothing to do with file
descriptors, it's just an array of jobs.
 1.329 24-Nov-2020  rillig make(1): fix error handling for dependency of .END in -k mode

Fix one bug, find 4 new ones. All these bugs have been around since
2005-05-08, when dependencies on the .BEGIN, .END and .INTERRUPT nodes
were implemented. Before that, checking gn->made == ERROR was
appropriate, but adding the dependencies made ABORTED a new possible
error value from Compat_Make.
 1.328 23-Nov-2020  rillig make(1): use comparisons in boolean expressions

The generated code stays exactly the same.
 1.327 23-Nov-2020  rillig make(1): align end-of-line comments with tabs
 1.326 16-Nov-2020  rillig make(1): use postfix increment where possible
 1.325 14-Nov-2020  rillig make(1): clean up JobExec, JobStart, JobDoOutput

The comments about temporary files for shell output are no longer
relevant since the output is always handled via pipes.
 1.324 14-Nov-2020  rillig make(1): remove indentation in JobOutput
 1.323 14-Nov-2020  rillig make(1): rename DEFAULT to defaultNode

In C, uppercase names are typically used for constants, and this is not
a constant.
 1.322 14-Nov-2020  rillig make(1): use stderr for error message about failed touch

Error messages belong on stderr, not stdout. Since at least 1993,
stdout had been used for no good reason. Plus, in all these years,
nobody ever tested this code path since otherwise the missing newline at
the end of the error message would have been obvious.

This is a good candidate for the "oldest bug in make" trophy.
 1.321 14-Nov-2020  rillig make(1): clean up Job_Touch

Several more outdated comments were removed. To compensate for that,
several new comments mark places where errors are not properly
propagated.
 1.320 14-Nov-2020  rillig make(1): rename JobClose to JobClosePipes, remove confusing comments

The comments referred to w_status, which had been there in 1993, but not
anymore. Several other details were outdated as well.
 1.319 14-Nov-2020  rillig make(1): fix grammar: setup -> set up
 1.318 14-Nov-2020  rillig make(1): replace macro DBPRINTF with JobPrintln

This macro had been bad in several ways. Its name started with DB, an
unnecessary abbreviation for DEBUG. Many places that used this macro
used it with the same format string, "%s\n". This format string can
better be expressed in a function name, JobPrintln.

Only in a few places was the macro used with different format strings.
The one for "set -x" was even forced to arbitrarily separate the
argument from the format string in order to match the expected macro
parameters.

A better choice would have been to use the standard form "%s\n", "set
-x" from the beginning. Anyway, that call is calling JobPrintln as well
now.

The remaining templates are user-specified, and if anyone should ever
define a completely custom shell with echo handling and error handling
enabled, they will easily crash make when the templates don't contain
exactly one %s conversion. That's the responsibility of the user, and
it has always been.
 1.317 14-Nov-2020  rillig make(1): rename JobState to JobStatus

The status is only part of the whole state of a job.
 1.316 08-Nov-2020  rillig make(1): use strict typing in conditions of the form !var
 1.315 08-Nov-2020  rillig make(1): change return type of Dir_MTime to void

Only some callers actually needed the updated time, and because of the
many branches, it was difficult to see that the return value was indeed
gn->mtime all the time.
 1.314 08-Nov-2020  rillig make(1): remove unused JOB_IGNDOTS

It had been used in 1993 at least, don't know when it was finally
removed.
 1.313 08-Nov-2020  rillig make(1): format source code in JobStart and JobDoOutput
 1.312 08-Nov-2020  rillig make(1): fix indentation in JobExec
 1.311 08-Nov-2020  rillig make(1): clean up debug output for running jobs

There is no remote anymore, therefore mentioning locally is redundant.
It was a bad idea anyway to build format strings that work with parts of
words.
 1.310 07-Nov-2020  rillig make(1): fix type of Job.suspended
 1.309 07-Nov-2020  rillig make(1): clean up JobStart

Initialize the fields in declaration order.
Initialize Job.flags in a single assignment.
 1.308 07-Nov-2020  rillig make(1): fix indentation in JobPrintCommand
 1.307 07-Nov-2020  rillig make(1): add pp_skip_hspace to skip horizontal whitespace during parsing
 1.306 07-Nov-2020  rillig make(1): clean up code stylistically

* Replace character literal 0 with '\0'.
* Replace pointer literal 0 with NULL.
* Remove redundant parentheses.
* Parentheses in multi-line conditions are not redundant at the
beginning of a line.
* Replace a few !ptr with ptr == NULL.
* Replace a few ptr with ptr != NULL.
* Replace (expr & mask) == 0 with !(expr & mask).
* Remove redundant braces for blocks in cases where the generated code
stays the same. (Assertions further down in the code would get
different line numbers.)
* Rename parameters in CondParser_String to reflect the data flow.
* Replace #ifdef notdef with #if 0.

The generated code stays exactly the same, at least with GCC 5.5.0 on
NetBSD 8.0 amd64 using the default configuration.
 1.305 07-Nov-2020  rillig make(1): rename Var_Set_with_flags to Var_SetWithFlags

Now that the function is exported from the var module, it should stick
to the naming conventions for public functions.
 1.304 06-Nov-2020  rillig make(1): rename dieQuietly to shouldDieQuietly

It was too confusing to have a function named die that doesn't actually
die. Plus, the return type int didn't give any clue about what the
function actually returns.
 1.303 05-Nov-2020  rillig make(1): remove redundant parentheses from sizeof operator

The parentheses are only needed if the argument is a type, not an
expression.
 1.302 01-Nov-2020  rillig make(1): fix indentation of source code
 1.301 01-Nov-2020  rillig make(1): rename JobMatchShell to FindShellByName

The word 'match' was too unspecific.
 1.300 01-Nov-2020  rillig make(1): negate NoExecute to GNode_ShouldExecute
 1.299 01-Nov-2020  rillig make(1): extract EscapeShellDblQuot from JobPrintCommand
 1.298 01-Nov-2020  rillig make(1): extract ParseRunOptions from JobPrintCommand
 1.297 31-Oct-2020  rillig make(1): do not look up local variables like .TARGET anywhere else

Nobody defines a global variable named .TARGET since that would have
many unpredictable effects, applying to all targets at once.

Nobody defines an environment variable named .TARGET since that's
against the naming conventions for environment variables and would have
the same effect.

Because of this, there is no point looking up the variables that are
local to a GNode anywhere else. This means they cannot come from the
environment and thus their value doesn't need to be freed after use,
which makes the code simpler.

The newly added accessor functions in make.h refer to external
functions, but since that header is not used anywhere outside of
usr.bin/make, it doesn't matter. Between 2020-08-25 and 2020-10-30,
that header had been referenced by usr.bin/xinstall.
 1.296 30-Oct-2020  rillig make(1): change char * to void * in Var_Value

The only purpose of the parameter freeIt is to free the memory
associated with the return value. To do this, no pointer arithmetic is
needed. Therefore, change to a void pointer, to catch accidental use of
that pointer.
 1.295 30-Oct-2020  rillig make(1): fix indentation in source code
 1.294 30-Oct-2020  rillig make(1): rename VAR_CMD to VAR_CMDLINE

Since make has to do with both the command line and child commands, the
former name was confusing.
 1.293 26-Oct-2020  rillig make(1): remove "Results: none" from the documentation of void functions
 1.292 26-Oct-2020  rillig make(1): use proper enum constants for aborting, instead of 0
 1.291 26-Oct-2020  rillig make(1): remove unnecessary double negation in Job_ParseShell
 1.290 26-Oct-2020  rillig make(1): group the command line options and arguments

By having a single struct that holds all command line options and
arguments, it is easy to see in the code when such a command line
argument is modified. It also cleans up the namespace since the command
line options don't follow a common naming style. Having them in a
struct also means that there is a single place for putting the
documentation, not two as before.

The struct also suggests to extract the initialization code out of main,
which is still too large, having more than 400 lines of code and
covering far too many topics.
 1.289 26-Oct-2020  rillig make(1): fix comments in job.c
 1.288 25-Oct-2020  rillig make(1): fix typos in job.c comments
 1.287 25-Oct-2020  rillig make(1): add GNode_Path to access the path of a GNode
 1.286 25-Oct-2020  rillig make(1): refactor JobDeleteTarget

Splitting the many conditions into separate pieces makes the code more
understandable.
 1.285 25-Oct-2020  rillig make(1): inline macro STATIC

It was a leftover from the remote code, which was removed on 2006-03-11.
 1.284 25-Oct-2020  rillig make(1): convert result of JobStart from macros to enum

Right now the result is not used by any code.
 1.283 25-Oct-2020  rillig make(1): convert abort reason macros to enum
 1.282 25-Oct-2020  rillig make(1): invert condition in Job_CheckCommands, reduce indentation
 1.281 25-Oct-2020  rillig make(1): reduce indentation in Job_CheckCommands
 1.280 25-Oct-2020  rillig make(1): split and invert complex condition in Job_CheckCommands
 1.279 25-Oct-2020  rillig make(1): inline error message

This saves a variable, and since bmake needs to adhere to C90, this
variable declaration prevents refactoring the code.
 1.278 25-Oct-2020  rillig make(1): clean up API comment in job.c
 1.277 23-Oct-2020  rillig make(1): negate OP_NOP and rename it to GNode_IsTarget
 1.276 23-Oct-2020  rillig make(1): rename Shell fields

Some of them should have been in an anonymous union, or should just kept
as separate fields. There is only a small, fixed number of shells,
therefore it doesn't make sense to squeeze two completely separate
meanings into a single field just because that field happens to have a
fitting data type.
 1.275 23-Oct-2020  rillig make(1): describe the Shell fields by topic

Describing each field in isolation does not help to understand how these
fields work together.
 1.274 23-Oct-2020  rillig make(1): add field names in declaration of DEFSHELL_CUSTOM
 1.273 23-Oct-2020  rillig make(1): remove unused null shell
 1.272 23-Oct-2020  rillig make(1): decorate shell declarations with field names

Without these names, the declarations were hard to read, even though
they were already grouped into lines. This grouping was inconsistent
though and the many string literals were hard to tell apart.
 1.271 23-Oct-2020  rillig make(1): convert JobState and JobFlags to enum types

Both GCC and Clang complained when JobFindPid had its parameter "status"
as an int. Strangely both compilers complained about a comparison
between unsigned and signed int, even though enums are defined to be
int, not unsigned.
 1.270 23-Oct-2020  rillig make(1): move handling of the "..." command to JobPrintCommands

Over there, the current list node is known and thus doesn't need to be
searched again.
 1.269 23-Oct-2020  rillig make(1): remove void pointers from JobPrintCommand
 1.268 22-Oct-2020  rillig make(1): remove redundant type casts

This mainly affects the void pointers in callback functions for lists.
These had been necessary once when the parameter type was still
ClientData instead of void pointer.
 1.267 19-Oct-2020  rillig make(1): clean up headers, no functional change
 1.266 19-Oct-2020  rillig make(1): move struct Shell from job.h to job.c

This type is only needed in job.c.
 1.265 18-Oct-2020  rillig make(1): rename Lst_Init to Lst_New

For the other types such as HashTable and Buffer, the Init function does
not allocate the memory for the structure itself, it only fills it.
 1.264 18-Oct-2020  rillig make(1): replace execError with execDie

All calls to this function were followed by _exit(1).
 1.263 17-Oct-2020  rillig make(1): normalize initialization and cleanup of the modules
 1.262 06-Oct-2020  rillig make(1): remove macro FILENO

This macro was obviously wrong since it would have converted file
numbers above 127 to very large numbers, close to 2^32.

The fact that it didn't blow up at all is that this macro was only ever
given the file descriptor 4 as an argument, which can well be
represented as a char, be it signed or unsigned. And this is how the
story goes:

In Job_Init, two jobs are started. The server job allocates file
descriptors 15 and above. The childExitJob is created next, and the
pipe that it creates is [3, 4]. Using F_DUPFD, fd 3 is mapped to fd 5,
and fd 3 is closed. After that, fd 4 is mapped to fd 3 (which had just
been closed), and fd 4 is closed.

After this initialization, file descriptors 0, 1, 2, 3 and 5 are taken.
This leaves a gap at file descriptor 4, and this gap is filled whenever
cmdFILE is created.

Because of this particular order of events, the macro is not necessary.
If it should ever become necessary on platforms like the old SunOS, the
parameter minfd for JobCreatePipe should be increased to 5, which would
leave the file descriptors 3 and 4 to be used by stdio streams.

On 1995-11-03, when the macro was added, SunOS must have been in its
very early development. In Solaris 8 (released in January 2000),
FILE._file is already an unsigned char, therefore the seeming need for
this macro must have been due to an older version, probably from the 2.x
series of SunOS.
 1.261 05-Oct-2020  rillig make(1): prepare job.c, main.c, parse.c, suff.c for WARNS=6

In job.c, GCC 5 complains about the macro FILENO that it has type
unsigned int, which is then passed as the argument of dup2, which
expects a simple int. Maybe this workaround from 1995 is not necessary
anymore, or maybe it is but can be restricted to the few affected
platforms.

This leaves meta.c and the filemon files to be converted. I didn't do
them since they are not well covered by the unit tests.
 1.260 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.259 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.258 04-Oct-2020  rillig make(1): remove dead code from JobOutput
 1.257 03-Oct-2020  rillig make(1): use consistent pattern for parsing whitespace

The pp and cpp in the function names stand for "parsing position" and
"const parsing position".
 1.256 03-Oct-2020  rillig make(1): fix shell definition for csh

The bug has been there since at least 1993-03-21. This is strong
evidence that nobody has ever used the csh in parallel mode.
 1.255 03-Oct-2020  rillig make(1): inline Str_FindSubstring in JobOutput
 1.254 01-Oct-2020  rillig make(1): remove redundant function prototypes
 1.253 28-Sep-2020  rillig make(1): replace Lst_Open with direct iteration
 1.252 28-Sep-2020  rillig make(1): replace += 1 with ++ and -= 1 with --

Just for visual consistency. The generated code stays exactly the same.
 1.251 28-Sep-2020  rillig make(1): make debug logging simpler

This avoids referring to the debug_file variable in many places where
this implementation detail is not necessary.
 1.250 28-Sep-2020  rillig make(1): make debugging code shorter
 1.249 28-Sep-2020  rillig make(1): split Job.jobPipe into 2 separate fields

Just because these file descriptors have to be in an array when they are
created is not reason enough to keep this array and a few access macros
in the Job struct. It's better to have separate fields, as they can be
documented independently.
 1.248 27-Sep-2020  rillig make(1): in JobCreatePipe, use descriptive field names
 1.247 27-Sep-2020  rillig make(1): fix indentation in JobCreatePipe
 1.246 27-Sep-2020  rillig make(1): normalize whitespace in source code

There is no more space tab. Either only tabs or only spaces or tabs
followed by spaces, but not spaces followed by tabs.
 1.245 27-Sep-2020  rillig make(1): reduce line noise in Job_ParseShell

The generated code is exactly the same.
 1.244 27-Sep-2020  rillig make(1): fix indentation in Job_ParseShell
 1.243 27-Sep-2020  rillig make(1): clean up comments in job.c and make.c
 1.242 26-Sep-2020  rillig make(1): revert migration from Lst_ForEachUntil to Lst_ForEach

There is a crucial difference between these functions, in that
Lst_ForEachUntil can cope with a few concurrent modifications while
iterating over the list. This is something that Lst_ForEach doesn't do.

This difference led to a crash very early in NetBSD's build.sh.
 1.241 26-Sep-2020  rillig make(1): inline and remove LstNode_Prev and LstNode_Next

These functions made the code larger than necessary. The prev and next
fields are published intentionally since navigating in a doubly-linked
list is simple to do and there is no need to wrap this in a layer of
function calls, not even syntactically. (On the execution level, the
function calls had been inlined anyway.)
 1.240 26-Sep-2020  rillig make(1): replace a few Lst_ForEachUntil with simpler Lst_ForEach
 1.239 26-Sep-2020  rillig make(1): clean up API for finding and creating GNodes

The previous API had complicated rules for the cases in which the single
function returned NULL or what it did. The flags for that function were
confusing since passing TARG_NOHASH would create a new node even though
TARG_CREATE was not included in that bit mask.

Splitting the function into 3 separate functions avoids this confusion.
It also reveals several places where the complicated API led to
unreachable code. Such code has been removed.
 1.238 25-Sep-2020  rillig make(1): document details on why JobRun runs .END in compat mode
 1.237 24-Sep-2020  rillig make(1): rename Lst_ForEach to Lst_ForEachUntil

Since the callback function returns a terminating condition, this is not
really a foreach loop.

Many of the calls to Lst_ForEachUntil don't make use of the terminating
condition, and several don't modify the list structurally, which means
they don't need this complicated implementation.

In a follow-up commit, Lst_ForEach will be added back with a much
simpler implementation that iterates over the list naively, without a
terminating condition and without taking the iteration state from
Lst_Open/Lst_Next/Lst_Close into account. The migration to this simpler
implementation will be done step by step since each callback function
needs to be examined closely.
 1.236 23-Sep-2020  rillig make(1): merge duplicate code for delayed commands
 1.235 23-Sep-2020  rillig make(1): fix assertion failure in -j mode with .END node

There had been two separate global variables for the .END node, and in
parallel mode, only the one in jobs.c was initialized.

The code in JobRun heads over to Compat_Make without calling Compat_Run
first, which left the variable ENDNode uninitialized.
 1.234 22-Sep-2020  rillig make(1): prepare Var_Subst for proper error handling

Returning a VarParseResult instead of a string makes it possible to let
the error bubble up, until it reaches the main expression.
 1.233 21-Sep-2020  rillig make(1): add specific typedefs for lists

These typedefs are only intended to help human readers, they do not
provide any type-safety. They also make the pointers explicit, which
had been hidden before by the typedef for Lst and LstNode. Typing a few
'*' is less work than finding out which of the many types are pointers
and which aren't.

In meta.c, the variable "ln" served two completely different purposes,
which have been split again. Register allocation is the job of the
compiler, not of the human source code reader.
 1.232 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.231 12-Sep-2020  rillig make(1): fix name and prototype of Compat_RunCommand

By convention, exported identifiers are written with underscore.

The prototype of an exported function must not use void * just because
it is used in Lst_ForEach. This is an implementation detail and must
remain so.
 1.230 11-Sep-2020  rillig make(1): add wrappers around ctype.h functions

This avoids casting the argument to unsigned char, and to cast the
result of toupper/tolower back to char.
 1.229 11-Sep-2020  rillig make(1): replace *a->b with a->b[0]

This allows the code to be read strictly from left to right. In most
places this style was already used.
 1.228 07-Sep-2020  rillig make(1): clean up comments in job.c
 1.227 30-Aug-2020  rillig make(1): replace brk_string with Str_Words

The API is much simpler, and there is less detail that is exposed by
default and fewer punctuation to type on the caller's side. To see that
there is some memory to be freed, one would have to look into the
struct. Having part of the return value as the actual return value and
the rest in output parameters was unnecessarily asymmetrical.
 1.226 30-Aug-2020  rillig make(1): remove ineffective malloc_options variable

According to jemalloc(3), the variable must be called _malloc_options,
with a leading underscore, to have an effect.

Renaming the variable indeed enables the option. There's not much point
having this variable around though, since it neither detects a trivial
double-free nor freeing an invalid pointer in the following code
snippet:

char *asdf = bmake_malloc(10);
fprintf(stderr, "%c\n", *asdf);
free(asdf + 8);
free(asdf);
free(asdf);
exit(1);

Instead, it just crashes with a segmentation fault.
 1.225 30-Aug-2020  rillig make(1): rename Lst_Memeber to Lst_FindDatum

The new name nicely aligns with Lst_Find and Lst_FindFrom.
 1.224 29-Aug-2020  rillig make(1): remove ReturnStatus, SUCCESS and FAILURE

These are used in so few places now that it is easier to use a simple
Boolean for them.
 1.223 29-Aug-2020  rillig make(1): rename LstNode functions to match their type
 1.222 29-Aug-2020  rillig make(1): clean up indentation, comments and variable scope in job.c
 1.221 28-Aug-2020  rillig make(1): remove unused variable not_parallel

The variable malloc_options seems unused as well, but the manual page
for jemalloc(3) mentions it.
 1.220 28-Aug-2020  rillig make(1): remove trailing 'S' from names of Lst functions

The migration from null-passing Lst functions to argument-checking Lst
functions is completed.

There were 2 surprises: The targets list may be NULL, and in Dir_AddDir,
the path may be NULL. The latter case is especially surprising since
that function turns into an almost-nop in that case. This is another
case where probably 2 independent functions have been squeezed into a
single function. This may be improved in a follow-up commit.

All other lists were fine. They were always defined and thus didn't
need much work.
 1.219 27-Aug-2020  rillig make(1): migrate Lst_IsEmpty to Lst_IsEmptyS
 1.218 27-Aug-2020  rillig make(1): migrate Lst_Succ to Lst_SuccS
 1.217 27-Aug-2020  rillig make(1): migrate Lst_ForEach to Lst_ForEachS

Most lists are always valid. Only the "targets" variable may be null in
some cases, probably.
 1.216 27-Aug-2020  rillig make(1): migrate Lst_ForEachFrom to Lst_ForEachFromS
 1.215 23-Aug-2020  rillig make(1): make brk_string return size_t for the number of words
 1.214 22-Aug-2020  rillig make(1): clean up headers

Remove redundant headers that are already included by "make.h".
Make <assert.h> available to all compilation units that use "make.h".
 1.213 22-Aug-2020  sjg Add .SHELL as read-only variable

The .SHELL variable represents the shellPath used to run
scripts.

Reviewed by: rillig, christos
 1.212 22-Aug-2020  rillig make(1): require argument of Lst_Member to be non-null

Since the lists don't contain null pointers, it doesn't make sense to
search for a null pointer. All calls but one already had obviously
non-null arguments. The one remaining call using targ->suff has been
guarded for now.

The code for Lst_Member became much simpler than before. Partly because
the old code had an extra condition for circular lists, which are not
used by make.
 1.211 22-Aug-2020  rillig make(1): convert remaining Lst_AtEnd to the stricter Lst_Append

The general-purpose list library that is included in make allows to call
Lst_AtEnd for invalid lists, silently ignoring this programming error.
This is a flexibility that make doesn't need.

Another unneeded "feature" is that list items can theoretically be null
pointers. This doesn't make sense as well and is therefore not needed
by make.

These programming errors are now caught early by assertions.
 1.210 22-Aug-2020  rillig make(1): replace "(void)Lst_AtEnd" with stricter "Lst_AppendS"

This change ensures that there is actually something added to the list.
Lst_AtEnd had silently skipped the addition if the list was invalid
(null pointer), which was not intended in these cases. The "(void)" is
assumed to mean "I know that this cannot fail", while it could also mean
"I don't care whether something actually happened".

Running "./build.sh -j6 tools" still succeeds after this change,
therefore chances are very low that this change breaks anything. If
there is any change, it's an obvious assertion failure. There is no
silent change in behavior though.
 1.209 22-Aug-2020  rillig make(1): fix constness of shellArgv

This is needed to build with -DCLEANUP, which apparently nobody did for
the last 17 years, or at least since -Werror was introduced.
 1.208 22-Aug-2020  rillig make(1): remove form feeds in the code
 1.207 21-Aug-2020  rillig make(1): remove unused code for circular lists

The list library had probably been imported from a general-purpose
library that also supported circular lists. These are not used by make
though.

After replacing Lst_Init(FALSE) with Lst_Init(), only a single call to
Lst_Init remained with a non-constant argument, and that was in
Lst_Concat, which was to be expected.
 1.206 10-Aug-2020  rillig make(1): replace str_concat with str_concat2 and str_concat3

The new functions have a simpler interface, and str_concat3 is even more
general-purpose, since the middle string is no longer required to be
exactly of length 1.
 1.205 01-Aug-2020  rillig make(1): use consistent indentation in source code

Tabs for multiples of 8, then spaces.

The usage string has been kept as-is since the spaces there are
indentional and do influence the output.
 1.204 01-Aug-2020  rillig make(1): avoid calls to free(3) in the common case of a NULL pointer
 1.203 28-Jul-2020  rillig make(1): remove dead code from Var_Subst

The first parameter from Var_Subst had been a literal NULL in all cases.
These have been fixed using this command:

sed -i 's|Var_Subst(NULL, |Var_Subst(|' *.c

The one remaining case was not found because the "NULL," was followed by
a line break instead of a space.

The removed code probably wouldn't have worked as expected anyway.
Expanding a single variable to a literal string would have led to
unexpected behavior for cases like ${VAR:M${pattern}}, in case pattern
would contain an unescaped ':' itself.
 1.202 19-Jul-2020  rillig make(1): rename Varf_Flags to VarEvalFlags

In var.c there are lots of different flag types. To make any accidental
mixture obvious, each flag group gets its own prefix.

The only flag group that is visible outside of var.c is concerned with
evaluating variables, therefore the "e", which replaces the former "f"
that probably just meant "flag".
 1.201 03-Jul-2020  rillig make(1): remove trailing whitespace
 1.200 03-Jul-2020  rillig make(1): remove redundant parentheses around return values
 1.199 02-Jul-2020  rillig make(1): remove useless parameter from Var_Set

The enum corresponding to this int parameter is only defined in var.c,
which makes it impractical for the outside to set this parameter to
anything but 0.

On x86_64, this reduces the size of the resulting executable by 5 kB.
 1.198 19-Jun-2020  sjg Avoid unnecessary noise when sub-make or sibling dies

When analyzing a build log, the first 'stopped' output
from make, is the end of interesting output.

Normally when a build fails deep down in a parallel build
the log ends with many blockes of error output from make,
with all but the fist being unhelpful.

We add a function dieQuietly() which will return true
if we should supress the error output from make.
If the failing node was a sub-make, we want to die quietly.

Also when we read an abort token we call dieQuietly telling we
want to die quietly.

This behavior is suppressed by -dj or
setting .MAKE.DIE_QUIETLY=no

Reviewed by: christos
 1.197 06-Feb-2020  sjg Fix meta_compat mode.

We need to call meta_job_output() from meta_compat_parent()
Also, the need for extra fds for meta mode only applies when
using filemon_ktrace.c.
Since we hope to see more interfaces like that, test for
USE_FILEMON_DEV being not defined.

Reviewed by: riastradh
 1.196 19-Jan-2020  riastradh Reimplement make(1) meta mode without filemon(4).
 1.195 13-May-2018  sjg branches: 1.195.2;
Just skip polling job token pipe.

The sigchld pipe ensures no busy wait.

PR: 53285
Reviewed by:
 1.194 13-May-2018  christos PR/53285: Andreas Gustafsson: Build times tripled with make/job.c 1.193
Revert previous:
2018.05.12.15.14.49/bracket.db:build_wall_time=4896.09
2018.05.12.18.17.04/bracket.db:build_wall_time=16268.98
 1.193 12-May-2018  sjg Skip setting wantToken.

polling the job token pipe adds a lot of overhead
for little gain.
For now, just leave wantToken=0

And avoid busy waiting when no tokens are available and
no jobs are running.

Reviewed by: christos
 1.192 08-Feb-2018  dholland branches: 1.192.2;
Typos.
 1.191 20-Jul-2017  sjg Make compat.c handle SIGINT etc more like job.c

If there is a running child, pass the signal on, and
wait for it to exit before we self-terminate.

Reviewed by: christos
 1.190 16-Apr-2017  riastradh Plug memory leak in JobPrintCommand.

CID 978366
 1.189 16-Apr-2017  riastradh Check fcntl return values out of paranoia.

CID 975277
CID 975278
 1.188 26-Aug-2016  dholland branches: 1.188.2;
Add a .DELETE_ON_ERROR: magic target that causes *failed* targets as
well as *interrupted* targets to be deleted. The name and behavior of
the variable matches gmake.

Also fix a glitch in newline output on error in compat mode that I
discovered while doing it.

Closes PR 51376.
 1.187 12-May-2016  sjg branches: 1.187.2;
Propagate errors from filemon.

If we encounter errors producing a .meta file,
we should not consider the target completed successfully.
 1.186 18-Feb-2016  christos Collapse the 3 boolean parameter to 1 flags parameter. No functional change.
 1.185 17-Jan-2016  christos remove free NULL checks (Tilman Sauerbeck)
 1.184 17-Jan-2016  christos provide missing FD_CLOEXEC for the havenots.
 1.183 17-Jan-2016  christos Use FD_CLOEXEC (Tilman Sauerbeck)
 1.182 09-Jan-2016  christos Preserve $$ in := assignments..

FOO=\$$CRAP
BAR:=${FOO}

all:
echo ${FOO}
echo ${BAR}
 1.181 11-Oct-2015  sjg Add Boolean wantit to Var_Parse and Var_Subst

wantit will be FALSE when we are just consuming to discard
in which case we skip "expensive" things like Cmd_Exec.

Reviewed by: christos
 1.180 16-Apr-2015  joerg Explain what max is and handle i reaching it again.
 1.179 16-Apr-2015  joerg Don't use memcpy for overlapping ranges. Simplify, memmove is good
enough to skip empty ranges.
 1.178 09-Apr-2015  sjg jobs mode handles '-' very differently to compat mode, but this is not
reflected in make.1
Also fix handling to match the behavior described in the comment
of JobPrintCommand (only matters if shell sets hasErrCtl).

A better long term solution is needed since the current behavior
is sub-optimal wrt '-' and different from all other makes.

Reviewed by: christos
 1.177 16-Jul-2014  christos PR/48367: David A. Holland: Mark possible submake nodes so that we can
avoid closing the job pipe on exec for them in order to make recursive
makes work in parallel.
 1.176 04-Aug-2013  sjg branches: 1.176.2;
Move the call to Job_SetPrefix() to Job_Init() so that
makefiles have had a chance to set .MAKE.JOB.PREFIX
 1.175 30-Jul-2013  sjg Allow an empty .MAKE.JOB.PREFIX to supress output of --- job --- tokens
 1.174 05-Jul-2013  sjg If commandShell hasErrCtl is true, set shellErrFlag for use by
CompatRunCommand() so that behavior in jobs and compat mode
remains consistent.
 1.173 05-Jun-2013  sjg JobCreatePipe: do fcntl() *after* any fiddling of fd's
to avoid leaking descriptors.
Job_ServerStart: set closed on exec for jp_0 and jp_1.
 1.172 05-Mar-2013  christos Add a .STALE special target that gets invoked when dependency files contain
stail entries.
 1.171 05-Mar-2013  christos Keep track of the location where a dependency is defined, so we can report
about it.
 1.170 26-Feb-2013  christos PR/45042: Thomas Cort: HAVE_foo for setrlimit(2) and setpgid(2)
 1.169 06-Feb-2013  christos fix broken logic:
- poll can return EINTR, it is not restartable like read/write
- check poll return
- it does not make sense to check readyfd() is nready < 0
- check read return
- always call Job_CatchChildren, it is harmless
- short circuit scanning of the poll array if we got all the ready descriptors
 1.168 02-Feb-2013  christos tools build is non-c-99
 1.167 02-Feb-2013  christos avoid the long shadow of i
 1.166 02-Feb-2013  christos Don't wait forever for output from a child job.
 1.165 26-Jan-2013  christos Check read and write errors to avoid warnings from linux.
XXX: Should we print an error and exit instead?
 1.164 25-Jan-2013  sjg Remove Check_Cwd - it is no longer needed.
 1.163 03-Jul-2012  sjg branches: 1.163.2;
An X!= command, can cause Shell_Init() to be called before Job_ParseShell().
Job_ParseShell() should call Shell_Init() again if needed
to ensure shellPath is correct.
 1.162 12-Jun-2012  joerg Replace __dead, __unused and the various printf format attributes
with versions prefixed by MAKE_ATTR_* to avoid modifying the
implementation namespace. Make sure they are available in all places
using nonints.h to fix bootstrap on Linux.
 1.161 07-Apr-2012  christos Remove recheck hackery that caused extra stats, and explicitly ask for
recheck when needed. Before it used to be the case that we could only
use the cached entry once. Once the cached entry was used, we removed
it from the cache. Now it is kept forever.
 1.160 16-Sep-2011  joerg branches: 1.160.2;
Use __dead consistently. If it doesn't exist, define it away.
 1.159 28-Aug-2011  sjg In meta mode, we create .meta files for most targets.
These capture all the interesting data - useful for debugging.
In such cases there is no need to replicate commands in the build log.
Rather than run the entire build .SILENT, allow meta mode to set that flag
per target iff a .meta file is created.
Normal behavior is retained for targets where no .meta file is created,
ensuring that no build data is lost.
 1.158 14-Aug-2011  christos - remove gcc-4.5 warnings
- simplify job printing code
- document non-literal format strings
 1.157 01-Aug-2011  christos Don't attempt to touch special targets; make -t would create .END in every
directory.
 1.156 31-Mar-2011  sjg We must now call meta_job_finish() after meta_job_error()
so that .ERROR_META_FILE is captured.
 1.155 13-Sep-2010  sjg Add meta.c which implements "meta" mode for make.
In this mode, a .meta file is created for each target, capturing
the expanded commands used, any command output, and if filemon(9)
is available, a record of system calls which are of interest.
Not enabled unless USE_META=yes is set when building make.
Also, if FILEMON_H exists, meta.c will be compiled to use filemon(9).
 1.154 07-Aug-2010  sjg In jobs mode, if we cannot make a target we die without any further
clue. Call PrintOnError() before DieHorribly().
 1.153 07-Aug-2010  sjg wait[pid]() is called in several places.
If we encounter an error and run the .ERROR target, we may
reap a pid which jobs is waiting for. Ensure that we
cleanup so that make isn't left waiting for an already
deceased child.
 1.152 20-Jul-2010  christos PR/43643: David A. Holland: dash prefix broken with make -j
As the comment says in JobPrintJob set JOB_IGNERR with - commands. Fix
whitespace so that the output is consistent, although there are two separate
execution logic implementations (command.c, job.c)
 1.151 17-Jun-2010  sjg JobFinish: call PrintOnError if we detected an error we are not ignoring.
This gives the .ERROR target a chance to run at the first sign of trouble.
 1.150 03-Jun-2010  sjg We have required sigaction() for quite a while.
Use bmake_signal() - a wrapper around sigaction()
rather than signal() to ensure that signals are handled
consistently.
 1.149 23-Apr-2010  sjg On darwin at least, vfork() fails in child of vfork().
It probably shouldn't work anyway, so avoid this.
We use the macro vFork() - a function seems to cause problems
and is unnecessary overhead.
 1.148 22-Apr-2010  sjg Just because $TMPDIR is set does not mean it is valid.
Add a central function for creating temp files so we have one place to
audit.

Reviewed by: dh
 1.147 07-Apr-2010  sjg Add:

.error "message"
.warning "message"
based on FreeBSD implementation.
add .info while were at it.

.ERROR: a target to run on error.
We pass the failing GNode to PrintOnError so it can set
.ERROR_TARGET.

.MAKE.MAKEFILE_PREFERENCE
As a means to control make's list of prefered makefile names.
(Default: "makefile Makefile")

.MAKE.DEPENDFILE
Names the file to read dependencies from
(Default ".depend")

.MAKE.MODE
Processed after all makefiles are read.
Can put make into "compat" mode (more to come).

Fix:

compat.c: Error code should not be sent to debug_file.
Make_DoAllVar: use DONE_ALLSRC to avoid processing a node multiple times.
ReadMakefile: we can simply use doing_depend to control setting MAKEFILE.
 1.146 26-Jun-2009  sjg JobExec: child of vfork must not empty the sigset_t that parent will
restore. Use a separate mask.
 1.145 11-Apr-2009  apb Honour the TMPDIR environment variable instead of always using /tmp
as a place to store temporary files.
 1.144 23-Jan-2009  dsl branches: 1.144.2;
Change 'ClientData' to 'void *' so that relevant parameters can
be made 'const void *'.
 1.143 19-Dec-2008  christos if brk_string fail, so do we.
 1.142 13-Dec-2008  dsl Use NULL instead of -1 cast to the relavant type (usually via NIL).
This was a suggestion from christos - so blame him if there is a deep
reason for using -1 :-)
 1.141 29-Oct-2008  sjg branches: 1.141.2;
If Parse_Error is called after curFile is invalid, set it to a dummy
to avoid seg-fault. Also the NULL filename will cause ParseVErrorInternal
to skip trying to report file and line number info.

If CondToken is called outside the context of a .if etc, variables in
the expression being parsed will already be expanded, so allow for
an unqouted number to jump us back into the compare logic.
This allows ${${SomeNumber:U42} > 0:?True:False} to work anywhere.

Job_Finish should process postCommands if it has commands or children.
 1.140 06-Oct-2008  joerg Don't use emalloc and friends directly, but call them consistently
bmake_malloc and friends. Implement them via macros for the native case
and provide fallback implementations otherwise. Avoid polluting the
namespace by not defining enomem globally. Don't bother to provide
strdup and strndup, they were only used for the estrdup and estrndup
comapt code.

This addresses the presence of emalloc in system libraries on A/UX and
resulted strange issues as reported by Timothy E. Larson.
 1.139 15-Feb-2008  christos back all changes out until I fix it properly.
 1.138 15-Feb-2008  christos Improve dh's fix:
- make sure i is initialized
- don't subtract 1 in comparison, add 1 to the other side
 1.137 15-Feb-2008  dholland Avoid SIGSEGV caused by signed/unsigned mismatch. (hi xtos)
 1.136 14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.135 19-Jan-2008  sjg Implement -dl (aka LOUD) to override '@' at the start of script lines.
Based on supplied patch.

PR: 37202
 1.134 21-Dec-2007  dsl If make can't find a rule to create a file it needs to satisfy a rule
that came from .depend then just output a message and contine.
 1.133 14-Oct-2007  apb Make it easier for the build environment (such as a configure script)
to override the default shell:

* Rename _BASENAME_DEFSHELL to DEFSHELL_CUSTOM, because it's no longer
always a basename, it might be a full path;
* Rename DEFSHELL to DEFSHELL_INDEX, because it's actually an index into
an array;
* Provide symbolic names for the possible values if DEFSHELL_INDEX;
* Document how the build environment may set DEFSHELL_INDEX or
DEFSHELL_CUSTOM to choose the default shell;
* Move the fallback definition of DEFSHELL_INDEX from config.h to job.c,
because it's used only in job.c.

Discussed with sjg.
 1.132 13-Oct-2007  apb Revert to revision 1.128. Now that the Var* functions no longer try to
write into const strings, it's safe to pass a truly constant string to
Var_Subst.
 1.131 13-Oct-2007  dsl The 'job_prefix' string can be static but not const 'hi xtos'.
 1.130 12-Oct-2007  christos improve on previous
 1.129 12-Oct-2007  dsl Var_Subst() seems to write into its input string! So we do need a copy.
 1.128 12-Oct-2007  dsl Remove tmp[] buffer and strncpy() call.
 1.127 11-Oct-2007  sjg If _BASENAME_DEFSHELL is defined, it might be a full path,
in which case we should not prepend _PATH_DEFSHELLDIR.
 1.126 05-Oct-2007  sjg Add the ability to .export variables to the environment.
 1.125 01-Oct-2007  sjg Add the ability to tweak the token output before targets in job mode.
Eg.
.MAKE.JOB.PREFIX=${.newline}---${.MAKE:T}[${.MAKE.PID}]
would produce
---make[1234] target ---
 1.124 27-Oct-2006  dsl branches: 1.124.2; 1.124.8;
Since 'ClientData' is 'void *', nuke almost all the (ClientData) casts.
 1.123 15-Oct-2006  dsl Output all debug trace output through 'debug_file' defaulting to 'stdout'.
(Almost all the debug output went there, but some went to stderr.)
Split the parsing of -d (debug flags) out into its own routine.
Allow the output filename to be changed by specifying -dF<file> to create
a log file, or -dF+<file> to append to it. <file> may be stdout or stderr.
Also change so that -d-<flags> acts on <flags> locally but doesn't copy
them to MAKEFLAGS so they aren't inherited by child makes.
I'm not 100% happy with the command line syntax for the above, so they are
currently undocumented.
 1.122 11-Oct-2006  dsl There is no need to resize the pollfd array, it can only ever have 2+maxJobs
entries, so allocate at startup.
Use an 'int jobPipe[2]' within the job structure, and create pipes directly
into it. Common up the code that creates all the pipes - making them all
non-block on the read side in the process.
Call Job_CatchChildren() directly from Job_CatchOutput() so that it only
gets called when a child actually exits.
NB: Something causes a 'pregnant pause' if (for example) you call 'nbmake obj'
in src/tools. Introduced between netbsd 3 and 4.
 1.121 09-Oct-2006  apb Allow make(1) to be built with something other than "sh" as the
shell. To use this, build with -D_PATH_DEFSHELLDIR=\"/path/to/dir\"
-D_BASENAME_DEFSHELL=\"shell\".

* Change the order of entries in shells[]. Now DEFSHELL defaults to 0,
and shells[0] describes the default shell. This will be "sh" in the
usual case.

* If _BASENAME_DEFSHELL is defined, insert an additional entry above
"sh" in the shells[] array, making this new entry shells[0]. The
new entry is assumed to refer to an sh-compatible shell with a
non-standard name. (Tested using _PATH_DEFSHELLDIR="/usr/pkg/bin" and
_BASENAME_DEFSHELL="bash".)

* In the shells[] entry for "sh", test defined(MAKE_NATIVE) &&
defined(__NetBSD__) to decide whether we can use the "q" flag.

OK sjg, christos
 1.120 09-Oct-2006  dsl Rip out the code for the undocumented -P (don't use pipes for command
output) option. I'm sure it is baggage from the past.
 1.119 09-Oct-2006  dsl Rip out the code for not 'USE_PGRP', I can't imagine it being useful!
My guess is that it is compat code for before the pgrp stuff was added.
 1.118 09-Oct-2006  dsl Instead of trying to report all the 'job suspended' and 'job resumed'
messages whan make itself is suspended (ie by ^Z) before make actually
suspends, supress the messages during this sequence.
This means we don't care that they would be output after the suspend
and we can stop attempting to reap child status from withing the signal
handler (which doesn't work for recursive parallel makes).
The code simplification means that we can remove much of the code that
blocked signals - since the signal handlers (expect that for ^C and friends)
now do almost no work.
 1.117 29-Sep-2006  dsl Reap any dead children that we have at startup.
If there are any undead ones set a flag so we don't report the 'Child (pid)
not in table' message when they die - it is impossible to (portably) find
the childrens pids.
This happens when make is run as 'make -f- ... <<EOF' and the shell uses
a child of (what will be) make to write the data into a pipe.
 1.116 23-Sep-2006  dsl Complete revamp of the way make handles job control signals.
- Send each type of signal to its own handler.
- Only call JobFinish when a process exits, in particular don't 'fake up'
'exitstatus' for jobs being continued, nor call it for suspends.
- When a job is stopped, use an entire variable to remember the fact, so
we know we need to send a SIGCONT. Don't change any other state.
- In order to report '*** [job3] Suspended' before we suspend ourselves we
have to call waitpid() from the signal handler - where we don't want to
process job termination events. Save the exit status and process later.
The code now handles:
- jobs that suspend themselves
- jobs exiting while suspended
- jobs that don't actually suspend at all
Hoewever it still does printfs() from the signal handler, and I haven't yet
stopped it thrashing the signal mask.
 1.115 22-Sep-2006  dsl Fix build on 64 bit systems.
Remove now-unecessary temporary local.
 1.114 22-Sep-2006  dsl Replace the two lists 'job_list' (previously 'jobs') and 'stoppedJobs'
with a table that is malloced with 'maxJobs' entries.
Add a 'job_state' field to the Job type that exactly follows which of
the old lists the job was on (or not).
Change all the code that scanned the lists to scan the array.
No logic changes in this commit.
(Soon we'll no longer need to lock out signals for the changes to job
statuses that are done from signal handlers now that there is no linked list.)
 1.113 21-Sep-2006  dsl Rename the variable 'jobs' to 'job_list' in preparation for making it an array.
 1.112 29-Jun-2006  rillig Fixed the bug reported in PR 33866, which is that the :Q operator does not
handle newlines correctly. Ok'ed by christos.
 1.111 31-Mar-2006  dsl There is no need to count jobs and job tokens.
If we don't create the job pipe, use the '-j n' option to limit the number
of tokens we will remove from the pipe.
 1.110 15-Mar-2006  dsl nJobs and jobTokensRunning are both counting the same thing.
Kill nJobs and just use the count of tokens in use.
Don't eat job tokens when we are ignoring errors.
 1.109 13-Mar-2006  dsl JOB_FIRST is always set (since we only execute the shell once for every
target). Nuke it.
 1.108 12-Mar-2006  dsl Remove the 'never non-NULL' 'previous' argument to JobStart.
Looks like it was intended as a minor (and pointless) optimisation to
remove a free() malloc() pair.
Make he comment about the stoppedJobs list more correct.
 1.107 12-Mar-2006  dsl It isn't possibly to execute any part of job.c that references compatMake
when it is 'true'. So delete the unexecutable code.
 1.106 11-Mar-2006  dsl Remove most of the code seemed to be there to support 'remote jobs'.
It isn't clear that it ever worked, if it did it has almost certainly
bitrotted in the last 12 years. I'm not even sure all the required
components were present.
I suspect it was written to attempt to use a 'farm' of diskless sun3s.
In any case the apparant random assignment fo jobs to other systems doesn't
actually seem like a good idea!
Things like 'distcc' han be used to help slow systems run native builds.
Removing this code also simplifies make, and should let me speed up some of
its processing - without worrying about bitrotting it further.
 1.105 08-Mar-2006  dsl Avoid calling JobRestartJobs() from the SIGCONT signal handler, instead
push a byte through the (now badly named) exit_pipe and call JobRestartJobs()
from the main code path when poll() wakes up.
Part of a plan to remove JobSigLock() and the zillions of system calls
it does.
 1.104 11-Feb-2006  dsl Actually SIG_DFL the correct signal (not SIGINT every time) just prior to
exec'ing a program in the child.
 1.103 22-Jan-2006  dsl Make .NOTPARALLEL stop the job engine issuing more than one token (instead
of trying to de-jobify the make.
You can now put .NOTPARALLEL in a submake of a recursive make (where it is
using a job-token pipe from the outer make and have it only run a single job.
You can also specify .NOTPARRALEL in the root makefile of a large recursive
make and have the submakes run multiple commands.
Add some diagnostics printfs (enabled with -dp) to the parser.
 1.102 21-Jan-2006  dsl Check the 'job_pipe' for the error token 'E' before every job, including
the first one for each make. This significantly speeds up the detection
of errors in other branches of the make (ie those running in a different
make process). The cost of reading and writing a byte from the pipe
should be insignificant.
Defer replacing job tokens until we've decided there is an error.
If we detect an error in another branch of the make, then call Fatal(),
setting 'aborting' and failing to return a token leads to infinite loops.
Now parallel makes actually stop with the failing command on the screen.
 1.101 04-Jan-2006  dsl When a parallel make job completes, always put the job token back into the
job_pipe and collect another one for the next job.
If we are aborting, remove all the 'normal' job tokens and add an 'error' one.
If we get an 'error' token, remove any other tokens, re-insert the error
token and exit (with error 'cos that is easier).
Add the current pid to some of the DEBUG(JOB) traces.
Combined effect is that parallel makes actually stop some fairly shortly
after an error, rather than running on long enough to fill the scrollback.
 1.100 04-Jan-2006  dsl F_DUPFD the job_pipe fds onto higher numbers (>15) to make it less likely
that they will get closed in a complex recursive parallel make.
 1.99 04-Jan-2006  dsl If -s (silent) is specified, don't output the target name before target
output in parallel makes.
After all with -s you wouldn't know the command for a non-parallel make.
Makes (sic) the output of parallel NetBSD build fathomable.
 1.98 08-Aug-2005  christos From Max Okumoto:
- Remove casts to NULL.
- Remove space between cast and object.
 1.97 05-Aug-2005  christos More KNF cleanups from Max Okumoto
 1.96 25-Jul-2005  christos Whitespace KNF cleanup from Max Okumoto
 1.95 29-Jun-2005  christos Don't apply .DEFAULT commands to special targets (.BEGIN, .END, .INTERRUPT).
 1.94 17-Jun-2005  jmc Add new debugging option '-dn' which will leave the scripts fed into make on
-j jobs in /tmp for debugging purposes. Add a note to the man page that
this could cause problems if run a lot (due to the number of files created)
 1.93 16-Jun-2005  jmc If the line being passed to the shell is a blank line and we're not in compat
mode, use the ignErr template for the command as shell doesn't like an empty
construct of the form { } || <something>. Fixes build breakage on cats
distrib where a command ends up expanding to nothing.
 1.92 08-May-2005  christos Don't complain that we cannot make .END.
 1.91 08-May-2005  christos Now that dependencies in .BEGIN, .END, and .INTERRUPT work, allow them.
 1.90 03-May-2005  christos Mark the interrupt job as special so that when we hit ^C with -j and we
have a .INTERRUPT target we don't print "token botch".
 1.89 16-Feb-2005  christos PR/29203, PR/29204: Max Okumoto: KNF changes to make [no functional changes]
 1.88 31-Jan-2005  christos PR/22559: Valeriy E. Ushakov: make -j can execute commands in wrong directory
(not in the obj dir).
Fixed by detecting when we cd, and cd'ing back.
 1.87 01-Jul-2004  jmc Change to use __unused instead and provide a compat definition in make.h if
not already defined from cdefs.h
 1.86 01-Jul-2004  jmc Add some checks for gcc around a few function declarations and note the
unused variables. Also fix a few other warnings that PR#22118 shows when
trying to compile bmake on non-NetBSD hosts
 1.85 07-May-2004  sjg Remove use of sh -e when running in compat mode.
Its not posix compliant and serves very little purpose.
With this change compat and jobs modes are consistent wrt how
they treat each line of a script.

Add support for the '+' command line prefix as required by posix.
Lines prefixed with '+' are executed even when -n is given.
[Actually posix says they should also be done for -q and -t]

PR:
Reviewed by: jmc
 1.84 07-May-2004  ross Simplify build, no functional changes.

Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().

It's now possible to build make on some hosts with: cc *.c */*.c
 1.83 20-Dec-2003  jmc branches: 1.83.2;
Fixes for PR#18573 (make -j not stopping correctly on error).
Using -e in sh/ksh to stop on error doesn't work with grouped commands. At
least for any SUSE compliant sh(1). Instead, extend the Shell struct and add
errOut which provides a template to use to check error status from commands.
 1.82 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.81 01-Aug-2003  sjg Allow .SHELL: to control the shell used by compat mode too.
Add a shell spec for ksh - a nice portable posix shell.
Document .SHELL:
 1.80 16-Jul-2003  itojun backout. make(1) either uses strcpy() to malloc'ed region (enough size),
or function signature prohibits us from using strlcpy().
 1.79 15-Jul-2003  itojun strlcpy (fixed)
 1.78 15-Jul-2003  itojun strlcpy
 1.77 14-Jul-2003  christos Pass WARNS=3
 1.76 08-Apr-2003  christos PR/1523: Chris Demetriou: don't count a library as built, if there is no way
to build it.
 1.75 09-Dec-2002  gson When JobExec() was called from JobRestartJobs() via JobRestart(), it
executed the make job with sigprocmask(SIG_BLOCK) in effect for a
number of signals including SIGCHLD. This caused recursive submakes
of the make process in question not to receive SIGCHLDs when their
jobs exited. This was a second, independent cause of bin/18895 in
addition to the race condition already fixed. Fixed by unblocking all
signals before executing the job.
 1.74 26-Nov-2002  enami Call fcntl() on the right file descriptors.
 1.73 16-Nov-2002  gson Fixed race condition that would cause make -j to pause for five
seconds if a SIGCHLD arrived while make was not blocked in poll(),
by making the SIGCHLD handler write to a pipe included in the poll.
Avoided the need to implement a duplicate fix for the USE_SELECT case
by emulating poll() in terms of select() when USE_SELECT is defined.
Fixes bin/18895.
 1.72 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.71 15-Apr-2002  christos PR/16361: J. Mallett: make(1)'s job.c does not properly initialise postCommands
 1.70 18-Mar-2002  pk Fix some of the syntax errors (in unused code) and layout glitches.
 1.69 18-Mar-2002  pk Block signals during Lst_Open/Lst_Close list traverals and in JobExec
while setting up a child process. This prevents the major sources of
list inconsistencies that may result from doing list manipulations
from a signal handler.

XXX - all Lst_*() operations are at risk; look for ways to avoid touching
so much global state from the signal handlers.
 1.68 18-Mar-2002  pk Fix signal-handling bogons in JobPassSig():
- don't block the signal we're about to send to ourselves to
take the default action for
- restore the signal handler for the current signal
- remove duplicate sigprocmask() call

As a result, restoring the SIGTSTP handler in JobContinueSig() is no longer
necessary.
 1.67 18-Mar-2002  pk JobInterrupt(): don't try to unlink JOIN or PHONY targets.
 1.66 18-Mar-2002  pk Remove bogons from JobMatchShell()
 1.65 15-Mar-2002  pk Job_ParseShell(): fix keyword counting error.
 1.64 14-Mar-2002  pk JobExec(): don't use Punt() in the child; it can't possibly DTRT, and will also
mess up the parents variables.

Instead, use execError() for all error paths in the child code.
 1.63 14-Mar-2002  pk Job_AbortAll(): add missing Lst_Close().
 1.62 13-Mar-2002  pk JobInterrupt(): add missing and fix a misplaced Lst_Close().
 1.61 13-Mar-2002  pk Add the job's name to the `*** Error/Suspended/Continuing' informational
output. Useful when doing, e.g. a `make -j42'
 1.60 04-Mar-2002  enami We don't want token while we're aborting. Otherwise, make spins wasting cpu.
 1.59 10-Feb-2002  pk Fix for previous: JobRestart() return value check was reversed.
 1.58 08-Feb-2002  pk JobRestartJobs() should cease scheduling stopped jobs if the maximum
number of running jobs limit has been reached, otherwise an infinite
loop is the result.

Give JobStart() a return value to report this condition.
 1.57 08-Feb-2002  pk JobStart(): if there no commands to execute for a node, set its status
to MADE before calling Make_Update(). This is necessary to complete
all rules associated with sources on an .ORDER dependency.
 1.56 06-Feb-2002  pk JobPrintCommand: avoid stale pointers on a node's command list.
The debugging value of the code that did this is limited, so drop it
altogether.
 1.55 16-Oct-2001  sjg When attempting to chdir to .CURDIR because Check_Cwd_Cmd says we need to
make sure that the dir actually exists. In compat mode the corresponding
chdir simply fails and all is well - the issue only arises when playing
tricky games with the value of .CURDIR.

Reviewed: christos
 1.54 20-Aug-2001  wiz precede, not preceed.
 1.53 24-Jul-2001  matt Print out errno when vfork fails.
 1.52 03-Jul-2001  christos add .USEBEFORE Attribute
 1.51 12-Jun-2001  sjg Add 4th arg (flags) to Var_Set so that VarLoopExpand can tell it not
to export interator variables when using context VAR_CMD.

Reviewed: christos
 1.50 11-Jun-2001  christos Revert Job_CatchOutput() change; it adds a considerable delay to make, and
it is not clear what problem it is trying to fix.
 1.49 01-Jun-2001  sjg A number of semi-related changes.
1. make -dx turns on DEBUG_SHELL which causes sh -x to be used where
possible.
2. PrintOnError() is now called when make is stopping due to an error.
This routine reports the curdir and the value of any variables listed
in MAKE_PRINT_VAR_ON_ERROR.
3. Variables set via command line, are propagated to child-makes via
MAKEFLAGS. This behaviour appears to be necessary for POSIX (according
to the GNU folk anyway).
4. Do not reset MAKEFILE when reading ".depend" as this rather eliminates the
usefulness of ${MAKEFILE}.
5. Added ${.newline} as a simple means of being able to include \n in the
result of a :@ loop expansion.
6. Set ${MAKE_VERSION} if defined. Need to come up with a useful value.

Reviewed: christos
 1.48 29-May-2001  christos better error messages on exec* failures. From Simon Burge.
 1.47 01-May-2001  sommerfeld bin/12734: fix SIGTSTP/SIGCONT handling.

- install SIGCONT handler which reestablishes SIGTSTP handler and then calls
JobRestartJobs() to restart all the suspended jobs.
- when SIGTSTP is handled, call JobCatchChildren() so *** Suspended messages
get printed before make stops rather than after.
 1.46 10-Jan-2001  christos PR/11800: Chris Demetriou: Add -W flag to exit on parse warnings.
While I am here, s/make:.*"/%s:\1", progname/
 1.45 01-Jan-2001  sommerfeld Delete forceSerial; just use compatMake for that.
Add -N flag to *really* not execute any commands (useful when using
the -d flags to debug usr/src/Makefile)
Document -N
Update documentation of -n to mention that it still executes commands
for targets marked .MAKE so that the -N/-n distinction is clear.
 1.44 30-Dec-2000  sommerfeld Include token counts in trace output.
Don't let tokensFree go negative.
 1.43 30-Dec-2000  sommerfeld Fix token accounting for .BEGIN/.END jobs
 1.42 30-Dec-2000  sommerfeld Avoid token leaks when aborting after an error.
 1.41 30-Dec-2000  sommerfeld Do lazy token release - don't return tokens to the pipe unless we're
waiting for something or we're done.
 1.40 30-Dec-2000  sommerfeld Add a token-passing scheme to allow a recursive make to successfully
use -j; all make's in a recursive build cooperate to limit the total
number of jobs, using a token-passing scheme.

The current token passing algorithm is similar to the one implemented
by gmake; there is a single pipe which is inherited through the entire
process hierarchy; tokens are obtained by reading a byte from the
"read end" of the pipe, and are returned by writing them to the "write
end". This exact algorithm is likely to change in the future.

Implementation details:
- Use the new trace facility to allow measurement of the
effectiveness of different token-passing schemes
- Get a token in MakeStartJobs(), return it in Make_Update()
- Eliminate Job_Full() and the jobFull global since they are
redundant with token system.
- Add an "internal" -J option (to pass the token pipe fd's down to
submakes) and a -T option for tracing.
- Change how compatMake is forced so that -j means something when
inherited by submakes.
- When waiting for a token, poll the token-passing pipe as well as
the output pipes of existing jobs.
 1.39 05-Dec-2000  mycroft Make the fds[] realloc O(n). Also make the rethreading a lot simpler.
 1.38 05-Dec-2000  sommerfeld Make clearfd() take O(1) time instead of O(N) by moving only the last
job in the arrays to the hole made by the now-dead job. No
measureable performance difference for -j4, but the code is simpler
this way.
 1.37 05-Dec-2000  sommerfeld correct performance regression of recent change from select() to
poll() for parallel make:
- Make the poll() code behave more like the select() code: sleep for
a bit waiting for output rather than busy-wait (eww).
- Install a no-op SIGCHLD handler so that poll/select wake up early
(with -1/EINTR) when a child exits.
- Change the default sleep time from 500ms to 5 seconds since we now
wake up promptly when a child exits.
 1.36 04-Dec-2000  christos mycroft did not like my O(n^2) lookup algorithm, so I made things much
more complicated.
 1.35 03-Dec-2000  christos 1. switch to using poll by default; can be overriden by compiling with
-DUSE_SELECT
2. make sure that we don't overrun our allocated fd_set if USE_SELECT is defined
 1.34 03-Dec-2000  christos 1. the tfile patch was incorrect. If we are doing multiple jobs, we
try to open tfile many times, passing bad strings to mkstemp
2. remove extra semicolon after the MESSAGE macro
3. more error checking
4. be more careful about setting things to NULL after freeing.
5. fix a comment that does not apply anymore
 1.33 20-Apr-2000  sjg Changes to make MAKEOBJDIRPREFIX useful.

Firstly, we ignore getenv("PWD") if MAKEOBJDIRPREFIX is set so that we always
get the same value for .CURDIR regardless of how make was invoked.

Second, when executing a command we check if it is ${.MAKE} or ${.MAKE:T}
without a preceeding chdir, if so we insert a chdir(${.CURDIR}) so that
the Makefile will be found by the child make. Note that this behaviour is
dissabled if MAKEOBJDIRPREFIX is not set or if NOCHECKMAKECHDIR is set.
See the comments in main.c for more detail.

With these two changes, one can successfully build usr/src using MAKEOBJDIRPREFIX
allowing the src to be mounted from a CD-ROM.
 1.32 21-Jan-2000  mycroft Nuke `extern int errno;' in code we compile with -Wstrict-prototypes. We get
the correct definition from errno.h.
 1.31 19-Jan-2000  christos Create temporary files carefully, to avoid security problems. Idea borrowed
from the botched FreeBSD implementation...
 1.30 15-Sep-1999  mycroft Don't bother iterating through all the data structures to free(3) everything
right before exiting.
(The code is still present, `#ifdef CLEANUP', in case someone needs it...)
 1.29 04-Sep-1999  christos PR/8259: Chris Demetriou: Fix stack overflow bugs exposed by the glibc-2.1.1
Makefile. Use snprintf everywhere.
 1.28 16-Jul-1999  christos Fix extreme brokeness with job control that appeared when we set USE_PGRP.
 1.27 06-Jul-1999  christos Regular bourne shells don't have the -q option (from Chuck Cranor)
 1.26 03-May-1999  christos killpg(pgrp, sig) == kill(-pgrp, sig) in the sysv case.
 1.25 04-Feb-1999  cjs branches: 1.25.2;
When giving the -v option to /bin/sh, also give the new -q option so that
the execution of $ENV isn't printed with every job that's started.
 1.24 06-Nov-1998  christos - full prototypes
- more conservative printf
- char -> unsigned char
 1.23 01-Nov-1998  itohy Reduced memory leaks.
I found some more leaks, but are not in inside of iterations.
 1.22 26-Mar-1998  christos PR/5210: Hauke Fath: make core dumps with .SHELL
Unfortunately this revealed a deeper problem with the brk_string code.
To fix it:
- remove sharing of the buffer between brk_string invocations
- change the semantics of brk_string so that the argument array
starts with 0, and return the buffer where the strings are
stored
 1.21 28-Sep-1997  lukem branches: 1.21.2;
wrap #include <sys/cdefs.h>, __RCSID(...) stuff in #ifndef MAKE_BOOTSTRAP
 1.20 25-Aug-1997  kleink Lseek(2) usage cleanup: the use of L_SET/L_INCR/L_XTND is deprecated,
use SEEK_SET/SEEK_CUR/SEEK_END instead.
 1.19 01-Jul-1997  christos Add WARNS=1
RCSID police
 1.18 06-May-1997  mycroft Make sure `-n' is actually disabled for targets with the .MAKE attribute.
 1.17 06-May-1997  mycroft Don't touch .PHONY targets.
 1.16 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.15 29-May-1996  christos Fix bug where make will always exit with 0, even when one or more parallel
jobs failed. (Only affects parallel make code)
 1.14 04-Feb-1996  christos branches: 1.14.4;
fix pr/1421 and pr/1997
 1.13 22-Nov-1995  christos Updates for POSIX/SVR4 compiling:

arch.c: Don't require ranlib stuff. Not everybody has it.
dir.c: SunOS-4 != Solaris; change #ifdef sun to #if sun && !__svr4__
job.c, compat.c: Don't use 'union wait', use int and the W*() macros.
main.c: Check for uname() == -1; some unames return > 0...
util.c, job.c: Add signal() with BSD semantics for svr4, don't use bsd
sigmask and friends.
 1.12 02-Nov-1995  christos Minor:
- ${.PREFIX} should never contain a full pathname
- Fixed gcc -Wall warnings
Major:
- compatMake is now FALSE. This means that we are now running in
full pmake mode:
* rules on dependency lines can be executed in parallel and or
out of sequence:

foo: bar baz

can fire the rule for baz before the rule for bar is fired.
To enforce bar to be fired before baz, another rule needs to be
added. [bar: baz]
* adjacent shell commands in a target are now executed by a single
invocation of the shell, not one invocation of the shell per line
(compatMake can be turned off using the -B flag)
- The -j flag now works... I.e. make -j 4 will fork up to four jobs in
parallel when it can. The target name is printed before each burst
of output caused by the target execution as '--- target ---', when j > 1
- I have changed all the Makefiles so that they work with make -j N, and
I have tested the whole netbsd by:
'make -j 4 cleandir; make -j 4 depend; make -j 4; make -j 4 install'
- I have not compiled or tested this version of make with -DREMOTE.
 1.11 27-Sep-1995  jtc Update lseek() constants:
L_SET -> SEEK_SET
And add off_t cast to offset argument.
 1.10 14-Jun-1995  christos - $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.9 24-Dec-1994  cgd a few casts, for peace and quiet.
 1.8 25-Nov-1994  christos Don't remove targets when the -n flag is given and make is interrupted.
(From Keith Bostic)
 1.7 16-Jun-1994  jtc Christos' fix for quoting variable extraction properly.
 1.6 06-Jun-1994  jtc Fixes from Christos Zoulas, who used purify, objectcenter and testcenter
to find memory leaks and illegal memory accesses.
 1.5 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.4 13-Jan-1994  jtc Include appropriate header files to bring prototypes into scope.
 1.3 01-Aug-1993  mycroft Add RCS identifiers.
 1.2 21-Mar-1993  cgd after 0.2.2 "stable" patches applied
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.14.4.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.21.2.1 08-May-1998  mycroft Sync with trunk, per request of christos.
 1.25.2.2 23-Jan-2000  he Pull up revisions 1.26-1.31 (requested by christos):
Several fixes:
o SystemV portability
o Avoid non-portable use of 'sh -q'
o Job control fixes when USE_PGRP is in use
o Fix stack overflow bugs, use snprintf (fixes PR#8259)
o Don't bother freeing mem right before exit()
o Be caseful when creating temporary files, to avoid
security problem.
 1.25.2.1 23-Jan-2000  he Pull up revision 1.32 (requested by mycroft):
Always do the errno indirection hack, so that non-threaded
libraries get the right errno value when linked with -lpthread.
This means "always include <errno.h> and never declare errno
yourself".
 1.83.2.2 10-May-2004  tron Pull up revision 1.85 (requested by sjg in ticket #282):
Remove use of sh -e when running in compat mode.
Its not posix compliant and serves very little purpose.
With this change compat and jobs modes are consistent wrt how
they treat each line of a script.
Add support for the '+' command line prefix as required by posix.
Lines prefixed with '+' are executed even when -n is given.
[Actually posix says they should also be done for -q and -t]
PR:
Reviewed by: jmc
 1.83.2.1 10-May-2004  tron Pull up revision 1.84 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.124.8.3 23-Mar-2008  matt sync with HEAD
 1.124.8.2 09-Jan-2008  matt sync with HEAD
 1.124.8.1 06-Nov-2007  matt sync with HEAD
 1.124.2.1 04-Aug-2010  bouyer Pull up following revision(s) (requested by dholland in ticket #1401):
usr.bin/make/job.c: revision 1.152 via patch
PR/43643: David A. Holland: dash prefix broken with make -j
As the comment says in JobPrintJob set JOB_IGNERR with - commands. Fix
whitespace so that the output is consistent, although there are two separate
execution logic implementations (command.c, job.c)
 1.141.2.1 21-Nov-2010  riz Pull up following revision(s) (requested by dholland in ticket #1433):
usr.bin/make/job.c: revision 1.152
PR/43643: David A. Holland: dash prefix broken with make -j
As the comment says in JobPrintJob set JOB_IGNERR with - commands. Fix
whitespace so that the output is consistent, although there are two separate
execution logic implementations (command.c, job.c)
 1.144.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.160.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.160.2.2 30-Oct-2012  yamt sync with head
 1.160.2.1 17-Apr-2012  yamt sync with head
 1.163.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.163.2.2 23-Jun-2013  tls resync from head
 1.163.2.1 25-Feb-2013  tls resync with head
 1.176.2.1 10-Aug-2014  tls Rebase.
 1.187.2.1 26-Apr-2017  pgoyette Sync with HEAD
 1.188.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.192.2.1 21-May-2018  pgoyette Sync with HEAD
 1.195.2.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.478.2.1 02-Aug-2025  perseant Sync with HEAD
 1.85 06-Jul-2025  rillig make: clean up
 1.84 22-Apr-2025  rillig make: clean up

Replace 'unsigned int' with simply 'unsigned'.

In compat.c, skipping whitespace is not needed, as the loop above
already skips it.

In job.c, remove the unused header <sys/file.h>.

Inline the TMPPAT macro, as it is only needed in a single place.
 1.83 22-Apr-2025  rillig make: group the code for handling the job token pool
 1.82 22-Apr-2025  rillig make: move struct Job from job.h to job.c

The content of this struct is an implementation detail, and other parts
of make only need to access very few parts of it.
 1.81 03-Jan-2025  rillig make: clean up job handling
 1.80 07-Jul-2024  rillig make: only generate code for cleanup functions in CLEANUP mode
 1.79 28-Jun-2024  rillig branches: 1.79.2;
make: reduce usage of the UNCONST hack
 1.78 19-Dec-2023  rillig make: clean up comments

No binary change, except for line numbers in assertions.
 1.77 15-Dec-2021  rillig make: format comments according to /usr/share/misc/style

Assisted by indent(1), with manual corrections due to its many remaining
bugs.

No functional change.
 1.76 15-Dec-2021  rillig make: use consistent indentation for statements and continuations

No binary change, except for line numbers in assertions in suff.c.
 1.75 15-Dec-2021  rillig make: remove redundant comments for multiple-inclusion guards
 1.74 15-Dec-2021  rillig make: mark several functions whose result must be used

Suggested by sjg, to catch more bugs like the memory leak in cond.c
1.303 from 2021-12-13.

No binary change.
 1.73 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.72 05-Feb-2021  sjg Avoid strdup in mkTempFile

Require caller to pass a buffer and size if they
want the tempfile not unlinked.

Add Job_TempFile to handle blocking signals around
call to mkTempFile, so that meta_open_filemon can use it
in jobs mode.
 1.71 30-Dec-2020  rillig make(1): format multi-line comments
 1.70 15-Dec-2020  rillig make(1): indent job.h with tabs instead of spaces
 1.69 12-Dec-2020  rillig make(1): move Job.xtraced to ShellWriter

This flag was placed wrong in the Job since it is only necessary as long
as the shell commands are written to the shell file.

Resetting it in JobStart and JobExec was completely misguided since that
is far away from writing the shell commands; this should have been done
in JobPrintCommands instead.

The status of this flag doesn't need to be printed in debugging mode
since it is controlled by a single command line option (-dx) and does
not interact with all the other switches.
 1.68 12-Dec-2020  rillig make(1): in jobs mode, extract writing of shell commands

Right now, the test sh-flags.mk demonstrates many variants to configure
echoing of the shell commands (-s, .SILENT, '@'), error handling (-i,
.IGNORE, '-') and whether the commands are run (-n, -N, .MAKE,
.RECURSIVE, '+').

Even more variants are possible by configuring the shell to have error
control. None of the built-in shell definitions has error control, so
it is unlikely that anybody uses them, but who knows.

Being able to configure these details at 3 levels is good, but what
makes all this really hard to understand is that some of these switches
interact in non-obvious ways. For example, in jobs mode, a single
command can change job->ignerr (in JobPrintSpecialsEchoCtl), which will
affect all further commands of that job.

The goal of this refactoring is to make the code easier to understand by
making the switches on the job level constant and by moving all
modifications to them to the ShellWriter.
 1.67 10-Dec-2020  rillig make(1): negate Job.silent to echo

This gets rid of a few explicit negations and an implicit negation in
the variable name.
 1.66 10-Dec-2020  rillig make(1): unpack struct JobFlags

The job flags are only used individually.
 1.65 10-Dec-2020  rillig make(1): split JobFlags into separate fields

Having all these flags in a single bitmask makes it harder to see where
exactly they can possibly be used since their state could also be
modified using the unsuspicious job->flags = 0. Using individual names
just leaves the single memset, and that is only used during
initialization.
 1.64 29-Nov-2020  rillig make(1): use space instead of tab for preprocessor directives
 1.63 14-Nov-2020  rillig make(1): fix grammar: setup -> set up
 1.62 14-Nov-2020  rillig make(1): rename JobState to JobStatus

The status is only part of the whole state of a job.
 1.61 08-Nov-2020  rillig make(1): remove unused JOB_IGNDOTS

It had been used in 1993 at least, don't know when it was finally
removed.
 1.60 07-Nov-2020  rillig make(1): fix type of Job.suspended
 1.59 07-Nov-2020  rillig make(1): clean up JobStart

Initialize the fields in declaration order.
Initialize Job.flags in a single assignment.
 1.58 26-Oct-2020  rillig make(1): group the command line options and arguments

By having a single struct that holds all command line options and
arguments, it is easy to see in the code when such a command line
argument is modified. It also cleans up the namespace since the command
line options don't follow a common naming style. Having them in a
struct also means that there is a single place for putting the
documentation, not two as before.

The struct also suggests to extract the initialization code out of main,
which is still too large, having more than 400 lines of code and
covering far too many topics.
 1.57 23-Oct-2020  rillig make(1): convert JobState and JobFlags to enum types

Both GCC and Clang complained when JobFindPid had its parameter "status"
as an int. Strangely both compilers complained about a comparison
between unsigned and signed int, even though enums are defined to be
int, not unsigned.
 1.56 19-Oct-2020  rillig make(1): move struct Shell from job.h to job.c

This type is only needed in job.c.
 1.55 05-Oct-2020  rillig make(1): prepare job.c, main.c, parse.c, suff.c for WARNS=6

In job.c, GCC 5 complains about the macro FILENO that it has type
unsigned int, which is then passed as the argument of dup2, which
expects a simple int. Maybe this workaround from 1995 is not necessary
anymore, or maybe it is but can be restricted to the few affected
platforms.

This leaves meta.c and the filemon files to be converted. I didn't do
them since they are not well covered by the unit tests.
 1.54 28-Sep-2020  rillig make(1): format job.h consistently
 1.53 28-Sep-2020  rillig make(1): split Job.jobPipe into 2 separate fields

Just because these file descriptors have to be in an array when they are
created is not reason enough to keep this array and a few access macros
in the Job struct. It's better to have separate fields, as they can be
documented independently.
 1.52 27-Sep-2020  rillig make(1): rewrite documentation of Job

The comment above a struct is supposed to give a high-level overview.
The previous comment didn't do that but instead listed the struct fields
in declaration order in a numbered list, which was not helpful.
 1.51 27-Sep-2020  rillig make(1): normalize whitespace in source code

There is no more space tab. Either only tabs or only spaces or tabs
followed by spaces, but not spaces followed by tabs.
 1.50 27-Sep-2020  rillig make(1): remove nonexistent function from header
 1.49 27-Sep-2020  rillig make(1): fix type of Shell.noPLen
 1.48 21-Sep-2020  rillig make(1): add specific typedefs for lists

These typedefs are only intended to help human readers, they do not
provide any type-safety. They also make the pointers explicit, which
had been hidden before by the typedef for Lst and LstNode. Typing a few
'*' is less work than finding out which of the many types are pointers
and which aren't.

In meta.c, the variable "ln" served two completely different purposes,
which have been split again. Register allocation is the job of the
compiler, not of the human source code reader.
 1.47 29-Aug-2020  rillig make(1): remove ReturnStatus, SUCCESS and FAILURE

These are used in so few places now that it is easier to use a simple
Boolean for them.
 1.46 27-Aug-2020  rillig make(1): remove unused declarations from job.h
 1.45 22-Aug-2020  rillig make(1): remove form feeds in the code
 1.44 13-Aug-2020  rillig make(1): follow naming conventions for multiple-inclusion guards

This avoids undefined behavior.
 1.43 03-Jul-2020  rillig make(1): remove trailing whitespace
 1.42 05-Jul-2013  sjg If commandShell hasErrCtl is true, set shellErrFlag for use by
CompatRunCommand() so that behavior in jobs and compat mode
remains consistent.
 1.41 05-Mar-2013  christos Add a .STALE special target that gets invoked when dependency files contain
stail entries.
 1.40 13-Sep-2010  sjg branches: 1.40.6; 1.40.12;
Add meta.c which implements "meta" mode for make.
In this mode, a .meta file is created for each target, capturing
the expanded commands used, any command output, and if filemon(9)
is available, a record of system calls which are of interest.
Not enabled unless USE_META=yes is set when building make.
Also, if FILEMON_H exists, meta.c will be compiled to use filemon(9).
 1.39 11-Apr-2009  apb Honour the TMPDIR environment variable instead of always using /tmp
as a place to store temporary files.
 1.38 13-Dec-2008  dsl branches: 1.38.2;
Use NULL instead of -1 cast to the relavant type (usually via NIL).
This was a suggestion from christos - so blame him if there is a deep
reason for using -1 :-)
 1.37 15-Feb-2008  christos back all changes out until I fix it properly.
 1.36 15-Feb-2008  dholland fix typo in comment
 1.35 14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.34 01-Oct-2007  sjg Add the ability to tweak the token output before targets in job mode.
Eg.
.MAKE.JOB.PREFIX=${.newline}---${.MAKE:T}[${.MAKE.PID}]
would produce
---make[1234] target ---
 1.33 11-Oct-2006  dsl branches: 1.33.8;
There is no need to resize the pollfd array, it can only ever have 2+maxJobs
entries, so allocate at startup.
Use an 'int jobPipe[2]' within the job structure, and create pipes directly
into it. Common up the code that creates all the pipes - making them all
non-block on the read side in the process.
Call Job_CatchChildren() directly from Job_CatchOutput() so that it only
gets called when a child actually exits.
NB: Something causes a 'pregnant pause' if (for example) you call 'nbmake obj'
in src/tools. Introduced between netbsd 3 and 4.
 1.32 09-Oct-2006  dsl Rip out the code for the undocumented -P (don't use pipes for command
output) option. I'm sure it is baggage from the past.
 1.31 09-Oct-2006  dsl Instead of trying to report all the 'job suspended' and 'job resumed'
messages whan make itself is suspended (ie by ^Z) before make actually
suspends, supress the messages during this sequence.
This means we don't care that they would be output after the suspend
and we can stop attempting to reap child status from withing the signal
handler (which doesn't work for recursive parallel makes).
The code simplification means that we can remove much of the code that
blocked signals - since the signal handlers (expect that for ^C and friends)
now do almost no work.
 1.30 23-Sep-2006  dsl Complete revamp of the way make handles job control signals.
- Send each type of signal to its own handler.
- Only call JobFinish when a process exits, in particular don't 'fake up'
'exitstatus' for jobs being continued, nor call it for suspends.
- When a job is stopped, use an entire variable to remember the fact, so
we know we need to send a SIGCONT. Don't change any other state.
- In order to report '*** [job3] Suspended' before we suspend ourselves we
have to call waitpid() from the signal handler - where we don't want to
process job termination events. Save the exit status and process later.
The code now handles:
- jobs that suspend themselves
- jobs exiting while suspended
- jobs that don't actually suspend at all
Hoewever it still does printfs() from the signal handler, and I haven't yet
stopped it thrashing the signal mask.
 1.29 22-Sep-2006  dsl Replace the two lists 'job_list' (previously 'jobs') and 'stoppedJobs'
with a table that is malloced with 'maxJobs' entries.
Add a 'job_state' field to the Job type that exactly follows which of
the old lists the job was on (or not).
Change all the code that scanned the lists to scan the array.
No logic changes in this commit.
(Soon we'll no longer need to lock out signals for the changes to job
statuses that are done from signal handlers now that there is no linked list.)
 1.28 29-Jun-2006  rillig Fixed the bug reported in PR 33866, which is that the :Q operator does not
handle newlines correctly. Ok'ed by christos.
 1.27 31-Mar-2006  dsl There is no need to count jobs and job tokens.
If we don't create the job pipe, use the '-j n' option to limit the number
of tokens we will remove from the pipe.
 1.26 13-Mar-2006  dsl JOB_FIRST is always set (since we only execute the shell once for every
target). Nuke it.
 1.25 11-Mar-2006  dsl Remove most of the code seemed to be there to support 'remote jobs'.
It isn't clear that it ever worked, if it did it has almost certainly
bitrotted in the last 12 years. I'm not even sure all the required
components were present.
I suspect it was written to attempt to use a 'farm' of diskless sun3s.
In any case the apparant random assignment fo jobs to other systems doesn't
actually seem like a good idea!
Things like 'distcc' han be used to help slow systems run native builds.
Removing this code also simplifies make, and should let me speed up some of
its processing - without worrying about bitrotting it further.
 1.24 22-Jan-2006  dsl Make .NOTPARALLEL stop the job engine issuing more than one token (instead
of trying to de-jobify the make.
You can now put .NOTPARALLEL in a submake of a recursive make (where it is
using a job-token pipe from the outer make and have it only run a single job.
You can also specify .NOTPARRALEL in the root makefile of a large recursive
make and have the submakes run multiple commands.
Add some diagnostics printfs (enabled with -dp) to the parser.
 1.23 04-Jan-2006  dsl Expunge last references to jobTokensFree
 1.22 04-Jan-2006  dsl When a parallel make job completes, always put the job token back into the
job_pipe and collect another one for the next job.
If we are aborting, remove all the 'normal' job tokens and add an 'error' one.
If we get an 'error' token, remove any other tokens, re-insert the error
token and exit (with error 'cos that is easier).
Add the current pid to some of the DEBUG(JOB) traces.
Combined effect is that parallel makes actually stop some fairly shortly
after an error, rather than running on long enough to fill the scrollback.
 1.21 20-Dec-2003  jmc Fixes for PR#18573 (make -j not stopping correctly on error).
Using -e in sh/ksh to stop on error doesn't work with grouped commands. At
least for any SUSE compliant sh(1). Instead, extend the Shell struct and add
errOut which provides a template to use to check error status from commands.
 1.20 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.19 01-Aug-2003  sjg Allow .SHELL: to control the shell used by compat mode too.
Add a shell spec for ksh - a nice portable posix shell.
Document .SHELL:
 1.18 14-Jul-2003  christos Pass WARNS=3
 1.17 16-Nov-2002  gson Fixed race condition that would cause make -j to pause for five
seconds if a SIGCHLD arrived while make was not blocked in poll(),
by making the SIGCHLD handler write to a pipe included in the poll.
Avoided the need to implement a duplicate fix for the USE_SELECT case
by emulating poll() in terms of select() when USE_SELECT is defined.
Fixes bin/18895.
 1.16 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.15 01-Jun-2001  sjg A number of semi-related changes.
1. make -dx turns on DEBUG_SHELL which causes sh -x to be used where
possible.
2. PrintOnError() is now called when make is stopping due to an error.
This routine reports the curdir and the value of any variables listed
in MAKE_PRINT_VAR_ON_ERROR.
3. Variables set via command line, are propagated to child-makes via
MAKEFLAGS. This behaviour appears to be necessary for POSIX (according
to the GNU folk anyway).
4. Do not reset MAKEFILE when reading ".depend" as this rather eliminates the
usefulness of ${MAKEFILE}.
5. Added ${.newline} as a simple means of being able to include \n in the
result of a :@ loop expansion.
6. Set ${MAKE_VERSION} if defined. Need to come up with a useful value.

Reviewed: christos
 1.14 30-Dec-2000  sommerfeld Include token counts in trace output.
Don't let tokensFree go negative.
 1.13 30-Dec-2000  sommerfeld Avoid token leaks when aborting after an error.
 1.12 30-Dec-2000  sommerfeld Do lazy token release - don't return tokens to the pipe unless we're
waiting for something or we're done.
 1.11 30-Dec-2000  sommerfeld Add a token-passing scheme to allow a recursive make to successfully
use -j; all make's in a recursive build cooperate to limit the total
number of jobs, using a token-passing scheme.

The current token passing algorithm is similar to the one implemented
by gmake; there is a single pipe which is inherited through the entire
process hierarchy; tokens are obtained by reading a byte from the
"read end" of the pipe, and are returned by writing them to the "write
end". This exact algorithm is likely to change in the future.

Implementation details:
- Use the new trace facility to allow measurement of the
effectiveness of different token-passing schemes
- Get a token in MakeStartJobs(), return it in Make_Update()
- Eliminate Job_Full() and the jobFull global since they are
redundant with token system.
- Add an "internal" -J option (to pass the token pipe fd's down to
submakes) and a -T option for tracing.
- Change how compatMake is forced so that -j means something when
inherited by submakes.
- When waiting for a token, poll the token-passing pipe as well as
the output pipes of existing jobs.
 1.10 05-Dec-2000  sommerfeld correct performance regression of recent change from select() to
poll() for parallel make:
- Make the poll() code behave more like the select() code: sleep for
a bit waiting for output rather than busy-wait (eww).
- Install a no-op SIGCHLD handler so that poll/select wake up early
(with -1/EINTR) when a child exits.
- Change the default sleep time from 500ms to 5 seconds since we now
wake up promptly when a child exits.
 1.9 04-Dec-2000  christos oops forgot to commit this one.
 1.8 03-Dec-2000  christos use 6 X's instead of 5 for portability.
 1.7 04-May-2000  drochner conditionalize prototypes for REMOTE support
(seems that REMOTE support is incomplete anyway)
 1.6 26-Mar-1998  christos PR/5210: Hauke Fath: make core dumps with .SHELL
Unfortunately this revealed a deeper problem with the brk_string code.
To fix it:
- remove sharing of the buffer between brk_string invocations
- change the semantics of brk_string so that the argument array
starts with 0, and return the buffer where the strings are
stored
 1.5 06-Nov-1996  christos branches: 1.5.2;
- Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.4 14-Jun-1995  christos branches: 1.4.6;
- $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.3 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.6.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.5.2.1 08-May-1998  mycroft Sync with trunk, per request of christos.
 1.33.8.1 06-Nov-2007  matt sync with HEAD
 1.38.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.40.12.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.40.12.1 23-Jun-2013  tls resync from head
 1.40.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.79.2.1 02-Aug-2025  perseant Sync with HEAD
 1.8 30-Jul-2005  christos Remove unused files. From Max Okumoto.
 1.7 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.6 16-May-2002  wiz Comment out token after #endif.
 1.5 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.4 14-Jun-1995  christos branches: 1.4.6;
- $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.3 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.6.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.108 27-Apr-2024  rillig make: simplify freeing of lists
 1.107 29-Dec-2023  rillig make: unexport list memory management functions

They are only used in a single source file.

No functional change.
 1.106 26-Feb-2022  rillig make: fix memory leak in Lst_Remove (since 2020-10-23)

The code to free the list node (as opposed to the node data) was
accidentally removed in lst.c 1.83 from 2020-10-23 as part of cleaning
up an unnecessarily complicated function for traversing linked lists.

The memory leak only affected a few lists that actually used Lst_Remove.
Most lists are append-only and are freed using Lst_Done or Lst_Free at
the end, which correctly free the memory.
 1.105 15-Mar-2021  rillig make: fix documentation of Lst_MoveAll

In CLEANUP mode, was originally meant to track memory allocations but is
useful during debugging as well, initialize the list. There is no
distinct constant representing an invalid pointer, otherwise that would
have been an even better choice.
 1.104 01-Feb-2021  rillig make: clean up comments
 1.103 01-Feb-2021  rillig make: remove unused Lst_Destroy

The code in job.c that seemed to use it is inside an '#if 0' block.
 1.102 30-Dec-2020  rillig make(1): format multi-line comments
 1.101 13-Dec-2020  rillig make(1): rename Vector.priv_cap to cap

There is no use case for accessing or even modifying the capacity of a
vector, therefore there is no need to hide it using the prefix "priv_".
This way, the member names are aligned between Buffer and Vector.
 1.100 04-Dec-2020  rillig make(1): inline Lst_Enqueue
 1.99 04-Dec-2020  rillig make(1): inline Vector_Done
 1.98 04-Dec-2020  rillig make(1): use consistent variable names for list nodes
 1.97 29-Nov-2020  rillig make(1): reduce memory allocation in suffix handling

The function Lst_MoveAll previously freed the source list. This
function was only used in a few places, and none of them really needed
the allocation.
 1.96 28-Nov-2020  rillig make(1): reduce pointer indirection for archives
 1.95 28-Nov-2020  rillig make(1): remove pointer indirection from GNode.commands

Just to save a few memory allocations. No noticeable effect on the
performance though.
 1.94 27-Nov-2020  rillig make(1): inline Lst_ForEachUntil in meta mode

This means no more unnecessary void pointers in function signatures and
no more abstraction level at checking a single element of a list. In
most cases it is more appropriate to define a function that operates on
the list as a whole, thereby hiding implementation details like the
ListNode from the caller.
 1.93 24-Nov-2020  rillig make(1): indent list functions with tabs instead of spaces
 1.92 08-Nov-2020  rillig make(1): rename list node to ln

That's the name that is used for list nodes outside lst.c, and there is
no reason to use a different name in the implementation of lists. Sure,
the "l" of the name "ln" is redundant, but it's still shorter than
"node", and the latter sounds too similar to GNode.
 1.91 28-Oct-2020  rillig make(1): inline Vector_Get

It is simple enough that it neither bloats the code nor warrants the
extra function call.
 1.90 25-Oct-2020  rillig make(1): replace PtrVector with Vector, which can contain any type
 1.89 25-Oct-2020  rillig make(1): rename type Vector to PtrVector

This allows the name Vector to be used for a more generic vector type,
which will be added soon.
 1.88 25-Oct-2020  rillig make(1): inline Lst_Copy in Make_ExpandUse
 1.87 24-Oct-2020  rillig make(1): remove unused Lst_Find and Lst_FindFrom
 1.86 24-Oct-2020  rillig make(1): clean up comments in list functions
 1.85 24-Oct-2020  rillig make(1): clean up code in lst.c
 1.84 24-Oct-2020  rillig make(1): refactor LstNodeNew
 1.83 23-Oct-2020  rillig make(1): remove Lst_ForEachUntilConcurrent

The remaining callers of that function don't modify the list
structurally and thus can use the simpler Lst_ForEachUntil instead.
 1.82 22-Oct-2020  rillig make(1): add Lst_ForEachUntilConcurrent

Previously, Lst_ForEachUntil allowed the list to be modified while
iterating. Almost none of the code needs this, and it's also confusing
for human readers.

None of the current unit tests makes use of this concurrent modification
right now, but that's not evidence enough. Only 72% of the code are
covered by unit tests right now, and there are lots of edge cases
(whether intended or not) that are not covered by unit tests.

Therefore, all calls to Lst_ForEachUntil were changed to
Lst_ForEachUntilConcurrent and those that were obvious were changed
back. The remaining calls probably don't need the concurrent
modification code, but that's not obvious from looking at the code.
 1.81 22-Oct-2020  rillig make(1): remove Lst_Open, Lst_Next, Lst_Close

These functions had made the Lst data type more complicated and hard to
understand than necessary. This additional complexity was not needed in
the vast majority of the cases.
 1.80 22-Oct-2020  rillig make(1): remove code for circular lists from Lst_Next

Since make does not use circular lists, they have been removed from the
list library a few weeks ago.
 1.79 19-Oct-2020  rillig make(1): inline simple Lst getters

The function call variant takes more screen space than the direct field
access. Having an abstract API is usually a good idea, in this case of
simple read-only member access it makes the code more difficult to read.

LstNode_Set has been kept as a function since it is not a read-only
accessor function.
 1.78 19-Oct-2020  rillig make(1): remove unused Lst_ForEach

All of its uses have been inlined since iterating through a linked list
is trivial. This avoids the cumbersome callback functions with void
pointer parameters, allowing the compiler to perform better type checks.
 1.77 18-Oct-2020  rillig make(1): rename Lst_Init to Lst_New

For the other types such as HashTable and Buffer, the Init function does
not allocate the memory for the structure itself, it only fills it.
 1.76 18-Oct-2020  rillig make(1): rename Stack to Vector

Both Var_Dump and GetActuallyIncludingFile access more than only the top
item of the stack, therefore it is more honest to rename the data type.
 1.75 17-Oct-2020  rillig make(1): fix indentation
 1.74 30-Sep-2020  rillig make(1): remove redundant assertions in lst.c

These pointers are dereferenced shortly after the assertion, which
reliably leads to a SIGSEGV.
 1.73 27-Sep-2020  rillig make(1): normalize whitespace in source code

There is no more space tab. Either only tabs or only spaces or tabs
followed by spaces, but not spaces followed by tabs.
 1.72 26-Sep-2020  rillig make(1): inline and remove LstNode_Prev and LstNode_Next

These functions made the code larger than necessary. The prev and next
fields are published intentionally since navigating in a doubly-linked
list is simple to do and there is no need to wrap this in a layer of
function calls, not even syntactically. (On the execution level, the
function calls had been inlined anyway.)
 1.71 25-Sep-2020  rillig make(1): fix build on Debian 9

lst.h:92:5: error: unknown type name 'uint8_t'

It had been broken since the previous commit on 2020-09-24 08:23:29.
 1.70 24-Sep-2020  rillig make(1): make the API of the List partially public

Accessing the fields List.first, List.last, ListNode.prev, ListNode.next
and ListNode.datum in read-only mode should be more efficient than a
whole function call.

All modifications to the lists or their nodes must still happen via
function calls.

This change reduces the code size, makes the code faster to execute and
allows Lst_ForEach to be written inline without the visual overhead of
function calls.
 1.69 24-Sep-2020  rillig make(1): move documentation for MakeAddAllSrc to its correct place
 1.68 24-Sep-2020  rillig make(1): merge Lst_ForEachFrom into Lst_ForEachUntil
 1.67 24-Sep-2020  rillig make(1): rename Lst_ForEach to Lst_ForEachUntil

Since the callback function returns a terminating condition, this is not
really a foreach loop.

Many of the calls to Lst_ForEachUntil don't make use of the terminating
condition, and several don't modify the list structurally, which means
they don't need this complicated implementation.

In a follow-up commit, Lst_ForEach will be added back with a much
simpler implementation that iterates over the list naively, without a
terminating condition and without taking the iteration state from
Lst_Open/Lst_Next/Lst_Close into account. The migration to this simpler
implementation will be done step by step since each callback function
needs to be examined closely.
 1.66 24-Sep-2020  rillig make(1): refactor add_wait_dep to not use Lst_ForEachFrom anymore

It was the last remaining use of that function outside of lst.c.

While here, clean up the code of add_wait_dep by removing unreachable
code (the GNode lists never contain NULL, only the GNode.commands lists
do that).
 1.65 22-Sep-2020  rillig make(1): use fine-grained type names for lists and their nodes

This is only intended to help the human reader. There is no additional
type safety yet.
 1.64 14-Sep-2020  rillig make(1): in debug mode, reset unused stack space to NULL
 1.63 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.62 12-Sep-2020  rillig make(1): fix inconsistent code indentation
 1.61 04-Sep-2020  rillig make(1): use a stack instead of a list for the nested include path

By using a Stack instead of a Lst, the available API is reduced to the
very few functions that are really needed for a stack. This prevents
accidental misuse (such as confusing Lst_Append with Lst_Prepend) and
clearly communicates what the expected behavior is.

A stack also needs fewer calls to bmake_malloc than an equally-sized
list, and the memory is contiguous. For the nested include path, all
this doesn't matter, but the type is so generic that it may be used in
other places as well.
 1.60 31-Aug-2020  rillig make(1): fix unbalanced Lst_Open/Lst_Close in SuffFindCmds

This bug had been there since the initial import of make, on 1993-03-21.
It just never broke the build because of the missing assertion.

https://mail-index.netbsd.org/tech-toolchain/2020/08/30/msg003847.html

The error message "cd: can't cd to include" that I got when I first
applied the fix was unrelated. It was caused by an extra directory
"include" in src/tools/compat that didn't belong there. With that
directory removed, running "./build.sh -j8 tools" succeeds as expected.
 1.59 30-Aug-2020  rillig make(1): fix comment for Lst_Destroy
 1.58 30-Aug-2020  rillig make(1): rename Lst_Datum to LstNode_Datum
 1.57 30-Aug-2020  rillig make(1): rename Lst_Memeber to Lst_FindDatum

The new name nicely aligns with Lst_Find and Lst_FindFrom.
 1.56 29-Aug-2020  rillig make(1): rename LstNode functions to match their type
 1.55 29-Aug-2020  rillig make(1): rename Lst_FindB back to Lst_Find

The migration from "comparison function" to "match function" is done,
the "B" in the names is no longer needed.
 1.54 29-Aug-2020  rillig make(1): migrate remaining Lst_Find to Lst_FindB

While here, rename SuffSuffIsSuffix to SuffSuffGetSuffix since a
function named "is" should return a boolean, not a string pointer.
 1.53 29-Aug-2020  rillig make(1): start replacing Lst_Find with Lst_FindB

Lst_Find is called with a "comparison" function that returns the integer
0 if the desired node is found. This leads to confusion since there are
so many different return value conventions for int, such as 0/1 for
mimicking false/true, -1/0 as in close(2), and the sign as in strcmp(3).
This API is much easier to understand if the "comparison" function is
not called a comparison function (since that is too close to strcmp),
but a "match" function that just returns a boolean.

In Lst_FindFromB, the node argument may be null. This deviates from the
other Lst functions, which require Lst and LstNode to generally be
non-null. In this case it is useful though to make the calling code
simpler.

In arch.c, this makes a lot of the previous documentation redundant.

In cond.c, the documentation is reduced a little bit since it had
already been cleaned up before. It also removes the strange negation
from CondFindStrMatch.

In dir.c, the documentation collapses as well.

In main.c, separating the ReadMakefile function from the callbacks for
Lst_FindB allows the former to get back its natural function signature,
with proper types and no unused parameters.

To catch any accidental mistakes during the migration from Lst_Find to
Lst_FindB, the code can be compiled with -DUSE_DOUBLE_BOOLEAN, which
will complain about incompatible function pointer types.
 1.52 28-Aug-2020  rillig make(1): inline LstIsValid and LstNodeIsValid

A simple null pointer comparison is easier to understand than the fuzzy
word "valid".
 1.51 28-Aug-2020  rillig make(1): fix build errors for USER_CPPFLAGS=-DNDEBUG

The functions LstIsValid and LstNodeIsValid are only used in assertions.

Without the always-false assertion, Enum_ValueToString could have
returned undefined behavior.
 1.50 28-Aug-2020  rillig make(1): remove trailing 'S' from names of Lst functions

The migration from null-passing Lst functions to argument-checking Lst
functions is completed.

There were 2 surprises: The targets list may be NULL, and in Dir_AddDir,
the path may be NULL. The latter case is especially surprising since
that function turns into an almost-nop in that case. This is another
case where probably 2 independent functions have been squeezed into a
single function. This may be improved in a follow-up commit.

All other lists were fine. They were always defined and thus didn't
need much work.
 1.49 28-Aug-2020  rillig make(1): migrate Lst_Find to Lst_FindS
 1.48 28-Aug-2020  rillig make(1): migrate Lst_First to Lst_FirstS
 1.47 27-Aug-2020  rillig make(1): migrate Lst_IsEmpty to Lst_IsEmptyS
 1.46 27-Aug-2020  rillig make(1): migrate Lst_Last to Lst_LastS
 1.45 27-Aug-2020  rillig make(1): migrate Lst_Succ to Lst_SuccS
 1.44 27-Aug-2020  rillig make(1): migrate Lst_ForEach to Lst_ForEachS

Most lists are always valid. Only the "targets" variable may be null in
some cases, probably.
 1.43 27-Aug-2020  rillig make(1): migrate remaining code from Lst_Open to Lst_OpenS
 1.42 26-Aug-2020  rillig make(1): add stricter variants for remaining Lst functions

In most cases the Lst functions are only called when the arguments are
indeed valid. It's not guaranteed though, therefore each function call
needs to be analyzed and converted individually.

While here, remove a few statements that were only useful when the Lst
functions handled circular lists.
 1.41 23-Aug-2020  rillig make(1): reverse order of the Lst_Find parameters

The other callbacks all have (function, param), only the Lst_Find had
(param, function), which was inconsistent.
 1.40 23-Aug-2020  rillig make(1): define aliases for function types in list processing

This makes the prototypes of the functions clearer.
 1.39 23-Aug-2020  rillig make(1): make navigating lists in debugging mode easier

Lst is an untyped list of pointers. During debugging, it is often
necessary to inspect the content of the list. To do this without manual
typecasting, add a few aliases for the LstNode.datum pointer, for
inspecting GNodes and strings.
 1.38 23-Aug-2020  rillig make(1): remove another piece of code for circular lists
 1.37 23-Aug-2020  rillig make(1): handle special case of a list containing null pointers

GNode.commands is the only place in make where a list can contain null
pointers. That's unexpected, and memory management in CompatRunCommand
looks suspicous enough to warrant extensive documentation.
 1.36 22-Aug-2020  rillig make(1): migrate Lst_AtFront to Lst_PrependS

This makes Lst_AtFront unused, as well as LstInsertBefore.
 1.35 22-Aug-2020  rillig make(1): replace Lst_Duplicate with Lst_CopyS

Lst_Duplicate would have passed through any null pointer, which was not
needed for make. It was the last function that used Lst_AtEnd, which in
turn was the last function that used LstInsertAfter. As a result, these
two functions have been removed.
 1.34 22-Aug-2020  rillig make(1): make moving and copying lists simpler

Instead of the two-in-one Lst_Concat, having two separate functions is
easier to understand. There is no need for a long API comment anymore
since the new functions have a single purpose that is accurately
described by their name.

The long comment inside Lst_Concat has been removed since it only
repeated the exact code, only in more words.

The comments in make.c about appending the cohorts had been wrong. They
were not appended but prepended. Once more, the function name expresses
everything that the comment said, making the comment redundant. There
is no need to test whether the cohorts list is empty, doing nothing is
implied by the word All in Lst_PrependAllS.
 1.33 22-Aug-2020  rillig make(1): make Lst_Prev stricter regarding null pointers
 1.32 22-Aug-2020  rillig make(1): clean up headers

Remove redundant headers that are already included by "make.h".
Make <assert.h> available to all compilation units that use "make.h".
 1.31 22-Aug-2020  rillig make(1): fix indentation
 1.30 22-Aug-2020  skrll #include <stdint.h> for uint8_t
 1.29 22-Aug-2020  rillig make(1): require argument of Lst_Member to be non-null

Since the lists don't contain null pointers, it doesn't make sense to
search for a null pointer. All calls but one already had obviously
non-null arguments. The one remaining call using targ->suff has been
guarded for now.

The code for Lst_Member became much simpler than before. Partly because
the old code had an extra condition for circular lists, which are not
used by make.
 1.28 22-Aug-2020  rillig make(1): replace Lst_Datum with non-null guaranteeing Lst_DatumS
 1.27 22-Aug-2020  rillig make(1): unexport Lst_InsertBefore and Lst_InsertAfter
 1.26 22-Aug-2020  rillig make(1): add strict argument checks for Lst_InsertBefore

As with the other modifying operations on lists, the callers already
made sure that the arguments are valid.
 1.25 22-Aug-2020  rillig make(1): convert Lst_Enqueue and Lst_Dequeue to nonnull variants

Except for once instance in parse.c, the usage pattern for Lst_Dequeue
was to first test whether the list is empty. This pattern allowed the
implementation of Lst_Dequeue to become simpler since the null check is
not needed anymore.

The calls to Lst_Enqueue never pass an invalid list or a null pointer,
therefore making them strict was trivial.
 1.24 22-Aug-2020  rillig make(1): allow the inconsistency with Lst_OpenS to be discovered

The -dL option is intended to find bugs in Makefiles and in make itself,
therefore enabling the consistency check is ok there. Having this check
available by default increases the chances of the bug being found and
finally fixed.
 1.23 22-Aug-2020  rillig make(1): convert remaining Lst_AtEnd to the stricter Lst_Append

The general-purpose list library that is included in make allows to call
Lst_AtEnd for invalid lists, silently ignoring this programming error.
This is a flexibility that make doesn't need.

Another unneeded "feature" is that list items can theoretically be null
pointers. This doesn't make sense as well and is therefore not needed
by make.

These programming errors are now caught early by assertions.
 1.22 22-Aug-2020  rillig make(1): make Make_HandleUse simpler

Since the function names now contain the text from the comments, the
comments can be shortened a bit.
 1.21 22-Aug-2020  rillig make(1): add Lst_Append to add an item at the end of the list

The previous variant of using a special case of Lst_InsertAfter was
unnecessarily complicated. Linked lists are a very basic data
structure, and there is no need to overcomplicate things by introducing
unnecessary conditions and branches.
 1.20 22-Aug-2020  rillig make(1): rename local list functions

Since the name of LstIsValid and LstNodeIsValid now matches exactly the
comment, the comment is not needed anymore.
 1.19 22-Aug-2020  rillig make(1): document the recently failed assertion in Lst_OpenS

In make, a list has a single iterator that can be used with Lst_Open,
Lst_Next and Lst_Close. Because this is a single iterator, it doesn't
make sense to call Lst_Open twice in a row without the corresponding
Lst_Close. Exactly this happens in jobs mode though.
 1.18 21-Aug-2020  rillig make(1): revert invalid assertion

When iterating over a list, it is currently not guaranteed that the list
is marked as "!isOpen", which I had wrongly and naively assumed.

This probably means that there is some hidden bug in make, but even if
there is, this bug would be quite old already and was too small to be
detected.

Therefore, remove the assertion again, until the situation is clear and
reproduced.
 1.17 21-Aug-2020  rillig make(1): clean up list handling

Lst_Init never returns NULL. Casting postfix increment to void is
unnecessary since that is quite common. Found a last instance of a
local variable named 'nlnode'.
 1.16 21-Aug-2020  rillig make(1): remove type information from local variables in list library

Every node in this file is of type LstNode, which makes the 'l' in the
name 'ln' redundant. The name 'ln' is quite close to the name 'l',
which in turn can easily be confused with the digit '1'. Therefore,
rename 'l' to 'list' and 'ln' to 'node'.
 1.15 21-Aug-2020  rillig make(1): use shorter field names in Lst and LstNode

In a doubly linked list, it is commonly known that the 'prev' and 'next'
fields of the nodes are pointers to other nodes, therefore this does not
need to be repeated in the variable name.
 1.14 21-Aug-2020  rillig make(1): condense the API comments in the list library

Most mentioned "side effects" were either implementation details or
rather "main effects". The wording of similar functions has been
aligned.
 1.13 21-Aug-2020  rillig make(1): remove unnecessary type duplication in list implementation

Having both the interface types Lst/LstNode and the implementation types
List/ListNode does not make the code clearer, it is an unnecessary
abstraction. Eliminating the implementation type means that some of the
local variables can be merged, which will make the code simpler than
before.
 1.12 21-Aug-2020  rillig make(1): extract creation of a list node into a separate function
 1.11 21-Aug-2020  rillig make(1): remove unnecessary macro PAlloc

The ptype parameter was never used, which made it redundant. The
remaining text is so simple that it's not worth having a macro for this
purpose. This makes it easier to read the code since the previously
implicit variable assignment is now clearly visible.
 1.10 21-Aug-2020  rillig make(1): use stricter list API for sequential access

In several places, it just doesn't make sense to have a null pointer
when a list is expected.

In the existing unit tests, the list passed to Lst_Open is always valid,
but that's not a guarantee for real-world usage. Therefore, Lst_Open
has been left for now, and Lst_OpenS is only the preferred alternative
to it.
 1.9 21-Aug-2020  rillig make(1): assert correct usage of the Lst_Open API

All calls to Lst_Next are properly protected by Lst_Open, so there is no
possible assertion failure here.
 1.8 21-Aug-2020  rillig make(1): make list library code stricter

Up to now, the list library didn't distinguish between programming
mistakes (violations of invariants, illegal parameter values) and
actually interesting situations like "element not found in list".

The current code contains many branches for conditions that are neither
exercised by the unit tests nor by real-world usage. There is no point
in keeping this unnecessary code.

The list functions will be migrated from their lenient variants to the
stricter variants in small parts, each function getting the S suffix
when it is made strict, to avoid any confusion about how strict a
particular function is. When all functions have been migrated, they
will be renamed back to their original names.

While here, the comments of the functions are cleaned up since they
mention irrelevant implementation details in the API comments, as well
as "side effects" that are really main effects.
 1.7 21-Aug-2020  rillig make(1): don't use bitfields in list processing

There is no need to squeeze unrelated fields of the struct into a single
object. A bitset with a single flag is the same as a simple boolean
variable.
 1.6 21-Aug-2020  rillig make(1): properly clean up the remaining code mentioning circular lists
 1.5 21-Aug-2020  rillig make(1): remove unused code for circular lists

The list library had probably been imported from a general-purpose
library that also supported circular lists. These are not used by make
though.

After replacing Lst_Init(FALSE) with Lst_Init(), only a single call to
Lst_Init remained with a non-constant argument, and that was in
Lst_Concat, which was to be expected.
 1.4 09-Aug-2020  rillig make(1): fix inconsistent formatting in lst.c
 1.3 01-Aug-2020  rillig make(1): use consistent indentation in source code

Tabs for multiples of 8, then spaces.

The usage string has been kept as-is since the spaces there are
indentional and do influence the output.
 1.2 26-Jul-2020  rillig make(1): replace macros with functions
 1.1 26-Jul-2020  rillig make(1): condense the list library into a single file

The list library is only used in make(1). Having it spread out over 28
files made it look more complex than it really is. In fact, it's just a
versatile generic data type like in hash.c.

Having all the list functions in a single file reduces the code size,
both by omitting the many RCS Ids and by inlining commonly used code.
 1.105 27-Apr-2024  rillig make: simplify freeing of lists
 1.104 29-Dec-2023  rillig make: unexport list memory management functions

They are only used in a single source file.

No functional change.
 1.103 03-Mar-2022  rillig make: improve comments and a parameter name

No binary change.
 1.102 15-Dec-2021  rillig make: use consistent indentation for statements and continuations

No binary change, except for line numbers in assertions in suff.c.
 1.101 15-Dec-2021  rillig make: remove redundant comments for multiple-inclusion guards
 1.100 15-Dec-2021  rillig make: mark several functions whose result must be used

Suggested by sjg, to catch more bugs like the memory leak in cond.c
1.303 from 2021-12-13.

No binary change.
 1.99 05-Dec-2021  rillig make: fix comments
 1.98 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.97 15-Mar-2021  rillig make: indent inline functions for lists

No functional change.
 1.96 01-Feb-2021  rillig make: remove unused Lst_Destroy

The code in job.c that seemed to use it is inside an '#if 0' block.
 1.95 03-Jan-2021  rillig make(1): remove anonymous union from struct ListNode

Anonymous structs and unions have been introduced in C11. The code of
make is supposed to be compatible with C90 though.

The additional members were intended to be used during an interactive
debugging session only and were thus not relevant to running the actual
code.
 1.94 30-Dec-2020  rillig make(1): format multi-line comments
 1.93 13-Dec-2020  rillig make(1): rename Vector.priv_cap to cap

There is no use case for accessing or even modifying the capacity of a
vector, therefore there is no need to hide it using the prefix "priv_".
This way, the member names are aligned between Buffer and Vector.
 1.92 04-Dec-2020  rillig make(1): inline Lst_Enqueue
 1.91 04-Dec-2020  rillig make(1): inline Vector_Done
 1.90 28-Nov-2020  rillig make(1): reduce memory allocation in Arch_ParseArchive
 1.89 28-Nov-2020  rillig make(1): reduce pointer indirection for archives
 1.88 28-Nov-2020  rillig make(1): remove pointer indirection from GNode.commands

Just to save a few memory allocations. No noticeable effect on the
performance though.
 1.87 27-Nov-2020  rillig make(1): inline Lst_ForEachUntil in meta mode

This means no more unnecessary void pointers in function signatures and
no more abstraction level at checking a single element of a list. In
most cases it is more appropriate to define a function that operates on
the list as a whole, thereby hiding implementation details like the
ListNode from the caller.
 1.86 24-Nov-2020  rillig make(1): indent list functions with tabs instead of spaces
 1.85 10-Nov-2020  rillig make(1): use consistent definition for MAKE_INLINE
 1.84 28-Oct-2020  rillig make(1): inline Vector_Get

It is simple enough that it neither bloats the code nor warrants the
extra function call.
 1.83 25-Oct-2020  rillig make(1): remove obsolete comment from lst.h
 1.82 25-Oct-2020  rillig make(1): replace PtrVector with Vector, which can contain any type
 1.81 25-Oct-2020  rillig make(1): rename type Vector to PtrVector

This allows the name Vector to be used for a more generic vector type,
which will be added soon.
 1.80 25-Oct-2020  rillig make(1): inline Lst_Copy in Make_ExpandUse
 1.79 24-Oct-2020  rillig make(1): remove unused Lst_Find and Lst_FindFrom
 1.78 23-Oct-2020  rillig make(1): remove Lst_ForEachUntilConcurrent

The remaining callers of that function don't modify the list
structurally and thus can use the simpler Lst_ForEachUntil instead.
 1.77 22-Oct-2020  rillig make(1): add Lst_ForEachUntilConcurrent

Previously, Lst_ForEachUntil allowed the list to be modified while
iterating. Almost none of the code needs this, and it's also confusing
for human readers.

None of the current unit tests makes use of this concurrent modification
right now, but that's not evidence enough. Only 72% of the code are
covered by unit tests right now, and there are lots of edge cases
(whether intended or not) that are not covered by unit tests.

Therefore, all calls to Lst_ForEachUntil were changed to
Lst_ForEachUntilConcurrent and those that were obvious were changed
back. The remaining calls probably don't need the concurrent
modification code, but that's not obvious from looking at the code.
 1.76 22-Oct-2020  rillig make(1): remove Lst_Open, Lst_Next, Lst_Close

These functions had made the Lst data type more complicated and hard to
understand than necessary. This additional complexity was not needed in
the vast majority of the cases.
 1.75 21-Oct-2020  rillig make(1): remove unused typedef LstActionProc
 1.74 19-Oct-2020  rillig make(1): inline simple Lst getters

The function call variant takes more screen space than the direct field
access. Having an abstract API is usually a good idea, in this case of
simple read-only member access it makes the code more difficult to read.

LstNode_Set has been kept as a function since it is not a read-only
accessor function.
 1.73 19-Oct-2020  rillig make(1): remove unused Lst_ForEach

All of its uses have been inlined since iterating through a linked list
is trivial. This avoids the cumbersome callback functions with void
pointer parameters, allowing the compiler to perform better type checks.
 1.72 18-Oct-2020  rillig make(1): add tags to enum types

This allows IDEs to offer better type information than "anonymous enum".
 1.71 18-Oct-2020  rillig make(1): rename Lst_Init to Lst_New

For the other types such as HashTable and Buffer, the Init function does
not allocate the memory for the structure itself, it only fills it.
 1.70 18-Oct-2020  rillig make(1): rename Stack to Vector

Both Var_Dump and GetActuallyIncludingFile access more than only the top
item of the stack, therefore it is more honest to rename the data type.
 1.69 26-Sep-2020  rillig make(1): inline and remove LstNode_Prev and LstNode_Next

These functions made the code larger than necessary. The prev and next
fields are published intentionally since navigating in a doubly-linked
list is simple to do and there is no need to wrap this in a layer of
function calls, not even syntactically. (On the execution level, the
function calls had been inlined anyway.)
 1.68 25-Sep-2020  rillig make(1): add tags to some of the unnamed structs

The tags prevent the structs from accidentally becoming compatible
types.

While here, remove a few typedefs for structs that are single-purpose,
since there is no point in abstracting from the actual representation of
these types.
 1.67 25-Sep-2020  rillig make(1): fix build on Debian 9

lst.h:92:5: error: unknown type name 'uint8_t'

It had been broken since the previous commit on 2020-09-24 08:23:29.
 1.66 24-Sep-2020  rillig make(1): make the API of the List partially public

Accessing the fields List.first, List.last, ListNode.prev, ListNode.next
and ListNode.datum in read-only mode should be more efficient than a
whole function call.

All modifications to the lists or their nodes must still happen via
function calls.

This change reduces the code size, makes the code faster to execute and
allows Lst_ForEach to be written inline without the visual overhead of
function calls.
 1.65 24-Sep-2020  rillig make(1): move documentation for MakeAddAllSrc to its correct place
 1.64 24-Sep-2020  rillig make(1): rename Lst_ForEach to Lst_ForEachUntil

Since the callback function returns a terminating condition, this is not
really a foreach loop.

Many of the calls to Lst_ForEachUntil don't make use of the terminating
condition, and several don't modify the list structurally, which means
they don't need this complicated implementation.

In a follow-up commit, Lst_ForEach will be added back with a much
simpler implementation that iterates over the list naively, without a
terminating condition and without taking the iteration state from
Lst_Open/Lst_Next/Lst_Close into account. The migration to this simpler
implementation will be done step by step since each callback function
needs to be examined closely.
 1.63 24-Sep-2020  rillig make(1): refactor add_wait_dep to not use Lst_ForEachFrom anymore

It was the last remaining use of that function outside of lst.c.

While here, clean up the code of add_wait_dep by removing unreachable
code (the GNode lists never contain NULL, only the GNode.commands lists
do that).
 1.62 22-Sep-2020  rillig make(1): use fine-grained type names for lists and their nodes

This is only intended to help the human reader. There is no additional
type safety yet.
 1.61 04-Sep-2020  rillig make(1): use a stack instead of a list for the nested include path

By using a Stack instead of a Lst, the available API is reduced to the
very few functions that are really needed for a stack. This prevents
accidental misuse (such as confusing Lst_Append with Lst_Prepend) and
clearly communicates what the expected behavior is.

A stack also needs fewer calls to bmake_malloc than an equally-sized
list, and the memory is contiguous. For the nested include path, all
this doesn't matter, but the type is so generic that it may be used in
other places as well.
 1.60 02-Sep-2020  rillig make(1): improve grouping of the Lst functions

Lst_IsEmpty does not belong in the "create and destroy" group, but in
"query information without modifying anything".

The functions named LstNode_* all belong together. They do not provide
much abstraction, but still they restrict the API and hide a few struct
fields that are only used internally by Lst_Open/Lst_Close and
Lst_ForEach.

Use consistent wording in the documentation of the functions (list,
node, datum).
 1.59 30-Aug-2020  rillig make(1): rename Lst_Datum to LstNode_Datum
 1.58 30-Aug-2020  rillig make(1): rename Lst_Memeber to Lst_FindDatum

The new name nicely aligns with Lst_Find and Lst_FindFrom.
 1.57 29-Aug-2020  rillig make(1): rename LstNode functions to match their type
 1.56 29-Aug-2020  rillig make(1): rename Lst_FindB back to Lst_Find

The migration from "comparison function" to "match function" is done,
the "B" in the names is no longer needed.
 1.55 29-Aug-2020  rillig make(1): migrate remaining Lst_Find to Lst_FindB

While here, rename SuffSuffIsSuffix to SuffSuffGetSuffix since a
function named "is" should return a boolean, not a string pointer.
 1.54 29-Aug-2020  rillig make(1): start replacing Lst_Find with Lst_FindB

Lst_Find is called with a "comparison" function that returns the integer
0 if the desired node is found. This leads to confusion since there are
so many different return value conventions for int, such as 0/1 for
mimicking false/true, -1/0 as in close(2), and the sign as in strcmp(3).
This API is much easier to understand if the "comparison" function is
not called a comparison function (since that is too close to strcmp),
but a "match" function that just returns a boolean.

In Lst_FindFromB, the node argument may be null. This deviates from the
other Lst functions, which require Lst and LstNode to generally be
non-null. In this case it is useful though to make the calling code
simpler.

In arch.c, this makes a lot of the previous documentation redundant.

In cond.c, the documentation is reduced a little bit since it had
already been cleaned up before. It also removes the strange negation
from CondFindStrMatch.

In dir.c, the documentation collapses as well.

In main.c, separating the ReadMakefile function from the callbacks for
Lst_FindB allows the former to get back its natural function signature,
with proper types and no unused parameters.

To catch any accidental mistakes during the migration from Lst_Find to
Lst_FindB, the code can be compiled with -DUSE_DOUBLE_BOOLEAN, which
will complain about incompatible function pointer types.
 1.53 28-Aug-2020  rillig make(1): remove trailing 'S' from names of Lst functions

The migration from null-passing Lst functions to argument-checking Lst
functions is completed.

There were 2 surprises: The targets list may be NULL, and in Dir_AddDir,
the path may be NULL. The latter case is especially surprising since
that function turns into an almost-nop in that case. This is another
case where probably 2 independent functions have been squeezed into a
single function. This may be improved in a follow-up commit.

All other lists were fine. They were always defined and thus didn't
need much work.
 1.52 28-Aug-2020  rillig make(1): migrate Lst_Find to Lst_FindS
 1.51 28-Aug-2020  rillig make(1): remove unused reference to Lst_Last
 1.50 28-Aug-2020  rillig make(1): migrate Lst_First to Lst_FirstS
 1.49 27-Aug-2020  rillig make(1): migrate Lst_IsEmpty to Lst_IsEmptyS
 1.48 27-Aug-2020  rillig make(1): migrate Lst_Succ to Lst_SuccS
 1.47 27-Aug-2020  rillig make(1): migrate Lst_ForEach to Lst_ForEachS

Most lists are always valid. Only the "targets" variable may be null in
some cases, probably.
 1.46 27-Aug-2020  rillig make(1): migrate remaining code from Lst_Open to Lst_OpenS
 1.45 26-Aug-2020  rillig make(1): remove header sprite.h

Make is independent of the Sprite operating system.
 1.44 26-Aug-2020  rillig make(1): add stricter variants for remaining Lst functions

In most cases the Lst functions are only called when the arguments are
indeed valid. It's not guaranteed though, therefore each function call
needs to be analyzed and converted individually.

While here, remove a few statements that were only useful when the Lst
functions handled circular lists.
 1.43 23-Aug-2020  rillig make(1): remove unused declarations from header files
 1.42 23-Aug-2020  rillig make(1): remove parameter names from function prototypes

Thanks kre for noticing.
 1.41 23-Aug-2020  rillig make(1): reverse order of the Lst_Find parameters

The other callbacks all have (function, param), only the Lst_Find had
(param, function), which was inconsistent.
 1.40 23-Aug-2020  rillig make(1): define aliases for function types in list processing

This makes the prototypes of the functions clearer.
 1.39 23-Aug-2020  rillig make(1): handle special case of a list containing null pointers

GNode.commands is the only place in make where a list can contain null
pointers. That's unexpected, and memory management in CompatRunCommand
looks suspicous enough to warrant extensive documentation.
 1.38 22-Aug-2020  rillig make(1): replace Lst_Duplicate with Lst_CopyS

Lst_Duplicate would have passed through any null pointer, which was not
needed for make. It was the last function that used Lst_AtEnd, which in
turn was the last function that used LstInsertAfter. As a result, these
two functions have been removed.
 1.37 22-Aug-2020  rillig make(1): make moving and copying lists simpler

Instead of the two-in-one Lst_Concat, having two separate functions is
easier to understand. There is no need for a long API comment anymore
since the new functions have a single purpose that is accurately
described by their name.

The long comment inside Lst_Concat has been removed since it only
repeated the exact code, only in more words.

The comments in make.c about appending the cohorts had been wrong. They
were not appended but prepended. Once more, the function name expresses
everything that the comment said, making the comment redundant. There
is no need to test whether the cohorts list is empty, doing nothing is
implied by the word All in Lst_PrependAllS.
 1.36 22-Aug-2020  rillig make(1): make Lst_Prev stricter regarding null pointers
 1.35 22-Aug-2020  rillig make(1): require argument of Lst_Member to be non-null

Since the lists don't contain null pointers, it doesn't make sense to
search for a null pointer. All calls but one already had obviously
non-null arguments. The one remaining call using targ->suff has been
guarded for now.

The code for Lst_Member became much simpler than before. Partly because
the old code had an extra condition for circular lists, which are not
used by make.
 1.34 22-Aug-2020  rillig make(1): replace Lst_Datum with non-null guaranteeing Lst_DatumS
 1.33 22-Aug-2020  rillig make(1): unexport Lst_InsertBefore and Lst_InsertAfter
 1.32 22-Aug-2020  rillig make(1): add strict argument checks for Lst_InsertBefore

As with the other modifying operations on lists, the callers already
made sure that the arguments are valid.
 1.31 22-Aug-2020  rillig make(1): convert Lst_Enqueue and Lst_Dequeue to nonnull variants

Except for once instance in parse.c, the usage pattern for Lst_Dequeue
was to first test whether the list is empty. This pattern allowed the
implementation of Lst_Dequeue to become simpler since the null check is
not needed anymore.

The calls to Lst_Enqueue never pass an invalid list or a null pointer,
therefore making them strict was trivial.
 1.30 22-Aug-2020  rillig make(1): convert remaining Lst_AtEnd to the stricter Lst_Append

The general-purpose list library that is included in make allows to call
Lst_AtEnd for invalid lists, silently ignoring this programming error.
This is a flexibility that make doesn't need.

Another unneeded "feature" is that list items can theoretically be null
pointers. This doesn't make sense as well and is therefore not needed
by make.

These programming errors are now caught early by assertions.
 1.29 22-Aug-2020  rillig make(1): make Make_HandleUse simpler

Since the function names now contain the text from the comments, the
comments can be shortened a bit.
 1.28 22-Aug-2020  rillig make(1): add Lst_Append to add an item at the end of the list

The previous variant of using a special case of Lst_InsertAfter was
unnecessarily complicated. Linked lists are a very basic data
structure, and there is no need to overcomplicate things by introducing
unnecessary conditions and branches.
 1.27 21-Aug-2020  rillig make(1): remove type information from local variables in list library

Every node in this file is of type LstNode, which makes the 'l' in the
name 'ln' redundant. The name 'ln' is quite close to the name 'l',
which in turn can easily be confused with the digit '1'. Therefore,
rename 'l' to 'list' and 'ln' to 'node'.
 1.26 21-Aug-2020  rillig make(1): use stricter list API for sequential access

In several places, it just doesn't make sense to have a null pointer
when a list is expected.

In the existing unit tests, the list passed to Lst_Open is always valid,
but that's not a guarantee for real-world usage. Therefore, Lst_Open
has been left for now, and Lst_OpenS is only the preferred alternative
to it.
 1.25 21-Aug-2020  rillig make(1): assert correct usage of the Lst_Open API

All calls to Lst_Next are properly protected by Lst_Open, so there is no
possible assertion failure here.
 1.24 21-Aug-2020  rillig make(1): make list library code stricter

Up to now, the list library didn't distinguish between programming
mistakes (violations of invariants, illegal parameter values) and
actually interesting situations like "element not found in list".

The current code contains many branches for conditions that are neither
exercised by the unit tests nor by real-world usage. There is no point
in keeping this unnecessary code.

The list functions will be migrated from their lenient variants to the
stricter variants in small parts, each function getting the S suffix
when it is made strict, to avoid any confusion about how strict a
particular function is. When all functions have been migrated, they
will be renamed back to their original names.

While here, the comments of the functions are cleaned up since they
mention irrelevant implementation details in the API comments, as well
as "side effects" that are really main effects.
 1.23 21-Aug-2020  rillig make(1): properly clean up the remaining code mentioning circular lists
 1.22 21-Aug-2020  rillig make(1): remove unused code for circular lists

The list library had probably been imported from a general-purpose
library that also supported circular lists. These are not used by make
though.

After replacing Lst_Init(FALSE) with Lst_Init(), only a single call to
Lst_Init remained with a non-constant argument, and that was in
Lst_Concat, which was to be expected.
 1.21 13-Aug-2020  rillig make(1): follow naming conventions for multiple-inclusion guards

This avoids undefined behavior.
 1.20 07-Sep-2014  joerg Revert all make changes except the unit tests to the state of three
weeks ago. Individual changes can be reapplied after review.
 1.19 23-Aug-2014  christos PR/46096: Jarmo Jaakkola: fix many problems with dependencies (PR 49086)

Quite extensive rewrite of the Suff module. Some ripple effects into
Parse and Targ modules too.

Dependency searches in general were made to honor explicit rules so
implicit and explicit sources are no longer applied on targets that
do not invoke a transformation rule.

Archive member dependency search was rewritten. Explicit rules now
work properly and $(.TARGET) is set correctly. POSIX semantics for
lib(member.o) and .s1.a rules are supported.

.SUFFIXES list maintenance was rewritten so that scanning of existing
rules works when suffixes are added and that clearing the suffix list
removes single suffix rules too. Transformation rule nodes are now
mixed with regular nodes so they are available as regular targets too
if needed (especially after the known suffixes are cleared).

The .NULL target was documented in the manual page, especially to
warn against using it when a single suffix rule would work.
A deprecation warning was also added to the manual and make also
warns the user if it encounters .NULL.

Search for suffix rules no longer allows the explicit dependencies
to override the selected transformation rule. A check is made in
the search that the transformation that would be tried does not
already exist in the chain. This prevents getting stuck in an infinite
loop under specific circumstances. Local variables are now set
before node's children are expanded so dynamic sources work in
multi-stage transformations. Make_HandleUse() no longer expands
the added children for transformation nodes, preventing triple
expansion and allowing the Suff module to properly postpone their
expansion until proper values are set for the local variables.

Directory prefix is no longer removed from $(.PREFIX) if the target
is found via directory search.

The last rule defined is now used instead of the first one (POSIX
requirement) in case a rule is defined multiple times. Everything
defined in the first instance is undone, but things added "globally"
are honored. To implement this, each node tracks attribute bits
which have been set by special targets (global) instead of special
sources (local). They also track dependencies that were added by
a rule with commands (local) instead of rule with no commands (global).

New attribute, OP_FROM_SYS_MK is introduced. It is set on all targets
found in system makefiles so that they are not eligible to become
the main target. We cannot just set OP_NOTMAIN because it is one of
the attributes inherited from transformation and .USE rules and would
make any eligible target that uses a built-in inference rule ineligible.

The $(.IMPSRC) local variable now works like in gmake: it is set to
the first prerequisite for explicit rules. For implicit rules it
is still the implied source.

The manual page is improved regarding the fixed features. Test cases
for the fixed problems are added.

Other improvements in the Suff module include:
- better debug messages for transformation rule search (length of
the chain is now visualized by indentation)
- Suff structures are created, destroyed and moved around by a set
of maintenance functions so their reference counts are easier
to track (this also gets rid of a lot of code duplication)
- some unreasonably long functions were split into smaller ones
- many local variables had their names changed to describe their
purpose instead of their type
 1.18 23-Jan-2009  dsl Sprinkle some const.
In particular for Lst_Find() and Lst_FindFrom().
Remove some unneeded casts and some now-undeeded UNCONST().
 1.17 23-Jan-2009  dsl Change 'ClientData' to 'void *' so that relevant parameters can
be made 'const void *'.
 1.16 13-Dec-2008  dsl Use NULL instead of -1 cast to the relavant type (usually via NIL).
This was a suggestion from christos - so blame him if there is a deep
reason for using -1 :-)
 1.15 11-Nov-2006  dsl Return the non-zero value that caused the Lst_ForEach[From] call to
terminate early to the caller.
 1.14 27-Oct-2006  dsl Rename 'struct Lst' to 'struct List' and 'struct LstNode' to 'struct 'ListNode'
in lst.d remove a small barrowload of casts from the lst.lib bloatset.
 1.13 25-Oct-2006  dsl Rename Lst_Append() to Lst_InsertAfter() and Lst_Insert() to Lst_InsertBefore()
to better explain their actions.
 1.12 25-Oct-2006  dsl Fix previous - need to add a lstPrev()
 1.11 09-Aug-2005  christos Add typedefs for DuplicateProc and FreeProc from Max Okumoto.
 1.10 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.9 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.8 29-Jul-1999  hubertf sprite.h is private to make, so #include it with "sprite.h",
not <sprite.h>.

Problem reported in PR 4381 bye Soren S. Jorvang <soren@t.dk>
 1.7 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.6 04-Feb-1996  christos branches: 1.6.4;
fix pr/1421 and pr/1997
 1.5 14-Jun-1995  christos - $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.4 06-Jun-1994  jtc Fixes from Christos Zoulas, who used purify, objectcenter and testcenter
to find memory leaks and illegal memory accesses.
 1.3 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.6.4.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.662 09-Aug-2025  rillig make: clean up
 1.661 06-Jul-2025  rillig make: clean up
 1.660 02-Jul-2025  rillig make: shorten diagnostic for invalid -J option

In the manual page, there's more space to properly explain the
complexity behind the warning.
 1.659 13-Jun-2025  rillig make: new sentence, new line
 1.658 13-Jun-2025  rillig make: add on-demand inter-process stack traces

When debugging a build that heavily uses nested calls to sub-makes, the
chain of calls is useful to quickly assess the situation. If explicitly
requested, include the actions from any parent processes in the stack
traces.

Reviewed by: sjg
 1.657 12-Jun-2025  rillig make: use a common style for unexpected error messages

In enomem, report the actual error instead of a fixed ENOMEM.
 1.656 05-Jun-2025  rillig make: remove empty line from diagnostic, add tests for output handling

The warning for the invalid internal option "-J" does not need a
trailing newline, as that is provided by Parse_Error already.

Having this newline in the output demonstrated a previously unknown bug
in handling the output of child commands in parallel mode. There, empty
lines are randomly discarded, depending on the chunks in which the
output from the child process is copied to make's stdout. See
job-output.mk for a demonstration.

The test for the Korn shell did not run the Korn shell in error handling
mode, as the error handling mode only affects the parallel mode but the
test didn't switch to that mode.

After fixing the shell-ksh.mk test, the single '"' in the output looked
suspicious, and indeed, the shell-csh.mk test had the same problem of
filtering more characters from the output than intended.
 1.655 28-May-2025  sjg make: delay warning about bogus -J flag

In MainParseArgJobsInternal just set bogusJflag to indicate
that the descriptors passed were invalid.

By the time we get to InitMaxJobs the command line and indeed
the makefile have had a chance to put us in compat mode,
in which case the warning is unnecessary.
Add suggestion of -B if compat mode is desired in the sub-make.

Reviewed by: rillig
 1.654 26-May-2025  rillig make: show contents of MAKEFLAGS in the stack trace

When the internal -J option refers to a closed file descriptor, it's
helpful to know what the MAKEFLAGS environment variable contains, in
addition to the executed command line. Same for parse errors in
variable assignments from the command line.
 1.653 23-May-2025  rillig make: add current directory to error messages from MAKEFLAGS

While parsing the additional command line arguments from the MAKEFLAGS
environment variable, the current directory was not initialized yet, so
swap the order.

As a side effect, this change would allow a "-m .../share/mk" option,
with a literal magic "...", thus looking up the system directory in any
ancestor directory of the current directory. This idea sounds unreliable
enough that probably nobody will try this in practice.
 1.652 23-May-2025  rillig make: warn when falling from parallel mode back to compat mode

Falling back may run fewer jobs than intended, thus increasing the build's
wall time.

Falling back may run more jobs than intended, when a sub-make creates
its own and independent token pool, thus overloading the system.

Warn in both cases. Since the -J option is internal, it is not obvious
how to fix the situation, so provide detailed instructions on the
possible fixes and their effects.
 1.651 20-May-2025  sjg Revert export of MAKEFLAGS from Cmd_Exec

Until we work out what the issue is.
Revert related unit-test changes as well
 1.650 18-May-2025  sjg make: Cmd_Exec call Main_ExportMAKEFLAGS

export MAKEFLAGS the fist time Cmd_Exec is called.
This allows ${.MAKE} run via x!= to see them.

Remove test case from varname-dot-makeflags that checked
this does not happen.

Reviewed by: christos
 1.649 18-May-2025  rillig make: rename variables, remove now-redundant comments
 1.648 18-May-2025  rillig make: remove redundant comments, summarize a few others
 1.647 11-May-2025  rillig make: clean up error message for malformed internal -J option

There's no point printing the usage, as the problem is typically
somewhere else. Reword the message to be easier to parse.
 1.646 10-May-2025  rillig make: rename token pool variables to be more descriptive
 1.645 03-May-2025  rillig make: miscellaneous cleanups
 1.644 22-Apr-2025  rillig make: clean up

Replace 'unsigned int' with simply 'unsigned'.

In compat.c, skipping whitespace is not needed, as the loop above
already skips it.

In job.c, remove the unused header <sys/file.h>.

Inline the TMPPAT macro, as it is only needed in a single place.
 1.643 22-Apr-2025  rillig make: group the code for handling the job token pool
 1.642 22-Apr-2025  rillig make: move struct Job from job.h to job.c

The content of this struct is an implementation detail, and other parts
of make only need to access very few parts of it.
 1.641 31-Mar-2025  riastradh make(1): Nix trailing whitespace.

No functional change intended.
 1.640 30-Mar-2025  sjg make: POSIX mode, check for sysV style modifiers first

A POSIX compatible makefile should not be using any
of our native modifiers, so give preference to the sysV style modifier
and only check the others as a fallback.

Reviewed by: rillig
 1.639 07-Mar-2025  rillig make: clean up comments and code for parallel mode

Most of the comments didn't help understand the code.

The Finish function was named way too soft for what it does, which is to
exit without cleaning up properly. Since it was used only once, inline
it. The code from that function causes jobs to be terminated early when
an unrelated target has failed, resulting in partially written files,
due to SIGPIPE.
 1.638 19-Jan-2025  rillig make: avoid memory allocation in error path after exec

Just to be on the extra-safe side.
 1.637 19-Jan-2025  rillig make: fix code coverage counts

See tests/usr.bin/gcov/t_gcov.sh.
 1.636 23-Nov-2024  rillig make: fix confusing error message when overriding a read-only variable
 1.635 10-Nov-2024  sjg make: allow -f .../Makefile

If the arg to -f or an entry in .MAKE.MAKEFILE_PREFERENCE
starts with ".../" look for the rest of the path in .CURDIR
and above.

Reviewed by: rillig
 1.634 27-Aug-2024  rillig make: treat recursive variables non-fatally

A recursive variable is no worse than an unknown modifier, so treat them
in the same way by continuing parsing until the end of the makefile.
 1.633 25-Aug-2024  rillig make: add more context to error message about recursive variables
 1.632 11-Jul-2024  sjg Compat_RunCommand use tempfile if cmd too big

Extract the logic recently added to Cmd_Exec to handle
long commands via temp file to Cmd_Argv,
so it can also be leveraged by Compat_RunCommand

Reviewed by: christos
 1.631 09-Jul-2024  rillig make: error out on parse/evaluation errors in shell commands

The expression ${VAR:X} has an unknown modifier ':X'. Previously, this
expression errored out when the expression was evaluated at parse time,
but not when the expression was evaluated when generating the commands
to bring a target up to date. The errors were previously reported, they
didn't affect the exit status, though.

Now, errors in expressions are handled in the same way, regardless of
the time at which they are evaluated.
 1.630 07-Jul-2024  rillig make: move initialization of variable scopes to targ.c

The variable scopes are freed by Targ_End, so initialize them there as
well. Separate printing statistics and freeing memory, which makes
Var_End unnecessary.
 1.629 07-Jul-2024  rillig make: only generate code for cleanup functions in CLEANUP mode
 1.628 06-Jul-2024  rillig make: clean up condition when printing an error
 1.627 05-Jul-2024  rillig make: reduce lint-specific comments about ARGSUSED
 1.626 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.625 30-Jun-2024  rillig make: add detailed exit status to message for failed sub-commands

Several commands communicate via the exit status and not only
distinguish between zero and non-zero, so make this information
available to ease investigations.

The command "false" is not guaranteed to exit with a consistent status,
so use "(exit 13)" instead in the tests, to keep these tests portable
across different operating systems. The exit status 127 is required for
a shell that cannot find a command, so keep that one.
 1.624 02-Jun-2024  rillig branches: 1.624.2;
make: sync VarEvalMode constant names with their debug log names
 1.623 01-Jun-2024  rillig make: fix memory leak in realpath cache
 1.622 01-Jun-2024  rillig make: replace strncpy with snprintf

There's no point copying a MAXPATHLEN buffer in its entirety when only
the initial string part is ever used.
 1.621 01-Jun-2024  rillig make: fix variable lifetime when initializing MAKE and .MAKE

The pathbuf buffer is aliased by abspath, which later escapes the block
where the buffer is declared.
 1.620 01-Jun-2024  sjg make: ensure loop termination in purge_relative_cached_realpaths

You cannot ignore the return from HashIter_Next
 1.619 31-May-2024  rillig make: clean up API for iterating over hash tables
 1.618 28-May-2024  sjg make: allow debugging the warning about .OBJDIR

When make complains about an unwritable .OBJDIR
it is not always obvious how we derrived that value.

If MAKE_DEBUG_OBJDIR_CHECK_WRITABLE is enabled call PrintOnError
so we can examine variables that are likely relevant.

Fix description of MAKE_OBJDIR_CHECK_WRITABLE in make.1
 1.617 24-May-2024  rillig make: in -DCLEANUP mode, free variables and their values

The variables in the 3 scopes must be freed before the scopes themselves
are freed by Targ_End.

The test opt-m-include-dir creates a directory of the form '*.tmp', thus
it must be removed before attempting to only remove regular files of
this name.

POSIX requires setenv to copy the passed name and value, so there is no
need to keep that memory allocated any longer.
 1.616 19-May-2024  sjg Dir_FindFile treat sysIncPath and defSysIncPath as special

Rather than play games with adding .DOTLAST and then having to
exclude that from .SYSPATH, just have Dir_FindFile check if
path is sysIncPath or defSysIncPath and behave as if .DOTLAST seen
and also skip the final search of .CURDIR.

Fix Dir_SetSYSPATH to use defSysIncPath if sysIncPath is empty.
 1.615 07-May-2024  sjg make: all command line overrides go in .MAKEOVERRIDES

Not all variables that start with '.' are internals,
and unless they are explicitly flagged as internal should go
into .MAKEOVERRIDES

Update varname-dot-makeoverrides to check this.

Also avoid using SCOPE_CMDLINE when ReadOnly will do.
 1.614 30-Apr-2024  sjg make: ensure '.include <makefile>' respects MAKESYSPATH

Since Dir_FindFile is used by '.include' and its variants,
and will first search .CURDIR unless the give path starts with
".DOTLAST".

Update unit-tests/opt-m-include-dir to test this.
 1.613 27-Apr-2024  rillig make: simplify freeing of lists
 1.612 10-Mar-2024  sjg make: record exit status in GNode

SetErrorVars can now set .ERROR_EXIT which allows
a .ERROR target to ignore the case of .ERROR_EXIT == 6
which means failure happened elsewhere.

Reviewed by:
 1.611 01-Mar-2024  sjg make: export target scope values

Pass target scope to Var_ReexportVars so that a target process
will see the correct values in its env.
We must then mark any Global scope variable as unexported
so targets without local value get the Global one.
 1.610 07-Feb-2024  rillig make: remove unneeded conditional-compilation toggles

The toggles INCLUDES, LIBRARIES, POSIX, SYSVINCLUDE, SYSVVARSUB,
GMAKEEXPORT and SUNSHCMD are no longer needed, they were unconditionally
set.

The toggle NO_REGEX was configurable from the command line, but
disabling it would result in various error messages about the unknown
':C' modifier.

OK sjg@.
 1.609 07-Jan-2024  sjg make: more consistent error messages

Move %s: progname from Job_CheckCommands to Fatal
to avoid is being repeated when Job_CheckCommands is passed Error.

This means some errors from var also report progname (and level)
which is useful.

Reviewed by: rillig
 1.608 05-Jan-2024  rillig make: miscellaneous cleanups
 1.607 05-Jan-2024  sjg Cmd_Exec use tempfile if cmd is too big

To avoid blowing commandline/env limits, if "cmd"
is more than 1000 bytes, write it to a file and pass that
to shell.

Reviewed by: rillig
 1.606 27-Dec-2023  sjg make: ensure shellPath is set before using it.
 1.605 17-Dec-2023  rillig make: clean up unused return value of str2Lst_Append

No functional change.
 1.604 17-Dec-2023  rillig make: clean up names of local variables

No binary change.
 1.603 02-Nov-2023  rillig make: miscellaneous cleanups

No functional change.
 1.602 02-Nov-2023  rillig make: clean up comments

No functional change.
 1.601 02-Nov-2023  rillig make: inline a single-line cross-file function

No functional change.
 1.600 19-Sep-2023  rillig make: clean up code for parsing the '-j' command line option

No binary change.
 1.599 10-Sep-2023  rillig make: fix typo
 1.598 10-Sep-2023  rillig make: add more details to usage message of -j option
 1.597 10-Sep-2023  rillig make: fix lint warning about strchr

main.c(416): warning:
call to 'strchr' effectively discards 'const' from argument [346]

Even though C23 turns strchr into a const-generic function, it doesn't
do the same for strtol, so use separate pointers for the current parsing
position and the end of a number, as their constness differs.
 1.596 09-Sep-2023  sjg Add .MAKE.JOBS.C to indicate wether -jC is supported
 1.595 09-Sep-2023  mrg add explicit cast for long -> int truncation warning-as-error.

as this is number of CPUs, i don't think we have to care about
it for a long, long, *long* time...
 1.594 09-Sep-2023  sjg make: allow -j to compute a multiple of ncpu

If _SC_NPROCESSORS_ONLN is supported; and -j arg is a floating point
number or ends in 'C' compute .MAKE.JOBS as a multiple of _SC_NPROCESSORS_ONLN

Based on a suggestion from des at freebsd.org
Discussed with: rillig, christos
 1.593 28-Mar-2023  rillig make: declare all common symbols in headers, unexport others

No functional change.
 1.592 25-Feb-2023  rillig make: rename function for parsing command line options

No binary change.
 1.591 15-Feb-2023  rillig make: inline macros for variable names

The variable name '.MAKEOVERRIDES' was already used in the non-macro
form.

No binary change.
 1.590 14-Feb-2023  rillig make: clean up calls to Var_Subst

None of the calls to Var_Subst used the return value, and the return
value was always VPR_OK.

No functional change.
 1.589 26-Jan-2023  sjg make: some variables should be read-only

Make variables like .newline and .MAKE.{GID,PID,PPID,UID} read-only.

Reviewed by: rillig
 1.588 24-Jan-2023  sjg make: .SYSPATH: to add dirs to sysIncPath

.SYSPATH: with no sources will clear sysIncPath
otherwise sources are added

Reviewed by: rillig
 1.587 19-Jan-2023  rillig make: inline macro for variable name

This fixes the inconsistency of using the macro name in one place and
its value in another place (since 2010).

No binary change.
 1.586 01-Jan-2023  rillig make: don't assemble identifiers from smaller tokens

No binary change.
 1.585 10-Oct-2022  rillig make: change return type of unlink_file back to int

As unlink_file is a wrapper around unlink, use the same encoding for the
possible return values as in the wrapped function. This consistency is
more important than expressing all possible return values in the return
type 'bool'.

https://mail-index.netbsd.org/tech-toolchain/2022/10/06/msg004155.html

No functional change.
 1.584 10-Oct-2022  rillig make: document the guard for directories in unlink_file

Document only the POSIX requirement for now, as I didn't find
information about _which_ ancient UNIX systems would corrupt the
filesystem on unlinking a directory.

http://man.cat-v.org/unix-1st/2/sys-unlink (1971) says:
> It is also illegal to unlink a directory (except for the super-user).

https://mail-index.netbsd.org/tech-toolchain/2022/10/06/msg004147.html
 1.583 28-Sep-2022  sjg Don't ignore return from snprintf or getcwd
 1.582 07-May-2022  rillig make: allow to randomize build order of targets

In complex dependency structures, when a build fails, a probable cause
is a missing dependency declaration between some files. In compat mode,
the build order is deterministic, in jobs mode, it is somewhat
deterministic. To explore more edge cases, add the line ".MAKE.MODE +=
randomize-targets" somewhere in the makefile.

Fixes PR bin/45226 by riastradh. Reviewed by christos.
 1.581 07-May-2022  rillig make: rename Compat_Run to Compat_MakeAll

No functional change.
 1.580 18-Apr-2022  rillig make: only switch to POSIX mode if '.POSIX:' is the first line

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html
says that in order to make a makefile POSIX-conforming, its first
non-comment line must be the special dependency line '.POSIX:' without
any source dependencies.

Previously, make switched to POSIX mode even if such a line occurred
anywhere else, which was allowed by POSIX but was deep in the
"unspecified behavior" area. For NetBSD make, there is no big
difference since it doesn't ship any <posix.mk> file, this change mainly
affects the bmake distribution.

Previously, makefiles that contain '.POSIX:' somewhere in the middle
could fail due to <posix.mk> resetting .SUFFIXES, among other things.

Suggested by Simon J. Gerraty, who also reviewed an earlier version of
this change.
 1.579 22-Mar-2022  rillig make: clean up comments and code for setting debug flags

No binary change.
 1.578 09-Feb-2022  rillig make: prefix the warning about read-only .OBJDIR with a colon

For consistency with the other warnings.
 1.577 29-Jan-2022  rillig make: print stack trace on fatal errors

The only fatal error that occurs while the makefiles are read in is the
one about recursive variables, which didn't give any hint about the
location before.

If a recursive variable is detected while evaluating the commands of a
target to be made, there is no location information, as before.
 1.576 27-Jan-2022  sjg Allow local variable assignments in dependency lines

The variable is set in the context of the target.
This syntax has been supported by gmake for ~ever.
If necessary a makefile can set .MAKE.TARGET_LOCAL_VARIABLES=false
to disable this.

Expose GetBooleanExpr so parse.c can use it.
 1.575 22-Jan-2022  rillig make: add missing newline after "cannot continue" message

It was wrong of Parse_File to output an unfinished line and hope for
some other code to finish it. As demonstrated in the test, PrintOnError
did not do that in the case of additional debug output.

To keep the overall behavior as close as possible to before, the other
callers of PrintOnError now have to pass the newline themselves. Passing
strings that start with newlines but don't end with them looked
suspicious anyway.
 1.574 22-Jan-2022  rillig make: clean up comments
 1.573 15-Jan-2022  rillig make: remove extra semicolon after statement

Lint will complain about this very soon.

No binary change.
 1.572 15-Jan-2022  rillig make: replace Var_Value with Var_Exists where applicable

The latter function already existed in 1993, no idea why it was not
used.

No functional change.
 1.571 15-Jan-2022  rillig make: remove unnecessary functions for expanding variable names

In meta mode, the affected variable patterns do not contain a '$'.

Outside of meta mode, Global_SetExpand was only called a single time, so
inline that call.

No functional change.
 1.570 15-Jan-2022  rillig make: merge duplicate code for expanding variable expressions

No functional change.
 1.569 10-Jan-2022  rillig make: add debug logging for capturing the output of external commands

This applies to all 4 situations in which the output of an external
command is used for modifying a variable or an expression:

* the assignment operator '!='
* the assignment modifier '::!='
* the SUN shell modifier ':sh'
* the other shell modifier ':!cmd!'

Previously, only the shell modifier ':!cmd!' had debug logging.

Suggested by Christoph Badura.
 1.568 09-Jan-2022  rillig make: in Cmd_Exec, return error message instead of format string

This change leaves only literal format strings in parse.c. It allows
for more detailed error messages than the current "non-zero status" or
"exited on a signal".

No functional change.
 1.567 07-Jan-2022  rillig make: have as few statements as possible between va_start and va_end

No functional change.
 1.566 07-Jan-2022  rillig make: clean up comments, variable names, function names

The comment in ApplyDependencySourceOther repeated the code, its second
half didn't match any current code.

The comment above ParseDependencySourcesEmpty repeated the code.

No binary change, except for assertion line numbers.
 1.565 01-Jan-2022  rillig make: fix error message when reading more than 1 GB from stdin

Previously, the error message was:
make: (null): file too large
Now it is:
make: (stdin): file too large
 1.564 01-Jan-2022  rillig make: reduce indentation in Main_SetObjdir

No functional change.
 1.563 31-Dec-2021  rillig make: unexport types VarAssignOp and VarAssign

These types are only needed in the parsing module.

No functional change.
 1.562 28-Dec-2021  rillig make: fix double-free in CLEANUP mode (since 2021.12.27.23.11.55)

When make is run without the '-f' option, it searches for the files
'makefile' and 'Makefile' in the current directory. The function
ReadFirstDefaultMakefile allocated memory for these filenames, added the
filenames to opts.makefiles and then freed the memory. From that
moment, opts.makefiles contained dangling pointers.

The function main_CleanUp cleans the list, but only if make is compiled
with -DCLEANUP. Since main.c 1.557 from 2021.12.27.23.11.55, the
strings in opts.makefiles are freed as well, before that, only the list
nodes were freed. Freeing the strings led to the double-free.

Fix this bug by using a separate list for these short-lived strings. At
the point where ReadFirstDefaultMakefile is called, opts.makefiles is
not used anymore, therefore there are no side effects.

To reproduce, run 'make test-coverage', which compiles with -DCLEANUP.
The test opt-chdir failed with a segmentation fault in main_Cleanup.
This test may be the only one that doesn't use the option '-f'.
 1.561 28-Dec-2021  rillig make: clean up stylistically

No binary change.
 1.560 28-Dec-2021  rillig make: constify cached_realpath

No binary change.
 1.559 27-Dec-2021  rillig make: clean up Cmd_Exec

Renaming savederr to saved_errno makes the comment redundant.

Group the conditions for setting errfmt, retaining their relative order.

No functional change.
 1.558 27-Dec-2021  rillig make: reduce indentation of Cmd_Exec

No functional change.
 1.557 27-Dec-2021  rillig make: free the names of the makefiles in cleanup mode

Since parse.c 1.576 from 2021-12-13 the filenames from opts.makefiles no
longer end up in the GNodes, they are copied by Str_Intern.
 1.556 27-Dec-2021  rillig make: merge local variables holding the path to the object directory

This is a similar pattern as in the other situations where a string is
fed through Var_Subst. In this case though, the unexpanded string may
need to be freed, therefore the FStr_Done that is not needed in the
other places.

No functional change.
 1.555 27-Dec-2021  rillig make: prevent out-of-bounds read for debug log file name

Even though the name of the debug log file currently only occurs in
strings of the form '-dFname' or '-dF+name', the code for replacing '%d'
with the PID accesses the passed string out of bounds. That's not a
problem in practice but looks suspicious anyway.
 1.554 27-Dec-2021  rillig make: remove usage message if the debug file cannot be opened

Since a non-writable file is not a syntax error, there is no point in
showing the usage in this situation. Showing the usage may have been a
copy-and-paste mistake from a few lines below, when this option was
added back in main.c 1.133 from 2006-10-15.
 1.553 27-Dec-2021  rillig make: narrow down the return type of ReadMakefile

No functional change.
 1.552 27-Dec-2021  rillig make: rename local variables to be simpler

No binary change.
 1.551 27-Dec-2021  rillig make: clean up 'explode'

Breaking out of the first 'for' loop was unnecessarily complicated. The
call to strlen was not necessary since f already pointed at the end of
the string.

No functional change.
 1.550 27-Dec-2021  rillig make: clean up comments
 1.549 27-Dec-2021  rillig make: remove unnecessary words from command line options

Several years ago, the command line options were individual global
variables. The global variable could therefore not be named 'silent'
since that would have conflicted with local variables of the same name.
After moving the global variable to the namespace 'struct CmdOpts',
there is no conflict anymore.

There doesn't seem to be any risk of naming collisions for the names
'touch' and 'query'.

No functional change.
 1.548 27-Dec-2021  rillig make: rename eunlink to unlink_file

The name eunlink suggested a relation with the similarly named functions
emalloc or esnprintf, but that was misleading. Instead, unlink_file
works like unlink, except that it refuses to remove an empty directory.

No functional change.
 1.547 15-Dec-2021  rillig make: format comments according to /usr/share/misc/style

Assisted by indent(1), with manual corrections due to its many remaining
bugs.

No functional change.
 1.546 15-Dec-2021  rillig make: use consistent indentation for statements and continuations

No binary change, except for line numbers in assertions in suff.c.
 1.545 15-Dec-2021  rillig make: remove bmake_free

It was only used in 2 places, and in both these places, the pointer was
never null.
 1.544 15-Dec-2021  rillig make: in CLEANUP mode, free interned strings at the very end

Noticed by sjg.
 1.543 13-Dec-2021  rillig make: convert debugging flags from enum to bit-field

This gets rid of the magic numbers, making it possible to add another
debug flag without renumbering the others.

No functional change.
 1.542 13-Dec-2021  rillig make: fix memory leak for filenames in .for loops (since 2013-06-18)

Previously, each time a .for directive pushed its buffer on the input
file stack, the current filename was duplicated. This was a waste of
memory.

The name of a file is typically only used while it is read in. There is
one situation when the filename is needed for longer, which is when a
target is defined.

Since .for loops are implemented as a special form of included files,
each .for loop duplicated the current filename as well.

$ cat << EOF > for.mk
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.endfor
.endfor
.endfor
.endfor
.endfor
.endfor
.endfor

all:
@ps -o rsz -p ${.MAKE.PID}
EOF

$ make-2021.12.13.03.55.16 -r -f for.mk
RSZ
10720

$ ./make -r -f for.mk
RSZ
1716

The difference is 8 MB, which amounts to 1 million .for loops.
 1.541 14-Aug-2021  rillig make: rename variable and function for handling parse errors

The word 'fatals' was an unnecessary abbreviation.

No functional change.
 1.540 18-Jun-2021  rillig make: clean up access to character iterator

Having both p[0] and *p intermixed was inconsistent.

No functional change.
 1.539 19-Apr-2021  rillig make: avoid double slash in name of temporary directory

If the environment variable TMPDIR is not set, make uses a default path
that includes a trailing '/'.

For extra correctness it always appended an extra '/', leading to paths
of the form '/tmp//makeXXXXXX'. This looked suspicious, as if there had
been a forgotten empty part between the two '/'. Avoid this ambiguity
by replacing '//' with '/'.
 1.538 14-Apr-2021  rillig make: turn run-time string concatenation into compile-time

No functional change.
 1.537 14-Apr-2021  rillig make: remove unnecessary modifier ':U' for certain fixed expressions

No functional change, since the expression is evaluated using
VARE_WANTRES, not using VARE_UNDEFERR.
 1.536 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.535 04-Apr-2021  rillig make: rename a few functions to be more descriptive

No functional change.
 1.534 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.533 05-Feb-2021  sjg Avoid strdup in mkTempFile

Require caller to pass a buffer and size if they
want the tempfile not unlinked.

Add Job_TempFile to handle blocking signals around
call to mkTempFile, so that meta_open_filemon can use it
in jobs mode.
 1.532 05-Feb-2021  rillig make: in the Var_ functions, move the scope to the front

This change provides for a more natural reading order in the code.
Placing the scope first makes it immediately clear in which context the
remaining parameters are interpreted.

No functional change.
 1.531 05-Feb-2021  rillig make: add shortcut Global_Delete for deleting a global variable
 1.530 04-Feb-2021  rillig make: rename some VAR constants to SCOPE

The word "context" does not fit perfectly to the variables that are
associate with a GNode, as the context is usually something from the
outside and the variables are more like properties inherent to the
GNode.

The term "global context" fits even less. Since the thing where
variables are looked up is commonly named a scope, use that term
instead.

This commit only renames the global variables VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE, plus a few very closely related comments. These are:

GNode.vars (because of line breaks)
GNode_Free (dito)
varname-make_print_var_on_error.mk
varname-make_print_var_on_error-jobs.mk

The debug message in Var_Stats is left as-is since there is no unit test
for it yet.

The other renamings (variable names "context", "ctxt", as well as
further comments) will be done in a follow-up commit.
 1.529 03-Feb-2021  rillig make: replace Global_AppendExpand with Global_Append

All callers with a variable name that is guaranteed to not contain a
dollar sign have been converted to call Global_Append instead of the
previous Global_AppendExpand. After that, Global_AppendExpand was
unused, therefore it was effectively just renamed.
 1.528 03-Feb-2021  rillig make: replace Global_SetExpand with Global_Set for constant names
 1.527 03-Feb-2021  rillig make: use shortcut functions Global_SetExpand and Global_AppendExpand

There are many places where global variables are set or appended to. To
reduce clutter and code size, encode the VAR_GLOBAL in the function
name.

The word Expand in the function names says that the variable name is
expanded. In most of the cases, this is not necessary, but there are no
corresponding functions Global_Set or Global_Append yet.

Encoding the information whether the name is expanded or not in the
function name will make inconsistencies obvious in future manual code
reviews. Letting the compiler check this by using different types for
unexpanded and expanded variable names is probably not worth the effort.
There are still a few bugs to be fixed, such as in SetVar, which expands
the variable name twice in a row.
 1.526 01-Feb-2021  rillig make: always use vfork, never fork

Before compat.c 1.217, job.c 1.390 and main.c 1.504 from 2020-12-27, the
exported make variables were exported from each freshly forked child
process. There was no practical difference though between exporting the
variables from the parent process or the child process since these two
processes share the same address space, except that the forked process
is very limited in what it may actually do. This limitation was
violated on a regular basis.

When an exported variable referred to a variable that used the :sh
variable modifier, this led to a fork from within vfork, which is not
allowed. Since 2020-12-27, exporting the variables is done from the
main process, which prevents this situation from ever occurring.

Since that day, there is no need anymore to distinguish between vfork
and fork, which removes any need for the macro.
 1.525 01-Feb-2021  rillig make: clean up main.c
 1.524 01-Feb-2021  rillig make: simplify MakeMode
 1.523 01-Feb-2021  rillig make: replace pre-increment with post-increment or simple addition

The rest of the code already prefers post-increment if there is no
actual difference.
 1.522 01-Feb-2021  rillig make: rename functions for parsing command line arguments

The function names now match the names around them.
 1.521 01-Feb-2021  rillig make: clean up comments
 1.520 30-Jan-2021  rillig make(1): inline Buf_Len
 1.519 30-Jan-2021  rillig make(1): inline Buf_GetAll
 1.518 30-Jan-2021  rillig make(1): split Buf_Destroy into Buf_Done and Buf_DoneData

In all cases except one, the boolean argument to Buf_Destroy was
constant. Removing that argument by splitting the function into two
separate functions makes the intention clearer on the call site. It
also removes the possibility for using the return value of Buf_Done,
which would have made no sense.

The function Buf_Done now pairs with Buf_Init, just as in HashTable and
Lst.

Even though Buf_Done is essentially a no-op, it is kept as a function,
both for symmetry with Buf_Init and for clearing the Buffer members
after use (this will be done only in CLEANUP mode, in a follow-up
commit).
 1.517 24-Jan-2021  rillig make(1): convert SearchPath to struct

This prepares for making dotLast a simple struct member instead of a
fake CachedDir, which is easier to understand.
 1.516 23-Jan-2021  rillig make(1): rename Dir_AddDir, reorder parameters of SearchPath_ToFlags
 1.515 23-Jan-2021  rillig make(1): rename Dir_Expand to SearchPath_Expand

The main subject of this function is the search path. In this search
path the pattern is expanded.
 1.514 19-Jan-2021  rillig make(1): remove do-not-format markers from comments

These markers had been used inconsistently. Furthermore the source code
had not been formatted automatically before 2020 at all, otherwise there
wouldn't have been any trailing whitespace left.
 1.513 16-Jan-2021  rillig make(1): fix a few inconsistencies for lint's strict bool mode
 1.512 10-Jan-2021  rillig make(1): make a few more bool expressions more precise

The previous version of lint(1) from a few hours ago didn't catch all
occurrences. And even the current one doesn't catch everything.
Function arguments and return types still need some work. The "return
quietly" from shouldDieQuietly still implicitly converts from int to
_Bool.

No functional change.
 1.511 10-Jan-2021  rillig make(1): consistently use boolean expressions in conditions

Most of the make code already followed the style of explicitly writing
(ptr != NULL) instead of the shorter (ptr) in conditions.

The remaining 50 instances have been found by an experimental,
unpublished check in lint(1) that treats bool expressions as
incompatible to any other scalar type, just as in Java, C#, Pascal and
several other languages.

The only unsafe operation on Boolean that is left over is (flags &
FLAG), for an enum implementing a bit set. If Boolean is an ordinary
integer type (the default), some high bits may get lost. But if Boolean
is the same as _Bool (by compiling with -DUSE_C99_BOOLEAN), C99 6.3.1.2
defines that a conversion from any scalar to the type _Bool acts as a
comparison to 0, which cannot lose any bits.
 1.510 09-Jan-2021  rillig make(1): fix lint warnings
 1.509 08-Jan-2021  sjg Ensure PrintOnError always reports 'stopped in' on first call.

We may still suppress the rest of the noise if shouldDieQuietly
says to, but the 'stopped in' output is too important to lose.
Avoid repeating it though in the same process.

For the case of aborting due to failure detected elsewhere,
exit 6 so we have a clue.

PR: 55578
Reviewed by:
 1.508 31-Dec-2020  rillig make(1): replace pointers in controlling conditions with booleans
 1.507 30-Dec-2020  rillig make(1): format multi-line comments
 1.506 28-Dec-2020  rillig make(1): replace global preserveUndefined with VARE_KEEP_UNDEF

Controlling the expansion of variable expressions using a global
variable and a VARE flag was inconsistent.

Converting the global variable into a flag had to prerequisites:

1. The unintended duplicate variable assignment had to be fixed, as
done in parse.c 1.520 from 2020-12-27. Without this fix, it would have
been necessary to add more flags to Var_Exists and Var_SetWithFlags, and
this would have become too complex.

2. There had to be a unit test demonstrating that VARE_KEEP_DOLLAR only
applies to the top-level expression and is not passed to the
subexpressions, while VARE_KEEP_UNDEF applies to all subexpressions as
well. This test is in var-op-expand.mk 1.10 from 2020-12-28, at least
for the ':@word@' modifier. In ParseModifierPartSubst, VARE_KEEP_UNDEF
is not passed down either, in the same way.
 1.505 27-Dec-2020  rillig make(1): exit 2 on technical errors

This allows the -q option to distinguish errors from out-of-date
targets. Granted, it's an edge case but it should be solved
consistently anyway.

The majority of cases in which make exits with exit status 1, even in -q
mode, is when there are parse errors. These have been kept as-is for
now as they affect many of the unit tests.

The technical errors, on the other hand, occur so rarely that it's hard
to write reliable tests for them that fail consistently on all platforms
supported by make.
 1.504 27-Dec-2020  rillig make(1): re-export variables from the actual make process

Since make uses vfork if available, re-exporting the variables happens
in the address space of the main process anyway, so there is no point in
mentioning anything about "our client process" anywhere.
 1.503 26-Dec-2020  sjg Use .MAKE.DEPENDFILE as makefiles set it
 1.502 23-Dec-2020  rillig make(1): fix a few lint warnings
 1.501 23-Dec-2020  rillig make(1): rename CmdOpts.lint to strict

When running lint(1) on the code, it defines the preprocessor macro
"lint" to 1, which generated a syntax error in the declaration "Boolean
lint", as that became "Boolean 1".
 1.500 20-Dec-2020  rillig make(1): remove constant parameter from MakeMode
 1.499 20-Dec-2020  rillig make(1): change return type of Var_Value to FStr
 1.498 13-Dec-2020  rillig make(1): add str_basename to reduce duplicate code

The function basename from POSIX has a few unfortunate properties, it is
allowed to return a pointer to static memory. This is too unreliable,
therefore this trivial own implementation.
 1.497 13-Dec-2020  rillig make(1): constify progname
 1.496 13-Dec-2020  rillig make(1): replace *line with line[0]

Since a line is not an iterator and since the expression *line typically
means "the current element", not "the first character", replacing *line
with line[0] more directly expresses the idea of accessing the first
character of a string.
 1.495 12-Dec-2020  rillig make(1): rename Var_ExportVars to Var_ReexportVars
 1.494 11-Dec-2020  rillig make(1): clean up comments for command line options
 1.493 11-Dec-2020  rillig make(1): remove DEFMAXLOCAL and DEFMAXJOBS

These have been hard-wired all the time. The word LOCAL doesn't make
sense anymore since the code for running jobs remotely has gone.
 1.492 05-Dec-2020  rillig make(1): define constants for enum zero-values
 1.491 01-Dec-2020  rillig make(1): remove Dir_InitDir

The function name had been too ambiguous since it didn't mention the
particular directory that was initialized. Instead of that function,
Dir_InitCur is called directly from main_Init.

The pseudo CachedDir entry ".DOTLAST" is initialized at the very
beginning. The observable behavior is unchanged since this a
memory-only object with no connection to the file system.
 1.490 29-Nov-2020  rillig make(1): reduce memory allocation for dirSearchPath
 1.489 29-Nov-2020  rillig make(1): fix main_CleanUp in -DCLEANUP mode (broken since 1 hour)

Broken since main.c 1.486 from 2020-11-28, about 1 hour ago.
 1.488 29-Nov-2020  rillig make(1): reduce memory allocation for targets

This change moves the initialization and finalization of the list of
targets to the same function. They had been split before.
 1.487 28-Nov-2020  rillig make(1): reduce memory allocation in ReadBuiltinRules
 1.486 28-Nov-2020  rillig make(1): reduce memory allocation for CmdOpts.create
 1.485 28-Nov-2020  rillig make(1): reduce memory allocation in CmdOpts.variables
 1.484 28-Nov-2020  rillig make(1): reduce memory allocation in CmdOpts.makefiles
 1.483 28-Nov-2020  rillig make(1): remove pointer indirection from GNode.commands

Just to save a few memory allocations. No noticeable effect on the
performance though.
 1.482 28-Nov-2020  rillig make(1): rename local variable in Cmd_Exec

It conflicts with the global fds in job.c.
 1.481 28-Nov-2020  rillig make(1): rename conflicting global variables called 'error'

When compiling make in all-in-one mode, these variable names conflict.
They could have been merged into a single variable, but that would have
required to make it a global variable for the other modules as well.
The parse module has a similar variable called 'fatals'. All these can
possibly be merged into a single variable, but not now.
 1.480 25-Nov-2020  sjg Add .MAKE.UID and .MAKE.GID
 1.479 24-Nov-2020  rillig make(1): fix indentation for short expressions in main.c
 1.478 23-Nov-2020  rillig make(1): use comparisons in boolean expressions

The generated code stays exactly the same.
 1.477 23-Nov-2020  rillig make(1): use properly typed comparisons in boolean contexts
 1.476 16-Nov-2020  rillig make(1): fix initialization order of modules (broken since today)

In CLEANUP mode, Var_Init depends on Targ_Init since the variable scopes
are implemented as GNodes.

By the way, since 1999-09-15 variables are no longer stored in lists but
in hash tables.
 1.475 16-Nov-2020  rillig make(1): use postfix increment where possible
 1.474 15-Nov-2020  rillig make(1): clean up ParseBoolean
 1.473 15-Nov-2020  rillig make(1): clean up getTmpdir

Reduce indentation, structure code into paragraphs.
 1.472 15-Nov-2020  rillig make(1): clean up PrintOnError

No functional change.
 1.471 15-Nov-2020  rillig make(1): fix previous commit for parse_debug_options
 1.470 15-Nov-2020  rillig make(1): reduce code size of parse_debug_options

Each access to a global variable requires a relocation. Skip these.
 1.469 14-Nov-2020  rillig make(1): switch cache for realpath from GNode to HashTable

An unintended side effect from the GNode implementation was that the
variable modifier :tA and the other places where cached_realpath are
used could be affected by setting a variable in the global scope,
thereby "redirecting" absolute paths to completely unrelated but
existing paths.

Another unintended side effect was that filenames containing a dollar
sign would not be resolved correctly since the dollar sign would be
expanded as a variable expression by Var_Set.

While here, the debugging output for the realpath cache has been
adjusted to the standard behavior. Previously, when a new entry was
added to the cache, this was logged for the module VAR, as a side effect
of calling Var_Set, but only if the preprocessor macro
DEBUG_REALPATH_CACHE was defined at compilation time. When relative
paths were purged from the cache because the current directory changed
and logging for the DIR module was active, the log output went directly
to stderr instead of the usual opts.debug_file. This deviation from the
standard behavior was probably not intended as well.

All logging concerning the realpath cache now goes into the standard
debug log file and is controlled by the -dd option, not -dv.
 1.468 14-Nov-2020  rillig make(1): document the -S option

This option has been available at least since 1993-03-21, and for the
same time it has been undocumented.
 1.467 14-Nov-2020  rillig make(1): fix trailing whitespace in usage (since 2009-08-27)
 1.466 14-Nov-2020  rillig make(1): don't modify progname in usage
 1.465 14-Nov-2020  rillig make(1): clean up Fatal

Use the shortest possible scope between va_start and the corresponding
va_end.
 1.464 14-Nov-2020  rillig make(1): clean up InitDefSysIncPath

Flipping the arguments to strncmp puts the subject first in the
sentence. Inverting the condition makes the code flow easier to follow.
 1.463 14-Nov-2020  rillig make(1): use progname instead of hard-coded 'make' in warning

This only affects the warning that chdir to objdir failed. In sub-makes
the progname includes the [n], allowing to narrow down the actual cause
of the problem.
 1.462 14-Nov-2020  rillig make(1): remove redundant parameter from str2Lst_Append
 1.461 14-Nov-2020  rillig make(1): rename Main_SetVarObjdir to SetVarObjdir

Only exported functions should be prefixed with the module name.
 1.460 14-Nov-2020  rillig make(1): use different style of accessing characters in MainParseArgs

The * is preferred for iterators. Since argv[i] is not an iterator but
a fixed string, argv[i][0] expresses the idea "read the first character"
more directly.
 1.459 14-Nov-2020  rillig make(1): rename DEFAULT to defaultNode

In C, uppercase names are typically used for constants, and this is not
a constant.
 1.458 13-Nov-2020  rillig make(1): clean up preprocessor macros in InitVarMachine
 1.457 13-Nov-2020  rillig make(1): flatten #ifdef in InitVarMachineArch

Without proper indentation, that chain of nested #ifndef directives was
really hard to read.
 1.456 12-Nov-2020  sjg Pass a writable flag to Main_SetObjdir to control writable check

For curdir and an explicit .OBJDIR target, we allow for
the directory to be read-only.
During InitObjdir we otherwise default to requiring objdir to be
writable - this can be controlled by env variable
MAKE_OBJDIR_CHECK_WRITABLE

Add unit-tests/objdir-writable

Reviewed by: christos rillig
 1.455 08-Nov-2020  rillig make(1): move lint option away from the debug flags

The lint option affects much more than a typical debug flag. Not only
does it produce additional diagnostics, it also changes the control flow
and fixes the traditional error handling in a few places.

No functional change.
 1.454 08-Nov-2020  rillig make(1): use strict typing in conditions of the form !var
 1.453 08-Nov-2020  rillig make(1): reformat main.c more closely to share/misc/style
 1.452 08-Nov-2020  rillig make(1): remove redundant comment from main_ReadFiles

The code has become so simple that it made the comment redundant.
 1.451 08-Nov-2020  rillig make(1): rename init_machine to InitVarMachine

For consistency with the other Init functions.
 1.450 08-Nov-2020  rillig make(1): move usage further to the top

This avoids a forward declaration.
 1.449 08-Nov-2020  rillig make(1): move documentation from main to the phase functions
 1.448 08-Nov-2020  rillig make(1): split main into manageable pieces

The purpose of a main function is to give a high-level overview about the
whole program. 270 lines of code with lots of tricky details did not serve this
purpose. Split the code into functions corresponding to the phases.
 1.447 08-Nov-2020  rillig make(1): indent main consistently
 1.446 08-Nov-2020  rillig make(1): inline ReadMakefileSucceeded into ReadFirstDefaultMakefile

This gets rid of a few void pointers and an unused function parameter.
 1.445 08-Nov-2020  rillig make(1): inline Lst_ForEachUntil in ReadBuiltinRules

The list of expanded filenames for sys.mk is freed in the end, but not
the filenames themselves, as these are still needed.
 1.444 08-Nov-2020  rillig make(1): use common indentation style for else
 1.443 08-Nov-2020  rillig make(1): split ReadMakefiles into separate functions

This keeps the indentation of the code small.

It also reduces the possible confusion about the two similar branches in
that function that differ in a small but important detail:
ReadAllMakefiles reads all the makefiles while ReadFirstDefaultMakefile
stops after the first existing makefile.
 1.442 08-Nov-2020  rillig make(1): fix unrealistic memory leak in Main_ParseArgLine

It's unlikely that anyone ever defines an environment variable named
".MAKE" and then runs make with the -e option, which would make the
environment variable stronger than the built-in global variable.
 1.441 08-Nov-2020  rillig make(1): add remarks for missing command line options in MAKEFLAGS
 1.440 08-Nov-2020  rillig make(1): parse the internal option -J strictly
 1.439 08-Nov-2020  rillig make(1): merge duplicate code in is_relpath
 1.438 08-Nov-2020  rillig make(1): clean up overview comment in main.c
 1.437 08-Nov-2020  rillig make(1): fix type mismatch between int and PrintVarsMode
 1.436 07-Nov-2020  rillig make(1): remove trailing whitespace
 1.435 07-Nov-2020  rillig make(1): make API of Buf_Init simpler

In most cases, the caller doesn't want to specify the exact number of
preallocated bytes.
 1.434 07-Nov-2020  rillig make(1): document InitDefSysIncPath
 1.433 07-Nov-2020  rillig make(1): clean up code stylistically

* Replace character literal 0 with '\0'.
* Replace pointer literal 0 with NULL.
* Remove redundant parentheses.
* Parentheses in multi-line conditions are not redundant at the
beginning of a line.
* Replace a few !ptr with ptr == NULL.
* Replace a few ptr with ptr != NULL.
* Replace (expr & mask) == 0 with !(expr & mask).
* Remove redundant braces for blocks in cases where the generated code
stays the same. (Assertions further down in the code would get
different line numbers.)
* Rename parameters in CondParser_String to reflect the data flow.
* Replace #ifdef notdef with #if 0.

The generated code stays exactly the same, at least with GCC 5.5.0 on
NetBSD 8.0 amd64 using the default configuration.
 1.432 06-Nov-2020  rillig make(1): rename getBoolean and s2Boolean
 1.431 06-Nov-2020  rillig make(1): fix comment of Error
 1.430 06-Nov-2020  rillig make(1): clean up Cmd_Exec stylistically
 1.429 06-Nov-2020  rillig make(1): rename dieQuietly to shouldDieQuietly

It was too confusing to have a function named die that doesn't actually
die. Plus, the return type int didn't give any clue about what the
function actually returns.
 1.428 06-Nov-2020  rillig make(1): fix typo from previous commit
 1.427 06-Nov-2020  rillig make(1): fix wrong condition in mkTempFile (since 2020-10-31)

The wrong negation had been added in main.c 1.414 from 2020-10-31.
Found by GCC 10, which complained about a potential null pointer
dereference in line 2188.
 1.426 05-Nov-2020  rillig make(1): remove redundant parentheses from sizeof operator

The parentheses are only needed if the argument is a type, not an
expression.
 1.425 04-Nov-2020  rillig make(1): move declaration of parseIncPath from main.c to make.h
 1.424 04-Nov-2020  rillig make(1): rename MAKEFILE_PREFERENCE for consistency

The names of the other special variables are all prefixed with MAKE_.
 1.423 04-Nov-2020  rillig make(1): negate discardUndefined to preserveUndefined
 1.422 04-Nov-2020  rillig make(1): rename oldVars to discardUndefined

While here, moved all the documentation about this variable into a
single place.
 1.421 01-Nov-2020  rillig make(1): in lint mode, exit with error status on errors

Calling Parse_Error during parsing has always led to a nonzero exit
status. Calling Parse_Error later, when expanding the shell commands,
has had no effect on the exit status. Neither had calling Error.

To make make a reliable tool, it has to report errors as they occur.
Enable this strict behavior in lint mode for now. Lint mode has to be
enabled explicitly, preserving the default behavior.
 1.420 31-Oct-2020  sjg Main_SetObjdir is first called for curdir which may be readonly

Skip access check if path is curdir.
This ensures that all proper initialization is done at least once.

If path is not curdir it should be writable to be useful.

Reviewed by: rillig
 1.419 31-Oct-2020  rillig make(1): revert requiring a writable objdir

The change in main.c 1.413 broke the NetBSD build.sh if it uses a
read-only source tree, as in the daily builds.

Original commit:
https://mail-index.netbsd.org/source-changes/2020/10/31/msg123560.html

Build log:
make warning: /home/source/ab/HEAD/src: Permission denied.
[1] Segmentation fault "${make}" -m ${T...
 1.418 31-Oct-2020  rillig make(1): reduce the scope where recursive expressions are detected

Only the call to Var_Subst needs to be protected since the other
functions have nothing to do with expanding variables.
 1.417 31-Oct-2020  rillig make(1): remove redundant :tl from getBoolean

Uppercase and lowercase letters are already handled the same by
s2Boolean, which makes the :tl modifier redundant.
 1.416 31-Oct-2020  rillig make(1): remove redundant null check from s2Boolean
 1.415 31-Oct-2020  rillig make(1): write s2Boolean in a more compact form
 1.414 31-Oct-2020  rillig make(1): clean up mkTempFile
 1.413 31-Oct-2020  sjg Do not use an objdir that is not writable.
 1.412 30-Oct-2020  rillig make(1): change char * to void * in Var_Value

The only purpose of the parameter freeIt is to free the memory
associated with the return value. To do this, no pointer arithmetic is
needed. Therefore, change to a void pointer, to catch accidental use of
that pointer.
 1.411 30-Oct-2020  rillig make(1): fix indentation in source code
 1.410 30-Oct-2020  rillig make(1): rename VAR_CMD to VAR_CMDLINE

Since make has to do with both the command line and child commands, the
former name was confusing.
 1.409 28-Oct-2020  rillig make(1): rename defIncPath to defSysIncPath

There are two variables, parseIncPath and sysIncPath, which made the
name defIncPath ambiguous.
 1.408 27-Oct-2020  rillig make(1): extract InitMaxJobs from main
 1.407 27-Oct-2020  rillig make(1): extract InitObjdir from main
 1.406 27-Oct-2020  rillig make(1): make InitVarMake simpler and document its intention
 1.405 27-Oct-2020  rillig make(1): extract InitVarMake from main
 1.404 27-Oct-2020  rillig make(1): extract InitRandom from main
 1.403 27-Oct-2020  rillig make(1): extract ReadMakefiles from main
 1.402 27-Oct-2020  rillig make(1): extract CleanUp from main

This makes it a bit easier to spot the main task of the main function,
which is the runTargets call.
 1.401 27-Oct-2020  rillig make(1): free the variable names given on the command line

These are not aliased anywhere. The opts.makefiles on the other hand
may be referenced in GNode.fname or pretty much anywhere else, so don't
free them. There's still a Targ_PrintGraph call below it that might use
them.
 1.400 27-Oct-2020  rillig make(1): extract InitVpath from main
 1.399 27-Oct-2020  rillig make(1): use constant string for Var_Subst

The times where Var_Subst needed a modifiable string are long gone.
 1.398 27-Oct-2020  rillig make(1): extract ReadBuiltinRules from main
 1.397 27-Oct-2020  rillig make(1): extract InitDefIncPath from main
 1.396 27-Oct-2020  rillig make(1): initialize all CmdOpts fiels
 1.395 27-Oct-2020  rillig make(1): extract CmdOpts_Init from main
 1.394 27-Oct-2020  rillig make(1): move debugVflag to CmdOpts
 1.393 27-Oct-2020  rillig make(1): extract UnlimitFiles from main
 1.392 26-Oct-2020  rillig make(1): remove "Results: none" from the documentation of void functions
 1.391 26-Oct-2020  rillig make(1): group the command line options and arguments

By having a single struct that holds all command line options and
arguments, it is easy to see in the code when such a command line
argument is modified. It also cleans up the namespace since the command
line options don't follow a common naming style. Having them in a
struct also means that there is a single place for putting the
documentation, not two as before.

The struct also suggests to extract the initialization code out of main,
which is still too large, having more than 400 lines of code and
covering far too many topics.
 1.390 25-Oct-2020  rillig make(1): rename hash functions to identify the type name

This makes it easier to spot mismatches between the function name and
its first parameter, although the compiler should already catch most of
them. Except for void pointers.
 1.389 25-Oct-2020  sjg Skip reading .MAKE.DEPENDFILE if set to
"/dev/null" or anything starting with "no".

Ref: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=223564
 1.388 24-Oct-2020  rillig make(1): convert macros for debug flags into enum
 1.387 24-Oct-2020  rillig make(1): remove unused Lst_Find and Lst_FindFrom
 1.386 24-Oct-2020  rillig make(1): inline ReadMakefileFailed, eliminating some void pointers
 1.385 23-Oct-2020  rillig make(1): remove void pointers from addErrorCMD
 1.384 22-Oct-2020  rillig make(1): clean up PrintVar

Conceptually, the last parameters of Var_Subst and Var_Value differ a
lot. The former is the actual variable value while the latter is just a
pointer to be freed. It will be changed to a void pointer in a few
commits.

To keep the number of needed variables small and the code simple, the
printf statement is mentioned in each branch. An additional benefit is
that in 2 of the 3 branches, no null pointer can occur.
 1.383 22-Oct-2020  rillig make(1): extract PrintVar from doPrintVars
 1.382 22-Oct-2020  rillig make(1): clean up HandlePWD
 1.381 22-Oct-2020  rillig make(1): extract HandlePWD from main
 1.380 22-Oct-2020  rillig make(1): remove redundant type casts

This mainly affects the void pointers in callback functions for lists.
These had been necessary once when the parameter type was still
ClientData instead of void pointer.
 1.379 19-Oct-2020  rillig make(1): inline simple Lst getters

The function call variant takes more screen space than the direct field
access. Having an abstract API is usually a good idea, in this case of
simple read-only member access it makes the code more difficult to read.

LstNode_Set has been kept as a function since it is not a read-only
accessor function.
 1.378 18-Oct-2020  rillig make(1): rename Lst_Init to Lst_New

For the other types such as HashTable and Buffer, the Init function does
not allocate the memory for the structure itself, it only fills it.
 1.377 18-Oct-2020  rillig make(1): rename HashEntry.name to key
 1.376 18-Oct-2020  rillig make(1): remove underscore from Hash_Table and Hash_Entry

For consistency with the other type names, such as GNodeListNode.
 1.375 18-Oct-2020  rillig make(1): prepare for WARNS=6

The FD_* macros from sys/sys/fd_set.h use signed integers on NetBSD 8
and thus produce conversion errors. On NetBSD 9, these macros are fixed
to use 1U instead of 1.
 1.374 18-Oct-2020  rillig make(1): make API for iterating over hash tables simpler
 1.373 18-Oct-2020  rillig make(1): remove USE_IOVEC

When a system call in a child process failed, there was no guarantee
that the error message would be written completely. Using writev
correctly is harder than building the string in a buffer and then
writing it in the traditional way.

According to POSIX 2004, using memory allocation or even calling
write(2) from the child process invokes undefined behavior. The
remaining code from make has done all this for several years now,
successfully, therefore adding one more of that won't hurt.

Make still tries to write the error message atomically by passing the
whole buffer at once to write(2), just as in the previous writev(2)
implementation.
 1.372 18-Oct-2020  rillig make(1): replace execError with execDie

All calls to this function were followed by _exit(1).
 1.371 05-Oct-2020  rillig make(1): remove pathname limit for Dir_FindHereOrAbove

While trying to compile the code with GCC's -Wformat-truncation, the
snprintf calls felt quite complicated. The function Dir_FindHereOrAbove
is not in a bottleneck execution path, therefore it doesn't hurt to
dynamically allocate the memory instead of using size-limited stack
memory.
 1.370 05-Oct-2020  rillig make(1): prepare job.c, main.c, parse.c, suff.c for WARNS=6

In job.c, GCC 5 complains about the macro FILENO that it has type
unsigned int, which is then passed as the argument of dup2, which
expects a simple int. Maybe this workaround from 1995 is not necessary
anymore, or maybe it is but can be restricted to the few affected
platforms.

This leaves meta.c and the filemon files to be converted. I didn't do
them since they are not well covered by the unit tests.
 1.369 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.368 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.367 05-Oct-2020  rillig make(1): extract init_machine and init_machine_arch from main
 1.366 04-Oct-2020  rillig make(1): remove duplicate code for parsing a variable name
 1.365 04-Oct-2020  rillig make(1): make documentation of Error more precise
 1.364 03-Oct-2020  rillig make(1): clean up #include sections
 1.363 03-Oct-2020  rillig make(1): replace backslash-newline with ordinary string literals

The character sequence backslash-newline is not mentioned in ISO C99.
 1.362 03-Oct-2020  rillig make(1): allow to disable debug logging options

This is only intended for the unit tests, to selectively enable and
disable debug logging as needed. Previously the tests for debug logging
required complicated postprocessing that was not obvious when looking at
the test .mk file alone, but was specified externally in
unit-tests/Makefile.

This is the simplest possible implementation. Another variant would
have been to selectively disable individual debug logging options, but
that would have made the code more complicated.

The -dL option is not affected by -d0 since that is not really a debug
option, even if it is implemented as one.
 1.361 01-Oct-2020  rillig make(1): clean up documentation of Main_ParseArgLine

The previous documentation contained lots of irrelevant implementation
details.
 1.360 01-Oct-2020  rillig make(1): add missing const for Parse_AddIncludeDir
 1.359 01-Oct-2020  rillig make(1): clean up option handling

The test for argvalue == NULL for the individual options was unnecessary
since that is already done in the common part.
 1.358 01-Oct-2020  rillig make(1): format code in MainParseArgs
 1.357 01-Oct-2020  rillig make(1): extract handling of the -m option into separate function
 1.356 01-Oct-2020  rillig make(1): extract option handling for -j/-J into separate functions
 1.355 01-Oct-2020  rillig make(1): extract MainParseArgChdir into separate function

This removes the struct stat from MainParseArg.
 1.354 01-Oct-2020  rillig make(1): extract MainParseArg into separate function

That part of the code is long enough and independent enough to get its
own function. Having a struct stat in MainParseArgs just didn't feel
like a correct abstraction level.
 1.353 01-Oct-2020  rillig make(1): remove redundant function prototypes
 1.352 28-Sep-2020  rillig make(1): make debugging code shorter
 1.351 27-Sep-2020  rillig make(1): normalize whitespace in source code

There is no more space tab. Either only tabs or only spaces or tabs
followed by spaces, but not spaces followed by tabs.
 1.350 27-Sep-2020  rillig make(1): rename Buf_Size to Buf_Len

The new name better matches the field name Buffer.len as well as the
variables around the calls to this function.
 1.349 26-Sep-2020  rillig make(1): revert migration from Lst_ForEachUntil to Lst_ForEach

There is a crucial difference between these functions, in that
Lst_ForEachUntil can cope with a few concurrent modifications while
iterating over the list. This is something that Lst_ForEach doesn't do.

This difference led to a crash very early in NetBSD's build.sh.
 1.348 26-Sep-2020  rillig make(1): inline and remove LstNode_Prev and LstNode_Next

These functions made the code larger than necessary. The prev and next
fields are published intentionally since navigating in a doubly-linked
list is simple to do and there is no need to wrap this in a layer of
function calls, not even syntactically. (On the execution level, the
function calls had been inlined anyway.)
 1.347 26-Sep-2020  rillig make(1): replace a few Lst_ForEachUntil with simpler Lst_ForEach
 1.346 26-Sep-2020  rillig make(1): clean up API for finding and creating GNodes

The previous API had complicated rules for the cases in which the single
function returned NULL or what it did. The flags for that function were
confusing since passing TARG_NOHASH would create a new node even though
TARG_CREATE was not included in that bit mask.

Splitting the function into 3 separate functions avoids this confusion.
It also reveals several places where the complicated API led to
unreachable code. Such code has been removed.
 1.345 25-Sep-2020  rillig make(1): fix undefined behavior for .MAKEFLAGS: -f file

Since at least 1993-03-21, adding other makefiles in a .MAKEFILES
dependency has invoked undefined behavior because the command line
arguments were copied directly into the global makefiles variable,
without a proper strdup. Shortly after that, the word list created by
Str_Words (formerly brk_string) was freed.

This applies to both the -f and the -v and -V options. Luckily it is an
edge case to use these options in .MAKEFLAGS at all.

The -T option had already been fixed at 2000-12-30, but not the other
options.
 1.344 25-Sep-2020  rillig make(1): extract parsing of the -dF option into separate function
 1.343 25-Sep-2020  rillig make(1): extract InitVarTarget from main
 1.342 24-Sep-2020  rillig make(1): rename Lst_ForEach to Lst_ForEachUntil

Since the callback function returns a terminating condition, this is not
really a foreach loop.

Many of the calls to Lst_ForEachUntil don't make use of the terminating
condition, and several don't modify the list structurally, which means
they don't need this complicated implementation.

In a follow-up commit, Lst_ForEach will be added back with a much
simpler implementation that iterates over the list naively, without a
terminating condition and without taking the iteration state from
Lst_Open/Lst_Next/Lst_Close into account. The migration to this simpler
implementation will be done step by step since each callback function
needs to be examined closely.
 1.341 22-Sep-2020  rillig make(1): prepare Var_Subst for proper error handling

Returning a VarParseResult instead of a string makes it possible to let
the error bubble up, until it reaches the main expression.
 1.340 22-Sep-2020  rillig make(1): fix unnecessary length limitation for -v option
 1.339 22-Sep-2020  rillig make(1): fix type of global variable 'create'
 1.338 22-Sep-2020  rillig make(1): use fine-grained type names for lists and their nodes

This is only intended to help the human reader. There is no additional
type safety yet.
 1.337 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.336 13-Sep-2020  rillig make(1): remove #endif comments for very short blocks
 1.335 13-Sep-2020  rillig make(1): remove redundant VARARGS comments

These had been necessary at a time when the functions were declared with
"unknown parameter types".

On 1994-03-05, conditional support for function prototypes was added,
for those compilers that already supported this feature.

On 2002-06-15, the prototypes were made mandatory, and since then the
VARARGS comments had been completely redundant, or worse, simply wrong
(for ParseVErrorInternal).
 1.334 13-Sep-2020  rillig make(1): consense documentation for Fatal
 1.333 12-Sep-2020  rillig make(1): move PrintAddr to where it belongs
 1.332 11-Sep-2020  rillig make(1): add wrappers around ctype.h functions

This avoids casting the argument to unsigned char, and to cast the
result of toupper/tolower back to char.
 1.331 30-Aug-2020  rillig make(1): replace brk_string with Str_Words

The API is much simpler, and there is less detail that is exposed by
default and fewer punctuation to type on the caller's side. To see that
there is some memory to be freed, one would have to look into the
struct. Having part of the return value as the actual return value and
the rest in output parameters was unnecessarily asymmetrical.
 1.330 30-Aug-2020  rillig make(1): rename Lst_Datum to LstNode_Datum
 1.329 29-Aug-2020  rillig make(1): trust that Var_Subst never returns NULL

It really never does, and it doesn't even report errors. It just
returns the content of the buffer, up to the first parse error.
 1.328 29-Aug-2020  rillig make(1): make getBoolean simpler

This function is so seldom used that there is no point having
complicated code for it.
 1.327 29-Aug-2020  rillig make(1): rename LstNode functions to match their type
 1.326 29-Aug-2020  rillig make(1): rename Lst_FindB back to Lst_Find

The migration from "comparison function" to "match function" is done,
the "B" in the names is no longer needed.
 1.325 29-Aug-2020  rillig make(1): start replacing Lst_Find with Lst_FindB

Lst_Find is called with a "comparison" function that returns the integer
0 if the desired node is found. This leads to confusion since there are
so many different return value conventions for int, such as 0/1 for
mimicking false/true, -1/0 as in close(2), and the sign as in strcmp(3).
This API is much easier to understand if the "comparison" function is
not called a comparison function (since that is too close to strcmp),
but a "match" function that just returns a boolean.

In Lst_FindFromB, the node argument may be null. This deviates from the
other Lst functions, which require Lst and LstNode to generally be
non-null. In this case it is useful though to make the calling code
simpler.

In arch.c, this makes a lot of the previous documentation redundant.

In cond.c, the documentation is reduced a little bit since it had
already been cleaned up before. It also removes the strange negation
from CondFindStrMatch.

In dir.c, the documentation collapses as well.

In main.c, separating the ReadMakefile function from the callbacks for
Lst_FindB allows the former to get back its natural function signature,
with proper types and no unused parameters.

To catch any accidental mistakes during the migration from Lst_Find to
Lst_FindB, the code can be compiled with -DUSE_DOUBLE_BOOLEAN, which
will complain about incompatible function pointer types.
 1.324 29-Aug-2020  rillig make(1): fix null pointer dereference when sys.mk is not found

This is quite hard to trigger in a real-life scenario since it requires
precise timing.

Instead, I created /tmp/sys.mk and ran "./make -m /tmp -f /dev/null" in
the debugger, after setting a breakpoint in this line:

ln = Lst_Find(sysMkPath, ReadMakefile, NULL);

Once this line was reached, I removed /tmp/sys.mk to make ReadMakefile
fail. Just adding a few parse errors won't help since ReadMakefile only
fails if the file cannot be found.
 1.323 29-Aug-2020  rillig make(1): allow for strict type checking for Boolean

Having Boolean aliased to int creates ambiguities since int is widely
used. Allow to occasionally compile make with -DUSE_DOUBLE_BOOLEAN to
check that the type definitions still agree.
 1.322 29-Aug-2020  rillig make(1): clean up code in make.c

Var_Subst never returns NULL.

In Main_ExportMAKEFLAGS, don't compare ints with booleans.

In MainParseArgs, use char for the current character. First, that's
more precise and correct, and second, it makes debugging easier for
those who don't know the ASCII table by heart.
 1.321 29-Aug-2020  rillig make(1): rename confusing function ReadAllMakefiles

The old name implied that the function would read multiple files, which
was not the case.

The comment above that function was highly confusing. It's not that the
function returns a boolean, but rather 0 or non-zero, and 0 means that
Lst_Find should stop searching.

One of the next refactorings will be to make Lst_Find return the first
list node for which the function returns TRUE. This will reduce the
confusion about the several functions called SomethingP in suff.c. The
P suffix means to return TRUE or FALSE, not 0 or non-zero.
 1.320 28-Aug-2020  rillig make(1): remove trailing 'S' from names of Lst functions

The migration from null-passing Lst functions to argument-checking Lst
functions is completed.

There were 2 surprises: The targets list may be NULL, and in Dir_AddDir,
the path may be NULL. The latter case is especially surprising since
that function turns into an almost-nop in that case. This is another
case where probably 2 independent functions have been squeezed into a
single function. This may be improved in a follow-up commit.

All other lists were fine. They were always defined and thus didn't
need much work.
 1.319 28-Aug-2020  rillig make(1): migrate Lst_Find to Lst_FindS
 1.318 28-Aug-2020  rillig make(1): migrate Lst_First to Lst_FirstS
 1.317 27-Aug-2020  rillig make(1): migrate Lst_IsEmpty to Lst_IsEmptyS
 1.316 27-Aug-2020  rillig make(1): migrate Lst_Succ to Lst_SuccS
 1.315 27-Aug-2020  rillig make(1): migrate Lst_ForEach to Lst_ForEachS

Most lists are always valid. Only the "targets" variable may be null in
some cases, probably.
 1.314 26-Aug-2020  rillig make(1): add stricter variants for remaining Lst functions

In most cases the Lst functions are only called when the arguments are
indeed valid. It's not guaranteed though, therefore each function call
needs to be analyzed and converted individually.

While here, remove a few statements that were only useful when the Lst
functions handled circular lists.
 1.313 25-Aug-2020  rillig make(1): fix obvious bugs in -DCLEANUP mode

The outdated type name FreeProc had been renamed to LstFreeProc.
Casting the function free to it is not necessary since the type of this
function is already exactly the correct type. Anything else would be
undefined behavior anyway.

The uninitialized sufflist in Suff_ClearSuffixes was ok until now
because the Lst functions had silently skipped any calls with invalid
arguments. This silent skipping is a good argument to have strict
argument validation since it detects these unintended control flows.
 1.312 23-Aug-2020  rillig make(1): make brk_string return size_t for the number of words
 1.311 23-Aug-2020  rillig make(1): reverse order of the Lst_Find parameters

The other callbacks all have (function, param), only the Lst_Find had
(param, function), which was inconsistent.
 1.310 22-Aug-2020  rillig make(1): remove unused variable jobServer
 1.309 22-Aug-2020  rillig make(1): fix indentation
 1.308 22-Aug-2020  rillig make(1): replace Lst_Datum with non-null guaranteeing Lst_DatumS
 1.307 22-Aug-2020  rillig make(1): replace "(void)Lst_AtEnd" with stricter "Lst_AppendS"

This change ensures that there is actually something added to the list.
Lst_AtEnd had silently skipped the addition if the list was invalid
(null pointer), which was not intended in these cases. The "(void)" is
assumed to mean "I know that this cannot fail", while it could also mean
"I don't care whether something actually happened".

Running "./build.sh -j6 tools" still succeeds after this change,
therefore chances are very low that this change breaks anything. If
there is any change, it's an obvious assertion failure. There is no
silent change in behavior though.
 1.306 22-Aug-2020  rillig make(1): split Dir_Init into two functions

There's just no point in having a function consisting of a big
if-then-else.
 1.305 21-Aug-2020  rillig make(1): remove unused code for circular lists

The list library had probably been imported from a general-purpose
library that also supported circular lists. These are not used by make
though.

After replacing Lst_Init(FALSE) with Lst_Init(), only a single call to
Lst_Init remained with a non-constant argument, and that was in
Lst_Concat, which was to be expected.
 1.304 11-Aug-2020  rillig make(1): replace snprintf/malloc in ReadMakefile with str_concat3
 1.303 10-Aug-2020  rillig make(1): replace str_concat with str_concat2 and str_concat3

The new functions have a simpler interface, and str_concat3 is even more
general-purpose, since the middle string is no longer required to be
exactly of length 1.
 1.302 09-Aug-2020  rillig make(1): clean up indentation, includes, add documentation
 1.301 09-Aug-2020  rillig make(1): remove outdated comment
 1.300 09-Aug-2020  rillig make(1): avoid undefined behavior in Cmd_Exec

Iterating the command output backwards was dangerous since at the end,
the pointer cp pointed outside of the array. Even without dereferencing
this pointer, this already invokes undefined behavior (C11, 6.5.6p8).
Don't risk anything. Iterating forwards is probably faster anyway, since
it is more common.
 1.299 09-Aug-2020  rillig make(1): remove redundant assignment from Cmd_Exec

A Buffer is always null-terminated.
 1.298 09-Aug-2020  rillig make(1): split local variable in Cmd_Exec into two

This avoids a mismatch between signed and unsigned types.
 1.297 08-Aug-2020  rillig make(1): remove trailing Z from buffer functions

This Z had been useful during the migration from int to size_t. This
migration is finished, at least for the Buffer type, so the Z is no
longer necessary.
 1.296 03-Aug-2020  rillig make(1): no declaration-after-statement anymore

NetBSD make is intended to be maximally portable, therefore it uses only
C89. This was not declared in the Makefile before.

There are still a few places in parse.c and metachar.c that use
end-of-line comments. These will be fixed in a follow-up commit.
 1.295 02-Aug-2020  rillig make(1): replace one instance of strncpy with snprintf

GCC 9 incorrectly claims that the string might not be null-terminated.
Since objdir is a global variable, it is initialized to zero, and the +1
in the size guarantees that this byte is always 0.

Still, using strncpy to initialize a string is a waste of memory access,
since it is enough if only the actual data is copied, without zeroing
out all the remaining bytes.
 1.294 01-Aug-2020  rillig make(1): switch Buffer size from int to size_t

This change helps to make the various integer types compatible and is a
preparational step for setting WARNS=6 in the Makefile.

The documentation of buf.c has been cleaned up and condensed since it
was mostly redundant, and some statements were even slightly wrong.

All code changes are covered by the existing unit tests, except for the
few lines in for.c around for_var_len. These changes have been reviewed
thoroughly and manually, like all the others in this commit.

Those buffer functions that deal with sizes have been renamed by
appending a Z, to make sure that no function call was accidentally
forgotten. They will be renamed back in a follow-up commit.

As usual, the scope of a few affected variables has been reduced, and
some variables had to be split since they had been incorrectly merged
before.

The order of the arguments to Buf_AddBytes has changed from (mem_len,
mem) to (mem, mem_len), in order to make it consistent with the
functions from the C standard library, such as snprintf.
 1.293 01-Aug-2020  rillig make(1): fix parameter name in Cmd_Exec

A format string is not a number.
 1.292 01-Aug-2020  rillig make(1): use ordinary string concatenation in usage text
 1.291 01-Aug-2020  rillig make(1): use consistent indentation in source code

Tabs for multiples of 8, then spaces.

The usage string has been kept as-is since the spaces there are
indentional and do influence the output.
 1.290 01-Aug-2020  rillig make(1): avoid calls to free(3) in the common case of a NULL pointer
 1.289 01-Aug-2020  rillig make(1): let Var_Value return a const char *

The return value must not be modified anyway, so let the compiler check
this for free.
 1.288 01-Aug-2020  rillig make(1): make Main_SetVarObjdir const-correct and use separate variables

The return value of Var_Value should be const char *, but changing that
now would be too large a change.
 1.287 01-Aug-2020  rillig make(1): merge duplicate code for concatenating strings
 1.286 01-Aug-2020  rillig make(1): eliminate unsatisfiable condition in is_relpath
 1.285 31-Jul-2020  sjg Add -dL for LINT

When parsing variable assignments other than := and if
value contains '$' attempt Var_Subst the same as for :=,
if the value does not parse correctly, we get a fatal error
including file an line number.

This can greatly help with finding the cause of problems.

Reviewed by: christos
 1.284 28-Jul-2020  rillig make(1): remove dead code from Var_Subst

The first parameter from Var_Subst had been a literal NULL in all cases.
These have been fixed using this command:

sed -i 's|Var_Subst(NULL, |Var_Subst(|' *.c

The one remaining case was not found because the "NULL," was followed by
a line break instead of a space.

The removed code probably wouldn't have worked as expected anyway.
Expanding a single variable to a literal string would have led to
unexpected behavior for cases like ${VAR:M${pattern}}, in case pattern
would contain an unescaped ':' itself.
 1.283 20-Jul-2020  sjg Make DEBUG_HASH less of a fire-hose.

Reporting keys on every lookup is overkill unless
playing with a new HASH, so wrap in #ifdef DEBUG_HASH_LOOKUP
Also add some stats at the end so we can see
final size and max chain length - maxchain is a better
variable name than maxlen.
 1.282 19-Jul-2020  rillig make(1): clean up unnecessary snprintf and multi-line function calls
 1.281 19-Jul-2020  rillig make(1): rename Varf_Flags to VarEvalFlags

In var.c there are lots of different flag types. To make any accidental
mixture obvious, each flag group gets its own prefix.

The only flag group that is visible outside of var.c is concerned with
evaluating variables, therefore the "e", which replaces the former "f"
that probably just meant "flag".
 1.280 18-Jul-2020  sjg Add -dh for DEBUG_HASH

Allow tracking of max chain length, to see how well the hash
tables are working.
Pull the actual hash operation into a marco so it can be
easily changed - for experimenting.

The current hash, is pretty good.

Reviewed by: christos
 1.279 03-Jul-2020  rillig make(1): remove trailing whitespace
 1.278 03-Jul-2020  rillig make(1): remove redundant parentheses around return values
 1.277 02-Jul-2020  rillig make(1): remove useless parameter from Var_Set

The enum corresponding to this int parameter is only defined in var.c,
which makes it impractical for the outside to set this parameter to
anything but 0.

On x86_64, this reduces the size of the resulting executable by 5 kB.
 1.276 22-Jun-2020  sjg dieQuietly: ignore OP_SUBMAKE

Stick to OP_MAKE for deciding when to supress noise
as OP_SUBMAKE can be too aggressive.

Reviewed by: gson
 1.275 19-Jun-2020  sjg Avoid unnecessary noise when sub-make or sibling dies

When analyzing a build log, the first 'stopped' output
from make, is the end of interesting output.

Normally when a build fails deep down in a parallel build
the log ends with many blockes of error output from make,
with all but the fist being unhelpful.

We add a function dieQuietly() which will return true
if we should supress the error output from make.
If the failing node was a sub-make, we want to die quietly.

Also when we read an abort token we call dieQuietly telling we
want to die quietly.

This behavior is suppressed by -dj or
setting .MAKE.DIE_QUIETLY=no

Reviewed by: christos
 1.274 30-Mar-2020  sjg make: fix -fno-common build

debug was declared extern, but debug_file was not; correct this and define
debug_file in main.c (as debug is) to fix the -fno-common build.

-fno-common will become the default with GCC10/LLVM11.

Patch from kevans at freebsd
 1.273 28-Oct-2017  sjg branches: 1.273.4; 1.273.6;
Ignore empty MAKEOBJDIR

Otherwise we end up with .OBJDIR = ${.CURDIR}/
which is quivalent, but fails the typial
.if ${.OBJDIR} == ${.CURDIR}
 1.272 19-Jun-2017  christos Add -v variable that always expands variables; restore -V the way it was.
 1.271 19-Jun-2017  christos make the code look like to 1.266
 1.270 19-Jun-2017  christos Remove previous variable expansion code; sjg had already added the code to
do it. Note that the manual page already documents this behavior and does
not need to change:

-dV -V VAR: prints the raw variable
-V VAR: prints the expanded variable
 1.269 17-Jun-2017  christos a variable that starts with \\ is not expanded.
 1.268 17-Jun-2017  christos simplify
 1.267 17-Jun-2017  christos -V: try to expand the variable again if the value contains a variable.
 1.266 17-Jun-2017  christos move some code out of the gigantic main function; no functional change.
 1.265 10-May-2017  sjg branches: 1.265.2;
Main_SetObjdir: ensure buf2 is in scope
 1.264 20-Apr-2017  sjg branches: 1.264.2;
We cannot tollerate things like trailing /.. etc in .CURDIR
so only accept -C arg "as is" if it contains no relative components.
 1.263 19-Apr-2017  sjg We cannot use buf as both src and destination for snprintf.
 1.262 16-Apr-2017  riastradh Factor out parts of cached_realpath.

This wacky API confused Coverity (CID 1405167) and is no good for
human readers either.
 1.261 16-Apr-2017  maya Use bmake_malloc where we don't test the return value of malloc currently.

Appeases coverity.
 1.260 13-Apr-2017  christos PR/52159: Jamie Landeg-Jones: Don't try to expand $'s in paths or system
variables. Only expand them ${MAKE} variable values.
 1.259 26-Mar-2017  sjg When we change .OBJDIR we should delete any cached realpath results
for relative paths.

Reviewed by: christos
 1.258 11-Mar-2017  sjg Do not consider using -C arg "as is" for .CURDIR unless it starts with '/'.

Reviewed by: christos
 1.257 08-Feb-2017  christos Use strncpy here because we need to be portable, and we have the +1 byte
to save us :-)
 1.256 07-Feb-2017  christos use the logical path for -C if correct.
 1.255 31-Jan-2017  sjg Partially initialize Dir before MainParseArgs can be called.

The rest can be done once curdir is finalized.
 1.254 10-Dec-2016  christos branches: 1.254.2;
Back in 1993 ${MACHINE} was a unique way to define objdirs for
every platform. Thus setting OBJMACHINE, allowed one to keep
in-tree objdirs with multiple builds. With the advent of evb*, this
has become impossible until now. Introduce OBJMACHINE_ARCH that
adds ${MACHINE_ARCH} to the objdir so that we have unique objdirs
per build again. Until we restructure things to that this is not
necessary, it is the simplest fix.
 1.253 07-Dec-2016  christos Don't apply the suffix (curdir) to MAKEOBJDIR
 1.252 07-Dec-2016  christos Refactor and simplify objdir setting code.
 1.251 26-Aug-2016  dholland Add a .DELETE_ON_ERROR: magic target that causes *failed* targets as
well as *interrupted* targets to be deleted. The name and behavior of
the variable matches gmake.

Also fix a glitch in newline output on error in compat mode that I
discovered while doing it.

Closes PR 51376.
 1.250 11-Aug-2016  sjg PR: 51405
Description:

addErrorCMD: in compat mode, cmdp may be NULL, skip it
and stop the calls (return 1).
 1.249 10-Aug-2016  sjg Set .ERROR_CMD if we can
 1.248 07-Jun-2016  christos branches: 1.248.2;
fix memory leak, simplify
 1.247 05-Jun-2016  christos NUL terminate.
 1.246 05-Jun-2016  sjg Avoid breaking !NetBSD build
 1.245 03-Jun-2016  sjg Add cached_realpath()

realpath(3) is expensive, and meta mode at least uses it extensively.
We use cached_realpath() to save the result of successful calls to
realpath(3) in a private variable context.

This improves the worst case performance (eg examining libc with
nothing to do) by a factor of 4.

Reviewed by: christos
 1.244 05-Apr-2016  sjg Skip looking for .MAKE.JOBS if either of compatMake or forceJob is true.

If -B compatMake will be true and should be honored.
If -j forceJobs will be true and the command line supplied .MAKE.JOBS
should be respected - for consistency with other usage.
 1.243 16-Mar-2016  matthias honor setting .MAKE.JOBS from the makefile. That way one can e.g. do:

CPUS!=sysctl -n hw.ncpuonline
.MAKE.JOBS?=$(CPUS)
 1.242 07-Mar-2016  christos str2Lst_Append tokenizes the string and uses it in the list so we can't
free the string afterwards. Keep a copy of it and cleanup at the end.
 1.241 19-Feb-2016  sjg getBoolean:
We need :U to ensure we get an empty string if knob isn't set.
 1.240 18-Feb-2016  sjg Add .export-literal to avoid the need for $$ dance when trying to put
unexpanded variables into environment.

Reviewed by: christos
 1.239 18-Feb-2016  christos Collapse the 3 boolean parameter to 1 flags parameter. No functional change.
 1.238 17-Jan-2016  christos remove free NULL checks (Tilman Sauerbeck)
 1.237 17-Jan-2016  christos provide missing FD_CLOEXEC for the havenots.
 1.236 09-Jan-2016  christos Preserve $$ in := assignments..

FOO=\$$CRAP
BAR:=${FOO}

all:
echo ${FOO}
echo ${BAR}
 1.235 25-Oct-2015  sjg PrintOnError: fflush stdout before running .ERROR

produces more consistent results in unit-tests.
 1.234 11-Oct-2015  sjg Add Boolean wantit to Var_Parse and Var_Subst

wantit will be FALSE when we are just consuming to discard
in which case we skip "expensive" things like Cmd_Exec.

Reviewed by: christos
 1.233 10-Sep-2015  sjg Output Entering/Leaving messages for objdir when != srcdir and -w flag
This helps ensure Emacs can find source of error.

Reviewed by: christos
 1.232 26-Mar-2015  sjg Move initialization of savederr to the block where it is used
to avoid spurious warning from gcc 5
 1.231 09-Sep-2014  dholland Restore apb's 20140820 commit (-r1.228 of main.c):
It should not be an error to have VAR != command that prints no output

Joerg reverted a bit too enthusiastically.
 1.230 07-Sep-2014  joerg Revert all make changes except the unit tests to the state of three
weeks ago. Individual changes can be reapplied after review.
 1.229 23-Aug-2014  christos PR/46096: Jarmo Jaakkola: fix many problems with dependencies (PR 49086)

Quite extensive rewrite of the Suff module. Some ripple effects into
Parse and Targ modules too.

Dependency searches in general were made to honor explicit rules so
implicit and explicit sources are no longer applied on targets that
do not invoke a transformation rule.

Archive member dependency search was rewritten. Explicit rules now
work properly and $(.TARGET) is set correctly. POSIX semantics for
lib(member.o) and .s1.a rules are supported.

.SUFFIXES list maintenance was rewritten so that scanning of existing
rules works when suffixes are added and that clearing the suffix list
removes single suffix rules too. Transformation rule nodes are now
mixed with regular nodes so they are available as regular targets too
if needed (especially after the known suffixes are cleared).

The .NULL target was documented in the manual page, especially to
warn against using it when a single suffix rule would work.
A deprecation warning was also added to the manual and make also
warns the user if it encounters .NULL.

Search for suffix rules no longer allows the explicit dependencies
to override the selected transformation rule. A check is made in
the search that the transformation that would be tried does not
already exist in the chain. This prevents getting stuck in an infinite
loop under specific circumstances. Local variables are now set
before node's children are expanded so dynamic sources work in
multi-stage transformations. Make_HandleUse() no longer expands
the added children for transformation nodes, preventing triple
expansion and allowing the Suff module to properly postpone their
expansion until proper values are set for the local variables.

Directory prefix is no longer removed from $(.PREFIX) if the target
is found via directory search.

The last rule defined is now used instead of the first one (POSIX
requirement) in case a rule is defined multiple times. Everything
defined in the first instance is undone, but things added "globally"
are honored. To implement this, each node tracks attribute bits
which have been set by special targets (global) instead of special
sources (local). They also track dependencies that were added by
a rule with commands (local) instead of rule with no commands (global).

New attribute, OP_FROM_SYS_MK is introduced. It is set on all targets
found in system makefiles so that they are not eligible to become
the main target. We cannot just set OP_NOTMAIN because it is one of
the attributes inherited from transformation and .USE rules and would
make any eligible target that uses a built-in inference rule ineligible.

The $(.IMPSRC) local variable now works like in gmake: it is set to
the first prerequisite for explicit rules. For implicit rules it
is still the implied source.

The manual page is improved regarding the fixed features. Test cases
for the fixed problems are added.

Other improvements in the Suff module include:
- better debug messages for transformation rule search (length of
the chain is now visualized by indentation)
- Suff structures are created, destroyed and moved around by a set
of maintenance functions so their reference counts are easier
to track (this also gets rid of a lot of code duplication)
- some unreasonably long functions were split into smaller ones
- many local variables had their names changed to describe their
purpose instead of their type
 1.228 20-Aug-2014  apb It should not be an error to have VAR != command that prints no output
 1.227 08-Aug-2014  gson Fix comment: Error, Fatal, and Punt take any number of arguments, not two.
 1.226 07-Feb-2014  pooka branches: 1.226.2;
Use Var_Value() instead of getenv() to obtain MAKEOBJDIR{,PREFIX}.

Fixes "make -X MAKEOBJDIR=foo". Purely uncoincidentally, build.sh
creates the nbmake wrapper with MAKEFLAGS -X on FreeBSD.
 1.225 14-Sep-2013  matt If MAKE_NATIVE, use sysctl to get MACHINE_ARCH from hw.machine_arch.
 1.224 04-Sep-2013  sjg Add VAR_INTERNAL as a context for variables set by make itself,
which should not override those set by makefiles.
Currently MAKEFILE is the only variable affected.

Reviewed by: christos
 1.223 04-Aug-2013  sjg Move the call to Job_SetPrefix() to Job_Init() so that
makefiles have had a chance to set .MAKE.JOB.PREFIX
 1.222 18-Jul-2013  sjg From bmake: move decl of pwd nearer to where it is used so the whole
thing can be ifdef'd out without causing unused variable errors.
 1.221 16-Jul-2013  christos branches: 1.221.2;
use bmake_foo instead of efoo()
 1.220 16-Jul-2013  christos More gmake compatibility:
1. add -w flag to print Entering and Leaving directory name the the beginning
and the end of processing.
2. export MAKELEVEL=$((MAKELEVEL + 1)) only in the child environment.
3. when printing error messages, prefix them with the program name [$MAKELEVEL]
for $MAKELEVEL > 0
4. if $MAKEFLAGS consists only of letters assume it is a set of flags (as
allowed by posix), convert them to -f -l -a -g -s, so that they get parsed
properly.
With those fixes gmake -> bmake -> gmake -> bmake etc. works as expected.
 1.219 15-Jul-2013  christos Make this work again like gmake. sjg: see the test program.
 1.218 09-Jul-2013  sjg For .MAKE.LEVEL.ENV use VAR_CMD so updates are ignored
 1.217 09-Jul-2013  sjg Set .MAKE.LEVEL.ENV to the name of the env variable used to communicate
the recursion level to sub-makes.
 1.216 06-Jul-2013  sjg If using gmake's MAKELEVEL; use it the same way
 1.215 29-Jun-2013  christos PR/47973: Justin Cormack: build uses <sys/signal.h> not in POSIX
 1.214 18-Jun-2013  sjg Use a #define for the variable name we put in environment to pass .MAKE.LEVEL
in case we don't want to use gmake's MAKELEVEL in a different way.
 1.213 10-Jun-2013  christos put back previous change
 1.212 10-Jun-2013  joerg Revert last, it doesn't even build.
 1.211 10-Jun-2013  christos 1. Don't export .MAKE.LEVEL, because this is an illegal variable name for
some shells; export MAKELEVEL like gmake(1) does.
2. It is absurd for the environment variable to be one greater than the
make variable!?!?! To wit...
printf 'all:\n\t@echo ${.MAKE.LEVEL}; printenv .MAKE.LEVEL' | make -f -
 1.210 23-Mar-2013  sjg If built with filemon support, set .MAKE.PATH_FILEMON to _PATH_FILEMON
so that makefiles can test for it.
 1.209 26-Feb-2013  christos PR/45042: Thomas Cort: HAVE_foo for setrlimit(2) and setpgid(2)
 1.208 25-Feb-2013  dholland typo in comment
 1.207 16-Feb-2013  christos we need utsname all the time.
 1.206 16-Feb-2013  christos Set .MAKE.OS to utsname.sysname so we can tell bogus OS's apart early in
the build process.
 1.205 26-Jan-2013  christos Check read and write errors to avoid warnings from linux.
XXX: Should we print an error and exit instead?
 1.204 25-Jan-2013  sjg Remove Check_Cwd - it is no longer needed.
 1.203 31-Aug-2012  sjg branches: 1.203.2;
Cast sizeof() to int, which is sufficent and consistent with other use
within make.
 1.202 31-Aug-2012  pgoyette Cast sizeof() to (ssize_t) to avoid build errors.
 1.201 30-Aug-2012  sjg Add a knob to control whether -V fully expands a plain variable by default.
The default retains the traditional NetBSD behavior, but the knob
can be set so that FreeBSD can retain their expected behavior.
This is a compromise to be sure.

Add a debug flag -dV to override the above, so that regardless of
the knob setting, the raw value of a variable can be easily seen.
 1.200 12-Jun-2012  joerg Replace __dead, __unused and the various printf format attributes
with versions prefixed by MAKE_ATTR_* to avoid modifying the
implementation namespace. Make sure they are available in all places
using nonints.h to fix bootstrap on Linux.
 1.199 24-Apr-2012  sjg Fix handling of -dF+/tmp/file
 1.198 16-Sep-2011  joerg branches: 1.198.2;
Use __dead consistently. If it doesn't exist, define it away.
 1.197 04-May-2011  sjg Add .MAKE.META.BAILIWICK - to identify the scope of make's control.
meta_oodate: if a file that was written or linked within our bailiwick,
but outside of .OBJDIR is missing, add it to missingFiles.
If we get to the end of the .meta file without seeing it [re]moved,
then consider the target out-of-date.
 1.196 20-Feb-2011  joerg Use the current directory at start time for .PARSEDIR, if the filename
contains no /.
 1.195 13-Feb-2011  sjg Mark unused args.
 1.194 25-Dec-2010  dholland branches: 1.194.2;
Improve confusing error message when getcwd() fails.
 1.193 25-Dec-2010  dholland Begin cleanup of the make parser: separate out the logic for reading files
from the parsing goo. This will now use mmap for reading if it works and
fall back to read only for pipes and such. Step 1 of a cleanup program
proposed without objection on tech-toolchain.
 1.192 13-Dec-2010  dholland Add const necessary for clean non-native build.
 1.191 09-Dec-2010  sjg meta_oodate(): we should track 'latestdir' on a per process basis.
Also, only consider target out of date if a not-found file is outside
'CWD'. Ignore anything in "/tmp/" or tmpdir.
 1.190 13-Sep-2010  sjg Add meta.c which implements "meta" mode for make.
In this mode, a .meta file is created for each target, capturing
the expanded commands used, any command output, and if filemon(9)
is available, a record of system calls which are of interest.
Not enabled unless USE_META=yes is set when building make.
Also, if FILEMON_H exists, meta.c will be compiled to use filemon(9).
 1.189 07-Aug-2010  sjg wait[pid]() is called in several places.
If we encounter an error and run the .ERROR target, we may
reap a pid which jobs is waiting for. Ensure that we
cleanup so that make isn't left waiting for an already
deceased child.
 1.188 03-Jun-2010  sjg We have required sigaction() for quite a while.
Use bmake_signal() - a wrapper around sigaction()
rather than signal() to ensure that signals are handled
consistently.
 1.187 17-May-2010  christos put back canonicalization, but avoid doing it for files that don't contain /
From dholland
 1.186 10-May-2010  sjg PrintOnError: run .ERROR last, so even if it causes problems we
still print MAKE_PRINT_VAR_ON_ERROR.
 1.185 05-May-2010  christos Revert bogus patch that attempted to canonicalize a non absolute argv[0] using
realpath(3). Consider: touch Makefile; mkdir make; make. This will set $MAKE
to $PWD/make so further attempts to use ${MAKE} will try to execute the
directory. This needs $ORIGIN to be fixed properly, or alternatively one
can duplicate the logic for execvp(3) and search the path for the make
executable. Not worth it. It was working just fine before!
 1.184 29-Apr-2010  sjg fflush stdout, before writing to stderr.
 1.183 23-Apr-2010  sjg On darwin at least, vfork() fails in child of vfork().
It probably shouldn't work anyway, so avoid this.
We use the macro vFork() - a function seems to cause problems
and is unnecessary overhead.
 1.182 22-Apr-2010  dholland Use _PATH_TMP instead of a literal /tmp; noted by Christos
 1.181 22-Apr-2010  dholland don't use strlcpy; it causes bootstrap issues. (noted by moof)
 1.180 22-Apr-2010  sjg Just because $TMPDIR is set does not mean it is valid.
Add a central function for creating temp files so we have one place to
audit.

Reviewed by: dh
 1.179 20-Apr-2010  sjg On some systems realpath will prefix make with cwd, so make sure
we can stat(2) the value for .MAKE
 1.178 14-Apr-2010  sjg If argv[0] is not an absolute path, attempt to resolve it
using realpath() for setting .MAKE
 1.177 08-Apr-2010  sjg Process .ERROR the same as .BEGIN, .END etc
so that it cannot be the default target.
Add unit-tests for .info - .error, and .ERROR.
 1.176 07-Apr-2010  sjg Add:

.error "message"
.warning "message"
based on FreeBSD implementation.
add .info while were at it.

.ERROR: a target to run on error.
We pass the failing GNode to PrintOnError so it can set
.ERROR_TARGET.

.MAKE.MAKEFILE_PREFERENCE
As a means to control make's list of prefered makefile names.
(Default: "makefile Makefile")

.MAKE.DEPENDFILE
Names the file to read dependencies from
(Default ".depend")

.MAKE.MODE
Processed after all makefiles are read.
Can put make into "compat" mode (more to come).

Fix:

compat.c: Error code should not be sent to debug_file.
Make_DoAllVar: use DONE_ALLSRC to avoid processing a node multiple times.
ReadMakefile: we can simply use doing_depend to control setting MAKEFILE.
 1.175 04-Jan-2010  sjg We need to have set curdir before calling Dir_FindHereOrAbove().
We can call getcwd again if -C is used.
 1.174 09-Sep-2009  sjg We must delay setting .CURDIR and .OBJDIR until after MainParseArgs()
in case -C is used - in which case we should also ignore $PWD.
 1.173 08-Sep-2009  sjg Reviewed by: apb

Use .MAKE.LEVEL to track recursion.
The first instance of make will have .MAKE.LEVEL 0, which
can be handy for excluding rules which should not apply
in a sub-make.
gmake and freebsd's make have a similar mechanism, but each
uses a different variable to track it. Since we cannot be
compatible with both, we allow the makefiles to cope if they want
by handling the export of .MAKE.LEVEL+1 in Var_Set().
 1.172 03-Sep-2009  dholland Use the W* macros to test wait results.
(Mentioned by Joerg in chat a few days ago.)
 1.171 26-Aug-2009  sjg Add -C directory, same as gmake and freebsd make.
 1.170 24-Mar-2009  perry per dholland, put back MAKE_VERSION for the benefit of third party users.
 1.169 20-Mar-2009  perry The Makefile and main.c arranged to put "netbsd-${DATE}" into the
executable. Remove this so that different compiles can be binary
compared. rcsid's for all files are already embedded in the executable
so versions can be easily distinguished. (I didn't catch this on
previous passes because I did my builds on the same day.)

Note: there's a special rule for main.o in Makefile with a purpose I
can't actually discern -- I think it isn't needed, and I've flagged it
with a comment.
 1.168 18-Mar-2009  christos use progname instead of getprogname() for portability.
 1.167 01-Mar-2009  christos use siginfo to report on the directory we are working on if available.
 1.166 24-Jan-2009  dsl branches: 1.166.2;
Move the bmake_malloc() functions into their own .c and .h files.
Include instead of make.h in a few places.
 1.165 23-Jan-2009  dsl Sprinkle some const.
In particular for Lst_Find() and Lst_FindFrom().
Remove some unneeded casts and some now-undeeded UNCONST().
 1.164 23-Jan-2009  dsl Change 'ClientData' to 'void *' so that relevant parameters can
be made 'const void *'.
 1.163 17-Jan-2009  dsl Change 'Buffer' so that it is the actual struct, not a pointer to it.
Saves having to malloc/free a fixed size structure.
Buf_Init() now takes ptr to Buffer to initialiase.
Change Buf_Destroy() to return ptr to string when not freed.
Remove large number of casts to (Byte) and (Byte *) - 'Byte' is 'char' here.
Buf_AddByte[s] guarantees that the data is 0 termininated, so never add '\0'.
Keep 'count' not 'left' and 'inPtr', code is simplier with only one update.
Fix fallou, no functional change.
 1.162 16-Jan-2009  dsl Send output of Error() to debug_file (unless stderr/stdout).
 1.161 13-Jan-2009  dsl Sprinkle a const. (arg of Main_ParseArgLine())
 1.160 20-Dec-2008  dsl Delete very splurious 'free(buf)' that xtos added.
Fixes PR bin/40233
 1.159 19-Dec-2008  christos if brk_string fail, so do we.
 1.158 13-Dec-2008  dholland fix typo in comment
 1.157 13-Dec-2008  dsl Use NULL instead of -1 cast to the relavant type (usually via NIL).
This was a suggestion from christos - so blame him if there is a deep
reason for using -1 :-)
 1.156 13-Dec-2008  dsl Do not let the variable name "" be set from the command line (-D "")
or from ::= modifiers (${::=foo}).
 1.155 07-Dec-2008  christos add debug flag for cwd.
 1.154 22-Oct-2008  apb Send debugging output to stderr by default, not to stderr.
If you really want debugging to stdout, specify "-dFstdout"
in MAKEFLAGS or on the command line.

Discussed in tech-userlevel.
 1.153 19-Oct-2008  apb Always make the debugging output unbuffered; in addition, if debugging
is enabled but debugging output is not directed to stdout, then make
stdout line buffered.

Previously, the code to make debug output unbuffered applied only if
debugging to a file, not if debugging to stdout or stderr. Making
stdout line buffered when debugging was suggested by Steven Bellovin.
 1.152 18-Oct-2008  apb Allow optional "+" in "-dF[+]filename" even if the filename is "stdout"
or "stderr". Previously, the "+" was alowed only for real file names,
but it's easier to write the documentation if the "+" is always allowed.
 1.151 06-Oct-2008  joerg Don't use emalloc and friends directly, but call them consistently
bmake_malloc and friends. Implement them via macros for the native case
and provide fallback implementations otherwise. Avoid polluting the
namespace by not defining enomem globally. Don't bother to provide
strdup and strndup, they were only used for the estrdup and estrndup
comapt code.

This addresses the presence of emalloc in system libraries on A/UX and
resulted strange issues as reported by Timothy E. Larson.
 1.150 21-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.
 1.149 15-Feb-2008  christos branches: 1.149.6;
back all changes out until I fix it properly.
 1.148 15-Feb-2008  christos fix != expansion bug I introduced.
 1.147 14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.146 19-Jan-2008  sjg Implement -dl (aka LOUD) to override '@' at the start of script lines.
Based on supplied patch.

PR: 37202
 1.145 21-Dec-2007  dsl If make can't find a rule to create a file it needs to satisfy a rule
that came from .depend then just output a message and contine.
 1.144 13-Oct-2007  apb * Convert all uses of strdup() to estrdup();
* Use estrndup() in a few cases where it simplifies the code;
* Provide compatibility definitions of strndup and estrndup;
 1.143 05-Oct-2007  sjg Add the ability to .export variables to the environment.
 1.142 01-Oct-2007  sjg Add the ability to tweak the token output before targets in job mode.
Eg.
.MAKE.JOB.PREFIX=${.newline}---${.MAKE:T}[${.MAKE.PID}]
would produce
---make[1234] target ---
 1.141 01-Jan-2007  dsl branches: 1.141.4;
Since the 'buf' code here is only used by make, we don't need two names
for the default buffer size of 256.
Also allow for the trailing 0 byte!
 1.140 16-Dec-2006  dsl Use open/read/close instead of stdio for makefiles.
Commons up the code for reading files and buffers, and allows a further
change where we don't copy the data out of the buffer when generating 'lines.
This will speed up makefile parsing (esp .if clauses).
 1.139 06-Dec-2006  dsl Add anewline to the end of the error message output when the debug log
file cannot be opened.
 1.138 03-Dec-2006  dsl Some minor changes:
- Only test 'printVars' once.
Has side effect of not trying to find the 'main' target for '-V varname'.
- Only reap the single child process in Cmd_Exec(),
I think this is for 'xx != cmd' so probobably no other children should exist.
- Don't read and parse .depend if '-r' and '-V varname' are set.
I suspect that .depend shouldn't affect the output of any -V command...
 1.137 17-Nov-2006  dsl branches: 1.137.2;
A rather large rototil in the way the parallel make code schedules jobs.
This gives a considerable speedup in the processing of .WAIT and .ORDER.
Both .WAIT and .ORDER stop both the commands of the node, and its dependant
nodes being built until the LH nodes are complete.
.WAIT only applies to the dependency line on which it appears, whereas
.ORDER applies globally between the two nodes.
In both cases dependant nodes can be built because other targets need them.
make now processes the target list left to right, scheduling child nodes
as they are needed to make other nodes (instead of attempting to generate
a bottom-up dependency graph at the start). This means that 'make -j1'
will tend to build in the same order as a non-parallel make.
Note that:
all: x y
x: a .WAIT b
y: b .WAIT a
does not generate a dependency loop.
But
x: y
.ORDER y x
does (unless something elswhere causes 'y' to be built).
 1.136 11-Nov-2006  dsl If the last 3 bytes of the debug filename supplied with -DFxxxx are .%d then
replace the %d with getpid().
Allows the trace files for different make process is a big recursive make
to be written to different files - and have a slight chance of being useful.
 1.135 01-Nov-2006  sjg Use of libutil to provide emalloc et al, should be predicated on
a native NetBSD build using TOOLDIR etc.
Otherwise use the local versions.

Reviewed by: christos
 1.134 27-Oct-2006  dsl Since 'ClientData' is 'void *', nuke almost all the (ClientData) casts.
 1.133 15-Oct-2006  dsl Output all debug trace output through 'debug_file' defaulting to 'stdout'.
(Almost all the debug output went there, but some went to stderr.)
Split the parsing of -d (debug flags) out into its own routine.
Allow the output filename to be changed by specifying -dF<file> to create
a log file, or -dF+<file> to append to it. <file> may be stdout or stderr.
Also change so that -d-<flags> acts on <flags> locally but doesn't copy
them to MAKEFLAGS so they aren't inherited by child makes.
I'm not 100% happy with the command line syntax for the above, so they are
currently undocumented.
 1.132 11-Oct-2006  dsl There is no need to resize the pollfd array, it can only ever have 2+maxJobs
entries, so allocate at startup.
Use an 'int jobPipe[2]' within the job structure, and create pipes directly
into it. Common up the code that creates all the pipes - making them all
non-block on the read side in the process.
Call Job_CatchChildren() directly from Job_CatchOutput() so that it only
gets called when a child actually exits.
NB: Something causes a 'pregnant pause' if (for example) you call 'nbmake obj'
in src/tools. Introduced between netbsd 3 and 4.
 1.131 09-Oct-2006  dsl Rip out the code for the undocumented -P (don't use pipes for command
output) option. I'm sure it is baggage from the past.
 1.130 26-Aug-2006  christos Fix non-native build.
 1.129 26-Aug-2006  christos More programs using efun.
 1.128 28-Jul-2006  sjg Fix minor mem leak in PrintOnError().
 1.127 29-Jun-2006  rillig Fixed gcc warnings about signed vs. unsigned in comparisons.
 1.126 19-May-2006  christos branches: 1.126.2;
Coverity CID 3147: Plug memory leak.
 1.125 22-Apr-2006  christos Coverity CID 527: Make it painfully obvious that av is freed.
 1.124 12-Apr-2006  sjg Change ReadMakefile to return 0 on success so that it better meets
the expectations of Lst_Find*. This way we only read the first sys.mk
found via sysIncPath.
At the same time we need to add a ReadAllMakefiles() for the case
where multiple -f makefile args are provided (uncommon, but documented).
 1.123 31-Mar-2006  dsl There is no need to count jobs and job tokens.
If we don't create the job pipe, use the '-j n' option to limit the number
of tokens we will remove from the pipe.
 1.122 17-Mar-2006  christos Coverity CID 2719: argvalue can be NULL when passed into functions.
De-obfuscate by undefining optarg, and check explicitly for NULL before
use.
 1.121 11-Mar-2006  dsl Remove most of the code seemed to be there to support 'remote jobs'.
It isn't clear that it ever worked, if it did it has almost certainly
bitrotted in the last 12 years. I'm not even sure all the required
components were present.
I suspect it was written to attempt to use a 'farm' of diskless sun3s.
In any case the apparant random assignment fo jobs to other systems doesn't
actually seem like a good idea!
Things like 'distcc' han be used to help slow systems run native builds.
Removing this code also simplifies make, and should let me speed up some of
its processing - without worrying about bitrotting it further.
 1.120 26-Feb-2006  apb Make ".WAIT" apply recursively to all children of nodes on the right
hand side of the .WAIT, except when the recursive interpretation would
cause a cycle in the dependency graph.

Discussed in tech-toolchain. Reviewed by christos, sjg.
 1.119 18-Feb-2006  tsutsui Don't use data in freed stack.
 1.118 22-Jan-2006  dsl Make .NOTPARALLEL stop the job engine issuing more than one token (instead
of trying to de-jobify the make.
You can now put .NOTPARALLEL in a submake of a recursive make (where it is
using a job-token pipe from the outer make and have it only run a single job.
You can also specify .NOTPARRALEL in the root makefile of a large recursive
make and have the submakes run multiple commands.
Add some diagnostics printfs (enabled with -dp) to the parser.
 1.117 04-Jan-2006  dsl When a parallel make job completes, always put the job token back into the
job_pipe and collect another one for the next job.
If we are aborting, remove all the 'normal' job tokens and add an 'error' one.
If we get an 'error' token, remove any other tokens, re-insert the error
token and exit (with error 'cos that is easier).
Add the current pid to some of the DEBUG(JOB) traces.
Combined effect is that parallel makes actually stop some fairly shortly
after an error, rather than running on long enough to fill the scrollback.
 1.116 09-Aug-2005  christos Add typedefs for DuplicateProc and FreeProc from Max Okumoto.
 1.115 08-Aug-2005  christos From Max Okumoto:
- Remove casts to NULL.
- Remove space between cast and object.
 1.114 05-Aug-2005  christos More KNF cleanups from Max Okumoto
 1.113 03-Aug-2005  christos from Max Okumoto: debug should be int, not boolean.
 1.112 25-Jul-2005  christos Whitespace KNF cleanup from Max Okumoto
 1.111 24-Jun-2005  lukem Revert rev 1.110 and restore the previous "automagic objdir" support;
at least until we clean up the objdir semantics in <bsd.obj.mk> for
NetBSD builds.
 1.110 23-Jun-2005  lukem Deprecate support for automagically setting the .OBJDIR to
./obj.${MACHINE}
./obj
/usr/obj/${PWD}

The rules for the default .OBJDIR setting are now simplified to
(and documented as) trying the chdir to the following
(if the appropriate variable is defined):
${MAKEOBJDIRPREFIX}${.CURDIR}
${MAKEOBJDIR}
${.CURDIR}

.OBJDIR can be overridden in the makefile.
<bsd.obj.mk> uses this to provide the "culled" .OBJDIR semantics
for NetBSD's /usr/src builds.

MAKEOBJDIRPREFIX & MAKEOBJDIR still can only be provided
in the environment or on make(1)'s command line.

Per discussion on tech-toolchain.
This should reduce a lot of lossage people have experienced over
the years with various .OBJDIR setups.
 1.109 17-Jun-2005  jmc Add new debugging option '-dn' which will leave the scripts fed into make on
-j jobs in /tmp for debugging purposes. Add a note to the man page that
this could cause problems if run a lot (due to the number of files created)
 1.108 03-Jun-2005  lukem appease gcc -Wuninitialized
 1.107 01-Jun-2005  sjg Add :Ox for random ordering, based on patch from
Mike M. Volokhov <mishka@apk.od.ua>
 1.106 16-Feb-2005  christos PR/29203, PR/29204: Max Okumoto: KNF changes to make [no functional changes]
 1.105 13-Jul-2004  wiz Sync usage with man page; from Kouichirou Hiratsuka in PR 26223.
 1.104 01-Jul-2004  jmc Change to use __unused instead and provide a compat definition in make.h if
not already defined from cdefs.h
 1.103 01-Jul-2004  jmc Add some checks for gcc around a few function declarations and note the
unused variables. Also fix a few other warnings that PR#22118 shows when
trying to compile bmake on non-NetBSD hosts
 1.102 07-May-2004  ross Simplify build, no functional changes.

Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().

It's now possible to build make on some hosts with: cc *.c */*.c
 1.101 22-Apr-2004  ross Recognize -- (dash dash) and apply the usual interpretation.

Notes:

* The immediately previous version of make errored out on --,
which is what needs fixing.

* Historic bsd make silently ate -- and continued to process
options, so this is a behavior change from that, too, but presumably
there is more to gain in fixing it than in being bug-compatible.
 1.100 27-Mar-2004  enami branches: 1.100.2;
Validate existence of arguemnt. PR#24933.
 1.99 24-Mar-2004  fair Fix comment per PR 24437; make(1) tries "makefile" first, and then
"Makefile", not the other way around as previously documented.
 1.98 05-Feb-2004  ross Parse args with open code to eliminate use of getopt(3).
No functional change under NetBSD.

Restarting a getopt(3) loop is an extension to the posix getopt(3)
behavior and is not portable.

Fixes tools build (tools/groff) under Cygwin.
 1.97 03-Feb-2004  chuck add parent directory search for make as discussed on tech-toolchain.
- new dir.c function: Dir_FindHereOrAbove:
Search for a path in the current directory and then all the directories
above it in turn until the path is found or we reach the root ("/").
- add hooks to use it in main.c for -m and syspath (compiled in
_PATH_DEFSYSPATH and $MAKESYSPATH).
- updated man page
 1.96 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.95 18-Dec-2003  jmc When looking for a makefile and curdir != objdir (i.e. working inside of an
objdir) try opening the file from curdir and if that fails try from objdir.
This way .depend files get picked up via their full path names rather than
just .depend so vars like PARSEDIR, PARSEFILE are then set correctly. This
fixes PR#13289 reporting incorrect pathnames for .depends with errors in
them
 1.94 07-Dec-2003  dsl Add a -Dg3 which outputs the 'input graph' only on error exit.
Lets you see the wood for the trees...
 1.93 10-Sep-2003  jmmv Add the 'e' debug flag (i.e., '-d e'): when enabled, show the "target
failed" and "command failed" messages added recently. These introduce
too much noise when debugging some kind of problems, specially in pkgsrc.
 1.92 05-Sep-2003  sjg Allow -V '${FOO}' to print the expanded version of FOO.
A side effect of adding and removing a -E option for the above is that
the cases in MainParseArgs are now ordered correctly?
 1.91 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.90 01-Aug-2003  sjg Allow .SHELL: to control the shell used by compat mode too.
Add a shell spec for ksh - a nice portable posix shell.
Document .SHELL:
 1.89 14-Jul-2003  christos Pass WARNS=3
 1.88 10-May-2003  jmmv Remove extra space in usage message.
 1.87 14-Mar-2003  thorpej Add a -X option, which prevents make(1) from putting variables
set on the command line into the environment individually. This
can be useful on systems which have a tight limit on the size
of the argument space.
 1.86 26-Feb-2003  sjg Add -B to MAKEFLAGS so that it propagates to sub-makes.
This allows one to use -j1 -B at some point in a tree to
overcome a -jN (which is the main reason one would use -B).
 1.85 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.84 27-Apr-2002  bjh21 Rather than hardcoding "/bin/sh", use _PATH_BSHELL. To allow bootstrapping,
provide a default for this in pathnames.h, and only include <paths.h> ifndef
MAKE_BOOTSTRAP.
 1.83 14-Mar-2002  pk JobExec(): don't use Punt() in the child; it can't possibly DTRT, and will also
mess up the parents variables.

Instead, use execError() for all error paths in the child code.
 1.82 27-Jan-2002  reinoud Fix major bug in make(1) ... due to shadowing of the dotLast path used for
the .DOTLAST primitive by a boolean variable with the same name, this whole
mechanism was broken ... it doesn't save much stat calls but it was wrong.

Thanks to Jason Thorpe for the other shadow-variable fixing patches he
made.
 1.81 11-Dec-2001  tv Allow MAKE_MACHINE to be unset if MAKE_BOOTSTRAP.
 1.80 30-Nov-2001  thorpej Clean up some MAKE_BOOTSTRAP issues wrt. MACHINE/MACHINE_ARCH.
 1.79 12-Nov-2001  tv Redo the hashtable for "." if .OBJDIR changes.
 1.78 12-Nov-2001  tv Add new make variable .ALLTARGETS, which lists all targets in the Makefile.
(Makes it possible to search the target list for particular things and
apply attributes to all the relevant targets.)
 1.77 11-Nov-2001  tv Back out my rev. 1.75 on recommendation of christos.

Instead of skipping the PWD check entirely, add a skip of the PWD override
if MAKEOBJDIR is set and contains a variable transform ($). This has
similar problems to what happens if MAKEOBJDIRPREFIX is set.
 1.76 02-Nov-2001  tv Apparently something was missed in the Main_SetObjdir commit. Fix a TRUE
value that should start out FALSE.
 1.75 02-Nov-2001  tv Strike getenv("PWD") entirely, based on prior discussion with sjg. This
breaks too many situations, including MAKEOBJDIR with a :C,foo,bar,
transform in many cases. It's ambiguous and unreliable, as the comment
above that code always indicated. In order to have reliable objdirs, they
need to work the same way Every Time.

(Note that taking this out is not a performance hit; we were already doing
the getcwd() call first. So the getenv("PWD") didn't increase performance.)
 1.74 31-Oct-2001  tv Overhaul the initialization and handling of .OBJDIR:

* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)

* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.

* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
 1.73 31-Oct-2001  tv Allow "-m" to be used in a .MAKEFLAGS: special target and get it to work.
(This splits out the "default system include paths" into its own Lst
variable, and uses it only if sysIncPath is empty. This allows sysIncPath
to be filled in by the Makefile itself.)
 1.72 16-Sep-2001  wiz Spell 'occurred' with two 'r's.
 1.71 12-Jun-2001  sjg Add 4th arg (flags) to Var_Set so that VarLoopExpand can tell it not
to export interator variables when using context VAR_CMD.

Reviewed: christos
 1.70 10-Jun-2001  sjg Simplify the exporting of VAR_CMD's via MAKEFLAGS.
We now just list the names of such variables in .MAKEOVERRIDES.
When we come to export MAKEFLAGS we quote the value of each exported variable
using :Q, using: ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}
The :O:u suppresses duplicate names.
Also modifed Parse_DoVar to re-export MAKEFLAGS whenever .MAKEOVERRIDES
is assigned to so .MAKEOVERRIDES+= PATH will export PATH=${PATH:Q}
to the environment, while .MAKEOVERRIDES= will disable export of VAR_CMD's.
 1.69 09-Jun-2001  sjg Do a better job of duplicate suppression in .MAKEOVERRIDES.
From Var_Set: We actually want the equivalent of
.MAKEOVERRIDES:= ${.MAKEOVERRIDES:Nname=*} name='val'
clearing the previous value for name is important, since
doing simple duplicate suppression does not handle:
$ make FOO=goo
which then runs a sub-make with FOO=boo
the commands from that sub-make should see just FOO=boo.
 1.68 09-Jun-2001  sjg Modify handling of command line variable assignments and their exporting
via MAKEFLAGS. Instead of appending them directly to .MAKEFLAGS, put
them in .MAKEOVERRIDES (and ensure they are quoted). This is now done
in Var_Set when it exports VAR_CMD's.
Use ExportMAKEFLAGS() to export MAKEFLAGS, using the combined content
of .MAKEFLAGS and .MAKEOVERRIDES (with duplicate supression).
If .MAKEFLAGS is assigned to in a Makefile, ExportMAKEFLAGS is called again.
This allows a line like:
.MAKEOVERRIDES=
to effectively stop the exporting of the command line vars in MAKEFLAGS.
 1.67 01-Jun-2001  sjg A number of semi-related changes.
1. make -dx turns on DEBUG_SHELL which causes sh -x to be used where
possible.
2. PrintOnError() is now called when make is stopping due to an error.
This routine reports the curdir and the value of any variables listed
in MAKE_PRINT_VAR_ON_ERROR.
3. Variables set via command line, are propagated to child-makes via
MAKEFLAGS. This behaviour appears to be necessary for POSIX (according
to the GNU folk anyway).
4. Do not reset MAKEFILE when reading ".depend" as this rather eliminates the
usefulness of ${MAKEFILE}.
5. Added ${.newline} as a simple means of being able to include \n in the
result of a :@ loop expansion.
6. Set ${MAKE_VERSION} if defined. Need to come up with a useful value.

Reviewed: christos
 1.66 29-May-2001  christos better error messages on exec* failures. From Simon Burge.
 1.65 16-Jan-2001  cgd Avoid accidental use of trigraphs. Pointed out by development version of gcc.
 1.64 14-Jan-2001  christos make the -W arg work; it was not put in the getopt string.
 1.63 10-Jan-2001  christos PR/11800: Chris Demetriou: Add -W flag to exit on parse warnings.
While I am here, s/make:.*"/%s:\1", progname/
 1.62 07-Jan-2001  sjg ReadMakefile: Don't simply fopen() fname before checking if we are in separate
objdir. This is the way freebsd does it, and apart from being more correct,
saves a lot of pointless fopen() calls.
 1.61 01-Jan-2001  sommerfeld Delete forceSerial; just use compatMake for that.
Add -N flag to *really* not execute any commands (useful when using
the -d flags to debug usr/src/Makefile)
Document -N
Update documentation of -n to mention that it still executes commands
for targets marked .MAKE so that the -N/-n distinction is clear.
 1.60 30-Dec-2000  sommerfeld Avoid token leaks when aborting after an error.
 1.59 30-Dec-2000  sommerfeld strdup tracefile so that it doesn't get smashed.
 1.58 30-Dec-2000  sommerfeld Add a token-passing scheme to allow a recursive make to successfully
use -j; all make's in a recursive build cooperate to limit the total
number of jobs, using a token-passing scheme.

The current token passing algorithm is similar to the one implemented
by gmake; there is a single pipe which is inherited through the entire
process hierarchy; tokens are obtained by reading a byte from the
"read end" of the pipe, and are returned by writing them to the "write
end". This exact algorithm is likely to change in the future.

Implementation details:
- Use the new trace facility to allow measurement of the
effectiveness of different token-passing schemes
- Get a token in MakeStartJobs(), return it in Make_Update()
- Eliminate Job_Full() and the jobFull global since they are
redundant with token system.
- Add an "internal" -J option (to pass the token pipe fd's down to
submakes) and a -T option for tracing.
- Change how compatMake is forced so that -j means something when
inherited by submakes.
- When waiting for a token, poll the token-passing pipe as well as
the output pipes of existing jobs.
 1.57 06-Jun-2000  sjg Check_Cwd_av: Ensure that word after a '(', '{' etc is considered a command,
so that we spot the cd/chdir and don't put one in.
 1.56 10-May-2000  sjg branches: 1.56.2;
Revert to the original behaviour wrt sysIncPath, ie if sysIncPath
is an empty list, use DEFSYSPATH.
The current behaviour may have been useful when DEFSYSMK was an
absolute path (hasn't been the case since 1996), but right now
make -m /no/such/dir will fail to find sys.mk and die.
 1.55 29-Apr-2000  sjg Allow MAKESYSPATH in the environment to override the default syspath.
 1.54 20-Apr-2000  sjg Changes to make MAKEOBJDIRPREFIX useful.

Firstly, we ignore getenv("PWD") if MAKEOBJDIRPREFIX is set so that we always
get the same value for .CURDIR regardless of how make was invoked.

Second, when executing a command we check if it is ${.MAKE} or ${.MAKE:T}
without a preceeding chdir, if so we insert a chdir(${.CURDIR}) so that
the Makefile will be found by the child make. Note that this behaviour is
dissabled if MAKEOBJDIRPREFIX is not set or if NOCHECKMAKECHDIR is set.
See the comments in main.c for more detail.

With these two changes, one can successfully build usr/src using MAKEOBJDIRPREFIX
allowing the src to be mounted from a CD-ROM.
 1.53 16-Apr-2000  christos prefix errors with the program name.
 1.52 14-Apr-2000  simonb Don't declare 'extern opt*' getopt variables.
 1.51 08-Feb-2000  sjg Make chdir_verify_path() do variable expansion on path in case
someone wants to do freaky stuff with $MAKEOBJDIR.
Initialize the Var system and set .CURDIR, MACHINE and MACHINE_ARCH
before chdir_verify_path() is called.
 1.50 15-Sep-1999  mycroft Rework how :: dependencies are handled.
Build a list of `cohorts' as before, but do *not* link each one into all the
parent nodes; instead, copy the `cohort' lists into the stream of targets to
be built inside Make_ExpandUse(). Also do the attribute propagation as a
separate pass after parsing.
This eliminates several O(n^2) algorithms.
 1.49 15-Sep-1999  mycroft More cleanup code bites it.
 1.48 04-Sep-1999  christos PR/8259: Chris Demetriou: Fix stack overflow bugs exposed by the glibc-2.1.1
Makefile. Use snprintf everywhere.
 1.47 02-Aug-1999  hubertf Save the walls, use fly swatters instead of machine guns!
(s/sscanf/strtol/, per Christos)
 1.46 02-Aug-1999  hubertf Detect invalid arguments to -j and -L by using sscanf() instead of atoi().
Fixes PR 6743 by Assar Westerlund <assar@sics.se>
 1.45 01-Nov-1998  itohy Reduced memory leaks.
I found some more leaks, but are not in inside of iterations.
 1.44 01-Nov-1998  itohy Avoid reading outside of allocated memory
on command execution if the output is empty.
 1.43 13-Oct-1998  wsanchez Use __ARCHITECTURE__, if defined, as MACHINE_ARCH
 1.42 02-Apr-1998  kleink Need <time.h> for time() prototype.
 1.41 28-Mar-1998  christos PR/5225: Jason Thorpe: make with -j 4 and subdirs core-dumps.
This revealed another long standing problem with pmake's port to bsd.
.MAKE was not set as the manual page states. Set it and remove another
typo in my last commit.
 1.40 26-Mar-1998  christos PR/5210: Hauke Fath: make core dumps with .SHELL
Unfortunately this revealed a deeper problem with the brk_string code.
To fix it:
- remove sharing of the buffer between brk_string invocations
- change the semantics of brk_string so that the argument array
starts with 0, and return the buffer where the strings are
stored
 1.39 08-Nov-1997  lukem getopt returns -1 not EOF, use memmove instead of bcopy
 1.38 28-Sep-1997  lukem branches: 1.38.2;
wrap #include <sys/cdefs.h>, __RCSID(...) stuff in #ifndef MAKE_BOOTSTRAP
 1.37 01-Jul-1997  christos Add WARNS=1
RCSID police
 1.36 08-May-1997  gwr Add the new .NOPATH feature which can be used to disable .PATH search
for particular targets, i.e. .depend, objects, etc. (from Christos).
 1.35 08-May-1997  cjs If the -m option is used, make will check for the existence of the
directory specified, and add it to sysIncPath only if it exists.
However, afterwards make tested for the presence of a -m option by
checking to see if sysIncPath was an empty list, and assumed that
the -m option was not used if it was empty. This obviously breaks
if -m specified a non-existent directory. So I have added a flag
that is set if the -m option is used, and I test that instead.
 1.34 24-Mar-1997  gwr Do not compile-in ${MACHINE} (as per PR#3386, OK'ed by christos)
 1.33 28-Jan-1997  christos make $MACHINE_ARCH settable from the environment.
 1.32 31-Dec-1996  christos - include <stdlib.h> to get getenv() prototype on SVR4
- if __STDC__ -> ifdef __STDC__ to appease SVR4
 1.31 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.30 13-Aug-1996  christos Add estrdup(), a checked version of strdup and use it.
 1.29 28-May-1996  christos - Move -D flags from Makefile to config.h and explain what they do. Add
-Wall -Wno-unused to CFLAGS. Add new define SYSVVARSUB to enable SysV
style variable substitutions and enable them.
- Add SunOS style command substitutions via SUNSHCMD
- Fix core dump with '{variable = value'
 1.28 31-Mar-1996  christos branches: 1.28.4;
make emalloc and erealloc return void *; closes PR/2276
 1.27 29-Mar-1996  jtc Added erealloc() function that calls enomem() if the allocation fails
(this is like the existing emalloc() function). Changed all realloc()
calls to erealloc().
 1.26 11-Mar-1996  christos Jonathan Stone's fixes:
main.c: Remove double include of <sys/resource.h>; if MACHINE is defined, use
that instead of uname.
Makefile: Add util.c.
 1.25 06-Mar-1996  christos Fix PR/2118; apply sysincludes patch.
 1.24 04-Feb-1996  christos fix pr/1421 and pr/1997
 1.23 22-Nov-1995  christos Updates for POSIX/SVR4 compiling:

arch.c: Don't require ranlib stuff. Not everybody has it.
dir.c: SunOS-4 != Solaris; change #ifdef sun to #if sun && !__svr4__
job.c, compat.c: Don't use 'union wait', use int and the W*() macros.
main.c: Check for uname() == -1; some unames return > 0...
util.c, job.c: Add signal() with BSD semantics for svr4, don't use bsd
sigmask and friends.
 1.22 08-Nov-1995  christos - Turn compat mode on by default. It gets turned off when the -j without
the -B flag is specified. [Thus you can use -j 1 to turn it off].
- Fix malloc -> emalloc as Gordon noted.
 1.21 02-Nov-1995  christos Minor:
- ${.PREFIX} should never contain a full pathname
- Fixed gcc -Wall warnings
Major:
- compatMake is now FALSE. This means that we are now running in
full pmake mode:
* rules on dependency lines can be executed in parallel and or
out of sequence:

foo: bar baz

can fire the rule for baz before the rule for bar is fired.
To enforce bar to be fired before baz, another rule needs to be
added. [bar: baz]
* adjacent shell commands in a target are now executed by a single
invocation of the shell, not one invocation of the shell per line
(compatMake can be turned off using the -B flag)
- The -j flag now works... I.e. make -j 4 will fork up to four jobs in
parallel when it can. The target name is printed before each burst
of output caused by the target execution as '--- target ---', when j > 1
- I have changed all the Makefiles so that they work with make -j N, and
I have tested the whole netbsd by:
'make -j 4 cleandir; make -j 4 depend; make -j 4; make -j 4 install'
- I have not compiled or tested this version of make with -DREMOTE.
 1.20 27-Sep-1995  jtc include <signal.h> instead of <sys/signal.h>
 1.19 14-Jun-1995  christos - $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.18 06-Jan-1995  christos Fixes from Paul Borman (prb@bsdi.com)
1. Honor environment variable $MACHINE if set over uname.machine
2. archives with :: are always out of date, even when they have no children.
3. VAR= a b c # comment, gets the trailing blanks trimmed, unless
escaped by \. I'll have to read the posix manul to make sure that it
is ok to handle escapes here.
 1.17 30-Sep-1994  gwr Get the name of this type of MACHINE from utsname
so we can share an executable for similar machines.
(i.e. m68k: amiga hp300, mac68k, sun3, ...)
 1.16 23-Sep-1994  mycroft Use getcwd(3), not getwd(3), and remove some old, unused compatibility code.
 1.15 16-Jun-1994  jtc Christos' fix for quoting variable extraction properly.
 1.14 06-Jun-1994  jtc Fixes from Christos Zoulas, who used purify, objectcenter and testcenter
to find memory leaks and illegal memory accesses.
 1.13 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.12 13-Jan-1994  jtc Include appropriate header files to bring prototypes into scope.
 1.11 22-Dec-1993  pk Introduced ${.OBJDIR}. The variable is similar to .CURDIR but points at
the directory where make builds the targets. It can be used to clean up
those cumbersome Makefiles that have to guess at the "obj" directory.
 1.10 17-Dec-1993  jtc POSIX.2 added the -S flag (opposite of -k). It was allready there,
just #ifdef'ed out.
 1.9 15-Dec-1993  jtc Fix bug (PR #42) with -j flag. Doesn't seem to do anything, but at
least it doesn't dump core anymore.
 1.8 04-Dec-1993  cgd add MACHINE_ARCH
 1.7 23-Oct-1993  cgd add support for an obj.${MACHINE} dir, which will be used rather than obj,
if both exist. basically, precedence is now:
MAKEOBJDIR or (obj.${MACHINE} then obj)
.
 1.6 23-Aug-1993  cgd fix from chmr@edvz.tu-graz.ac.at (Christoph Robitschko)
to get things right if obj is a symlink and points to nowhere.
 1.5 01-Aug-1993  mycroft Add RCS identifiers.
 1.4 08-Jul-1993  cgd remember curdir as something other than ".", so that makes
of things which include files in directories won't get hosed...
 1.3 23-Mar-1993  cgd made .CURDIR be absolute, not relative, thereby eliminating
the need for some of the makefile trickery when making objects,
and fixing a few .PATH bugs
 1.2 21-Mar-1993  cgd after 0.2.2 "stable" patches applied
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.28.4.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.38.2.1 08-May-1998  mycroft Sync with trunk, per request of christos.
 1.56.2.1 23-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.100.2.2 10-May-2004  tron Pull up revision 1.102 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.100.2.1 10-May-2004  tron Pull up revision 1.101 (requested by sjg in ticket #282):
Recognize -- (dash dash) and apply the usual interpretation.
Notes:
* The immediately previous version of make errored out on --,
which is what needs fixing.
* Historic bsd make silently ate -- and continued to process
options, so this is a behavior change from that, too, but presumably
there is more to gain in fixing it than in being bug-compatible.
 1.126.2.2 19-May-2006  christos Coverity CID 3147: Plug memory leak.
 1.126.2.1 19-May-2006  christos file main.c was added on branch chap-midi on 2006-05-19 17:21:47 +0000
 1.137.2.2 05-Jun-2007  bouyer Apply patch (requested by tron in ticket #696):
usr.bin/make/compat.c patch
usr.bin/make/cond.c patch
usr.bin/make/dir.c patch
usr.bin/make/for.c patch
usr.bin/make/main.c patch
usr.bin/make/make.1 patch
usr.bin/make/make.c patch
usr.bin/make/make.h patch
usr.bin/make/nonints.h patch
usr.bin/make/parse.c patch
usr.bin/make/str.c patch
usr.bin/make/targ.c patch
usr.bin/make/util.c patch
usr.bin/make/var.c patch

Synchronize make(1) with HEAD branch to increase perfomance and
improve stability.
 1.137.2.1 20-Dec-2006  bouyer branches: 1.137.2.1.2;
Pull up following revision(s) (requested by dsl in ticket #285):
usr.bin/make/cond.c: revision 1.36
usr.bin/make/parse.c: revision 1.121-1.124
usr.bin/make/make.h: revision 1.65
usr.bin/make/targ.c: revision 1.46
usr.bin/make/main.c: revision 1.138-1.139
Simplify the code that processes .if lines.
It doesn't need a two-dimensional array to remember the states of .if lines.
It would be even simpler if we didn't try to detect .else and .elif lines
that follow .else lines.
Unfortunately this isn't the code that is stupendously slow...
Unknot this code slightly by avoiding 'break/return; else' and by putting
the short parts of some conditionals first.
First step towards speeding up the parsing of makefiles (esp. the unwanted
parts of .if clauses).
There should be no changes to the logic.
There really is no point calling estrdup() to get a copy of the makefile name
into every 'gnode' (aka target), instead just copy a pointer to the string
and avoid freeing the original name when we close the file.
I can't imagine any makefile set where this gives a larger footprint!
Add anewline to the end of the error message output when the debug log
file cannot be opened.
Put the big block of code that was common to ParseDoInclude() and
ParseTraditionalInclude() into a separate routine.
Fix the 'use after free' and 'free on item not malloced' that got added
to ParseTraditionalInclude() in Feb 2006 (rev 1.111).
Kill the 'PTR' struct and put both its members into IFile.
Remove the parameter from ParseEOF(), 1 of the 3 calls passed the wrong value!
Fortunately another test stopped anything nasty happening, we'll use that
test instead.
Revert part of a recent commit.
ParseEOF() shouldn't close the original file.
Some minor changes:
- Only test 'printVars' once.
Has side effect of not trying to find the 'main' target for '-V varname'.
- Only reap the single child process in Cmd_Exec(),
I think this is for 'xx != cmd' so probobably no other children should exist.
- Don't read and parse .depend if '-r' and '-V varname' are set.
I suspect that .depend shouldn't affect the output of any -V command...
 1.137.2.1.2.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.141.4.3 23-Mar-2008  matt sync with HEAD
 1.141.4.2 09-Jan-2008  matt sync with HEAD
 1.141.4.1 06-Nov-2007  matt sync with HEAD
 1.149.6.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.166.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.194.2.2 05-Mar-2011  bouyer Sync with HEAD
 1.194.2.1 17-Feb-2011  bouyer Sync with HEAD
 1.198.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.198.2.2 30-Oct-2012  yamt sync with head
 1.198.2.1 23-May-2012  yamt sync with head.
 1.203.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.203.2.2 23-Jun-2013  tls resync from head
 1.203.2.1 25-Feb-2013  tls resync with head
 1.221.2.1 23-Jul-2013  riastradh sync with HEAD
 1.226.2.1 10-Aug-2014  tls Rebase.
 1.248.2.3 26-Apr-2017  pgoyette Sync with HEAD
 1.248.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.248.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.254.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.264.2.1 11-May-2017  pgoyette Sync with HEAD
 1.265.2.2 07-May-2021  martin Pull up following revision(s) (requested by mrg in ticket #1678):

bin/pax/options.c: revision 1.119
usr.bin/config/scan.l: revision 1.32
usr.bin/make/main.c: revision 1.274
bin/pax/extern.h: revision 1.60
usr.bin/config/defs.h: revision 1.106
usr.bin/make/make.h: revision 1.105
sbin/newfs_udf/udf_create.c: revision 1.27 (patch)
sbin/newfs_udf/newfs_udf.h: revision 1.7 (patch)
usr.bin/config/main.c: revision 1.100
usr.sbin/installboot/Makefile: revisions 1.53,1.54 (patch)
usr.sbin/installboot/installboot.h: revision 1.41 (patch)
usr.sbin/installboot/machines.c: revisisons 1.41,1.42 (patch)

Avoid depending on common symbols.
 1.265.2.1 18-Jul-2017  snj Pull up following revision(s) (requested by jmcneill in ticket #113):
usr.bin/make/main.c: 1.266-1.272
usr.bin/make/make.1: revision 1.267
move some code out of the gigantic main function; no functional change.
--
-V: try to expand the variable again if the value contains a variable.
--
simplify
--
a variable that starts with \\ is not expanded.
--
Remove previous variable expansion code; sjg had already added the code to
do it. Note that the manual page already documents this behavior and does
not need to change:
-dV -V VAR: prints the raw variable
-V VAR: prints the expanded variable
--
make the code look like to 1.266
--
Add -v variable that always expands variables; restore -V the way it was.
 1.273.6.1 30-Apr-2021  martin Pull up following revision(s) (requested by mrg in ticket #1263):

bin/pax/options.c: revision 1.119
usr.bin/config/scan.l: revision 1.32
usr.bin/make/main.c: revision 1.274
bin/pax/extern.h: revision 1.60
usr.bin/config/defs.h: revision 1.106
usr.bin/make/make.h: revision 1.105
sbin/newfs_udf/udf_create.c: revision 1.27 (patch)
sbin/newfs_udf/newfs_udf.h: revision 1.7 (patch)
usr.bin/config/main.c: revision 1.100

Avoid depending on common symbols.
 1.273.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.624.2.2 02-Aug-2025  perseant Sync with HEAD
 1.624.2.1 01-Jul-2024  perseant Sync with HEAD.
 1.387 02-Jul-2025  rillig make: shorten diagnostic for invalid -J option

In the manual page, there's more space to properly explain the
complexity behind the warning.
 1.386 28-Jun-2025  rillig make: add POSIX $^ support

POSIX 2024 [1] introduced the $^ internal macro. Implement it as an
alias for $> (.ALLSRC), following the suggestion from defect 1520 [2].

[1]: https://pubs.opengroup.org/onlinepubs/9799919799/utilities/make.html
[2]: https://www.austingroupbugs.net/view.php?id=1520

Patch provided by Diogo Santos in PR bin/59018.
 1.385 13-Jun-2025  rillig make: add on-demand inter-process stack traces

When debugging a build that heavily uses nested calls to sub-makes, the
chain of calls is useful to quickly assess the situation. If explicitly
requested, include the actions from any parent processes in the stack
traces.

Reviewed by: sjg
 1.384 04-Apr-2025  sjg make.1: elaborate on use of .OODATE:M
 1.383 04-Apr-2025  sjg make.1 further describe meta mode

This is long overdue. Explain how meta mode affects
the behavior of make.
 1.382 30-Mar-2025  sjg make: POSIX mode, check for sysV style modifiers first

A POSIX compatible makefile should not be using any
of our native modifiers, so give preference to the sysV style modifier
and only check the others as a fallback.

Reviewed by: rillig
 1.381 14-Nov-2024  sjg make.1 clarify use of MAKEOBJDIRPREFIX

Note that MAKEOBJDIRPREFIX should be an absolute path.
Also that MAKEOBJDIRPREFIX and MAKEOBJDIR *can* be set
via makefile variables, but that care is needed to avoid
unwanted side effects.
 1.380 10-Nov-2024  sjg make: allow -f .../Makefile

If the arg to -f or an entry in .MAKE.MAKEFILE_PREFERENCE
starts with ".../" look for the rest of the path in .CURDIR
and above.

Reviewed by: rillig
 1.379 21-Sep-2024  sjg Only list the defaults for MAKEFILE_PREFERENCE once
 1.378 01-Jul-2024  sjg make: add :tc to capitalize first letter of each word

This is very hard to do without :tc

Reviewed by: rillig
 1.377 01-Jun-2024  sjg branches: 1.377.2;
make: add .export-all

An explicit syntax for exporting all global variables is much safer
than allowing .export with no argument to do the same.

Add .export-all and have .export with no argument throw a warning saying
to use .export-all

Reviewed by: rillig
 1.376 28-May-2024  sjg make: allow debugging the warning about .OBJDIR

When make complains about an unwritable .OBJDIR
it is not always obvious how we derrived that value.

If MAKE_DEBUG_OBJDIR_CHECK_WRITABLE is enabled call PrintOnError
so we can examine variables that are likely relevant.

Fix description of MAKE_OBJDIR_CHECK_WRITABLE in make.1
 1.375 10-Mar-2024  sjg make: record exit status in GNode

SetErrorVars can now set .ERROR_EXIT which allows
a .ERROR target to ignore the case of .ERROR_EXIT == 6
which means failure happened elsewhere.

Reviewed by:
 1.374 25-Jan-2024  sjg Note that in both :U and :D newval may be empty
 1.373 25-Jan-2024  sjg Indicate that for :U newval is optional
 1.372 24-Dec-2023  sjg Compat_RunCommand call Shell_Init is shellPath is NULL

Since .SHELL is potentially used in compat mode as well,
the man page description should not imply it is only used in jobs mode.

Remove path="sh" from shell-sh unit-test - and it would have detected
this bug.

Reviewed by: rillig
 1.371 10-Sep-2023  rillig make: fix typo
 1.370 09-Sep-2023  sjg Add .MAKE.JOBS.C to indicate wether -jC is supported
 1.369 09-Sep-2023  sjg make: allow -j to compute a multiple of ncpu

If _SC_NPROCESSORS_ONLN is supported; and -j arg is a floating point
number or ends in 'C' compute .MAKE.JOBS as a multiple of _SC_NPROCESSORS_ONLN

Based on a suggestion from des at freebsd.org
Discussed with: rillig, christos
 1.368 20-Aug-2023  sjg make.1: note that %s should only be used with :localtime
 1.367 28-Jun-2023  rillig make.1: clean up wording, clarify scope of '!' in conditions
 1.366 10-May-2023  sjg Make :mtime operate on each word in variable value.

Reviewed by: rillig
 1.365 09-May-2023  sjg make: :mtime=error throw error on stat(2) failure

Sometimes we want fatal error if stat fails on the
presumed pathname.
 1.364 09-May-2023  sjg make: add :mtime to provide mtime of file

The value of the variable is passed to stat(2)
and st_mtime is new value.
An optional arg can be used if stat(2) fails, otherwise
the current time is used.

See varmod-mtime.mk for usage examples.
 1.363 07-May-2023  sjg make.1: lose the trailing blank lines
 1.362 07-May-2023  sjg make: fix description of .PREFIX

For at least 20 years, the setting of .PREFIX in make
has not matched the documentation.
Since the documented behavior does not match reality or
POSIX make, fix the documentation.

In FindDepsRegularPath str_basename is applied to .PREFIX
this is wrong, but I was unable to verify fixing it
was benign in NetBSD build - my NetBSD box (7.2)
was unable to build known-good src with or without any patches.

For now just document the behavior more accurately.
 1.361 23-Mar-2023  sjg Document unexplained *** Error code 6
 1.360 26-Jan-2023  sjg make: some variables should be read-only

Make variables like .newline and .MAKE.{GID,PID,PPID,UID} read-only.

Reviewed by: rillig
 1.359 24-Jan-2023  sjg make: .SYSPATH: to add dirs to sysIncPath

.SYSPATH: with no sources will clear sysIncPath
otherwise sources are added

Reviewed by: rillig
 1.358 23-Jan-2023  sjg make: .[NO]READONLY for control of read-only variables

Reviewed by: rillig
 1.357 01-Jan-2023  rillig make.1: bump date
 1.356 01-Jan-2023  rillig make.1: fix markup
 1.355 01-Jan-2023  rillig make.1: sync list of built-in variables with reality

Fixes PR 57029.
 1.354 01-Jan-2023  rillig make.1: sort list of built-in variables
 1.353 01-Jan-2023  rillig make.1: use consistent markup for boolean flags
 1.352 01-Jan-2023  rillig make.1: move description of .MAKE.MODE below the .MAKE.META block
 1.351 01-Jan-2023  rillig make.1: reduce indentation of the long list of variable names
 1.350 29-Nov-2022  rillig branches: 1.350.2;
make.1: clarify in which case an expression may omit braces
 1.349 15-Nov-2022  rillig make.1: make horizontal and vertical spacing more consistent
 1.348 02-Oct-2022  rillig make.1: clean up style, typography, accuracy

In a code example, replace the deprecated `pwd` with the preferred form
$$(pwd).

Shorten the paragraph about escaping a dollar in modifiers, as the
various escaping mechanisms are described in the section 'Expansion of
variables'.

Summarize the previously many cases of the ':from=to' modifier to be
simpler to understand, actually mention what the pattern matching
character '%' can match.

Describe the syntax of function call expressions in conditionals.
Previously, only the function names had been documented.
 1.347 15-Sep-2022  uwe make(1): fix and simplify optional negation on conditional
 1.346 15-Sep-2022  uwe make(1): use .Dl for one-line literal display
 1.345 14-Sep-2022  rillig make.1: make typography more consistent
 1.344 14-Sep-2022  rillig make.1: fix typography, especially spacing
 1.343 12-Sep-2022  rillig make.1: fix style of ellipsis

In most places, '...' is not intended to be entered verbatim, instead it
is a placeholder, so don't use a fixed-width font for it.
 1.342 12-Sep-2022  rillig make.1: remove extraneous .El, update date
 1.341 12-Sep-2022  rillig make.1: split section on directives into several subsections

Directives such as .error or .undef are not conditionals. Having these
directives mixed in a single list made it more difficult to see how the
directives relate.
 1.340 09-Sep-2022  uwe make(1): add space before the punctuation argument
 1.339 09-Sep-2022  rillig make.1: clean up and make the description more accurate

Most changes are editorial. Notable exceptions are:

The ':Q' in MAKE_PRINT_VAR_ON_ERROR was wrongly added in the previous
commit. As that variable does not produce a shell command, there is no
point in quoting the characters.

Since 2012.10.07.19.17.31, make doesn't complain anymore if a shell
command in compat mode expands to an empty string, which removes the
need to "keep make happy".
 1.338 09-Sep-2022  rillig make.1: only use .Pa for actual pathnames
 1.337 08-Sep-2022  rillig make.1: rewrite many details in a more precise way
 1.336 07-Sep-2022  rillig make.1: clean up style, grammar, punctuation, improve clarity
 1.335 07-Sep-2022  rillig make.1: remove redundant 'then' from conditional sentences.
 1.334 07-Sep-2022  rillig make.1: use present tense in conditional sentences

These sentences are about general, timeless rules, rather than about
predictions about the future.
 1.333 05-Sep-2022  rillig make.1: clarify interpretation of conditionals

String literals in quotes are never interpreted as numbers.

The operators '<', '<=', '>', '>=' are only allowed in numeric
comparisons.

Avoid the term 'C relational operators' since in C, the relational
operators exclude '==' and '!=', which are called equality operators
instead.
 1.332 03-Sep-2022  rillig make: clean up handling of .break in .for loops

Move For_Break further up, as the functions in that file are sorted from
small to big. The cast from size_t to unsigned int is required by lint.

In parse.c, move the code into a separate function to keep
ParseDirective small. Its only job is to parse the directive and then
delegate to another function doing the actual work.

In the manual page, remove empty lines.

In the test, ensure that .break stops processing of the .for loop
immediately; anything after the .break is not processed anymore.
Replace ':=' with '=', as there is no need to evaluate '$i' early.
Check the expected value in the .mk file instead of the .exp file, to
keep the reading scope as small as possible.
 1.331 02-Sep-2022  sjg make: add .break to terminate .for loop early

When .break is encountered within a .for loop
it causes immediate termination.

Outside of a .for loop .break causes a parse error.

Reviewed by: christos
 1.330 14-Aug-2022  uwe make(1): mark up the variable expansion example
 1.329 14-Aug-2022  uwe make(1): use .Dl for .MAKE.JOB.PREFIX examples
 1.328 14-Aug-2022  uwe make(1): prettify .for index variable example
 1.327 14-Aug-2022  uwe make(1): more .Va fixes
 1.326 14-Aug-2022  uwe make(1): mark up FRC in BUGS
 1.325 14-Aug-2022  uwe make(1): Use .Dq instead of literal ASCII quotes
 1.324 14-Aug-2022  uwe make(1): Be consistent about using .Va for make variables
 1.323 14-Aug-2022  rillig make.1: fix accidental removal of the directive 'export'
 1.322 14-Aug-2022  uwe make(1): more .Ar fixes
 1.321 14-Aug-2022  uwe make(1): ".../" in -m option description is literal ".../"
 1.320 14-Aug-2022  uwe make(1): Consistent formatting for -i and -s descriptions.
 1.319 14-Aug-2022  uwe make(1): Fix markup of the -d[flags] section.

The debug flags are literals, not syntactic variables (.Ar).
While here use .Dq for quoted words in the text.
 1.318 14-Aug-2022  uwe make(1): Fix some obviously wrong uses of .Va
 1.317 14-Aug-2022  rillig make.1: clean up formatting and grammar, be more accurate
 1.316 14-Aug-2022  rillig make.1: not every '-' is a flag
 1.315 12-Jul-2022  rillig make.1: fix markup for variable modifiers, add italic correction
 1.314 12-Jul-2022  rillig make.1: fix markup for options, they are not arguments
 1.313 12-Jul-2022  rillig make.1: fix ugly line break in PostScript output
 1.312 12-Jul-2022  rillig make.1: fix markup

Not all square brackets are options, some are wildcards.
 1.311 12-Jul-2022  rillig make.1: replace redundant .Ql with .Sq
 1.310 12-Jul-2022  rillig make: describe variable assignment and evaluation more precisely

Variables in make are not "much like variables in the shell", they only
look that way. Their behavior is more similar to C preprocessor macros.

The spaces around a variable value are removed when parsing the variable
assignment, not after evaluating it.

Before describing the variable assignment operators, introduce the
general syntax of a variable assignment.

Add a separate subsection "Expansion of variables", since assignment and
expansion are unrelated. Illustrate how variable expansions look
instead of describing it in many words.

Describe how variables are expanded in conditionals, since that is
different from everywhere else.
 1.309 07-May-2022  rillig make: allow to randomize build order of targets

In complex dependency structures, when a build fails, a probable cause
is a missing dependency declaration between some files. In compat mode,
the build order is deterministic, in jobs mode, it is somewhat
deterministic. To explore more edge cases, add the line ".MAKE.MODE +=
randomize-targets" somewhere in the makefile.

Fixes PR bin/45226 by riastradh. Reviewed by christos.
 1.308 18-Apr-2022  rillig make: only switch to POSIX mode if '.POSIX:' is the first line

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html
says that in order to make a makefile POSIX-conforming, its first
non-comment line must be the special dependency line '.POSIX:' without
any source dependencies.

Previously, make switched to POSIX mode even if such a line occurred
anywhere else, which was allowed by POSIX but was deep in the
"unspecified behavior" area. For NetBSD make, there is no big
difference since it doesn't ship any <posix.mk> file, this change mainly
affects the bmake distribution.

Previously, makefiles that contain '.POSIX:' somewhere in the middle
could fail due to <posix.mk> resetting .SUFFIXES, among other things.

Suggested by Simon J. Gerraty, who also reviewed an earlier version of
this change.
 1.307 26-Mar-2022  sjg Mention 'make -r' with .POSIX
 1.306 25-Mar-2022  sjg Include posix.mk when .POSIX: first encountered

Since .POSIX: is required to be the first non-comment line
in a Makefile, including ${MAKE_POSIX_MK} or whatever _PATH_POSIX_MK is
set to at this point is equivalent to an extension of sys.mk

This is a minimal change that can allow a better approximation of
POSIX compliance

Reviewed by: rillig
 1.305 09-Feb-2022  rillig make: fix mistakes, spelling and typos in comments and manual page

No binary change for -DNDEBUG.
 1.304 29-Jan-2022  sjg Tweak description of local variable assignments
 1.303 29-Jan-2022  sjg Document quirks of target local variable assignments
 1.302 27-Jan-2022  sjg Allow local variable assignments in dependency lines

The variable is set in the context of the target.
This syntax has been supported by gmake for ~ever.
If necessary a makefile can set .MAKE.TARGET_LOCAL_VARIABLES=false
to disable this.

Expose GetBooleanExpr so parse.c can use it.
 1.301 13-Jan-2022  sjg meta.c: add .MAKE.META.CMP_FILTER

On rare occasions it is useful to be able to filter command lines
before comparison.
 1.300 12-Dec-2021  sjg Add .SUFFIXES as read-only variable.

References to ${.SUFFIXES} are handled dynamically in
ParseVarnameLong by calling Suff_NamesStr.

The variable cannot be set normally.

Reviewed by: rillig
 1.299 03-Aug-2021  wiz Document :On modifiers in more detail.
 1.298 30-Jul-2021  rillig make: fix typo in manual page, add more tests for the new ':On'
 1.297 30-Jul-2021  sjg Add :On for numeric sort

Reviewed by: christos rillig
 1.296 04-Feb-2021  rillig make: rename context and ctxt to scope

This continues the previous commit, in which VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE were renamed.

Renaming the variable 'ctxt' was trivial since that word is used nowhere
else. In the comments though, each occurrence of the word 'context' had
to be checked individually since the word 'context' was not only used
for referring to a variable scope. It is also used to distinguish
different situations where characters are escaped in a certain way
('parsing context') and in a few other expressions.
 1.295 23-Dec-2020  rillig make(1): remove trailing whitespace in manual page
 1.294 22-Dec-2020  rillig make(1): allow .undef to undefine multiple variables at once

Since make doesn't support variable names containing spaces, this edge
case is not enough reason to stop this feature. Having multiple
variable names as arguments nicely aligns with other directives such as
.for and .export.
 1.293 25-Nov-2020  sjg Add .MAKE.UID and .MAKE.GID
 1.292 14-Nov-2020  rillig make(1): document the -S option

This option has been available at least since 1993-03-21, and for the
same time it has been undocumented.
 1.291 12-Nov-2020  sjg Pass a writable flag to Main_SetObjdir to control writable check

For curdir and an explicit .OBJDIR target, we allow for
the directory to be read-only.
During InitObjdir we otherwise default to requiring objdir to be
writable - this can be controlled by env variable
MAKE_OBJDIR_CHECK_WRITABLE

Add unit-tests/objdir-writable

Reviewed by: christos rillig
 1.290 01-Nov-2020  rillig make(1): fix manual page regarding numerical comparisons

Make uses double, not int, for comparing things.
 1.289 28-Aug-2020  rillig make(1): fix manual page about the modifiers of the :C modifier
 1.288 22-Aug-2020  sjg Add .SHELL as read-only variable

The .SHELL variable represents the shellPath used to run
scripts.

Reviewed by: rillig, christos
 1.287 19-Aug-2020  rillig make(1): fix a few inconsistencies in the manual page
 1.286 05-Aug-2020  dholland Also mention that make dependency operators must be uniform.

This wasn't previously documented, I think.
 1.285 05-Aug-2020  dholland Rework the description of the :, !, and :: dependence operators to make sense.

Bump date.
 1.284 31-Jul-2020  sjg Add -dL for LINT

When parsing variable assignments other than := and if
value contains '$' attempt Var_Subst the same as for :=,
if the value does not parse correctly, we get a fatal error
including file an line number.

This can greatly help with finding the cause of problems.

Reviewed by: christos
 1.283 18-Jul-2020  sjg Add -dh for DEBUG_HASH

Allow tracking of max chain length, to see how well the hash
tables are working.
Pull the actual hash operation into a marco so it can be
easily changed - for experimenting.

The current hash, is pretty good.

Reviewed by: christos
 1.282 06-Jun-2020  wiz Remove trailing whitespace.
 1.281 05-Jun-2020  sjg make: add :Or for reverse sort

:Or is more efficient than :O:[-1..1]

Reviewed by: christos
 1.280 27-Apr-2020  christos document the SYSV ${VAR:old=new} corner cases.
 1.279 04-Feb-2020  wiz Remove trailing whitespace.
 1.278 03-Feb-2020  uwe Make delimiters in <file> and "file" literal.
 1.277 03-Feb-2020  kamil Fix usage of angle-brackets and quotes in make(1) manpage

make(1) has commands .include <file> and .include "file",
but the manpage was (inconsistently) rendering <file> with
angle-brackets (e.g. in UTF8 ) and "file" with curly-quotes
in HTML output (but not text).

This is an attempt to fix that and output only literal <file>
and "file" as is actually required in the makefile.fileoutput,

https://reviews.freebsd.org/D21470

Submitted by Mateusz Piotrowski (FreeBSD)
 1.276 19-Dec-2019  maxv Revert the filemon removal in bmake, as pointed out by maya we do care
about not introducing divergence with FreeBSD, and the cost of unused
is acceptable here.
 1.275 18-Dec-2019  maxv Retire filemon, discussed on tech-kern@.
 1.274 16-Feb-2019  gutteridge make(1): minor grammar fixes in BUGS section
 1.273 27-May-2018  christos branches: 1.273.2;
- Introduce :q modifier for make variables and make it double escape $'s so
that passing variables to recursive makes with :q works as expected.
- Revert :Q to work as before.
- Adjust makefiles that use recursive make to use :q

Discussed on tech-toolchain@
XXX: pullup 8
 1.272 02-Apr-2018  dholland Fix bad markup.
 1.271 03-Jul-2017  wiz branches: 1.271.4;
Remove workaround for ancient HTML generation code.
 1.270 22-Jun-2017  dholland Improve description of -V. Can probably be improved further.
 1.269 22-Jun-2017  wiz Whitespace fixes.
 1.268 22-Jun-2017  dholland Document what the magic variable .MAKE.EXPAND_VARIABLES actually does.
 1.267 19-Jun-2017  christos Add -v variable that always expands variables; restore -V the way it was.
 1.266 01-Feb-2017  sjg branches: 1.266.4;
Since we are avoiding VAR_INTERNAL, allow the variable :_ stores to
to be specified, also allows for multiple stages of modification to
be stashed.
 1.265 30-Jan-2017  sjg Add :range and :_

:range replaces var value with an integer sequence one per word
in the current var value.

:_ stores the current var value in $_ so that it can be referred to
later in the modifier series.

Reviewed by: christos
 1.264 14-Jan-2017  sjg branches: 1.264.2;
Allow providing a utc value to :{gm,local}time

Reviewed by: christos
 1.263 26-Aug-2016  dholland Document .DELETE_ON_ERROR.
 1.262 18-Aug-2016  wiz Whitespace.
 1.261 15-Aug-2016  sjg Add .MAKE.META.IGNORE_FILTER to allow more complicated filtering of filemon data.

The filter is applied to paths Read or Excuted, and if it expands to
nothing, the entry is skipped.

For example; dirdeps.mk can set this to:

.MAKE.META.IGNORE_FILTER = M*/${.MAKE.DEPENDFILE_PREFIX}*

when checking if DIRDEPS_CACHE is up to date, where only Makefile.depend*
are of interest.
 1.260 10-Aug-2016  sjg Set .ERROR_CMD if we can
 1.259 03-Jun-2016  wiz branches: 1.259.2;
Fix typo in width argument; end sentence with dot.
 1.258 03-Jun-2016  sjg Refactor the logic for deciding when a .meta file is needed.

Both meta_create() and meta_oodate() now share meta_needed()
to indicate if a .meta file is needed.

This allows for deciding that missing .meta file is cause of out-of-date.
The new knob 'missing-meta' controlls this, and is off by default
since the side effect files of generators like yacc will typically need
.NOMETA to avoid problems.

This however makes it much easier for folk to switch back and forth
with meta mode (eg. FreeBSD's normal build can leverage meta mode for
improved reliablility without need to clean).

Also if .MAKE.MODE does not contain 'nofilemon', the knob
'missing-filemon' allows control as to whether missing filemon data
should cause the target to be out-of-date.
Again off by default.
 1.257 10-May-2016  sjg Allow for ignoring paths that match a set of patterns.
This can be expensive, so use with caution.
 1.256 16-Mar-2016  sjg Fix syntax
 1.255 14-Mar-2016  matthias make $@ an alias for $! in archive member rules (compatibility with
other makes).
 1.254 20-Feb-2016  wiz Spelling fixes.
 1.253 20-Feb-2016  sjg Add a knob .MAKE.SAVE_DOLLARS to control the behavior of $$ during :=

If TRUE '$$' are not consumed (saved).
If FALSE '$$' becomes '$' just like normal expansion rules.

default is TRUE.

Reviewed by: christos
 1.252 18-Feb-2016  sjg Add .export-literal to avoid the need for $$ dance when trying to put
unexpanded variables into environment.

Reviewed by: christos
 1.251 18-Feb-2016  sjg It's 2016
 1.250 18-Feb-2016  sjg Add support for .dinclude

Like .sinclude missing file will be ignored.
Like .depend stale dependencies will be ignored.
Allows better implementation of auto depend.

Reviewed by: christos
Requested by: Bryan Drewery at FreeBSD.
 1.249 05-Jun-2015  wiz Drop trailing whitespace.
 1.248 05-Jun-2015  sjg Document .OBJDIR target.
 1.247 10-Apr-2015  wiz It's 2015.
 1.246 10-Apr-2015  wiz Remove trailing whitespace.
 1.245 09-Apr-2015  sjg Forgot to tweak date
 1.244 09-Apr-2015  sjg jobs mode handles '-' very differently to compat mode, but this is not
reflected in make.1
Also fix handling to match the behavior described in the comment
of JobPrintCommand (only matters if shell sets hasErrCtl).

A better long term solution is needed since the current behavior
is sub-optimal wrt '-' and different from all other makes.

Reviewed by: christos
 1.243 14-Sep-2014  apb Small markup fixes:
* Use \e instead of \\ to represent a backslash;
* Dont' start a line with .SUFFIXES.
 1.242 14-Sep-2014  dholland bump date; I think I'm done for tonight
 1.241 14-Sep-2014  dholland Add some notes on compatibility with other make dialects.

I was originally intending to preserve some of Jarmo Jaakkola's notes
on POSIX make from the PR 49085 changes... but really there's no point
wandering into details about $? and such when the big picture is
"almost everything in this manual works only in BSD make".

Maybe the exact details can be stuffed into a chapter of the mythical
make reference manual if that ever gets (re)written.
 1.240 14-Sep-2014  dholland Improve the documentation of rule-local variables. Cherry-picked from
the PR 49085 changes, with some adjustments by me.
 1.239 14-Sep-2014  dholland Improvements pertaining to shell commands and chdir. Some of this
appeared in the PR 49085 changes, even though it's not actually
relevant there except tangentially. However, I've reworked most of
that for clarity and added some more.
 1.238 09-Sep-2014  dholland Restore -r1.234 of make.1, which was an unrelated fix from sjg pertaining
to the docs for the -w option.
 1.237 09-Sep-2014  dholland Revert the man page as well. (hi joerg)

Revert it to 20140823 (-r1.230), before the controversial commits,
which changed it a good deal.
 1.236 05-Sep-2014  wiz Reduce pirate slang.
 1.235 04-Sep-2014  christos document commented out .INVISIBLE and .JOIN.
 1.234 28-Aug-2014  sjg Enter/leave flag is -w not -dw
 1.233 23-Aug-2014  christos PR/46096: Jarmo Jaakkola: fix many problems with dependencies (PR 49086)

Quite extensive rewrite of the Suff module. Some ripple effects into
Parse and Targ modules too.

Dependency searches in general were made to honor explicit rules so
implicit and explicit sources are no longer applied on targets that
do not invoke a transformation rule.

Archive member dependency search was rewritten. Explicit rules now
work properly and $(.TARGET) is set correctly. POSIX semantics for
lib(member.o) and .s1.a rules are supported.

.SUFFIXES list maintenance was rewritten so that scanning of existing
rules works when suffixes are added and that clearing the suffix list
removes single suffix rules too. Transformation rule nodes are now
mixed with regular nodes so they are available as regular targets too
if needed (especially after the known suffixes are cleared).

The .NULL target was documented in the manual page, especially to
warn against using it when a single suffix rule would work.
A deprecation warning was also added to the manual and make also
warns the user if it encounters .NULL.

Search for suffix rules no longer allows the explicit dependencies
to override the selected transformation rule. A check is made in
the search that the transformation that would be tried does not
already exist in the chain. This prevents getting stuck in an infinite
loop under specific circumstances. Local variables are now set
before node's children are expanded so dynamic sources work in
multi-stage transformations. Make_HandleUse() no longer expands
the added children for transformation nodes, preventing triple
expansion and allowing the Suff module to properly postpone their
expansion until proper values are set for the local variables.

Directory prefix is no longer removed from $(.PREFIX) if the target
is found via directory search.

The last rule defined is now used instead of the first one (POSIX
requirement) in case a rule is defined multiple times. Everything
defined in the first instance is undone, but things added "globally"
are honored. To implement this, each node tracks attribute bits
which have been set by special targets (global) instead of special
sources (local). They also track dependencies that were added by
a rule with commands (local) instead of rule with no commands (global).

New attribute, OP_FROM_SYS_MK is introduced. It is set on all targets
found in system makefiles so that they are not eligible to become
the main target. We cannot just set OP_NOTMAIN because it is one of
the attributes inherited from transformation and .USE rules and would
make any eligible target that uses a built-in inference rule ineligible.

The $(.IMPSRC) local variable now works like in gmake: it is set to
the first prerequisite for explicit rules. For implicit rules it
is still the implied source.

The manual page is improved regarding the fixed features. Test cases
for the fixed problems are added.

Other improvements in the Suff module include:
- better debug messages for transformation rule search (length of
the chain is now visualized by indentation)
- Suff structures are created, destroyed and moved around by a set
of maintenance functions so their reference counts are easier
to track (this also gets rid of a lot of code duplication)
- some unreasonably long functions were split into smaller ones
- many local variables had their names changed to describe their
purpose instead of their type
 1.232 23-Aug-2014  wiz Bump date for previous.
 1.231 23-Aug-2014  christos PR/49085: Jarmo Jaakkola: fix several parsing errors

Don't exit from var.c:Var_Parse() before possible modifiers are handled
on D and F modified versions of local variables. Properly expand $(?D)
and $(?F) too.

Make line continuations in rule's commands POSIX compliant.

Fix the syntax error caused by lib(member) as the last target before
a dependency operator.

Document the line continuation change in the manual page. Also talk
more about the POSIX style local variables and their modifiers.

Add tests covering the fixed problems into d_posix.mk. The test is
a known failure at the moment because of PR 49086 and PR 49092.

[XXX: unconverted tests]
 1.230 15-Feb-2014  sjg Put .INCLUDEDFROM* in the right section
 1.229 19-Jan-2014  apb Emphasise the fact that the regexp and replacement in :C/// are
subjected to variable expansion before regexp parsing. This was already
documented if you read carefully enough, but more emphasis would have
helped me to figure out why I needed three or four backslashes where I
expected to need only two.
 1.228 10-Jan-2014  wiz Bump date for previous.
 1.227 10-Jan-2014  christos add .INCLUDEDFROM{FILE,DIR}
 1.226 07-Nov-2013  dholland apostrophe's do not make plural's.
 1.225 27-Oct-2013  wiz Remove trailing whitespace.
 1.224 25-Oct-2013  apb Explain that ${VAR:M*} will normalise the inter-word spacing.
 1.223 25-Oct-2013  apb The :C/// modifier takes an extendedregular expression.
 1.222 11-Aug-2013  apb Use Va markup to show that the "suffix" part of ".PATH.suffix"
is a placeholder, not a literal string.
Also bump date.
 1.221 11-Aug-2013  dholland Document .PATH.suffix:. Noted by apb back in December of 2008
(that's how long my queue is...)
 1.220 30-Jul-2013  sjg Allow an empty .MAKE.JOB.PREFIX to supress output of --- job --- tokens
 1.219 16-Jul-2013  christos More gmake compatibility:
1. add -w flag to print Entering and Leaving directory name the the beginning
and the end of processing.
2. export MAKELEVEL=$((MAKELEVEL + 1)) only in the child environment.
3. when printing error messages, prefix them with the program name [$MAKELEVEL]
for $MAKELEVEL > 0
4. if $MAKEFLAGS consists only of letters assume it is a set of flags (as
allowed by posix), convert them to -f -l -a -g -s, so that they get parsed
properly.
With those fixes gmake -> bmake -> gmake -> bmake etc. works as expected.
 1.218 26-Jun-2013  agc fix a typo
 1.217 25-Jun-2013  wiz Remove trailing whitespace.
 1.216 25-Jun-2013  sjg Add .MAKE.META.IGNORE_PATHS to facilitate local additions to the paths
which should be ignored by meta_oodate().
 1.215 22-May-2013  christos improve wording
 1.214 22-May-2013  christos put a note on what FRC means.
 1.213 31-Mar-2013  sjg Refine the effect of .OODATE on command comparison.
Rather than apply it to the whole script, just the current command line
is affected. This allows a trick like ${.OODATE:M.NOMETA_CMP}
to cause command comparison to be supressed for one command only.
 1.212 23-Mar-2013  sjg If built with filemon support, set .MAKE.PATH_FILEMON to _PATH_FILEMON
so that makefiles can test for it.
 1.211 05-Mar-2013  christos Add a .STALE special target that gets invoked when dependency files contain
stail entries.
 1.210 27-Jan-2013  sjg In SHELL COMMANDS section, provide some clues about different
behavior in jobs vs non-jobs mode.
Move the comment about when shell is skipped to this discussion
from COMPATABILITY.
Remove the incorrect statement about default mode being somehow
neither jobs mode or compat mode (it is compat mode).
 1.209 08-Oct-2012  christos It is Sprite, not Sprint; pointed out by Todd Miller.
 1.208 17-Sep-2012  christos spelling
 1.207 17-Sep-2012  sjg Document the fact that lack of shell meta chars in a command
results in direct exec in compat mode.
 1.206 30-Aug-2012  wiz branches: 1.206.2;
Add an s.
 1.205 30-Aug-2012  sjg Add a knob to control whether -V fully expands a plain variable by default.
The default retains the traditional NetBSD behavior, but the knob
can be set so that FreeBSD can retain their expected behavior.
This is a compromise to be sure.

Add a debug flag -dV to override the above, so that regardless of
the knob setting, the raw value of a variable can be easily seen.
 1.204 24-Apr-2012  sjg Restore previous behavior - supressing duplicate entries in
.MAKE.MAKEFILES - it is more efficient.
 1.203 20-Apr-2012  sjg Fix some typos in/around ParseGmakeExport.
Remove the suppresssion of duplicate entries in .MAKE.MAKEFILES
 1.202 08-Apr-2012  wiz Remove unnecessary Bk/Ek pairs from SYNOPSIS.
No effective change except where I used the opportunity to sort options
and/or option descriptions.
 1.201 31-Mar-2012  christos document gmake export command
 1.200 03-Feb-2012  sjg Fix description of 'silent' in .MAKE.MODE
Also document 'env' in that context.
 1.199 23-Dec-2011  sjg Mention limits of :P
 1.198 17-Dec-2011  sjg The :@ example gives the impression that we encourage the ODE
convention of naming loop variables like .LINK., when in fact
single char variables are far more common in NetBSD.
 1.197 13-Nov-2011  dholland Fix xref to the PSD; PR 45568 from Petri Laakso.
 1.196 06-Nov-2011  christos explain how to use .PARSEDIR and .PARSEFILE
 1.195 28-Aug-2011  sjg branches: 1.195.2;
In meta mode, we create .meta files for most targets.
These capture all the interesting data - useful for debugging.
In such cases there is no need to replicate commands in the build log.
Rather than run the entire build .SILENT, allow meta mode to set that flag
per target iff a .meta file is created.
Normal behavior is retained for targets where no .meta file is created,
ensuring that no build data is lost.
 1.194 18-Aug-2011  sjg Make some dashes em-dashes (based on patch from Andrew O. Shadoura).
Note behavior of .META flag wrt out-of-date.
 1.193 30-Jun-2011  wiz dependant -> dependent
 1.192 28-May-2011  cheusov fix bug in section .ORDER of make.1
 1.191 04-May-2011  wiz Remove trailing whitespace.
 1.190 04-May-2011  christos Document what I wrote for PR/40115
 1.189 04-May-2011  sjg Add .MAKE.META.BAILIWICK - to identify the scope of make's control.
meta_oodate: if a file that was written or linked within our bailiwick,
but outside of .OBJDIR is missing, add it to missingFiles.
If we get to the end of the .meta file without seeing it [re]moved,
then consider the target out-of-date.
 1.188 11-Apr-2011  wiz Remove trailing whitespace.
 1.187 11-Apr-2011  sjg Add :localtime and :gmtime which use value as format string for strftime.
 1.186 07-Apr-2011  joerg Add the :hash modifier to compute a 32bit hash of an variable.
This uses MurmurHash3 to get a reasonable collission-free hash with
small code. The result is endian neutral.
 1.185 27-Mar-2011  sjg Use curdirOk as the token
 1.184 27-Mar-2011  sjg When .MAKE.MODE inlcudes 'meta'; 'curdir=true' enables creating .meta
files in .CURDIR - such as when running make in .OBJDIR with a generated
makefile.
 1.183 26-Feb-2011  sjg Fix rendering of :? example
 1.182 14-Sep-2010  wiz branches: 1.182.2;
Remove trailing spaces, add a few serial commas.
 1.181 13-Sep-2010  sjg Bump date
 1.180 13-Sep-2010  sjg Add meta.c which implements "meta" mode for make.
In this mode, a .meta file is created for each target, capturing
the expanded commands used, any command output, and if filemon(9)
is available, a record of system calls which are of interest.
Not enabled unless USE_META=yes is set when building make.
Also, if FILEMON_H exists, meta.c will be compiled to use filemon(9).
 1.179 30-Jun-2010  dholland Document that suffix rules are not applied to PHONY targets, and also
document the .TARGETS builtin variable, which has existed since 4.4 days.
Bump date. Arises from discussion in PR 43502.
 1.178 27-Jun-2010  dholland fix previous, the source isn't exactly crystal clear and there's a bug that
makes the behavior misleading.
 1.177 27-Jun-2010  dholland Clarify $(.PREFIX) / $*. Bump date.
 1.176 10-Jun-2010  wiz Whitespace.
 1.175 09-Jun-2010  christos Explain variable expansion better. Requested by Aleksey Cheusov
 1.174 06-Jun-2010  wiz Bump date for previous.
 1.173 06-Jun-2010  sjg Add .export-env which tells make to export a variable to the environment
but not to track it - as is done for .export
This allows the variable to be updated without affecting what was put
into the environment.
Older versions of make will simply treat this as .export
 1.172 13-May-2010  joerg Drop trailing white space. Use .Oo / .Oc explicitly to annotate that the
empty content is intended.
 1.171 22-Apr-2010  sjg PR: 42850
Reviewed by:

modmisc: since we apply an exists() test to $paths, be conservative
in what we expect.

Run the unit tests with -r -m / so that we do not fail if there
is no sys.mk present.
 1.170 15-Apr-2010  sjg Add :tA to attempt to resolve to absoute path using realpath().
 1.169 07-Apr-2010  wiz Sort a bit more.
 1.168 07-Apr-2010  sjg Add:

.error "message"
.warning "message"
based on FreeBSD implementation.
add .info while were at it.

.ERROR: a target to run on error.
We pass the failing GNode to PrintOnError so it can set
.ERROR_TARGET.

.MAKE.MAKEFILE_PREFERENCE
As a means to control make's list of prefered makefile names.
(Default: "makefile Makefile")

.MAKE.DEPENDFILE
Names the file to read dependencies from
(Default ".depend")

.MAKE.MODE
Processed after all makefiles are read.
Can put make into "compat" mode (more to come).

Fix:

compat.c: Error code should not be sent to debug_file.
Make_DoAllVar: use DONE_ALLSRC to avoid processing a node multiple times.
ReadMakefile: we can simply use doing_depend to control setting MAKEFILE.
 1.167 22-Feb-2010  joerg \\ -> \e
 1.166 19-Nov-2009  wiz New sentence, new line; remove trailing whitespace.
 1.165 19-Nov-2009  sjg Add .unexport - the exact opposite of .export
and .unexport-env which unexport's all previously .export'd globals
as well as clearing environ[].
Allow's sys.mk near total controll.

Reviewed by: apb
 1.164 15-Oct-2009  joerg Do not work around ancient groff limits with .Xo/.Xc.
 1.163 02-Oct-2009  wiz Remove trailing whitespace.
 1.162 01-Oct-2009  dsl Add example of how to use the ?: modifier properly.
 1.161 08-Sep-2009  sjg Reviewed by: apb

Use .MAKE.LEVEL to track recursion.
The first instance of make will have .MAKE.LEVEL 0, which
can be handy for excluding rules which should not apply
in a sub-make.
gmake and freebsd's make have a similar mechanism, but each
uses a different variable to track it. Since we cannot be
compatible with both, we allow the makefiles to cope if they want
by handling the export of .MAKE.LEVEL+1 in Var_Set().
 1.160 26-Aug-2009  sjg Bump date
 1.159 26-Aug-2009  sjg Add -C directory, same as gmake and freebsd make.
 1.158 01-Jun-2009  sjg Missing ':' in .ORDER example
 1.157 13-May-2009  wiz Whitespace fix.
 1.156 11-Apr-2009  snj Typo fix: many file -> many files.
 1.155 11-Apr-2009  wiz Bump date for previous.
 1.154 11-Apr-2009  apb Honour the TMPDIR environment variable instead of always using /tmp
as a place to store temporary files.
 1.153 24-Jan-2009  wiz branches: 1.153.2;
Sort sections. Fix typo (last line).
 1.152 24-Jan-2009  dsl Correct the definition of the :? modifier - in particular the modifier
applies to the variable name, not its value!
Remove the set of examples that were recently added that failed to
explain why some worked and some didn't.
Add a not to the compatability section about the change in .for loop
substitution post 5.0.
Add a BUGS section.
XXX the BUGS section needs more entries :-)
 1.151 12-Jan-2009  dholland Fix blatantly wrong exposition of .WAIT example.
PR bin/40372 from Gao Ya'nan.
 1.150 21-Dec-2008  dsl Note that an unrecognised word in a .if is the same as in .ifdef and that
such a word has to be white-space separated.
From PR bin/30967 bin/37222 and maybe others!
 1.149 21-Dec-2008  dsl Add some notes about recursive expansion and expansion of variable names.
Note that any of "${}()" in variable names will be griefsome!
Remove the example of using ::= to apply a modifier to a .for loop
variable as that is no longer necessary.
Remember to change the date :-)
 1.148 07-Dec-2008  christos explain compatibility mode better.
 1.147 07-Dec-2008  christos add debug flag for cwd.
 1.146 26-Nov-2008  wiz I think ':' is called "colon", not "column" :)
 1.145 25-Nov-2008  christos PR/40026: Aleksej Saushev: make(1) doesn't document VPATH, document it.
 1.144 30-Oct-2008  wiz branches: 1.144.2;
Whitespace.
 1.143 30-Oct-2008  sjg Update the modification date
 1.142 29-Oct-2008  sjg Add some examples of how to use :?
 1.141 22-Oct-2008  apb Send debugging output to stderr by default, not to stderr.
If you really want debugging to stdout, specify "-dFstdout"
in MAKEFLAGS or on the command line.

Discussed in tech-userlevel.
 1.140 19-Oct-2008  wiz Add missing dot before macro.
 1.139 19-Oct-2008  apb Always make the debugging output unbuffered; in addition, if debugging
is enabled but debugging output is not directed to stdout, then make
stdout line buffered.

Previously, the code to make debug output unbuffered applied only if
debugging to a file, not if debugging to stdout or stderr. Making
stdout line buffered when debugging was suggested by Steven Bellovin.
 1.138 18-Oct-2008  apb Document how "-dF[+]filename" works.
 1.137 10-Aug-2008  wiz Drop trailing whitespace. Use .Dq.
 1.136 10-Aug-2008  cube Clarify a bit .SUFFIXES and .IMPSRC. Should fix PR#37822.
 1.135 19-Jan-2008  sjg branches: 1.135.6;
Implement -dl (aka LOUD) to override '@' at the start of script lines.
Based on supplied patch.

PR: 37202
 1.134 08-Oct-2007  sjg Use .MAKE.MAKEFILES to track all the makefiles that have been read
so they can be used in dependency rules.
 1.133 05-Oct-2007  sjg Add the ability to .export variables to the environment.
 1.132 01-Oct-2007  sjg Add the ability to tweak the token output before targets in job mode.
Eg.
.MAKE.JOB.PREFIX=${.newline}---${.MAKE:T}[${.MAKE.PID}]
would produce
---make[1234] target ---
 1.131 13-Aug-2007  rillig branches: 1.131.2;
A small word can sometimes express things clearer ...
 1.130 23-Jan-2007  wiz 4 -> 4.0, since Nx does not accept all arguments without complaint.
 1.129 23-Dec-2006  wiz Fix a typo. Use Nx.
 1.128 19-Nov-2006  dsl branches: 1.128.2; 1.128.4;
Update information on .ORDER and .WAIT.
Document the -d-flags and -dFfilename.%d options.
Mention MAKEFLAGS at the top, reword to make it clear that makefile and
Makefile are only used if no -f makefile is given.
 1.127 29-Jun-2006  rillig Fixed the bug reported in PR 33866, which is that the :Q operator does not
handle newlines correctly. Ok'ed by christos.
 1.126 17-Jun-2006  reed Fix mispelling.
 1.125 19-Mar-2006  wiz branches: 1.125.2;
New sentence, new line.
 1.124 19-Mar-2006  sjg Document an interesting kwirk in := handling of undefined variables.
 1.123 11-Mar-2006  wiz Markup fixes.
 1.122 26-Feb-2006  apb Make ".WAIT" apply recursively to all children of nodes on the right
hand side of the .WAIT, except when the recursive interpretation would
cause a cycle in the dependency graph.

Discussed in tech-toolchain. Reviewed by christos, sjg.
 1.121 26-Feb-2006  wiz Fix typo.
 1.120 26-Feb-2006  sjg Update man page and add test case for specifying modifiers via variable.
Also allow said variable to appear anywhere in the modifier list.
 1.119 22-Jan-2006  dsl Make .NOTPARALLEL stop the job engine issuing more than one token (instead
of trying to de-jobify the make.
You can now put .NOTPARALLEL in a submake of a recursive make (where it is
using a job-token pipe from the outer make and have it only run a single job.
You can also specify .NOTPARRALEL in the root makefile of a large recursive
make and have the submakes run multiple commands.
Add some diagnostics printfs (enabled with -dp) to the parser.
 1.118 27-Jun-2005  wiz Consistency. Use Pp instead of br.
 1.117 27-Jun-2005  lukem Restore the rework from rev 1.115 and expand the description of .OBJDIR
to document the behaviour that is currently in use (the "./obj" and
"/usr/obj/`pwd`" behaviour).
Hopefully the existing .OBJDIR behaviour is clearer now.
 1.116 26-Jun-2005  wiz Since the obj dir handling changes in the code have been
reverted, revert them in the man page too (i.e., revert v1.115).
 1.115 23-Jun-2005  lukem Deprecate support for automagically setting the .OBJDIR to
./obj.${MACHINE}
./obj
/usr/obj/${PWD}

The rules for the default .OBJDIR setting are now simplified to
(and documented as) trying the chdir to the following
(if the appropriate variable is defined):
${MAKEOBJDIRPREFIX}${.CURDIR}
${MAKEOBJDIR}
${.CURDIR}

.OBJDIR can be overridden in the makefile.
<bsd.obj.mk> uses this to provide the "culled" .OBJDIR semantics
for NetBSD's /usr/src builds.

MAKEOBJDIRPREFIX & MAKEOBJDIR still can only be provided
in the environment or on make(1)'s command line.

Per discussion on tech-toolchain.
This should reduce a lot of lossage people have experienced over
the years with various .OBJDIR setups.
 1.114 19-Jun-2005  wiz Fix an article, and drop trailing whitespace.
 1.113 18-Jun-2005  rpaulo Change "non-escaped" to "unescaped".
Reviewed by hubertf.
 1.112 17-Jun-2005  wiz Bump date for -jn, and add some formatting.
 1.111 17-Jun-2005  jmc Add new debugging option '-dn' which will leave the scripts fed into make on
-j jobs in /tmp for debugging purposes. Add a note to the man page that
this could cause problems if run a lot (due to the number of files created)
 1.110 15-Jun-2005  rpaulo We now support comments until the end of a non-escaped line.
Ok'ed by hubertf.
 1.109 01-Jun-2005  wiz New sentence, new line; grammar improvements.
 1.108 01-Jun-2005  sjg Add :Ox for random ordering, based on patch from
Mike M. Volokhov <mishka@apk.od.ua>
 1.107 08-May-2005  christos Now that dependencies in .BEGIN, .END, and .INTERRUPT work, allow them.
 1.106 01-May-2005  christos PR/9566: Arne H. Juul: Document special targets that do not obey dependencies.
 1.105 23-Feb-2005  sjg branches: 1.105.2;
In the case of :? modifier, variable can be an expression - say so.
 1.104 13-Jul-2004  wiz Sort options in synopsis.
 1.103 07-May-2004  wiz Add comma in enumerations; fix a sentence; plural needs no apostrophe.
 1.102 07-May-2004  sjg Remove use of sh -e when running in compat mode.
Its not posix compliant and serves very little purpose.
With this change compat and jobs modes are consistent wrt how
they treat each line of a script.

Add support for the '+' command line prefix as required by posix.
Lines prefixed with '+' are executed even when -n is given.
[Actually posix says they should also be done for -q and -t]

PR:
Reviewed by: jmc
 1.101 05-Feb-2004  wiz branches: 1.101.2;
Bump date; uppercase POSIX.
 1.100 05-Feb-2004  ross Briefly document the posix command line order and add that this
is (unfortunately) not enforced.
 1.99 04-Feb-2004  wiz Use more mdoc macros; new sentence, new line; bump date for previous.
 1.98 03-Feb-2004  chuck add parent directory search for make as discussed on tech-toolchain.
- new dir.c function: Dir_FindHereOrAbove:
Search for a path in the current directory and then all the directories
above it in turn until the path is found or we reach the root ("/").
- add hooks to use it in main.c for -m and syspath (compiled in
_PATH_DEFSYSPATH and $MAKESYSPATH).
- updated man page
 1.97 27-Jan-2004  lukem Document more SPECIAL SOURCES (aka ATTRIBUTES).
Improve description of variable modifiers.
In the variable list, be more specific referring to "environment variables"
rather than just relying upon the formatting difference between .Ev and .Va.
 1.96 26-Dec-2003  wiz Bump date for previous; use macros for marking up
the dollar sign.
 1.95 26-Dec-2003  jmc Note that variable expansion can occur within SYSV style = substitions.
 1.94 07-Dec-2003  wiz Drop trailing spaces.
 1.93 07-Dec-2003  dsl Add back 'on error' that got deleted by mistake.
 1.92 07-Dec-2003  dsl Add a -Dg3 which outputs the 'input graph' only on error exit.
Lets you see the wood for the trees...
 1.91 07-Nov-2003  lukem Add some subsections in the VARIABLE ASSIGNMENTS section.

In the "modifier description" list, show each modifier with the leading `:'.
Rationale: it's hard to search for modifiers without it, and we already do
the same thing in the -options and .makecommands lists. I now find it much
easier to find the description for a modifier in the man page.
 1.90 09-Oct-2003  jdolecek properly dottify .\" comments; this fixes output of [range] paragraph
 1.89 27-Sep-2003  sjg Implement :[] modifier to allow picking a range of words out of a variable.
Also :tW and a W flag to :C and :S to allow treating value as a single word.
Add unit tests for the above, and fix some corner cases.
Based on patches supplied by Alan Barrett <apb@cequrux.com>
 1.88 10-Sep-2003  jmmv Add the 'e' debug flag (i.e., '-d e'): when enabled, show the "target
failed" and "command failed" messages added recently. These introduce
too much noise when debugging some kind of problems, specially in pkgsrc.
 1.87 10-Sep-2003  jmmv Document the '-d f' flag.
 1.86 05-Sep-2003  wiz Whitespace nits.
 1.85 05-Sep-2003  sjg Allow -V '${FOO}' to print the expanded version of FOO.
A side effect of adding and removing a -E option for the above is that
the cases in MainParseArgs are now ordered correctly?
 1.84 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.83 01-Aug-2003  sjg Allow .SHELL: to control the shell used by compat mode too.
Add a shell spec for ksh - a nice portable posix shell.
Document .SHELL:
 1.82 16-Jul-2003  wiz Bump date for tu addition; drop trailing space; sort a bit.
 1.81 14-Jul-2003  sjg Add a :ts[c] modifier to allow controlling the separator used between
words in a variable expansion. If 'c' is omitted no separator is used.
 1.80 26-Jun-2003  wiz Misc mdoc fixes (mostly quoting).
 1.79 23-May-2003  wiz New sentence, new line; bump date for last.
 1.78 23-May-2003  christos PR/10917: John Hawkinson: Document $MAKE and say which one we want to be using.
 1.77 16-Apr-2003  wiz Bump date for last.
 1.76 01-Apr-2003  jrf Added MAKESYSPATH environment variable as per jmmv's suggestion in
PR 18030
 1.75 14-Mar-2003  thorpej Add a -X option, which prevents make(1) from putting variables
set on the command line into the environment individually. This
can be useful on systems which have a tight limit on the size
of the argument space.
 1.74 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.73 04-Feb-2003  perry "Utilize" has exactly the same meaning as "use," but it is more
difficult to read and understand. Most manuals of English style
therefore say that you should use "use".
 1.72 09-Jan-2003  uebayasi Be more specific how to call arguments of modifiers.

Reviewed By: wiz
 1.71 03-Jan-2003  mjl Tyop fixes
 1.70 29-Nov-2002  wiz Bump date for .PATH description; begin sentence with upper case letter;
new sentence, new line.
 1.69 26-Nov-2002  sjg Whenever we update .PATH, set the variable ${.PATH} to reflect the
search list that will be used. Thus 'dot' and 'cur' will appear in
${.PATH} either at the start or end depending on .DOTLAST even though
they are not strictly in dirSearchPath.

When .CURDIR is assigned to - re-set the 'cur' Path.

Finally, when checking subdirs, look in 'dot' and 'cur' (first or last
depending on .DOTLAST) just as we do in other situations.
 1.68 02-Nov-2002  perry environment variables, not environmental variables
 1.67 30-Sep-2002  grant New sentence, new line.
 1.66 24-Sep-2002  wiz Fix an Xr, add a comma and join two short lines. In short, minor changes :)
 1.65 24-Sep-2002  christos add missing Lt.
 1.64 19-Aug-2002  wiz End some sentences with a dot. bin/17987 by Julio Merino.
 1.63 19-Mar-2002  lukem clarify how :U works
 1.62 08-Feb-2002  ross Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.61 07-Feb-2002  ross Edit -mdoc usage.

* There is no -indent option to .Bd or .Bl, although you would
never know that from its frequent use in this tree. There is a
"-offset indent" combination that makes sense, and you can certainly
say "-width indent".

* Also, you can't markup the -width option argument, tho you CAN
use a callable macro. So "-width Ar filename" doesn't make sense,
but either "-width Ar" or "-width filename" does, as might something
like "-width xxfilename" for a little extra space.

* There are a lot of needlessly complex hanging tag macros in man4 used
to create simple item lists. Those should be simplified one of these
days before someone copies and edits yet another man4 page.
 1.60 06-Feb-2002  pk Add `tu' and `tl' variable expansion modifiers, which transform the
value to uppercase and lowercase, respectively. From Kevin Neal from FreeBSD.
 1.59 01-Feb-2002  bgrayson - Several paragraphs were indented one level further than needed.
- The endfor example needed some spacing readjustments.
 1.58 23-Dec-2001  lukem outdent description of variable expansion modifiers
 1.57 12-Nov-2001  wiz Whitespace/punctuation nits.
 1.56 12-Nov-2001  tv Add new make variable .ALLTARGETS, which lists all targets in the Makefile.
(Makes it possible to search the target list for particular things and
apply attributes to all the relevant targets.)
 1.55 12-Nov-2001  tv Sort list of make variables.
 1.54 23-Oct-2001  jmc Fix typo in definition of PARSEFILE. It should refer to PARSEDIR (and not
itself twice) when describing the variables lifetime
 1.53 13-Aug-2001  ad Nit.
 1.52 03-Jul-2001  christos add .USEBEFORE Attribute
 1.51 10-Jun-2001  sjg Simplify the exporting of VAR_CMD's via MAKEFLAGS.
We now just list the names of such variables in .MAKEOVERRIDES.
When we come to export MAKEFLAGS we quote the value of each exported variable
using :Q, using: ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}
The :O:u suppresses duplicate names.
Also modifed Parse_DoVar to re-export MAKEFLAGS whenever .MAKEOVERRIDES
is assigned to so .MAKEOVERRIDES+= PATH will export PATH=${PATH:Q}
to the environment, while .MAKEOVERRIDES= will disable export of VAR_CMD's.
 1.50 09-Jun-2001  sjg Mention .MAKEOVERRIDES
 1.49 01-Jun-2001  sjg A number of semi-related changes.
1. make -dx turns on DEBUG_SHELL which causes sh -x to be used where
possible.
2. PrintOnError() is now called when make is stopping due to an error.
This routine reports the curdir and the value of any variables listed
in MAKE_PRINT_VAR_ON_ERROR.
3. Variables set via command line, are propagated to child-makes via
MAKEFLAGS. This behaviour appears to be necessary for POSIX (according
to the GNU folk anyway).
4. Do not reset MAKEFILE when reading ".depend" as this rather eliminates the
usefulness of ${MAKEFILE}.
5. Added ${.newline} as a simple means of being able to include \n in the
result of a :@ loop expansion.
6. Set ${MAKE_VERSION} if defined. Need to come up with a useful value.

Reviewed: christos
 1.48 04-Apr-2001  wiz getcwd lives in 3, not 2. Whitespace fixes.
 1.47 14-Jan-2001  christos Provide a new .if commands(<target>) primitive that returns true if the
target has commands associated with it.
 1.46 10-Jan-2001  christos PR/11800: Chris Demetriou: Add -W flag to exit on parse warnings.
While I am here, s/make:.*"/%s:\1", progname/
 1.45 01-Jan-2001  sommerfeld Delete forceSerial; just use compatMake for that.
Add -N flag to *really* not execute any commands (useful when using
the -d flags to debug usr/src/Makefile)
Document -N
Update documentation of -n to mention that it still executes commands
for targets marked .MAKE so that the -N/-n distinction is clear.
 1.44 30-Dec-2000  sommerfeld Add a token-passing scheme to allow a recursive make to successfully
use -j; all make's in a recursive build cooperate to limit the total
number of jobs, using a token-passing scheme.

The current token passing algorithm is similar to the one implemented
by gmake; there is a single pipe which is inherited through the entire
process hierarchy; tokens are obtained by reading a byte from the
"read end" of the pipe, and are returned by writing them to the "write
end". This exact algorithm is likely to change in the future.

Implementation details:
- Use the new trace facility to allow measurement of the
effectiveness of different token-passing schemes
- Get a token in MakeStartJobs(), return it in Make_Update()
- Eliminate Job_Full() and the jobFull global since they are
redundant with token system.
- Add an "internal" -J option (to pass the token pipe fd's down to
submakes) and a -T option for tracing.
- Change how compatMake is forced so that -j means something when
inherited by submakes.
- When waiting for a token, poll the token-passing pipe as well as
the output pipes of existing jobs.
 1.43 05-Sep-2000  christos :u modifier a'la uniq(1) [from der Mouse]
 1.42 01-Jun-2000  sjg branches: 1.42.2;
Rats! ${FOO:=bar} is a common usage of the SysV = modifier.
To avoid that, we now do ::[+?!]*= but the SysV = modifier can
conflict with any new modifier. At there are currently no Makefiles
in our tree that use ${FOO::=bar}
 1.41 30-May-2000  sjg Implemented a set of assignment modifiers. These solve obscure
problems such as using modifiers on .for loop iterators derived from
local variables (eg .TARGET).
Unless the variable already exists in a global context, these assignments are
local to the current context (this is usually what is wanted).
 1.40 29-Apr-2000  sjg branches: 1.40.2;
Added the :U :D :L :P :! and :@ modifiers as used by ODE make.
These allow some very useful magic in the makefiles.
The comment in var.c describing their behaviour is mostly lifted
from ODE make, but the implementation of the modifiers themselves
is quite different (much simpler) due to divergence of our code base.
 1.39 16-Apr-2000  christos PR/9899: David A. Holland: multi-variable .for constructs in make
 1.38 08-Feb-2000  sjg Mention MAKEOBJDIRPREFIX and explain how it or MAKEOBJDIR are used.
Also fixed a typo in the .SUFFIXES bit.
 1.37 08-Oct-1999  msaitoh s/ the the / the /
 1.36 12-Sep-1999  christos branches: 1.36.2;
Add :O var modifier, that sorts the words in a variable.
 1.35 09-Aug-1999  aidan Added .PARSEDIR and .PARSEFILE variables to make(1).
 1.34 12-Jul-1999  thorpej Fix a typo.
 1.33 11-Jul-1999  thorpej Add a mechanism for specifying that ${.CURDIR} will be searched last
in the presence of .PATH directives by specifying:

.PATH: .DOTLAST

This will be used to fixup the build system to work with both crypto-us
and crypto-intl sub-trees.

Make(1) changes by Christos Zoulas, after much badgering by me :-)
 1.32 10-Mar-1999  erh Add missing .El line.
 1.31 09-Mar-1999  ross Missing .El.
 1.30 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.29 17-Nov-1998  ross Fix a bug that apparently prevented, since day 1, the .-include / .sinclude
feature from ever working. Also, fix the man page that incorrectly described
the syntax of the feature that didn't work.
 1.28 06-Aug-1998  christos - Add {.,}[s-]include for silent include file failures
- Make traditional include statement include more than one file if present
on the line.

Keeping up with the other's :-)
 1.27 01-Apr-1998  christos Add conditional variable evaluation from Alistair Crooks.
 1.26 24-Feb-1998  hubertf Fix typos from PR 5055 by NAKAJIMA Yoshihiro <nakayosh@kcn.or.jp>.
 1.25 19-Oct-1997  lukem branches: 1.25.2;
fix up .Nm usage
 1.24 12-Oct-1997  mikel add missing .Nm argument
 1.23 26-May-1997  pk Erase spurious character.
 1.22 26-May-1997  pk Minor formatting glitch.
 1.21 08-May-1997  mycroft Fix description of .NOPATH.
 1.20 08-May-1997  gwr Add the new .NOPATH feature which can be used to disable .PATH search
for particular targets, i.e. .depend, objects, etc. (from Christos).
 1.19 06-May-1997  mycroft Document .PHONY better.
 1.18 10-Mar-1997  christos Add a .MADE directive to indicated that the children of a target are
up-to-date, even when they are not. This is to simulate our current
make install behavior with proper dependencies.
 1.17 24-Dec-1996  christos [initial version of the substitution/regexp changes were courtesy of Der Mouse]

- fix the variable substitution code in make [PR/2748]
1. change s/a/b/ so that it substitutes the first occurance of the
pattern on each word, not only the first word.
2. add flag '1' to the variable substitution so that the substitutions
get performed only once.

***THIS IS AN INCOMPATIBLE CHANGE!***

Unfortunately there was no way to make things consistent without
modifying the current behavior. Fortunately none of our Makefiles
depended on this.

OLD:

VAR = aa1 aa2 aa3 aa4

S/a/b/ = ba1 aa2 aa3 aa4
S/a/b/g = bb1 bb2 bb3 bb4

NEW:

VAR = aa1 aa2 aa3 aa4

S/a/b/ = ba1 ba2 ba3 ba4
S/a/b/1 = ba1 aa2 aa3 aa4
S/a/b/g = bb1 bb2 bb3 bb4
S/a/b/1g = bb1 aa2 aa3 aa4

- add regexp variable substitution via 'C/foo/bar/' [PR/2752]

- add variable quoting via the ${VAR:Q} modifier. This is useful when running
recursive invocations of make(1):

make VAR=${VAR:Q}

will always work... (This may prove useful in the kernel builds...) [PR/2981]
 1.16 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.15 30-Aug-1996  thorpej Tidy up some RCS ids a bit.
 1.14 15-Mar-1996  christos branches: 1.14.4;
Add PHONY attribute and target. This is the first step to cleanup the
xinstall and xlint crud.
 1.13 06-Mar-1996  christos Fix PR/2118; apply sysincludes patch.
 1.12 16-Dec-1995  christos - Added .WAIT to synchronize between sources like other pmake variants.
- Updated documentation to include .ORDER .PARALLEL .NO_PARALLEL .NONPARALLEL
 1.11 08-Nov-1995  christos - Turn compat mode on by default. It gets turned off when the -j without
the -B flag is specified. [Thus you can use -j 1 to turn it off].
- Fix malloc -> emalloc as Gordon noted.
 1.10 02-Nov-1995  christos Minor:
- ${.PREFIX} should never contain a full pathname
- Fixed gcc -Wall warnings
Major:
- compatMake is now FALSE. This means that we are now running in
full pmake mode:
* rules on dependency lines can be executed in parallel and or
out of sequence:

foo: bar baz

can fire the rule for baz before the rule for bar is fired.
To enforce bar to be fired before baz, another rule needs to be
added. [bar: baz]
* adjacent shell commands in a target are now executed by a single
invocation of the shell, not one invocation of the shell per line
(compatMake can be turned off using the -B flag)
- The -j flag now works... I.e. make -j 4 will fork up to four jobs in
parallel when it can. The target name is printed before each burst
of output caused by the target execution as '--- target ---', when j > 1
- I have changed all the Makefiles so that they work with make -j N, and
I have tested the whole netbsd by:
'make -j 4 cleandir; make -j 4 depend; make -j 4; make -j 4 install'
- I have not compiled or tested this version of make with -DREMOTE.
 1.9 14-Jun-1995  christos branches: 1.9.2;
- $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.8 29-Apr-1995  christos Fix small typo; from Chris Torek
 1.7 23-Jan-1995  mycroft Fix 4 typos pointed out by Jordan, and 1 by me.
 1.6 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.5 10-Feb-1994  jtc Fix typos & spelling errors
 1.4 22-Dec-1993  pk Introduced ${.OBJDIR}. The variable is similar to .CURDIR but points at
the directory where make builds the targets. It can be used to clean up
those cumbersome Makefiles that have to guess at the "obj" directory.
 1.3 01-Aug-1993  mycroft Add RCS indentifiers.
 1.2 22-Apr-1993  mycroft Fix various bugs in man pages (from 386BSD patch 130).
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9.2.1 05-Dec-1995  jtc environmental -> environment
 1.14.4.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.25.2.1 08-May-1998  mycroft Sync with trunk, per request of christos.
 1.36.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.40.2.1 23-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.42.2.1 26-Apr-2001  he Pull up revision 1.48 (via patch, requested by wiz):
Correct getcwd reference, plus whitespace fixes.
 1.101.2.2 10-May-2004  tron Pull up revision 1.103 (requested by sjg in ticket #282):
Add comma in enumerations; fix a sentence; plural needs no apostrophe.
 1.101.2.1 10-May-2004  tron Pull up revision 1.102 (requested by sjg in ticket #282):
Remove use of sh -e when running in compat mode.
Its not posix compliant and serves very little purpose.
With this change compat and jobs modes are consistent wrt how
they treat each line of a script.
Add support for the '+' command line prefix as required by posix.
Lines prefixed with '+' are executed even when -n is given.
[Actually posix says they should also be done for -q and -t]
PR:
Reviewed by: jmc
 1.105.2.4 02-Jul-2005  tron Pull up revision 1.113 (requested by rpaulo in ticket #491):
Change "non-escaped" to "unescaped".
Reviewed by hubertf.
 1.105.2.3 02-Jul-2005  tron Pull up revision 1.110 (requested by rpaulo in ticket #491):
We now support comments until the end of a non-escaped line.
Ok'ed by hubertf.
 1.105.2.2 16-Jun-2005  tron Backout ticket 458, it causes PR toolchain/30536.
 1.105.2.1 16-Jun-2005  tron Pull up revision 1.110 (requested by rpaulo in ticket #458):
We now support comments until the end of a non-escaped line.
Ok'ed by hubertf.
 1.125.2.1 19-Jun-2006  chap Sync with head.
 1.128.4.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.128.2.2 15-Jan-2009  bouyer Pull up following revision(s) (requested by dholland in ticket #1262):
usr.bin/make/make.1: revision 1.151
Fix blatantly wrong exposition of .WAIT example.
PR bin/40372 from Gao Ya'nan.
 1.128.2.1 05-Jun-2007  bouyer branches: 1.128.2.1.2;
Apply patch (requested by tron in ticket #696):
usr.bin/make/compat.c patch
usr.bin/make/cond.c patch
usr.bin/make/dir.c patch
usr.bin/make/for.c patch
usr.bin/make/main.c patch
usr.bin/make/make.1 patch
usr.bin/make/make.c patch
usr.bin/make/make.h patch
usr.bin/make/nonints.h patch
usr.bin/make/parse.c patch
usr.bin/make/str.c patch
usr.bin/make/targ.c patch
usr.bin/make/util.c patch
usr.bin/make/var.c patch

Synchronize make(1) with HEAD branch to increase perfomance and
improve stability.
 1.128.2.1.2.1 15-Jan-2009  bouyer Pull up following revision(s) (requested by dholland in ticket #1262):
usr.bin/make/make.1: revision 1.151
Fix blatantly wrong exposition of .WAIT example.
PR bin/40372 from Gao Ya'nan.
 1.131.2.2 23-Mar-2008  matt sync with HEAD
 1.131.2.1 06-Nov-2007  matt sync with HEAD
 1.135.6.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.144.2.3 16-Jan-2009  bouyer Pull up following revision(s) (requested by dholland in ticket #271):
usr.bin/make/make.1: revision 1.151
Fix blatantly wrong exposition of .WAIT example.
PR bin/40372 from Gao Ya'nan.
 1.144.2.2 28-Nov-2008  snj Pull up following revision(s) (requested by christos in ticket #135):
usr.bin/make/make.1: revision 1.146
I think ':' is called "colon", not "column" :)
 1.144.2.1 28-Nov-2008  snj Pull up following revision(s) (requested by christos in ticket #135):
usr.bin/make/make.1: revision 1.145
PR/40026: Aleksej Saushev: make(1) doesn't document VPATH, document it.
 1.153.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.182.2.1 05-Mar-2011  bouyer Sync with HEAD
 1.195.2.5 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.195.2.4 30-Oct-2012  yamt sync with head
 1.195.2.3 23-May-2012  yamt sync with head.
 1.195.2.2 17-Apr-2012  yamt sync with head
 1.195.2.1 10-Nov-2011  yamt sync with head
 1.206.2.4 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.206.2.3 23-Jun-2013  tls resync from head
 1.206.2.2 25-Feb-2013  tls resync with head
 1.206.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.259.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.264.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.266.4.2 09-Jun-2018  martin Pull up following revision(s) (requested by christos in ticket #870):

sys/lib/libgnuefi/Makefile.inc: revision 1.5
external/mit/xorg/xorg-pkg-ver.mk: revision 1.9
sys/arch/i386/stand/lib/Makefile.inc: revision 1.17
sys/compat/common/Makefile.inc: revision 1.25
usr.bin/make/unit-tests/varquote.exp: revision 1.1, 1.2
sys/lib/libsa/Makefile.inc: revision 1.24
usr.bin/make/var.c: revision 1.220
sys/arch/ia64/stand/efi/libefi/Makefile.inc: revision 1.5
sys/arch/hppa/spmath/Makefile.inc: revision 1.10
usr.bin/make/unit-tests/varquote.mk: revision 1.1, 1.2
usr.bin/make/unit-tests/Makefile: revision 1.53
sys/lib/libkern/Makefile.inc: revision 1.45
sys/arch/acorn32/stand/lib/Makefile.inc: revision 1.4
sys/arch/m68k/fpsp/Makefile.inc: revision 1.21
usr.bin/make/make.1: revision 1.273
sys/lib/libz/Makefile.inc: revision 1.17

- Introduce :q modifier for make variables and make it double escape $'s so
that passing variables to recursive makes with :q works as expected.
- Adjust makefiles that use recursive make to use :q

Discussed on tech-toolchain@

XXX: pullup 8
 1.266.4.1 18-Jul-2017  snj Pull up following revision(s) (requested by jmcneill in ticket #113):
usr.bin/make/main.c: 1.266-1.272
usr.bin/make/make.1: revision 1.267
move some code out of the gigantic main function; no functional change.
--
-V: try to expand the variable again if the value contains a variable.
--
simplify
--
a variable that starts with \\ is not expanded.
--
Remove previous variable expansion code; sjg had already added the code to
do it. Note that the manual page already documents this behavior and does
not need to change:
-dV -V VAR: prints the raw variable
-V VAR: prints the expanded variable
--
make the code look like to 1.266
--
Add -v variable that always expands variables; restore -V the way it was.
 1.271.4.2 25-Jun-2018  pgoyette Sync with HEAD
 1.271.4.1 07-Apr-2018  pgoyette Sync with HEAD. 77 conflicts resolved - all of them $NetBSD$
 1.273.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.273.2.1 10-Jun-2019  christos Sync with HEAD
 1.350.2.1 02-Jan-2023  martin Pull up following revision(s) (requested by rillig in ticket #31):

usr.bin/make/make.1: revision 1.351
usr.bin/make/make.1: revision 1.352
usr.bin/make/make.1: revision 1.353
usr.bin/make/make.1: revision 1.354
usr.bin/make/make.1: revision 1.355
usr.bin/make/make.1: revision 1.356

make.1: reduce indentation of the long list of variable names

make.1: move description of .MAKE.MODE below the .MAKE.META block

make.1: use consistent markup for boolean flags

make.1: sort list of built-in variables

make.1: sync list of built-in variables with reality
Fixes PR 57029.

make.1: fix markup
 1.377.2.1 02-Aug-2025  perseant Sync with HEAD
 1.273 06-Jul-2025  rillig make: clean up
 1.272 18-May-2025  rillig make: clean up an error message and a debug message

When adding a .WAIT dependency, use the common format "target: source"
instead of the unusual "source -> target".
 1.271 18-May-2025  rillig make: rename variables, remove now-redundant comments
 1.270 18-May-2025  rillig make: remove redundant comments, summarize a few others
 1.269 09-May-2025  rillig make: replace bitset in trace output with descriptive node attributes
 1.268 23-Apr-2025  rillig make: fix grammar in debug log message
 1.267 22-Apr-2025  rillig make: clean up

Replace 'unsigned int' with simply 'unsigned'.

In compat.c, skipping whitespace is not needed, as the loop above
already skips it.

In job.c, remove the unused header <sys/file.h>.

Inline the TMPPAT macro, as it is only needed in a single place.
 1.266 22-Apr-2025  rillig make: group the code for handling the job token pool
 1.265 22-Apr-2025  rillig make: move struct Job from job.h to job.c

The content of this struct is an implementation detail, and other parts
of make only need to access very few parts of it.
 1.264 02-Jun-2024  rillig branches: 1.264.2;
make: sync VarEvalMode constant names with their debug log names
 1.263 25-May-2024  rillig make: fix a few more memory leaks
 1.262 05-Jan-2024  rillig make: miscellaneous cleanups
 1.261 29-Dec-2023  rillig make: fix declared types of list nodes

No functional change.
 1.260 29-Dec-2023  rillig make: simplify memory allocation for string buffers

In edge cases and short-lived buffers, the initial buffer size is
irrelevant, so use the default.

No functional change.
 1.259 14-Feb-2023  rillig make: clean up calls to Var_Subst

None of the calls to Var_Subst used the return value, and the return
value was always VPR_OK.

No functional change.
 1.258 05-Dec-2022  rillig make: inline local macro in GNodeFlags_ToString

No binary change.
 1.257 27-Sep-2022  rillig make: set WARNS to 6, from the default 5

No binary change on x86_64.
 1.256 17-Aug-2022  rillig make: fix exit status for '-q' (since 1994)
 1.255 07-May-2022  rillig make: allow to randomize build order of targets

In complex dependency structures, when a build fails, a probable cause
is a missing dependency declaration between some files. In compat mode,
the build order is deterministic, in jobs mode, it is somewhat
deterministic. To explore more edge cases, add the line ".MAKE.MODE +=
randomize-targets" somewhere in the makefile.

Fixes PR bin/45226 by riastradh. Reviewed by christos.
 1.254 07-May-2022  rillig make: inline MakeBuildParent

The word "parent" didn't match exactly, since this part is about the
predecessor/successor relationship due to the .ORDER attribute.

No functional change.
 1.253 07-May-2022  rillig make: inline make_abort, improve error details

This function was only called a single time, making the source code line
number redundant. Instead, print the name of the state instead of its
ordinal value.
 1.252 09-Jan-2022  rillig make: use consistent variable names for varargs

No binary change.
 1.251 08-Jan-2022  rillig make: remove redundant braces

No binary change, except for assertion line numbers.
 1.250 27-Dec-2021  rillig make: remove unnecessary words from command line options

Several years ago, the command line options were individual global
variables. The global variable could therefore not be named 'silent'
since that would have conflicted with local variables of the same name.
After moving the global variable to the namespace 'struct CmdOpts',
there is no conflict anymore.

There doesn't seem to be any risk of naming collisions for the names
'touch' and 'query'.

No functional change.
 1.249 15-Dec-2021  rillig make: format comments according to /usr/share/misc/style

Assisted by indent(1), with manual corrections due to its many remaining
bugs.

No functional change.
 1.248 28-Nov-2021  rillig make: fix a few lint warnings about type mismatch in enum comparisons

These warnings were triggered with the lint flag '-e', which enables
additional checks on enums. This check would have detected the type
mismatch from the previous commit.

The check has a few strange warnings though, complaining about
initialization of 'unsigned long' with 'unsigned long', so don't enable
it for the official builds.

No functional change.
 1.247 28-Nov-2021  rillig make: move duplicate function Buf_AddFlag to buf.c

It is used only for debug output, therefore performance doesn't matter.

No functional change.
 1.246 28-Nov-2021  rillig make: convert GNodeFlags from enum into bit-fields

Now that Enum_ToString is implemented for each type separately, it's
easy to convert them to bit-fields. This gets rid of the magic numbers
12 for CYCLE and 13 for DONECYCLE that left a suspicious gap in the
numbers. This gap was not needed since the code didn't make use of the
relative ordering of the enum constants.

The effects of this conversion are fewer capital letters in the code,
smaller scope for the GNode flags, and clearer code especially when
setting a flag back to false.

One strange thing is that GCC 10.3.0 doesn't optimize GNodeFlags_IsNone
to an single bitmasking instruction, at least on x86_64. Instead it
generates a testb instruction for each of the flags, even loading bit 8
separately from the others. Clang 12.0.1 knows this optimization
though and generates the obvious sequence of movzwl, testl, jz.

No functional change.
 1.245 28-Nov-2021  rillig make: replace bloated bit-set-to-string code with simple code

It was a nice idea to implement a bit-set using an enum type and have a
generic ToString function for them. In the end, the implementation
involved really heavy preprocessor magic and was probably difficult to
understand. Replace all the code with a few bits of straight-forward
preprocessor magic that can be readily understood by just looking 5
lines around, instead of digging through 130 lines of lengthy macro
definitions.

Curiously, this reduces the binary size even though the 3 ToString
functions now have a few lines of duplicate code and there are more
explicit function calls.

The ToString functions are only seldom used, so the additional memory
allocation is acceptable.

No functional change.
 1.244 04-Apr-2021  rillig make: rename a few functions to be more descriptive

No functional change.
 1.243 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.242 05-Feb-2021  rillig make: in the Var_ functions, move the scope to the front

This change provides for a more natural reading order in the code.
Placing the scope first makes it immediately clear in which context the
remaining parameters are interpreted.

No functional change.
 1.241 04-Feb-2021  rillig make: rename context and ctxt to scope

This continues the previous commit, in which VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE were renamed.

Renaming the variable 'ctxt' was trivial since that word is used nowhere
else. In the comments though, each occurrence of the word 'context' had
to be checked individually since the word 'context' was not only used
for referring to a variable scope. It is also used to distinguish
different situations where characters are escaped in a certain way
('parsing context') and in a few other expressions.
 1.240 02-Feb-2021  rillig make: remove unused INTERNAL flag

It had been used for cached_realpaths, until this variable had its type
changed from GNode to HashTable in main.c 1.469 from 2020-11-14.
 1.239 02-Feb-2021  rillig make: remove overengineered Enum_ValueToString

For printing the status of a GNode, there was already made_name (now
renamed to GNodeMade_Name), which prints user-friendly text instead of
the bare enum constant names.

To do this change confidently, I first had to demonstrate that the
output really affects something other than just the word "UNMADE". There
had not been a test for that case before, and the test immediately
discovered a bug in the -dg2 and -dg3 options. This bug is one of the
oldest in make, dating back to at least 1993.
 1.238 01-Feb-2021  rillig make: remove unused return type of MakeBuildParent
 1.237 01-Feb-2021  rillig make: reduce indentation in MakeAddAllSrc

No functional change.
 1.236 30-Jan-2021  rillig make(1): reduce boilerplate for printing bit sets in debug mode

No functional change.
 1.235 16-Jan-2021  rillig make(1): fix a few inconsistencies for lint's strict bool mode
 1.234 10-Jan-2021  rillig make(1): consistently use boolean expressions in conditions

Most of the make code already followed the style of explicitly writing
(ptr != NULL) instead of the shorter (ptr) in conditions.

The remaining 50 instances have been found by an experimental,
unpublished check in lint(1) that treats bool expressions as
incompatible to any other scalar type, just as in Java, C#, Pascal and
several other languages.

The only unsafe operation on Boolean that is left over is (flags &
FLAG), for an enum implementing a bit set. If Boolean is an ordinary
integer type (the default), some high bits may get lost. But if Boolean
is the same as _Bool (by compiling with -DUSE_C99_BOOLEAN), C99 6.3.1.2
defines that a conversion from any scalar to the type _Bool acts as a
comparison to 0, which cannot lose any bits.
 1.233 30-Dec-2020  rillig make(1): format multi-line comments
 1.232 19-Dec-2020  rillig make(1): rename parameter line to lineno
 1.231 18-Dec-2020  rillig make(1): spell nonexistent consistently
 1.230 18-Dec-2020  rillig make(1): use symbolic time for 0 in Make_Recheck

This makes the test depsrc-optional independent from the current time
zone.
 1.229 15-Dec-2020  rillig make(1): indent make.c with tabs instead of spaces
 1.228 15-Dec-2020  rillig make(1): extract MakeChildren from MakeStartJobs
 1.227 06-Dec-2020  rillig make(1): remove comment decoration
 1.226 28-Nov-2020  rillig make(1): reduce memory allocation for toBeMade
 1.225 28-Nov-2020  rillig make(1): reduce memory allocation in Make_ProcessWait
 1.224 28-Nov-2020  rillig make(1): reduce memory allocation in Make_ExpandUse
 1.223 28-Nov-2020  rillig make(1): reduce pointer indirection for GNode.implicitParents
 1.222 28-Nov-2020  rillig make(1): reduce pointer indirection for GNode.cohorts
 1.221 28-Nov-2020  rillig make(1): reduce pointer indirection for GNode.order_pred and order_succ
 1.220 28-Nov-2020  rillig make(1): reduce memory allocation for GNode.parents and GNode.children
 1.219 28-Nov-2020  rillig make(1): remove pointer indirection from GNode.commands

Just to save a few memory allocations. No noticeable effect on the
performance though.
 1.218 27-Nov-2020  rillig make(1): inline Lst_ForEachUntil in meta mode

This means no more unnecessary void pointers in function signatures and
no more abstraction level at checking a single element of a list. In
most cases it is more appropriate to define a function that operates on
the list as a whole, thereby hiding implementation details like the
ListNode from the caller.
 1.217 24-Nov-2020  rillig make(1): indent some functions in make.c with tabs instead of spaces
 1.216 24-Nov-2020  rillig make(1): remove void pointers from MakeBuildParent
 1.215 24-Nov-2020  rillig make(1): inline Lst_ForEachUntil in Make_Update
 1.214 24-Nov-2020  rillig make(1): remove void pointers from MakeBuildChild
 1.213 24-Nov-2020  rillig make(1): inline Lst_ForEachUntil in MakeStartJobs
 1.212 24-Nov-2020  rillig make(1): inline Lst_ForEachUntil in MakeBuildChild

This prepares for removing the void pointers from the function
signature.
 1.211 24-Nov-2020  rillig make(1): add high-level API for GNode.made

Having an enum whose constants must be ordered in a certain way may be
unexpected to casual readers. Hide this implementation detail in
separate functions.
 1.210 21-Nov-2020  rillig make(1): fix indentation in Make_HandleUse
 1.209 16-Nov-2020  rillig make(1): clean up code style in make.c and suff.c
 1.208 16-Nov-2020  rillig make(1): rename Targ_NewGN to GNode_New

This function is a classical constructor function, and if it weren't for
CLEANUP mode, it would have no dependencies on anything else besides the
memory allocator. Therefore it doesn't really matter which module
defines this function, and there is no need for the "Targ" to be part of
the function name.
 1.207 15-Nov-2020  rillig make(1): clean up make.c stylistically
 1.206 15-Nov-2020  rillig make(1): rename checked to checked_seqno

The new name is more precise and also matches the GNode field.
 1.205 14-Nov-2020  rillig make(1): fix debug output for GNode details
 1.204 14-Nov-2020  rillig make(1): use symbolic names in debug output of GNodes
 1.203 08-Nov-2020  rillig make(1): clean up Make_ExpandUse

The targets need to be copied to the 'examine' queue, not because the
targets list would be modified but because the queue is modified and the
targets list should not be affected by that.
 1.202 08-Nov-2020  rillig make(1): fix type of have_token in MakeStartJobs
 1.201 08-Nov-2020  rillig make(1): inline MakeCheckOrder into IsWaitingForOrder

This gets rid of a few void pointers and an unnecessary and unused
function parameter.

The variable name "bn" may have meant "before", but that was not
obvious. The new name "ogn" nicely matches the ".ORDER" in the debug
message.
 1.200 08-Nov-2020  rillig make(1): inline MakeAddChild into ExamineLater

This gets rid of a few void pointers and unspecific variable names like
"l" for the list that should have rather been called "examine" all the
time.

Add quotes around placeholders in debug messages. Especially for targets
like "all" the message had been syntactically misleading.
 1.199 08-Nov-2020  rillig make(1): inline MakeFindChild into PretendAllChildrenAreMade

This gets rid of a few void pointers and some function calls. The
documentation of MakeFindChild essentially repeated what the code does,
and the redundant parts of it have been removed.
 1.198 08-Nov-2020  rillig make(1): extract PretendAllChildrenAreMade from Make_ExpandUse
 1.197 08-Nov-2020  rillig make(1): fix debug output in out-of-date for cohorts (since 2003-11-14)

Before, a wrong cause for being out-of-date was printed in the debug log,
for optional cohorts. This was caused by having the same conditions
duplicated in the code, instead of putting them in a separate function.

Now the optional cohort is correctly identified as using the '::'
dependency operator.
 1.196 08-Nov-2020  rillig make(1): add test for wrong debug message in GNode_IsOODate
 1.195 08-Nov-2020  rillig make(1): extract condition from GNode_IsOODate into separate function
 1.194 08-Nov-2020  rillig make(1): change return type of Dir_MTime to void

Only some callers actually needed the updated time, and because of the
many branches, it was difficult to see that the return value was indeed
gn->mtime all the time.
 1.193 08-Nov-2020  rillig make(1): change return type of Arch_MemberMTime to void

This makes it easier to prove that Dir_MTime always returns gn->mtime,
without looking at the implementation of Arch_UpdateMemberMTime.
 1.192 08-Nov-2020  rillig make(1): clean up comments in Make_Recheck
 1.191 08-Nov-2020  rillig make(1): use common indentation style for else
 1.190 08-Nov-2020  rillig make(1): rename Make_OODate to GNode_IsOODate

It doesn't matter which of the make modules is in charge of determining
whether a node is out-of-date. Therefore, remove the module name from
the function name.
 1.189 08-Nov-2020  rillig make(1): rename Make_TimeStamp to GNode_UpdateYoungestChild
 1.188 07-Nov-2020  rillig make(1): clean up Make_OODate and Make_Run
 1.187 07-Nov-2020  rillig make(1): clean up code stylistically

* Replace character literal 0 with '\0'.
* Replace pointer literal 0 with NULL.
* Remove redundant parentheses.
* Parentheses in multi-line conditions are not redundant at the
beginning of a line.
* Replace a few !ptr with ptr == NULL.
* Replace a few ptr with ptr != NULL.
* Replace (expr & mask) == 0 with !(expr & mask).
* Remove redundant braces for blocks in cases where the generated code
stays the same. (Assertions further down in the code would get
different line numbers.)
* Rename parameters in CondParser_String to reflect the data flow.
* Replace #ifdef notdef with #if 0.

The generated code stays exactly the same, at least with GCC 5.5.0 on
NetBSD 8.0 amd64 using the default configuration.
 1.186 01-Nov-2020  rillig make(1): negate NoExecute to GNode_ShouldExecute
 1.185 31-Oct-2020  rillig make(1): format #include directives consistently
 1.184 31-Oct-2020  rillig make(1): do not look up local variables like .TARGET anywhere else

Nobody defines a global variable named .TARGET since that would have
many unpredictable effects, applying to all targets at once.

Nobody defines an environment variable named .TARGET since that's
against the naming conventions for environment variables and would have
the same effect.

Because of this, there is no point looking up the variables that are
local to a GNode anywhere else. This means they cannot come from the
environment and thus their value doesn't need to be freed after use,
which makes the code simpler.

The newly added accessor functions in make.h refer to external
functions, but since that header is not used anywhere outside of
usr.bin/make, it doesn't matter. Between 2020-08-25 and 2020-10-30,
that header had been referenced by usr.bin/xinstall.
 1.183 30-Oct-2020  rillig make(1): change char * to void * in Var_Value

The only purpose of the parameter freeIt is to free the memory
associated with the return value. To do this, no pointer arithmetic is
needed. Therefore, change to a void pointer, to catch accidental use of
that pointer.
 1.182 30-Oct-2020  rillig make(1): fix indentation in source code
 1.181 26-Oct-2020  rillig make(1): group the command line options and arguments

By having a single struct that holds all command line options and
arguments, it is easy to see in the code when such a command line
argument is modified. It also cleans up the namespace since the command
line options don't follow a common naming style. Having them in a
struct also means that there is a single place for putting the
documentation, not two as before.

The struct also suggests to extract the initialization code out of main,
which is still too large, having more than 400 lines of code and
covering far too many topics.
 1.180 25-Oct-2020  rillig make(1): add GNode_Path to access the path of a GNode
 1.179 25-Oct-2020  rillig make(1): inline Lst_Copy in Make_ExpandUse
 1.178 23-Oct-2020  rillig make(1): rename GNode.cmgn to youngestChild

The name is longer than before but also clearer.
 1.177 23-Oct-2020  rillig make(1): negate OP_NOP and rename it to GNode_IsTarget
 1.176 23-Oct-2020  rillig make(1): remove Lst_ForEachUntilConcurrent

The remaining callers of that function don't modify the list
structurally and thus can use the simpler Lst_ForEachUntil instead.
 1.175 22-Oct-2020  rillig make(1): fix MakePrintStatusList

The current unit tests don't cover a situation where there are more than
100 errors reported at once. This fixes the bug introduced in the
previous commit, a few minutes ago.
 1.174 22-Oct-2020  rillig make(1): remove void pointers from MakePrintStatus
 1.173 22-Oct-2020  rillig make(1): remove void pointers from MakePrintStatusOrder
 1.172 22-Oct-2020  rillig make(1): add Lst_ForEachUntilConcurrent

Previously, Lst_ForEachUntil allowed the list to be modified while
iterating. Almost none of the code needs this, and it's also confusing
for human readers.

None of the current unit tests makes use of this concurrent modification
right now, but that's not evidence enough. Only 72% of the code are
covered by unit tests right now, and there are lots of edge cases
(whether intended or not) that are not covered by unit tests.

Therefore, all calls to Lst_ForEachUntil were changed to
Lst_ForEachUntilConcurrent and those that were obvious were changed
back. The remaining calls probably don't need the concurrent
modification code, but that's not obvious from looking at the code.
 1.171 22-Oct-2020  rillig make(1): replace Lst_Open with simple iteration in Make_ProcessWait
 1.170 22-Oct-2020  rillig make(1): replace Lst_Open with simple iteration in Make_Update
 1.169 22-Oct-2020  rillig make(1): extract UpdateImplicitParentsVars from Make_Update
 1.168 22-Oct-2020  rillig make(1): replace Lst_Open with simple iteration in Make_Update

This iteration is safe from concurrent modification.
 1.167 22-Oct-2020  rillig make(1): remove redundant type casts

This mainly affects the void pointers in callback functions for lists.
These had been necessary once when the parameter type was still
ClientData instead of void pointer.
 1.166 19-Oct-2020  rillig make(1): clean up headers, no functional change
 1.165 19-Oct-2020  rillig make(1): inline simple Lst getters

The function call variant takes more screen space than the direct field
access. Having an abstract API is usually a good idea, in this case of
simple read-only member access it makes the code more difficult to read.

LstNode_Set has been kept as a function since it is not a read-only
accessor function.
 1.164 19-Oct-2020  rillig make(1): inline link_parent into Make_ProcessWait
 1.163 19-Oct-2020  rillig make(1): inline MakeTimeStamp in Make_OODate
 1.162 19-Oct-2020  rillig make(1): eliminate void pointer from MakeAddAllSrc
 1.161 18-Oct-2020  rillig make(1): replace Lst_Open with simple iteration in Make_HandleUse
 1.160 18-Oct-2020  rillig make(1): rename Lst_Init to Lst_New

For the other types such as HashTable and Buffer, the Init function does
not allocate the memory for the structure itself, it only fills it.
 1.159 18-Oct-2020  rillig make(1): convert NoExecute to non-inline

The header make.h is not only used by usr.bin/make but also by
usr.bin/xinstall, to get the needshell function.

That program does not declare the variables noRecursiveExecute and
noExecute, leading to an "unresolved reference" at link time. To fix
this, move the inline functions away from make.h.

It's a quirk that make.h gets included by other programs since it
contains a whole lot of definitions that are only useful in make itself.
If any, there should be a separate header that defines the public
library API of make, and only that.
 1.158 17-Oct-2020  rillig make(1): fix indentation
 1.157 01-Oct-2020  rillig make(1): remove redundant function prototypes
 1.156 28-Sep-2020  rillig make(1): replace += 1 with ++ and -= 1 with --

Just for visual consistency. The generated code stays exactly the same.
 1.155 28-Sep-2020  rillig make(1): migrate Make_ProcessWait from Lst_ForEachUntil to Lst_ForEach
 1.154 28-Sep-2020  rillig make(1): remove the inline attribute from debug_printf

The code size overhead of a varargs function is much more than I had
expected. Since GCC 5 didn't inline the function anyway and it is only
used in debug mode, there is no point keeping multiple copies of that
code around.
 1.153 28-Sep-2020  rillig make(1): make debug logging simpler

This avoids referring to the debug_file variable in many places where
this implementation detail is not necessary.
 1.152 28-Sep-2020  rillig make(1): make debugging code shorter
 1.151 27-Sep-2020  rillig make(1): normalize whitespace in source code

There is no more space tab. Either only tabs or only spaces or tabs
followed by spaces, but not spaces followed by tabs.
 1.150 27-Sep-2020  rillig make(1): inline Lst_ForEachUntil in Make_ExpandUse

The tricky detail here is that the current node from the iteration is
removed if it is no longer needed.

The Lst_FindDatum that has been removed was both inefficient and
misleading since it could never return null, yet there was a null check
for it. The callback API from Lst_ForEachUntil would have required to
define a custom struct for passing this parameter to the callback
function, in addition to the parent node.

Inlining the whole Lst_ForEach and passing the list node as a parameter
is much more obvious.
 1.149 27-Sep-2020  rillig make(1): clean up comments in job.c and make.c
 1.148 26-Sep-2020  rillig make(1): revert migration from Lst_ForEachUntil to Lst_ForEach

There is a crucial difference between these functions, in that
Lst_ForEachUntil can cope with a few concurrent modifications while
iterating over the list. This is something that Lst_ForEach doesn't do.

This difference led to a crash very early in NetBSD's build.sh.
 1.147 26-Sep-2020  rillig make(1): inline and remove LstNode_Prev and LstNode_Next

These functions made the code larger than necessary. The prev and next
fields are published intentionally since navigating in a doubly-linked
list is simple to do and there is no need to wrap this in a layer of
function calls, not even syntactically. (On the execution level, the
function calls had been inlined anyway.)
 1.146 26-Sep-2020  rillig make(1): replace a few Lst_ForEachUntil with simpler Lst_ForEach
 1.145 26-Sep-2020  rillig make(1): clean up API for finding and creating GNodes

The previous API had complicated rules for the cases in which the single
function returned NULL or what it did. The flags for that function were
confusing since passing TARG_NOHASH would create a new node even though
TARG_CREATE was not included in that bit mask.

Splitting the function into 3 separate functions avoids this confusion.
It also reveals several places where the complicated API led to
unreachable code. Such code has been removed.
 1.144 25-Sep-2020  rillig make(1): inline Lst_ForEach in MakeUnmark

By the way, the additional argument to Lst_ForEach was not used at all.
 1.143 24-Sep-2020  rillig make(1): migrate MakeTimeStamp and MakeUnmark to Lst_ForEach
 1.142 24-Sep-2020  rillig make(1): migrate MakeAddAllSrc to Lst_ForEach
 1.141 24-Sep-2020  rillig make(1): move documentation for MakeAddAllSrc to its correct place
 1.140 24-Sep-2020  rillig make(1): rename Lst_ForEach to Lst_ForEachUntil

Since the callback function returns a terminating condition, this is not
really a foreach loop.

Many of the calls to Lst_ForEachUntil don't make use of the terminating
condition, and several don't modify the list structurally, which means
they don't need this complicated implementation.

In a follow-up commit, Lst_ForEach will be added back with a much
simpler implementation that iterates over the list naively, without a
terminating condition and without taking the iteration state from
Lst_Open/Lst_Next/Lst_Close into account. The migration to this simpler
implementation will be done step by step since each callback function
needs to be examined closely.
 1.139 24-Sep-2020  rillig make(1): refactor add_wait_dep to not use Lst_ForEachFrom anymore

It was the last remaining use of that function outside of lst.c.

While here, clean up the code of add_wait_dep by removing unreachable
code (the GNode lists never contain NULL, only the GNode.commands lists
do that).
 1.138 22-Sep-2020  rillig make(1): prepare Var_Subst for proper error handling

Returning a VarParseResult instead of a string makes it possible to let
the error bubble up, until it reaches the main expression.
 1.137 22-Sep-2020  rillig make(1): use fine-grained type names for lists and their nodes

This is only intended to help the human reader. There is no additional
type safety yet.
 1.136 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.135 12-Sep-2020  rillig make(1): fix API of Targ_PrintNode

There was no need to export Targ_PrintNode at all. All the callers need
is a high-level API for printing a single node or a list of nodes. The
implementation detail that Targ_PrintNode was used as a callback to
Lst_ForEach should have never leaked into the API.
 1.134 07-Sep-2020  rillig make(1): remove redundant includes
 1.133 30-Aug-2020  rillig make(1): rename GNode.iParents to implicitParents

The i alone was too ambiguous. It could have meant ignore, implicit,
interactive, and probably many more.
 1.132 30-Aug-2020  rillig make(1): rename Lst_Datum to LstNode_Datum
 1.131 30-Aug-2020  rillig make(1): rename Lst_Memeber to Lst_FindDatum

The new name nicely aligns with Lst_Find and Lst_FindFrom.
 1.130 29-Aug-2020  rillig make(1): trust that Var_Subst never returns NULL

It really never does, and it doesn't even report errors. It just
returns the content of the buffer, up to the first parse error.
 1.129 28-Aug-2020  rillig make(1): remove trailing 'S' from names of Lst functions

The migration from null-passing Lst functions to argument-checking Lst
functions is completed.

There were 2 surprises: The targets list may be NULL, and in Dir_AddDir,
the path may be NULL. The latter case is especially surprising since
that function turns into an almost-nop in that case. This is another
case where probably 2 independent functions have been squeezed into a
single function. This may be improved in a follow-up commit.

All other lists were fine. They were always defined and thus didn't
need much work.
 1.128 28-Aug-2020  rillig make(1): migrate Lst_First to Lst_FirstS
 1.127 27-Aug-2020  rillig make(1): migrate Lst_IsEmpty to Lst_IsEmptyS
 1.126 27-Aug-2020  rillig make(1): migrate Lst_ForEach to Lst_ForEachS

Most lists are always valid. Only the "targets" variable may be null in
some cases, probably.
 1.125 27-Aug-2020  rillig make(1): migrate Lst_ForEachFrom to Lst_ForEachFromS
 1.124 26-Aug-2020  rillig make(1): add stricter variants for remaining Lst functions

In most cases the Lst functions are only called when the arguments are
indeed valid. It's not guaranteed though, therefore each function call
needs to be analyzed and converted individually.

While here, remove a few statements that were only useful when the Lst
functions handled circular lists.
 1.123 25-Aug-2020  rillig make(1): distinguish enum flags and values in debugging mode

When printing an enum value in debugging mode, distinguish between
bitsets containing flags and ordinary enums that just contain different
values.

Make the macros in enum.h more uniform. Provide a simple scheme for
defining the run-time type information of enums whose number of values
is a number with more than 2 bits set in the binary representation.
This case was not obvious before, and it was pure luck that the current
interesting enum types only had 3, 10 or 32 different values.

The type with the 32 different values actually only has 31 significant
bits since the enum constant OP_OPMASK is only used when querying the
enum, not for defining or describing the possible values. For this
reason, it was unavoidable to refactor the rtti macros, to support even
this case.
 1.122 24-Aug-2020  rillig make(1): in debug mode, print GNode details in symbols

A string like OP_DEPENDS|OP_OPTIONAL|OP_PRECIOUS is much easier to read
and understand than the bit pattern 00000089.

The implementation in enum.h looks really bloated and ugly, but using
this API is as simple and natural as possible. That's the trade-off.

In enum.h, I thought about choosing the numbers in the macros such that
it is always possible to combine two of them in order to reach an
arbitrary number, because of the "part1, part2" in the ENUM__SPEC macro.
The powers of 2 are not these numbers, as 7 cannot be expressed as the
sum of two of them. Neither are the fibonacci numbers since 12 cannot
be expressed as the sum of 2 fibonacci numbers. I tried to find a
general pattern to generate these minimal 2-sum numbers, but failed.
 1.121 22-Aug-2020  rillig make(1): replace Lst_Duplicate with Lst_CopyS

Lst_Duplicate would have passed through any null pointer, which was not
needed for make. It was the last function that used Lst_AtEnd, which in
turn was the last function that used LstInsertAfter. As a result, these
two functions have been removed.
 1.120 22-Aug-2020  rillig make(1): make moving and copying lists simpler

Instead of the two-in-one Lst_Concat, having two separate functions is
easier to understand. There is no need for a long API comment anymore
since the new functions have a single purpose that is accurately
described by their name.

The long comment inside Lst_Concat has been removed since it only
repeated the exact code, only in more words.

The comments in make.c about appending the cohorts had been wrong. They
were not appended but prepended. Once more, the function name expresses
everything that the comment said, making the comment redundant. There
is no need to test whether the cohorts list is empty, doing nothing is
implied by the word All in Lst_PrependAllS.
 1.119 22-Aug-2020  rillig make(1): use Lst_OpenS in make.c

The fields GNode.children, parents and iParents are guaranteed to be
valid lists.
 1.118 22-Aug-2020  rillig make(1): require argument of Lst_Member to be non-null

Since the lists don't contain null pointers, it doesn't make sense to
search for a null pointer. All calls but one already had obviously
non-null arguments. The one remaining call using targ->suff has been
guarded for now.

The code for Lst_Member became much simpler than before. Partly because
the old code had an extra condition for circular lists, which are not
used by make.
 1.117 22-Aug-2020  rillig make(1): replace Lst_Datum with non-null guaranteeing Lst_DatumS
 1.116 22-Aug-2020  rillig make(1): add strict argument checks for Lst_InsertBefore

As with the other modifying operations on lists, the callers already
made sure that the arguments are valid.
 1.115 22-Aug-2020  rillig make(1): convert Lst_Enqueue and Lst_Dequeue to nonnull variants

Except for once instance in parse.c, the usage pattern for Lst_Dequeue
was to first test whether the list is empty. This pattern allowed the
implementation of Lst_Dequeue to become simpler since the null check is
not needed anymore.

The calls to Lst_Enqueue never pass an invalid list or a null pointer,
therefore making them strict was trivial.
 1.114 22-Aug-2020  rillig make(1): replace two instances of Lst_AtFront with Lst_Prepend

In these cases, the list is guaranteed to be valid, therefore no
assertion is expected.

For comparison, the Lst_AtFront in dir.c needs to be kept since the path
may be null there.
 1.113 22-Aug-2020  rillig make(1): convert remaining Lst_AtEnd to the stricter Lst_Append

The general-purpose list library that is included in make allows to call
Lst_AtEnd for invalid lists, silently ignoring this programming error.
This is a flexibility that make doesn't need.

Another unneeded "feature" is that list items can theoretically be null
pointers. This doesn't make sense as well and is therefore not needed
by make.

These programming errors are now caught early by assertions.
 1.112 22-Aug-2020  rillig make(1): make Make_HandleUse simpler

Since the function names now contain the text from the comments, the
comments can be shortened a bit.
 1.111 22-Aug-2020  rillig make(1): make .USEBEFORE handling simpler

There is no need to duplicate the list of .USEBEFORE commands, just to
destroy that list immediately. Instead, it's simpler to just prepend
the commands from the .USEBEFORE node to the parent.
 1.110 22-Aug-2020  rillig make(1): replace "(void)Lst_AtEnd" with stricter "Lst_AppendS"

This change ensures that there is actually something added to the list.
Lst_AtEnd had silently skipped the addition if the list was invalid
(null pointer), which was not intended in these cases. The "(void)" is
assumed to mean "I know that this cannot fail", while it could also mean
"I don't care whether something actually happened".

Running "./build.sh -j6 tools" still succeeds after this change,
therefore chances are very low that this change breaks anything. If
there is any change, it's an obvious assertion failure. There is no
silent change in behavior though.
 1.109 22-Aug-2020  rillig make(1): condense the comment for Make_HandleUse

The "side effects" were already mentioned in the main section.
 1.108 22-Aug-2020  rillig make(1): remove form feeds in the code
 1.107 21-Aug-2020  rillig make(1): use stricter list API for sequential access

In several places, it just doesn't make sense to have a null pointer
when a list is expected.

In the existing unit tests, the list passed to Lst_Open is always valid,
but that's not a guarantee for real-world usage. Therefore, Lst_Open
has been left for now, and Lst_OpenS is only the preferred alternative
to it.
 1.106 21-Aug-2020  rillig make(1): assert correct usage of the Lst_Open API

All calls to Lst_Next are properly protected by Lst_Open, so there is no
possible assertion failure here.
 1.105 21-Aug-2020  rillig make(1): make list library code stricter

Up to now, the list library didn't distinguish between programming
mistakes (violations of invariants, illegal parameter values) and
actually interesting situations like "element not found in list".

The current code contains many branches for conditions that are neither
exercised by the unit tests nor by real-world usage. There is no point
in keeping this unnecessary code.

The list functions will be migrated from their lenient variants to the
stricter variants in small parts, each function getting the S suffix
when it is made strict, to avoid any confusion about how strict a
particular function is. When all functions have been migrated, they
will be renamed back to their original names.

While here, the comments of the functions are cleaned up since they
mention irrelevant implementation details in the API comments, as well
as "side effects" that are really main effects.
 1.104 21-Aug-2020  rillig make(1): remove unused code for circular lists

The list library had probably been imported from a general-purpose
library that also supported circular lists. These are not used by make
though.

After replacing Lst_Init(FALSE) with Lst_Init(), only a single call to
Lst_Init remained with a non-constant argument, and that was in
Lst_Concat, which was to be expected.
 1.103 01-Aug-2020  rillig make(1): avoid calls to free(3) in the common case of a NULL pointer
 1.102 01-Aug-2020  rillig make(1): let Var_Value return a const char *

The return value must not be modified anyway, so let the compiler check
this for free.
 1.101 28-Jul-2020  rillig make(1): remove dead code from Var_Subst

The first parameter from Var_Subst had been a literal NULL in all cases.
These have been fixed using this command:

sed -i 's|Var_Subst(NULL, |Var_Subst(|' *.c

The one remaining case was not found because the "NULL," was followed by
a line break instead of a space.

The removed code probably wouldn't have worked as expected anyway.
Expanding a single variable to a literal string would have led to
unexpected behavior for cases like ${VAR:M${pattern}}, in case pattern
would contain an unescaped ':' itself.
 1.100 19-Jul-2020  rillig make(1): rename Varf_Flags to VarEvalFlags

In var.c there are lots of different flag types. To make any accidental
mixture obvious, each flag group gets its own prefix.

The only flag group that is visible outside of var.c is concerned with
evaluating variables, therefore the "e", which replaces the former "f"
that probably just meant "flag".
 1.99 03-Jul-2020  rillig make(1): remove trailing whitespace
 1.98 03-Jul-2020  rillig make(1): remove redundant parentheses around return values
 1.97 02-Jul-2020  rillig make(1): remove useless parameter from Var_Set

The enum corresponding to this int parameter is only defined in var.c,
which makes it impractical for the outside to set this parameter to
anything but 0.

On x86_64, this reduces the size of the resulting executable by 5 kB.
 1.96 10-Nov-2016  sjg Report node name rather than (null) when modified before src
 1.95 18-Feb-2016  christos branches: 1.95.2;
Collapse the 3 boolean parameter to 1 flags parameter. No functional change.
 1.94 17-Jan-2016  christos remove free NULL checks (Tilman Sauerbeck)
 1.93 09-Jan-2016  christos Preserve $$ in := assignments..

FOO=\$$CRAP
BAR:=${FOO}

all:
echo ${FOO}
echo ${BAR}
 1.92 11-Oct-2015  sjg Add Boolean wantit to Var_Parse and Var_Subst

wantit will be FALSE when we are just consuming to discard
in which case we skip "expensive" things like Cmd_Exec.

Reviewed by: christos
 1.91 18-Oct-2014  snj src is too big these days to tolerate superfluous apostrophes. It's
"its", people!
 1.90 07-Sep-2014  joerg Revert all make changes except the unit tests to the state of three
weeks ago. Individual changes can be reapplied after review.
 1.89 23-Aug-2014  christos PR/46096: Jarmo Jaakkola: fix many problems with dependencies (PR 49086)

Quite extensive rewrite of the Suff module. Some ripple effects into
Parse and Targ modules too.

Dependency searches in general were made to honor explicit rules so
implicit and explicit sources are no longer applied on targets that
do not invoke a transformation rule.

Archive member dependency search was rewritten. Explicit rules now
work properly and $(.TARGET) is set correctly. POSIX semantics for
lib(member.o) and .s1.a rules are supported.

.SUFFIXES list maintenance was rewritten so that scanning of existing
rules works when suffixes are added and that clearing the suffix list
removes single suffix rules too. Transformation rule nodes are now
mixed with regular nodes so they are available as regular targets too
if needed (especially after the known suffixes are cleared).

The .NULL target was documented in the manual page, especially to
warn against using it when a single suffix rule would work.
A deprecation warning was also added to the manual and make also
warns the user if it encounters .NULL.

Search for suffix rules no longer allows the explicit dependencies
to override the selected transformation rule. A check is made in
the search that the transformation that would be tried does not
already exist in the chain. This prevents getting stuck in an infinite
loop under specific circumstances. Local variables are now set
before node's children are expanded so dynamic sources work in
multi-stage transformations. Make_HandleUse() no longer expands
the added children for transformation nodes, preventing triple
expansion and allowing the Suff module to properly postpone their
expansion until proper values are set for the local variables.

Directory prefix is no longer removed from $(.PREFIX) if the target
is found via directory search.

The last rule defined is now used instead of the first one (POSIX
requirement) in case a rule is defined multiple times. Everything
defined in the first instance is undone, but things added "globally"
are honored. To implement this, each node tracks attribute bits
which have been set by special targets (global) instead of special
sources (local). They also track dependencies that were added by
a rule with commands (local) instead of rule with no commands (global).

New attribute, OP_FROM_SYS_MK is introduced. It is set on all targets
found in system makefiles so that they are not eligible to become
the main target. We cannot just set OP_NOTMAIN because it is one of
the attributes inherited from transformation and .USE rules and would
make any eligible target that uses a built-in inference rule ineligible.

The $(.IMPSRC) local variable now works like in gmake: it is set to
the first prerequisite for explicit rules. For implicit rules it
is still the implied source.

The manual page is improved regarding the fixed features. Test cases
for the fixed problems are added.

Other improvements in the Suff module include:
- better debug messages for transformation rule search (length of
the chain is now visualized by indentation)
- Suff structures are created, destroyed and moved around by a set
of maintenance functions so their reference counts are easier
to track (this also gets rid of a lot of code duplication)
- some unreasonably long functions were split into smaller ones
- many local variables had their names changed to describe their
purpose instead of their type
 1.88 09-Nov-2012  sjg Do not stop looking for children, just because one has a .ORDER dependency.
 1.87 12-Jun-2012  joerg branches: 1.87.2;
Replace __dead, __unused and the various printf format attributes
with versions prefixed by MAKE_ATTR_* to avoid modifying the
implementation namespace. Make sure they are available in all places
using nonints.h to fix bootstrap on Linux.
 1.86 10-May-2012  christos Don't use the cache when building nodes that might have changed since the
last exec.
 1.85 07-Apr-2012  christos Remove recheck hackery that caused extra stats, and explicitly ask for
recheck when needed. Before it used to be the case that we could only
use the cached entry once. Once the cached entry was used, we removed
it from the cache. Now it is kept forever.
 1.84 16-Sep-2011  joerg branches: 1.84.2;
Use __dead consistently. If it doesn't exist, define it away.
 1.83 25-Nov-2010  christos Instead of keeping around the mtime of the youngest child, keep a pointer
to it, so that we can print it when we do the out of date determination.
 1.82 13-Sep-2010  sjg Add meta.c which implements "meta" mode for make.
In this mode, a .meta file is created for each target, capturing
the expanded commands used, any command output, and if filemon(9)
is available, a record of system calls which are of interest.
Not enabled unless USE_META=yes is set when building make.
Also, if FILEMON_H exists, meta.c will be compiled to use filemon(9).
 1.81 06-Jul-2010  dholland Revert 1.80, which somehow manages to produce different (wrong)
behavior with -jN. Unfixes PR 43534. Need a different approach...
 1.80 30-Jun-2010  dholland Set .PREFIX early the same place .TARGET is set. This makes sure it's
defined even in cases where the suffix search logic is skipped, such
as .PHONY targets, and fixes PR 43534.

Note: because .PHONY targets do not get suffix searching, .PREFIX will
not have any suffixes removed. This seems vaguely logical, although
it's not the only reasonable interpretation.

We may also want to reconsider whether suffix rules are skipped for
phony targets, too. That behavior is somewhat counterintuitive.
 1.79 07-Apr-2010  sjg Add:

.error "message"
.warning "message"
based on FreeBSD implementation.
add .info while were at it.

.ERROR: a target to run on error.
We pass the failing GNode to PrintOnError so it can set
.ERROR_TARGET.

.MAKE.MAKEFILE_PREFERENCE
As a means to control make's list of prefered makefile names.
(Default: "makefile Makefile")

.MAKE.DEPENDFILE
Names the file to read dependencies from
(Default ".depend")

.MAKE.MODE
Processed after all makefiles are read.
Can put make into "compat" mode (more to come).

Fix:

compat.c: Error code should not be sent to debug_file.
Make_DoAllVar: use DONE_ALLSRC to avoid processing a node multiple times.
ReadMakefile: we can simply use doing_depend to control setting MAKEFILE.
 1.78 23-Jan-2009  dsl Change 'ClientData' to 'void *' so that relevant parameters can
be made 'const void *'.
 1.77 13-Dec-2008  dsl Use NULL instead of -1 cast to the relavant type (usually via NIL).
This was a suggestion from christos - so blame him if there is a deep
reason for using -1 :-)
 1.76 15-Feb-2008  christos back all changes out until I fix it properly.
 1.75 14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.74 01-Jan-2007  dsl Request the 'verbose' node print when aborting and scheduling nodes.
 1.73 01-Jan-2007  dsl Add the other half of the fix to stop stuff that depends on .WAIT nodes
being always rebuilt.
 1.72 01-Jan-2007  dsl Don't force things that have dependencies against .WAIT nodes to be rebuilt.
This is what causes all of ksh to be built every time through.
 1.71 21-Dec-2006  dsl Fix breakage of previous commit.
 1.70 20-Dec-2006  dsl Fix detection and reporting of dependency loops in parallel makes.
make's unit_tests should now run again.
 1.69 18-Dec-2006  christos From Anon Ymous:
Removed two "(void)&" constructs as there is no setjmp() or vfork() insight.
Flagged a few parameters __unused so this will compile with -Wextra now.
 1.68 17-Nov-2006  dsl branches: 1.68.2; 1.68.4;
A rather large rototil in the way the parallel make code schedules jobs.
This gives a considerable speedup in the processing of .WAIT and .ORDER.
Both .WAIT and .ORDER stop both the commands of the node, and its dependant
nodes being built until the LH nodes are complete.
.WAIT only applies to the dependency line on which it appears, whereas
.ORDER applies globally between the two nodes.
In both cases dependant nodes can be built because other targets need them.
make now processes the target list left to right, scheduling child nodes
as they are needed to make other nodes (instead of attempting to generate
a bottom-up dependency graph at the start). This means that 'make -j1'
will tend to build in the same order as a non-parallel make.
Note that:
all: x y
x: a .WAIT b
y: b .WAIT a
does not generate a dependency loop.
But
x: y
.ORDER y x
does (unless something elswhere causes 'y' to be built).
 1.67 27-Oct-2006  dsl Since 'ClientData' is 'void *', nuke almost all the (ClientData) casts.
 1.66 15-Oct-2006  dsl Output all debug trace output through 'debug_file' defaulting to 'stdout'.
(Almost all the debug output went there, but some went to stderr.)
Split the parsing of -d (debug flags) out into its own routine.
Allow the output filename to be changed by specifying -dF<file> to create
a log file, or -dF+<file> to append to it. <file> may be stdout or stderr.
Also change so that -d-<flags> acts on <flags> locally but doesn't copy
them to MAKEFLAGS so they aren't inherited by child makes.
I'm not 100% happy with the command line syntax for the above, so they are
currently undocumented.
 1.65 11-Oct-2006  dsl There is no need to resize the pollfd array, it can only ever have 2+maxJobs
entries, so allocate at startup.
Use an 'int jobPipe[2]' within the job structure, and create pipes directly
into it. Common up the code that creates all the pipes - making them all
non-block on the read side in the process.
Call Job_CatchChildren() directly from Job_CatchOutput() so that it only
gets called when a child actually exits.
NB: Something causes a 'pregnant pause' if (for example) you call 'nbmake obj'
in src/tools. Introduced between netbsd 3 and 4.
 1.64 09-Oct-2006  dsl Rip out the code for the undocumented -P (don't use pipes for command
output) option. I'm sure it is baggage from the past.
 1.63 23-Sep-2006  dsl Complete revamp of the way make handles job control signals.
- Send each type of signal to its own handler.
- Only call JobFinish when a process exits, in particular don't 'fake up'
'exitstatus' for jobs being continued, nor call it for suspends.
- When a job is stopped, use an entire variable to remember the fact, so
we know we need to send a SIGCONT. Don't change any other state.
- In order to report '*** [job3] Suspended' before we suspend ourselves we
have to call waitpid() from the signal handler - where we don't want to
process job termination events. Save the exit status and process later.
The code now handles:
- jobs that suspend themselves
- jobs exiting while suspended
- jobs that don't actually suspend at all
Hoewever it still does printfs() from the signal handler, and I haven't yet
stopped it thrashing the signal mask.
 1.62 31-Mar-2006  dsl There is no need to count jobs and job tokens.
If we don't create the job pipe, use the '-j n' option to limit the number
of tokens we will remove from the pipe.
 1.61 11-Feb-2006  dsl Add some more debug prints.
 1.60 11-Feb-2006  dsl Debug trace all the targets we are actually intending making.
De-optimise the getting of a job token so we don't re-order the job
list when there are no tokens.
This might have helped etc/Makefile, but isn't enough.
 1.59 04-Jan-2006  dsl For parallel makes, don't recycle the job token when we decide not to
run anything.
 1.58 08-Aug-2005  christos From Max Okumoto:
- Remove casts to NULL.
- Remove space between cast and object.
 1.57 25-Jul-2005  christos Whitespace KNF cleanup from Max Okumoto
 1.56 16-Feb-2005  christos PR/29203, PR/29204: Max Okumoto: KNF changes to make [no functional changes]
 1.55 01-Jul-2004  jmc Change to use __unused instead and provide a compat definition in make.h if
not already defined from cdefs.h
 1.54 01-Jul-2004  jmc Add some checks for gcc around a few function declarations and note the
unused variables. Also fix a few other warnings that PR#22118 shows when
trying to compile bmake on non-NetBSD hosts
 1.53 07-May-2004  ross Simplify build, no functional changes.

Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().

It's now possible to build make on some hosts with: cc *.c */*.c
 1.52 14-Nov-2003  dsl branches: 1.52.2;
Don't create targets if dependant files marked .OPTIONAL are missing.
 1.51 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.50 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.49 21-Mar-2002  pk Darn.. remove test code from previous commit.
 1.48 21-Mar-2002  pk When looking at predecessor/successor dependencies, we need to consult a
cohort's centurion as well.
 1.47 20-Mar-2002  pk Xref: parse.c, rev 1.46; make.c, rev 1.23

In these revisions `::' dependency handling was simplified by not linking
the cohort nodes into the dependency graph. This broke dependency checking
on all but the first instance of a `::' target since all of the cohort nodes
now just form a collection of disconnected dependency graphs.

Fix this by keeping a back-reference in each cohort to its leader (the
first instance of a :: node with the same name) and a count of the number
of cohorts that need to be made before dependent nodes are scheduled.

Classically, we'd need six centurions for cohort, but in this case one
suffices...
 1.46 12-Mar-2002  pk MakeAddAllSrc(): check for empty .ALLSRC variable before using its value.
 1.45 08-Mar-2002  pk Propagate a .JOIN node's .ALLSRC contents to the parent's .ALLSRC.
 1.44 18-Feb-2002  pk Make{_}HandleUse(): update comments and layout, re-arrange to avoid some
code duplication.
 1.43 18-Feb-2002  pk The use of OP_MARK in the MakeHandleUse() list callback function prevents
the removal of .USE nodes from a node's children list in case a given .USE
nodes appears multiple times on that list, preventing the target from ever
making it on the `to be made' queue.

Since the suffix rule processing code deals itself with removing the
transformation nodes from the parents to which it applies them, arrange
for doing the same for .USE nodes in MakeHandleUse() instead of in
Make_HandleUse(), and still use the OP_MARK stuff to avoid duplication
of commands.

Also, since Make_HandleUse() is not a list callback function and its
return value is no longer used, make its return type void.
 1.42 07-Feb-2002  pk When making a node which is the source of both a .MADE target and a
normal target (the latter dependency being the reason why it's made),
the .MADE parent should not be put on the `toBeMade' list again (in
Make_Update()) since it was already put on it in Make_ExpandUse().
Doing so would cause the rules for the .MADE target to be executed
(at least) twice, and also mess up the unmade children count of _its_
parent, resulting in spurious graph cylce detection.

To achieve this, make sure the unmade children count of the .MADE target
is set to zero before enqueueing it on the `toBeMade' list in
Make_ExpandUse(). Then, in Make_Update(), check if the parent has the
.MADE attribute before diddling with the queue.

For the same reason the status of a node must not be set to UPTODATE
unconditionally in compat mode, since that will prevent the node from
being built even if it is the source of a normal target. Instead,
check both its state and the type of the parent to decide whether to
continue on behalf of the current parent.
 1.41 03-Feb-2002  pk Don't bother to apply suffix rules to find sources for a target marked
as .MADE.
 1.40 27-Jan-2002  reinoud Fix major bug in make(1) ... due to shadowing of the dotLast path used for
the .DOTLAST primitive by a boolean variable with the same name, this whole
mechanism was broken ... it doesn't save much stat calls but it was wrong.

Thanks to Jason Thorpe for the other shadow-variable fixing patches he
made.
 1.39 03-Jul-2001  christos add .USEBEFORE Attribute
 1.38 12-Jun-2001  sjg Add 4th arg (flags) to Var_Set so that VarLoopExpand can tell it not
to export interator variables when using context VAR_CMD.

Reviewed: christos
 1.37 11-Jun-2001  wiz Fix various misspellings of compatible/compatibility.
 1.36 05-Mar-2001  sjg Test for non-existant LIB was incorrect (using cmtime cf. mtime).
 1.35 15-Jan-2001  christos .PHONY gnode's don't get a PREFIX, so don't try to set the parent's prefixes
on a parallel make.
 1.34 01-Jan-2001  sommerfeld Delete forceSerial; just use compatMake for that.
Add -N flag to *really* not execute any commands (useful when using
the -d flags to debug usr/src/Makefile)
Document -N
Update documentation of -n to mention that it still executes commands
for targets marked .MAKE so that the -N/-n distinction is clear.
 1.33 30-Dec-2000  sommerfeld Fix token accounting for .BEGIN/.END jobs
 1.32 30-Dec-2000  sommerfeld Add a token-passing scheme to allow a recursive make to successfully
use -j; all make's in a recursive build cooperate to limit the total
number of jobs, using a token-passing scheme.

The current token passing algorithm is similar to the one implemented
by gmake; there is a single pipe which is inherited through the entire
process hierarchy; tokens are obtained by reading a byte from the
"read end" of the pipe, and are returned by writing them to the "write
end". This exact algorithm is likely to change in the future.

Implementation details:
- Use the new trace facility to allow measurement of the
effectiveness of different token-passing schemes
- Get a token in MakeStartJobs(), return it in Make_Update()
- Eliminate Job_Full() and the jobFull global since they are
redundant with token system.
- Add an "internal" -J option (to pass the token pipe fd's down to
submakes) and a -T option for tracing.
- Change how compatMake is forced so that -j means something when
inherited by submakes.
- When waiting for a token, poll the token-passing pipe as well as
the output pipes of existing jobs.
 1.31 11-Jun-2000  mycroft Readd optimization last night. Problems earlier were partially due to the
arguments names on one function being swapped (by a previous author).

Do not do any duplicate suppression when a source list is created. Instead:
* OP_MADE protects against trying to make the source multiple times.
* A new OP_MARK flag is introduced to suppress duplicates while expanding
the .ALLSRC variable and .USE targets.
This turns the O(n^2) insertion into O(n) in most cases.

This is tested with a `make build' and some special test cases.
 1.30 10-Jun-2000  mycroft Back out last night's optimization for now.
 1.29 10-Jun-2000  mycroft Don't use OP_MARK when attaching suffix transformations.
 1.28 10-Jun-2000  mycroft Introduce an OP_MARK bit, and use it to suppress duplicates during .ALLSRC
and .USE expansion. Also, remove some more Lst_Member() checks that are now
redundant.
 1.27 29-Feb-2000  sjg branches: 1.27.2;
Fixed the oodate test to include the check of gn->cmtime == 0 without
breaking the original intent.

PR: 9503
 1.26 15-Feb-2000  sjg Non-existent libs are always out of date.
This was not handled correctly on ELF where libs do not have T.O.C.

PR: 9393
Reviewed by: christos
 1.25 31-Jan-2000  sjg You cannot meaningfully test if a non-existent file has a correct
archive header, so don't try - just believe gn->type & OP_LIB.
 1.24 16-Sep-1999  mycroft Some minor cleanup of :: tests.
 1.23 15-Sep-1999  mycroft Rework how :: dependencies are handled.
Build a list of `cohorts' as before, but do *not* link each one into all the
parent nodes; instead, copy the `cohort' lists into the stream of targets to
be built inside Make_ExpandUse(). Also do the attribute propagation as a
separate pass after parsing.
This eliminates several O(n^2) algorithms.
 1.22 11-Nov-1998  christos This patch fixes the problem introduced in the previous commit where
parents would be get remade, even if children were not really updated
by the commands executed for them. It also makes all the children have
the real modification time set if possible, so it should fix some other
timing weirdnesses...

- collapse childMade and make fields into flags and convert them to bits
CHILDMADE and REMAKE
- introduce FORCE flag that gets set in all the parents of a child that
has no sources and does not exist.
- set oodate if the FORCE flag is set, and not if CHILDMADE
- centralize the RECHECK into Make_Recheck() and use this in make.c and compat.c
- use Make_TimeStamp for all child -> parent timestamp propagations
 1.21 11-Nov-1998  christos PR/6426: Jim Bernard: make sometimes does not make directories on top of
a union mount.

eg.
src: FORCE

FORCE is a fake target that does not have sources. When FORCE is
considered made it gets updated with the current timestamp. If the
directory happens to have the same timestamp too, then it will not
be made because it is considered to be up-to-date with respect to
the child. This can happen because the time resolution is only in
seconds. It is more likely to happen on a union filesystem where
the timestamps take longer to update.

The fix is to consider the parent unmade when children have been
updated.
 1.20 26-Mar-1998  christos PR/5210: Hauke Fath: make core dumps with .SHELL
Unfortunately this revealed a deeper problem with the brk_string code.
To fix it:
- remove sharing of the buffer between brk_string invocations
- change the semantics of brk_string so that the argument array
starts with 0, and return the buffer where the strings are
stored
 1.19 28-Sep-1997  lukem branches: 1.19.2;
wrap #include <sys/cdefs.h>, __RCSID(...) stuff in #ifndef MAKE_BOOTSTRAP
 1.18 01-Jul-1997  christos Add WARNS=1
RCSID police
 1.17 07-Jun-1997  christos Deal with archive.a(member.o) nodes when expanding .USE dependencies or
adding children to .OODATE.
 1.16 06-May-1997  mycroft Make sure `-n' is actually disabled for targets with the .MAKE attribute.
 1.15 02-May-1997  christos - Target searching addition:
Make used to only use the search path for nodes that were pure
sources (not targets of other sources). This has been corrected
and now gnu-autoconf generated Makefiles work in directories other
than the source one.

- Suffix transformation rescanning:
Suffix transformations (.c.o:; cc ...) were only recognized in
the past when both suffixes were members of the suffix list.
Thus a sequence like:
.z.b:
echo ${.TARGET}
.SUFFIXES: .z
would cause .z.b: to be inserted as a regular target (and the main
target in this case). Other make programs always add rules that
start with a period in the transformation list and never consider
them as targets. We cannot do that (consider .depend files) so we
resort to scanning the list of the current targets every time a
suffix gets added, and we mutate existing targets that are now
valid transformation rules into transformation rules. If the
transformed target was also the main target, we set the main target
to be the next target in the targets list.
 1.14 28-Mar-1997  christos Make sure that the children of nodes that are marked .MADE, are marked
UPTODATE and their timestamps are consistent.
 1.13 23-Mar-1997  christos Locate all the children of a node marked as MADE.
 1.12 10-Mar-1997  christos Add a .MADE directive to indicated that the children of a target are
up-to-date, even when they are not. This is to simulate our current
make install behavior with proper dependencies.
 1.11 20-Feb-1997  christos Reported by cgd: fix .USE directive problems:
1. ${.*} variables did not get expanded in dependencies.
2. expanded ${.*} variables in .USE dependencies can cause tree
restructuring; handle it.
3. in compat mode, expand .USE before evaluating the list of targets,
instead of doing .USE expansions on demand, because they can cause
tree restructuring.
 1.10 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.9 30-Aug-1996  christos Fix bug reported by Greg Hudson where leaf (source only) nodes were
referenced only by their basename and not by their full pathname. This
breaks when .PATH or MAKEOBJDIR are used. There might be Makefiles around
that try to work around this bug by prepending ${.CURDIR} to the sources,
and they should be found and fixed. Also a lot of the gunk in suff.c that
was attempting to work around the same problem could be removed.
 1.8 15-Mar-1996  christos branches: 1.8.4;
Add PHONY attribute and target. This is the first step to cleanup the
xinstall and xlint crud.
 1.7 14-Jun-1995  christos - $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.6 06-Jan-1995  christos Fixes from Paul Borman (prb@bsdi.com)
1. Honor environment variable $MACHINE if set over uname.machine
2. archives with :: are always out of date, even when they have no children.
3. VAR= a b c # comment, gets the trailing blanks trimmed, unless
escaped by \. I'll have to read the posix manul to make sure that it
is ok to handle escapes here.
 1.5 06-Jun-1994  jtc Fixes from Christos Zoulas, who used purify, objectcenter and testcenter
to find memory leaks and illegal memory accesses.
 1.4 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.3 13-Jan-1994  jtc Include appropriate header files to bring prototypes into scope.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8.4.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.19.2.1 08-May-1998  mycroft Sync with trunk, per request of christos.
 1.27.2.1 23-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.52.2.1 10-May-2004  tron Pull up revision 1.53 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.68.4.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.68.2.1 05-Jun-2007  bouyer Apply patch (requested by tron in ticket #696):
usr.bin/make/compat.c patch
usr.bin/make/cond.c patch
usr.bin/make/dir.c patch
usr.bin/make/for.c patch
usr.bin/make/main.c patch
usr.bin/make/make.1 patch
usr.bin/make/make.c patch
usr.bin/make/make.h patch
usr.bin/make/nonints.h patch
usr.bin/make/parse.c patch
usr.bin/make/str.c patch
usr.bin/make/targ.c patch
usr.bin/make/util.c patch
usr.bin/make/var.c patch

Synchronize make(1) with HEAD branch to increase perfomance and
improve stability.
 1.84.2.4 16-Jan-2013  yamt sync with (a bit old) head
 1.84.2.3 30-Oct-2012  yamt sync with head
 1.84.2.2 23-May-2012  yamt sync with head.
 1.84.2.1 17-Apr-2012  yamt sync with head
 1.87.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.95.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.264.2.1 02-Aug-2025  perseant Sync with HEAD
 1.361 06-Jul-2025  rillig make: clean up
 1.360 13-Jun-2025  rillig make: skip inter-process stack trace when MAKE_STACK_TRACE=no

Previously, setting MAKE_STACK_TRACE to any other value than "yes"
accidentally generated almost-complete inter-process stack traces.
 1.359 13-Jun-2025  rillig make: add on-demand inter-process stack traces

When debugging a build that heavily uses nested calls to sub-makes, the
chain of calls is useful to quickly assess the situation. If explicitly
requested, include the actions from any parent processes in the stack
traces.

Reviewed by: sjg
 1.358 11-Jun-2025  sjg make: check variable names for invalid characters

Variable names should not contain white-space.
As is; make quietly ignores gmake syntax like
$(addprefix -I, $(INCLUDE_DIR_LIST))
which means we are not doing what the makefile wants, and the
user has no clue.

CheckVarname is called only if there are no modifiers to be applied
as :L and others legitimately can handle white-space,
it will issue a warning if illegal characters are found.
Currently only white-space is checked.

The NetBSD build produces a few warnings - in one case a makefile
intended for gmake, and the other some dubious constructs by bsd.prog.mk
in support of ATF tests such as OBJS.${PROG} when PROG is actually a list.

Reviewed by: rillig
 1.357 26-May-2025  rillig make: prepare for inter-process stack traces

To understand how chains of sub-makes interact and how they are called,
it's useful to have stack traces that span multiple processes. To
implement this, a stack trace needs not only be printed but also stored
as a string.
 1.356 26-May-2025  rillig make: show contents of MAKEFLAGS in the stack trace

When the internal -J option refers to a closed file descriptor, it's
helpful to know what the MAKEFLAGS environment variable contains, in
addition to the executed command line. Same for parse errors in
variable assignments from the command line.
 1.355 18-May-2025  rillig make: rename variables, remove now-redundant comments
 1.354 09-May-2025  rillig make: replace bitset in trace output with descriptive node attributes
 1.353 22-Apr-2025  rillig make: clean up

Replace 'unsigned int' with simply 'unsigned'.

In compat.c, skipping whitespace is not needed, as the loop above
already skips it.

In job.c, remove the unused header <sys/file.h>.

Inline the TMPPAT macro, as it is only needed in a single place.
 1.352 30-Mar-2025  sjg make: POSIX mode, check for sysV style modifiers first

A POSIX compatible makefile should not be using any
of our native modifiers, so give preference to the sysV style modifier
and only check the others as a fallback.

Reviewed by: rillig
 1.351 29-Mar-2025  rillig make: in a stack trace with details and includes, list the current file
 1.350 07-Mar-2025  rillig make: clean up comments and code for parallel mode

Most of the comments didn't help understand the code.

The Finish function was named way too soft for what it does, which is to
exit without cleaning up properly. Since it was used only once, inline
it. The code from that function causes jobs to be terminated early when
an unrelated target has failed, resulting in partially written files,
due to SIGPIPE.
 1.349 19-Jan-2025  rillig make: fix code coverage counts

See tests/usr.bin/gcov/t_gcov.sh.
 1.348 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.347 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.346 27-Aug-2024  rillig make: treat recursive variables non-fatally

A recursive variable is no worse than an unknown modifier, so treat them
in the same way by continuing parsing until the end of the makefile.
 1.345 25-Aug-2024  rillig make: add more context to error message about recursive variables
 1.344 11-Jul-2024  sjg Compat_RunCommand use tempfile if cmd too big

Extract the logic recently added to Cmd_Exec to handle
long commands via temp file to Cmd_Argv,
so it can also be leveraged by Compat_RunCommand

Reviewed by: christos
 1.343 09-Jul-2024  rillig make: error out on parse/evaluation errors in shell commands

The expression ${VAR:X} has an unknown modifier ':X'. Previously, this
expression errored out when the expression was evaluated at parse time,
but not when the expression was evaluated when generating the commands
to bring a target up to date. The errors were previously reported, they
didn't affect the exit status, though.

Now, errors in expressions are handled in the same way, regardless of
the time at which they are evaluated.
 1.342 07-Jul-2024  rillig make: move initialization of variable scopes to targ.c

The variable scopes are freed by Targ_End, so initialize them there as
well. Separate printing statistics and freeing memory, which makes
Var_End unnecessary.
 1.341 07-Jul-2024  rillig make: only generate code for cleanup functions in CLEANUP mode
 1.340 05-Jul-2024  rillig make: reduce lint-specific comments about ARGSUSED
 1.339 15-Jun-2024  rillig branches: 1.339.2;
make: clean up collection of context information for error messages
 1.338 02-Jun-2024  rillig make: sync VarEvalMode constant names with their debug log names
 1.337 01-Jun-2024  sjg make: add .export-all

An explicit syntax for exporting all global variables is much safer
than allowing .export with no argument to do the same.

Add .export-all and have .export with no argument throw a warning saying
to use .export-all

Reviewed by: rillig
 1.336 01-Jun-2024  rillig make: remove unused VARE_EVAL_KEEP_DOLLAR
 1.335 25-May-2024  rillig make: fix memory leak for command strings
 1.334 25-May-2024  rillig make: fix a few more memory leaks
 1.333 07-May-2024  sjg make: all command line overrides go in .MAKEOVERRIDES

Not all variables that start with '.' are internals,
and unless they are explicitly flagged as internal should go
into .MAKEOVERRIDES

Update varname-dot-makeoverrides to check this.

Also avoid using SCOPE_CMDLINE when ReadOnly will do.
 1.332 27-Apr-2024  rillig make: clean up, test .NOPATH

Trim down the comments in the archive module, as they mainly repeated
the code. Trim down the binary code size in the archive module, as it
is rarely used.

In Var_Parse, delay two variable assignments until they are actually
needed.
 1.331 23-Apr-2024  rillig make: clean up comments, code and tests
 1.330 20-Apr-2024  rillig make: provide more context information for parse/evaluate errors
 1.329 10-Mar-2024  sjg make: record exit status in GNode

SetErrorVars can now set .ERROR_EXIT which allows
a .ERROR target to ignore the case of .ERROR_EXIT == 6
which means failure happened elsewhere.

Reviewed by:
 1.328 01-Mar-2024  sjg make: export target scope values

Pass target scope to Var_ReexportVars so that a target process
will see the correct values in its env.
We must then mark any Global scope variable as unexported
so targets without local value get the Global one.
 1.327 17-Dec-2023  rillig make: clean up unused return value of str2Lst_Append

No functional change.
 1.326 02-Nov-2023  rillig make: inline a single-line cross-file function

No functional change.
 1.325 10-Sep-2023  rillig make: remove redundant 'extern' from function declaration
 1.324 24-Jun-2023  rillig make: remove redundant 'extern' in function declaration

No binary change.
 1.323 20-Jun-2023  rillig make: allow targets to be used as multiple-inclusion guards

This style is used by FreeBSD, among others.
 1.322 19-Jun-2023  rillig make: if a makefile is protected by a guard, only include it once

"looks reasonable" sjg@
 1.321 16-Jun-2023  rillig make: remove parameter names from function declarations

No binary change.
 1.320 01-Jun-2023  rillig make: shorten function names, clean up comments

No functional change.
 1.319 28-Mar-2023  rillig make: declare all common symbols in headers, unexport others

No functional change.
 1.318 09-Mar-2023  rillig make: document how read-only variables can be made read-write
 1.317 18-Feb-2023  rillig make: fix parsing of unevaluated subexpressions with unbalanced '{}'

Since var.c 1.323 from 2020-07-26, modifiers containing unbalanced
braces or parentheses were parsed differently, depending on whether they
were relevant or not.

For example, the expression '${VAR:...}' is enclosed with braces. When
this expression has a modifier ':S,},}},g' that would double each '}' in
that expression, the parser got confused:

If the expression was relevant, the modifier was parsed as usual, taking
into account that the 3 '}' in the modifier are ordinary characters.

If the expression was irrelevant, the parser only counted the '{' and
the '}', without taking into account that a '}' might be escaped by a
'\' or be an ordinary character. Parsing therefore stopped at the first
'}', assuming it would finish the expression '${VAR:S,}'.

This parsing mode of only counting balanced '{' and '}' makes sense for
the modifier ':@var@...@', which expands each word of the expression
using the template from the '...'. These templates tend to be simple
enough that counting the '{' and '}' suffices.
 1.316 15-Feb-2023  rillig make: inline macros for variable names

The variable name '.MAKEOVERRIDES' was already used in the non-macro
form.

No binary change.
 1.315 15-Feb-2023  rillig make: inline macro for variable name ".MAKE.EXPORTED"

The variable name is distinctive enough to be searched directly in the
code instead of having a named constant for it.

No binary change.
 1.314 14-Feb-2023  rillig make: remove redundant type VarParseResult

No functional change.
 1.313 14-Feb-2023  rillig make: clean up calls to Var_Subst

None of the calls to Var_Subst used the return value, and the return
value was always VPR_OK.

No functional change.
 1.312 14-Feb-2023  rillig make: reduce complexity of evaluating expressions

No functional change.
 1.311 26-Jan-2023  sjg make: some variables should be read-only

Make variables like .newline and .MAKE.{GID,PID,PPID,UID} read-only.

Reviewed by: rillig
 1.310 23-Jan-2023  sjg make: .[NO]READONLY for control of read-only variables

Reviewed by: rillig
 1.309 19-Jan-2023  rillig make: inline macro for variable name

This fixes the inconsistency of using the macro name in one place and
its value in another place (since 2010).

No binary change.
 1.308 10-Oct-2022  rillig make: change return type of unlink_file back to int

As unlink_file is a wrapper around unlink, use the same encoding for the
possible return values as in the wrapped function. This consistency is
more important than expressing all possible return values in the return
type 'bool'.

https://mail-index.netbsd.org/tech-toolchain/2022/10/06/msg004155.html

No functional change.
 1.307 24-Sep-2022  rillig make: clean up tracking of depth of nested .if directives

The variable cond_min_depth was redundant. It was only accessed while
parsing the makefiles. Merging it into struct IncludedFile removes the
possible confusion between cond_min_depth and including_cond_min_depth.

No functional change.
 1.306 24-Sep-2022  rillig make: fix variable and function names relating to .if nesting

The previous names were confusing since they suggested that cond_depth
instead of cond_min_depth would be saved and restored.

No functional change.
 1.305 23-Sep-2022  sjg Cond_reset_depth just use cond_min_depth

To avoid errors from unclosed conditionals on .break
it is sufficient to just set cond_depth = cond_min_depth.

Patch from rillig
 1.304 02-Sep-2022  sjg make: add .break to terminate .for loop early

When .break is encountered within a .for loop
it causes immediate termination.

Outside of a .for loop .break causes a parse error.

Reviewed by: christos
 1.303 12-Jun-2022  rillig make: reorganize Parse_Error

Determining the location where the error occurred is now done by
ParseVErrorInternal. This frees the remaining code from keeping the
filename and the line number together. It also makes Parse_Error short
enough that it might be worth providing a separate function for each of
the 3 log levels.

No functional change.
 1.302 07-May-2022  rillig make: allow to randomize build order of targets

In complex dependency structures, when a build fails, a probable cause
is a missing dependency declaration between some files. In compat mode,
the build order is deterministic, in jobs mode, it is somewhat
deterministic. To explore more edge cases, add the line ".MAKE.MODE +=
randomize-targets" somewhere in the makefile.

Fixes PR bin/45226 by riastradh. Reviewed by christos.
 1.301 07-May-2022  rillig make: rename Compat_Run to Compat_MakeAll

No functional change.
 1.300 18-Apr-2022  rillig make: only switch to POSIX mode if '.POSIX:' is the first line

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html
says that in order to make a makefile POSIX-conforming, its first
non-comment line must be the special dependency line '.POSIX:' without
any source dependencies.

Previously, make switched to POSIX mode even if such a line occurred
anywhere else, which was allowed by POSIX but was deep in the
"unspecified behavior" area. For NetBSD make, there is no big
difference since it doesn't ship any <posix.mk> file, this change mainly
affects the bmake distribution.

Previously, makefiles that contain '.POSIX:' somewhere in the middle
could fail due to <posix.mk> resetting .SUFFIXES, among other things.

Suggested by Simon J. Gerraty, who also reviewed an earlier version of
this change.
 1.299 26-Mar-2022  rillig make: prefer 'long long' over 'long' on 32-bit C99 platforms

When sorting the words of an expression numerically using the modifier
':On' (added on 2021-07-30), use 64-bit numbers even on 32-bit
platforms. A typical use case is comparing file sizes.

When tracing the execution of jobs, fix an integer overflow after 2038.
32-bit platforms that use a pre-C99 compiler still have this problem.

No change to the test suite since most tests simply skip any potential
differences between 32-bit platforms and 64-bit platforms (see
varmod-order-numeric.mk) or already account for both variants (see
varmod-localtime.mk).
 1.298 05-Feb-2022  rillig make: improve C90 support

Do not use inline functions, remove trailing comma in enum declaration,
do not use 'long long' for printing a timestamp. This re-introduces the
Year 2038 Problem for pre-C99 compilers when printing the trace log, but
that is a seldom used feature.
 1.297 04-Feb-2022  rillig make: use unsigned int for line numbers everywhere

Previously, some line numbers were stored as signed int while others
were stored as size_t. Since line numbers are never negative, use an
unsigned type. Since the maximum file size for makefiles is 1 GB (see
loadfile), unsigned int is large enough even on 64-bit platforms.

Using a single data types reduces the number of type conversions. Using
unsigned int improves compatibility with C90 (printf %u instead of %zu),
which is needed by bmake, which is derived from usr.bin/make.

No functional change.
 1.296 31-Jan-2022  rillig make: make DEBUG0 simpler

All arguments to DEBUG0 are string literals, and none of them contains a
'%', which makes them safe to pass to printf directly. Any accidental
'%' would be caught by the compiler.

No functional change.
 1.295 30-Jan-2022  christos Make the GNode lineno unsigned to fix lint warning in var.c calling
PrintLocation()
 1.294 29-Jan-2022  rillig make: for recursive variables in commands, print location

Print the approximate location based on the last command that has been
defined for the target. It would be possible to get more detailed
location information by counting the number of commands of the target,
but that would get messy due to .USEBEFORE, .USE and .DEFAULT, and
still, this is an edge case, so don't waste too much code for it now.
Having this hint about the location is more helpful than just a plain
"Variable X is recursive" without any further details.
 1.293 29-Jan-2022  rillig make: print stack trace on fatal errors

The only fatal error that occurs while the makefiles are read in is the
one about recursive variables, which didn't give any hint about the
location before.

If a recursive variable is detected while evaluating the commands of a
target to be made, there is no location information, as before.
 1.292 29-Jan-2022  rillig make: inline functions that have a single call site

No functional change.
 1.291 27-Jan-2022  sjg Allow local variable assignments in dependency lines

The variable is set in the context of the target.
This syntax has been supported by gmake for ~ever.
If necessary a makefile can set .MAKE.TARGET_LOCAL_VARIABLES=false
to disable this.

Expose GetBooleanExpr so parse.c can use it.
 1.290 23-Jan-2022  rillig make: merge nonints.h into make.h

No functional change.
 1.289 15-Jan-2022  rillig make: use islower for parsing directives

None of the directives has an uppercase letter, so there is no need to
test for it.

No functional change.
 1.288 09-Jan-2022  rillig make: extract low-level character operations into utility function

Suggested by nia.
https://mail-index.netbsd.org/source-changes-d/2022/01/09/msg013564.html

No functional change.
 1.287 07-Jan-2022  rillig make: merge duplicate variables for the main target

No functional change.
 1.286 07-Jan-2022  rillig make: rename and inline Targ_Precious

No functional change.
 1.285 07-Jan-2022  rillig make: rename IFile and its fields to match their actual content

For lines that use backslash continuation, the human-readable line
number does not equal the number of raw lines that have been read from
the file.

The big comment in PrintStackTrace has become outdated, it still
referred to first_lineno. Due to the bugs documented in
opt-debug-parse.mk, that function needs to be redone completely.

No functional change.
 1.284 29-Dec-2021  rillig make: merge duplicate types CondEvalResult and CondResult

No binary change.
 1.283 29-Dec-2021  rillig make: merge duplicate enum constants for CondEvalResult and CondResult

No binary change.
 1.282 29-Dec-2021  rillig make: merge types CondResult and CondEvalResult

No functional change.
 1.281 28-Dec-2021  rillig make: do not treat .USEBEFORE as candidate for the main target

A .USE target is not a candidate, so .USEBEFORE shouldn't either.

Since make.h 1.36 from 2001-07-03. In that commit, OP_USEBEFORE should
have been added to OP_NOTARGET.
 1.280 28-Dec-2021  rillig make: extract OP_NOTARGET into separate function

No binary change, except for line numbers in assertions.
 1.279 27-Dec-2021  rillig make: remove unnecessary words from command line options

Several years ago, the command line options were individual global
variables. The global variable could therefore not be named 'silent'
since that would have conflicted with local variables of the same name.
After moving the global variable to the namespace 'struct CmdOpts',
there is no conflict anymore.

There doesn't seem to be any risk of naming collisions for the names
'touch' and 'query'.

No functional change.
 1.278 15-Dec-2021  rillig make: amend leftover cleanups from the previous commits

No functional change.
 1.277 15-Dec-2021  rillig make: format comments according to /usr/share/misc/style

Assisted by indent(1), with manual corrections due to its many remaining
bugs.

No functional change.
 1.276 15-Dec-2021  rillig make: remove redundant comments for multiple-inclusion guards
 1.275 15-Dec-2021  rillig make: remove space after ':' in bit-field declarations

As seen in /usr/share/misc/style.
 1.274 15-Dec-2021  rillig make: mark several functions whose result must be used

Suggested by sjg, to catch more bugs like the memory leak in cond.c
1.303 from 2021-12-13.

No binary change.
 1.273 15-Dec-2021  rillig make: prevent memory leaks from buffers

The warning about unused function results would have prevented the
memory leak that was fixed in cond.c 1.303 from 2021-12-13.
 1.272 13-Dec-2021  rillig make: convert debugging flags from enum to bit-field

This gets rid of the magic numbers, making it possible to add another
debug flag without renumbering the others.

No functional change.
 1.271 13-Dec-2021  rillig make: fix memory leak for filenames in .for loops (since 2013-06-18)

Previously, each time a .for directive pushed its buffer on the input
file stack, the current filename was duplicated. This was a waste of
memory.

The name of a file is typically only used while it is read in. There is
one situation when the filename is needed for longer, which is when a
target is defined.

Since .for loops are implemented as a special form of included files,
each .for loop duplicated the current filename as well.

$ cat << EOF > for.mk
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.endfor
.endfor
.endfor
.endfor
.endfor
.endfor
.endfor

all:
@ps -o rsz -p ${.MAKE.PID}
EOF

$ make-2021.12.13.03.55.16 -r -f for.mk
RSZ
10720

$ ./make -r -f for.mk
RSZ
1716

The difference is 8 MB, which amounts to 1 million .for loops.
 1.270 28-Nov-2021  rillig make: fix a few lint warnings about type mismatch in enum comparisons

These warnings were triggered with the lint flag '-e', which enables
additional checks on enums. This check would have detected the type
mismatch from the previous commit.

The check has a few strange warnings though, complaining about
initialization of 'unsigned long' with 'unsigned long', so don't enable
it for the official builds.

No functional change.
 1.269 28-Nov-2021  rillig make: fix leftover typo from previous refactoring
 1.268 28-Nov-2021  rillig make: convert GNodeFlags from enum into bit-fields

Now that Enum_ToString is implemented for each type separately, it's
easy to convert them to bit-fields. This gets rid of the magic numbers
12 for CYCLE and 13 for DONECYCLE that left a suspicious gap in the
numbers. This gap was not needed since the code didn't make use of the
relative ordering of the enum constants.

The effects of this conversion are fewer capital letters in the code,
smaller scope for the GNode flags, and clearer code especially when
setting a flag back to false.

One strange thing is that GCC 10.3.0 doesn't optimize GNodeFlags_IsNone
to an single bitmasking instruction, at least on x86_64. Instead it
generates a testb instruction for each of the flags, even loading bit 8
separately from the others. Clang 12.0.1 knows this optimization
though and generates the obvious sequence of movzwl, testl, jz.

No functional change.
 1.267 28-Nov-2021  rillig make: replace bloated bit-set-to-string code with simple code

It was a nice idea to implement a bit-set using an enum type and have a
generic ToString function for them. In the end, the implementation
involved really heavy preprocessor magic and was probably difficult to
understand. Replace all the code with a few bits of straight-forward
preprocessor magic that can be readily understood by just looking 5
lines around, instead of digging through 130 lines of lengthy macro
definitions.

Curiously, this reduces the binary size even though the 3 ToString
functions now have a few lines of duplicate code and there are more
explicit function calls.

The ToString functions are only seldom used, so the additional memory
allocation is acceptable.

No functional change.
 1.266 27-Nov-2021  rillig make: remove CONSTCOND comments, lint no longer needs them
 1.265 12-Sep-2021  rillig make: error out if a pre-C99 platform defines bool in some cases

On NetBSD/amd64 9.99.88, when compiling make in C90 mode, make.h defined
its own boolean type as an alias for unsigned int. Not plain int since
that would make the value of bit-fields -1 instead of 1.

This worked fine for all files except main.c, which includes
<sys/sysctl.h>, which in turn includes <stdbool.h> unconditionally, even
in C90 mode. This meant that in main.c, sizeof(bool) was 1, while in
all other files it was 4.

This in turn led to a segmentation fault when ParseDependencySourceMain
tried to access opts.create. Since parse.c assumed sizeof(bool) == 4,
it computed an offset outside of struct CmdOpts, which was defined in
main.c with sizeof(bool) == 1.

Rather than risking these segmentation faults, prevent building make on
platforms like these and suggest a proper workaround.
 1.264 31-Jul-2021  rillig make: fix lint warnings

The string functions from str.h are declared as 'static __unused' when
compiled with GCC, but lint explicitly undefines __GCC__ during
preprocessing. Therefore, make those functions inline, to prevent
warnings that they are unused.

The macro UNCONST is used in a few places, and (again) since lint
undefines __GCC__, that macro expanded to a simple type cast, which lint
warned about. To prevent this warning, implement UNCONST as a function
that works everywhere and hides the type cast.

In filemon_open, the code for closing F->in was obviously unreachable.

No functional change.
 1.263 21-Jun-2021  rillig make: document where to find tests for the dependency lines
 1.262 14-Apr-2021  rillig make: let the compiler decide whether to inline string functions

On x86_64, this reduces the binary size by 2 kB.
 1.261 11-Apr-2021  rillig make: add types Substring and LazyBuf

These will be used for making the string handling more efficient,
avoiding allocations, especially when evaluating variable expressions.

Since the string handling has grown quite a bit in the last months,
extract it into its own header file.

No functional change.
 1.260 04-Apr-2021  rillig make: rename a few functions to be more descriptive

No functional change.
 1.259 03-Apr-2021  rillig make: revert accidental change from the previous commit

The definition of MAKE_GNUC_PREREQ was not supposed to be changed. This
change only slipped accidentally, the test for __STDC_VERSION__ was only
supposed to be for UNCONST.
 1.258 03-Apr-2021  rillig make: backport to C90

In the past few months I had accidentally used C99 features in the make
code. According to tools/README, tools that are used in the build
system should restrict themselves to C90.

This allows make to build with GCC's options "-pedantic
-Wno-system-headers -Dinline= -Wno-error=cast-qual".

I didn't notice anyone actively complaining though, I just wanted to see
how much work this backporting would be. The identifier __func__ is
still used, as in other tools.

No functional change.
 1.257 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.256 05-Feb-2021  sjg Avoid strdup in mkTempFile

Require caller to pass a buffer and size if they
want the tempfile not unlinked.

Add Job_TempFile to handle blocking signals around
call to mkTempFile, so that meta_open_filemon can use it
in jobs mode.
 1.255 05-Feb-2021  rillig make: improve documentation about variable scopes

In an experiment, I tried to separate the concepts of a GNode and a
variable scope. The global variables SCOPE_GLOBAL, SCOPE_INTERNAL and
SCOPE_CMDLINE are implemented as GNode even though they only need the
members 'name' and 'vars'. All their other members are unused.
Therefore it seemed natural to extract this part of the GNode into a
separate type called Scope.

The resulting code was harder to read though since it had split the
namespace of the functions into several parts that were not obviously
related: The Var_ functions, the Scope_ functions, and the short-cut
Global_ functions. Because of this, I threw away the experiment.

All that is left are a few updated comments.
 1.254 04-Feb-2021  rillig make: rename Var_ValueDirect to GNode_ValueDirect
 1.253 04-Feb-2021  rillig make: rename context and ctxt to scope

This continues the previous commit, in which VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE were renamed.

Renaming the variable 'ctxt' was trivial since that word is used nowhere
else. In the comments though, each occurrence of the word 'context' had
to be checked individually since the word 'context' was not only used
for referring to a variable scope. It is also used to distinguish
different situations where characters are escaped in a certain way
('parsing context') and in a few other expressions.
 1.252 04-Feb-2021  rillig make: rename some VAR constants to SCOPE

The word "context" does not fit perfectly to the variables that are
associate with a GNode, as the context is usually something from the
outside and the variables are more like properties inherent to the
GNode.

The term "global context" fits even less. Since the thing where
variables are looked up is commonly named a scope, use that term
instead.

This commit only renames the global variables VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE, plus a few very closely related comments. These are:

GNode.vars (because of line breaks)
GNode_Free (dito)
varname-make_print_var_on_error.mk
varname-make_print_var_on_error-jobs.mk

The debug message in Var_Stats is left as-is since there is no unit test
for it yet.

The other renamings (variable names "context", "ctxt", as well as
further comments) will be done in a follow-up commit.
 1.251 02-Feb-2021  rillig make: remove unused INTERNAL flag

It had been used for cached_realpaths, until this variable had its type
changed from GNode to HashTable in main.c 1.469 from 2020-11-14.
 1.250 01-Feb-2021  rillig make: clean up comments
 1.249 01-Feb-2021  rillig make: indent preprocessor directives consistently

As seen in share/misc/style.
 1.248 01-Feb-2021  rillig make: always use vfork, never fork

Before compat.c 1.217, job.c 1.390 and main.c 1.504 from 2020-12-27, the
exported make variables were exported from each freshly forked child
process. There was no practical difference though between exporting the
variables from the parent process or the child process since these two
processes share the same address space, except that the forked process
is very limited in what it may actually do. This limitation was
violated on a regular basis.

When an exported variable referred to a variable that used the :sh
variable modifier, this led to a fork from within vfork, which is not
allowed. Since 2020-12-27, exporting the variables is done from the
main process, which prevents this situation from ever occurring.

Since that day, there is no need anymore to distinguish between vfork
and fork, which removes any need for the macro.
 1.247 01-Feb-2021  rillig make: use bit shifts in enum constants for GNodeFlags

Same as in the other enum bit sets. This makes it easier to spot the
gap between bit 6 and bit 12.
 1.246 24-Jan-2021  rillig make(1): convert SearchPath to struct

This prepares for making dotLast a simple struct member instead of a
fake CachedDir, which is easier to understand.
 1.245 21-Jan-2021  rillig make(1): merge duplicate code in Parse_MainName
 1.244 19-Jan-2021  rillig make(1): remove do-not-format markers from comments

These markers had been used inconsistently. Furthermore the source code
had not been formatted automatically before 2020 at all, otherwise there
wouldn't have been any trailing whitespace left.
 1.243 16-Jan-2021  rillig make(1): fix a few inconsistencies for lint's strict bool mode
 1.242 10-Jan-2021  rillig make(1): consistently use boolean expressions in conditions

Most of the make code already followed the style of explicitly writing
(ptr != NULL) instead of the shorter (ptr) in conditions.

The remaining 50 instances have been found by an experimental,
unpublished check in lint(1) that treats bool expressions as
incompatible to any other scalar type, just as in Java, C#, Pascal and
several other languages.

The only unsafe operation on Boolean that is left over is (flags &
FLAG), for an enum implementing a bit set. If Boolean is an ordinary
integer type (the default), some high bits may get lost. But if Boolean
is the same as _Bool (by compiling with -DUSE_C99_BOOLEAN), C99 6.3.1.2
defines that a conversion from any scalar to the type _Bool acts as a
comparison to 0, which cannot lose any bits.
 1.241 30-Dec-2020  rillig make(1): format multi-line comments
 1.240 28-Dec-2020  rillig make(1): replace global preserveUndefined with VARE_KEEP_UNDEF

Controlling the expansion of variable expressions using a global
variable and a VARE flag was inconsistent.

Converting the global variable into a flag had to prerequisites:

1. The unintended duplicate variable assignment had to be fixed, as
done in parse.c 1.520 from 2020-12-27. Without this fix, it would have
been necessary to add more flags to Var_Exists and Var_SetWithFlags, and
this would have become too complex.

2. There had to be a unit test demonstrating that VARE_KEEP_DOLLAR only
applies to the top-level expression and is not passed to the
subexpressions, while VARE_KEEP_UNDEF applies to all subexpressions as
well. This test is in var-op-expand.mk 1.10 from 2020-12-28, at least
for the ':@word@' modifier. In ParseModifierPartSubst, VARE_KEEP_UNDEF
is not passed down either, in the same way.
 1.239 23-Dec-2020  rillig make(1): fix lint warnings for constant condition in DEBUG calls
 1.238 23-Dec-2020  rillig make(1): fix MAKE_RCSID for lint mode

Previously, running lint mode didn't define MAKE_RCSID at all, which
resulted in a syntax error.

While here, reduced the indentation and nesting of the preprocessor
directives.
 1.237 23-Dec-2020  rillig make(1): rename CmdOpts.lint to strict

When running lint(1) on the code, it defines the preprocessor macro
"lint" to 1, which generated a syntax error in the declaration "Boolean
lint", as that became "Boolean 1".
 1.236 22-Dec-2020  rillig make(1): fix return type of macro DEBUG

This macro was supposed to return a boolean expression all the time, it
just hadn't been implemented this way. This resulted in wrong output
for the test sh-flags, in compilation modes -DUSE_UCHAR_BOOLEAN and
-DUSE_CHAR_BOOLEAN, since in ParseCommandFlags, the expression
DEBUG(LOUD) didn't fit into a boolean.
 1.235 18-Dec-2020  rillig make(1): support using C99 bool for Boolean
 1.234 13-Dec-2020  rillig make(1): constify progname
 1.233 11-Dec-2020  rillig make(1): clean up comments for command line options
 1.232 06-Dec-2020  rillig make(1): clean up macros for debug logging

Using a do-while loop prevents compiler warnings about possible dangling
else. It also removes the unnecessary negation.
 1.231 05-Dec-2020  rillig make(1): define constants for enum zero-values
 1.230 29-Nov-2020  rillig make(1): use space instead of tab for preprocessor directives
 1.229 29-Nov-2020  rillig make(1): reduce memory allocation for dirSearchPath
 1.228 28-Nov-2020  rillig make(1): reduce memory allocation for CmdOpts.create
 1.227 28-Nov-2020  rillig make(1): reduce memory allocation in CmdOpts.variables
 1.226 28-Nov-2020  rillig make(1): reduce memory allocation in CmdOpts.makefiles
 1.225 28-Nov-2020  rillig make(1): reduce pointer indirection for GNode.implicitParents
 1.224 28-Nov-2020  rillig make(1): reduce pointer indirection for GNode.cohorts
 1.223 28-Nov-2020  rillig make(1): reduce pointer indirection for GNode.order_pred and order_succ
 1.222 28-Nov-2020  rillig make(1): reduce memory allocation for GNode.parents and GNode.children
 1.221 28-Nov-2020  rillig make(1): remove pointer indirection from GNode.commands

Just to save a few memory allocations. No noticeable effect on the
performance though.
 1.220 28-Nov-2020  rillig make(1): allow multiple RCS IDs in all-in-one mode
 1.219 24-Nov-2020  rillig make(1): indent make.h with tabs instead of spaces
 1.218 24-Nov-2020  rillig make(1): add high-level API for GNode.made

Having an enum whose constants must be ordered in a certain way may be
unexpected to casual readers. Hide this implementation detail in
separate functions.
 1.217 24-Nov-2020  rillig make(1): fix error handling for dependency of .END in -k mode

Fix one bug, find 4 new ones. All these bugs have been around since
2005-05-08, when dependencies on the .BEGIN, .END and .INTERRUPT nodes
were implemented. Before that, checking gn->made == ERROR was
appropriate, but adding the dependencies made ABORTED a new possible
error value from Compat_Make.
 1.216 24-Nov-2020  rillig make(1): document the enum GNodeMade

Given only the state names and their individual documentation, it is
hard to see the full picture. To make this easier, provide typical
examples of the ways that a GNode takes through these states.
 1.215 23-Nov-2020  rillig make(1): align end-of-line comments with tabs
 1.214 22-Nov-2020  rillig make(1): add more debugging for searching transformation rules
 1.213 22-Nov-2020  rillig make(1): renumber the flags in GNodeType

In plain C, bit 31 of an enum is not guaranteed to play well with binary
operators. Bit 23 was unused until now, so shift them all down.

The order of the bits is only used in Targ_PrintType.
 1.212 21-Nov-2020  rillig make(1): rename type Suff to Suffix

This avoids confusion with the module suff.c of the same name.

The existing naming convention is that the module's public functions are
named Suff_Func and its private functions are named SuffFunc. This
collides with the naming convention that a the functions of the type Suff
are called Suff_Func as well.

To resolve this collision, rename Suff to Suffix. The related types like
SuffList and the affected functions like SuffRef will be renamed in a
follow-up commit.
 1.211 21-Nov-2020  rillig make(1): rename GNode.context to vars

Especially in the variables module, the expression 'ctxt->context' looked
redundant. Having a GNode as a context sounds ok, but a context of a
context just doesn't make sense.
 1.210 16-Nov-2020  rillig make(1): clean up and extend comments in targ.c
 1.209 15-Nov-2020  rillig make(1): clean up make.h, meta.c, parse.c, str.c

The main changes are in the comments, which have been shortened and
corrected.

Some local variables changed their names.

In ParseErrorInternal, the scope of va_start is now narrower.

In ParseDoDependency, the type of tOp has been fixed.

ParseGetLine doesn't take flags anymore but instead a parsing mode.
Previously, the flags had not been combined anyway.

At the beginning of Parse_File, fatals is already guaranteed to be 0, and
even if not, it would be wrong to just discard the fatal errors.
 1.208 14-Nov-2020  rillig make(1): remove redundant parameter from str2Lst_Append
 1.207 14-Nov-2020  rillig make(1): rename DEFAULT to defaultNode

In C, uppercase names are typically used for constants, and this is not
a constant.
 1.206 12-Nov-2020  sjg Pass a writable flag to Main_SetObjdir to control writable check

For curdir and an explicit .OBJDIR target, we allow for
the directory to be read-only.
During InitObjdir we otherwise default to requiring objdir to be
writable - this can be controlled by env variable
MAKE_OBJDIR_CHECK_WRITABLE

Add unit-tests/objdir-writable

Reviewed by: christos rillig
 1.205 10-Nov-2020  rillig make(1): use consistent definition for MAKE_INLINE
 1.204 08-Nov-2020  rillig make(1): move lint option away from the debug flags

The lint option affects much more than a typical debug flag. Not only
does it produce additional diagnostics, it also changes the control flow
and fixes the traditional error handling in a few places.

No functional change.
 1.203 08-Nov-2020  rillig make(1): sort debug flags alphabetically

DEBUG_FOR had been accidentally left at the end of the list.
 1.202 08-Nov-2020  rillig make(1): fix documentation of preserveUndefined

Since it is a global variable and not a VarEvalFlags, it affects nested
subexpressions as well, and there is no way to escape it.
 1.201 08-Nov-2020  rillig make(1): fix debug output in out-of-date for cohorts (since 2003-11-14)

Before, a wrong cause for being out-of-date was printed in the debug log,
for optional cohorts. This was caused by having the same conditions
duplicated in the code, instead of putting them in a separate function.

Now the optional cohort is correctly identified as using the '::'
dependency operator.
 1.200 08-Nov-2020  rillig make(1): rename Make_OODate to GNode_IsOODate

It doesn't matter which of the make modules is in charge of determining
whether a node is out-of-date. Therefore, remove the module name from
the function name.
 1.199 08-Nov-2020  rillig make(1): rename Make_TimeStamp to GNode_UpdateYoungestChild
 1.198 08-Nov-2020  rillig make(1): fix type mismatch between int and PrintVarsMode
 1.197 07-Nov-2020  rillig make(1): add pp_skip_hspace to skip horizontal whitespace during parsing
 1.196 06-Nov-2020  rillig make(1): merge duplicate code for skipping horizontal whitespace
 1.195 06-Nov-2020  rillig make(1): move name of inline functions to the beginning of the line
 1.194 06-Nov-2020  rillig make(1): rename dieQuietly to shouldDieQuietly

It was too confusing to have a function named die that doesn't actually
die. Plus, the return type int didn't give any clue about what the
function actually returns.
 1.193 06-Nov-2020  rillig make(1): document DEBUG_LINT
 1.192 06-Nov-2020  rillig make(1): sort and renumber debug flags
 1.191 06-Nov-2020  rillig make(1): document progname
 1.190 06-Nov-2020  rillig make(1): clean up comments in make.h
 1.189 05-Nov-2020  rillig make(1): extend documentation for GNodeType constants
 1.188 04-Nov-2020  rillig make(1): group GNode fields by topic, document ParseErrorLevel
 1.187 04-Nov-2020  rillig make(1): align comments on a few commonly used variables
 1.186 04-Nov-2020  rillig make(1): move declaration of parseIncPath from main.c to make.h
 1.185 04-Nov-2020  rillig make(1): rename MAKEFILE_PREFERENCE for consistency

The names of the other special variables are all prefixed with MAKE_.
 1.184 04-Nov-2020  rillig make(1): remove unused names DTARGET, FPREFIX, etc.
 1.183 04-Nov-2020  rillig make(1): negate discardUndefined to preserveUndefined
 1.182 04-Nov-2020  rillig make(1): rename oldVars to discardUndefined

While here, moved all the documentation about this variable into a
single place.
 1.181 04-Nov-2020  rillig make(1): add missing enum tag for GNodeMade
 1.180 04-Nov-2020  rillig make(1): document that "old-style" variables are older than 1993
 1.179 01-Nov-2020  rillig make(1): negate NoExecute to GNode_ShouldExecute
 1.178 31-Oct-2020  rillig make(1): do not look up local variables like .TARGET anywhere else

Nobody defines a global variable named .TARGET since that would have
many unpredictable effects, applying to all targets at once.

Nobody defines an environment variable named .TARGET since that's
against the naming conventions for environment variables and would have
the same effect.

Because of this, there is no point looking up the variables that are
local to a GNode anywhere else. This means they cannot come from the
environment and thus their value doesn't need to be freed after use,
which makes the code simpler.

The newly added accessor functions in make.h refer to external
functions, but since that header is not used anywhere outside of
usr.bin/make, it doesn't matter. Between 2020-08-25 and 2020-10-30,
that header had been referenced by usr.bin/xinstall.
 1.177 30-Oct-2020  rillig make(1): clean up comments and local variables in var.c
 1.176 30-Oct-2020  rillig make(1): rename VAR_CMD to VAR_CMDLINE

Since make has to do with both the command line and child commands, the
former name was confusing.
 1.175 28-Oct-2020  rillig make(1): rename defIncPath to defSysIncPath

There are two variables, parseIncPath and sysIncPath, which made the
name defIncPath ambiguous.
 1.174 27-Oct-2020  rillig make(1): move debugVflag to CmdOpts
 1.173 26-Oct-2020  rillig make(1): group the command line options and arguments

By having a single struct that holds all command line options and
arguments, it is easy to see in the code when such a command line
argument is modified. It also cleans up the namespace since the command
line options don't follow a common naming style. Having them in a
struct also means that there is a single place for putting the
documentation, not two as before.

The struct also suggests to extract the initialization code out of main,
which is still too large, having more than 400 lines of code and
covering far too many topics.
 1.172 25-Oct-2020  rillig make(1): add GNode_Path to access the path of a GNode
 1.171 24-Oct-2020  rillig make(1): remove macros MIN and MAX

These macros typically evaluate one of their arguments twice. Until
2020-08-31, they had not parenthesized their arguments properly. They
are only used in a few places, therefore it doesn't hurt much to have
them expanded.
 1.170 24-Oct-2020  rillig make(1): convert macros for debug flags into enum
 1.169 24-Oct-2020  rillig make(1): remove lengthy comments from archive handling

The relevant information is already documented on OP_ARCHV, but only
since a few weeks.
 1.168 23-Oct-2020  rillig make(1): fix typos in comments
 1.167 23-Oct-2020  rillig make(1): convert error level for Parse_Error to an enum
 1.166 23-Oct-2020  rillig make(1): rename GNode.cmgn to youngestChild

The name is longer than before but also clearer.
 1.165 23-Oct-2020  rillig make(1): add test for the '::' dependency operator
 1.164 23-Oct-2020  rillig make(1): negate OP_NOP and rename it to GNode_IsTarget
 1.163 23-Oct-2020  rillig make(1): merge duplicate documentation for OP_NOP
 1.162 23-Oct-2020  rillig make(1): only define TRUE and FALSE if necessary

For -DUSE_ENUM_BOOLEAN, the macros are not necessary.
 1.161 23-Oct-2020  rillig make(1): allow compilation with Boolean implemented as char
 1.160 19-Oct-2020  rillig make(1): clean up headers, no functional change
 1.159 18-Oct-2020  rillig make(1): add tags to enum types

This allows IDEs to offer better type information than "anonymous enum".
 1.158 18-Oct-2020  rillig make(1): remove underscore from Hash_Table and Hash_Entry

For consistency with the other type names, such as GNodeListNode.
 1.157 18-Oct-2020  rillig make(1): convert NoExecute to non-inline

The header make.h is not only used by usr.bin/make but also by
usr.bin/xinstall, to get the needshell function.

That program does not declare the variables noRecursiveExecute and
noExecute, leading to an "unresolved reference" at link time. To fix
this, move the inline functions away from make.h.

It's a quirk that make.h gets included by other programs since it
contains a whole lot of definitions that are only useful in make itself.
If any, there should be a separate header that defines the public
library API of make, and only that.
 1.156 05-Oct-2020  rillig make(1): enable format string truncation warnings for parse.c

No node is ever going to have a million or more cohorts. And even if
there were, this name is only used for printing informational messages.
 1.155 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.154 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.153 05-Oct-2020  rillig make(1): replace GNode macros with inline functions

Curiously, this affects the size of the generated code: it gets smaller
than before.
 1.152 03-Oct-2020  rillig make(1): use consistent pattern for parsing whitespace

The pp and cpp in the function names stand for "parsing position" and
"const parsing position".
 1.151 28-Sep-2020  rillig make(1): remove the inline attribute from debug_printf

The code size overhead of a varargs function is much more than I had
expected. Since GCC 5 didn't inline the function anyway and it is only
used in debug mode, there is no point keeping multiple copies of that
code around.
 1.150 28-Sep-2020  rillig make(1): make debug logging simpler

This avoids referring to the debug_file variable in many places where
this implementation detail is not necessary.
 1.149 28-Sep-2020  rillig make(1): make debugging code shorter
 1.148 27-Sep-2020  rillig make(1): normalize whitespace in source code

There is no more space tab. Either only tabs or only spaces or tabs
followed by spaces, but not spaces followed by tabs.
 1.147 26-Sep-2020  rillig make(1): clean up API for finding and creating GNodes

The previous API had complicated rules for the cases in which the single
function returned NULL or what it did. The flags for that function were
confusing since passing TARG_NOHASH would create a new node even though
TARG_CREATE was not included in that bit mask.

Splitting the function into 3 separate functions avoids this confusion.
It also reveals several places where the complicated API led to
unreachable code. Such code has been removed.
 1.146 24-Sep-2020  rillig make(1): migrate MakeTimeStamp and MakeUnmark to Lst_ForEach
 1.145 23-Sep-2020  rillig make(1): fix assertion failure in -j mode with .END node

There had been two separate global variables for the .END node, and in
parallel mode, only the one in jobs.c was initialized.

The code in JobRun heads over to Compat_Make without calling Compat_Run
first, which left the variable ENDNode uninitialized.
 1.144 22-Sep-2020  rillig make(1): use fine-grained type names for lists and their nodes

This is only intended to help the human reader. There is no additional
type safety yet.
 1.143 21-Sep-2020  rillig make(1): add specific typedefs for lists

These typedefs are only intended to help human readers, they do not
provide any type-safety. They also make the pointers explicit, which
had been hidden before by the typedef for Lst and LstNode. Typing a few
'*' is less work than finding out which of the many types are pointers
and which aren't.

In meta.c, the variable "ln" served two completely different purposes,
which have been split again. Register allocation is the job of the
compiler, not of the human source code reader.
 1.142 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.141 13-Sep-2020  rillig make(1): clean up API for evaluating conditions

There was no need to make struct If publicly visible.

There was no need to have parameters in the public API that were passed
the same constants all the time.

The former function names had not been distinctive.
 1.140 13-Sep-2020  rillig make(1): remove #endif comments for very short blocks
 1.139 11-Sep-2020  rillig make(1): add wrappers around ctype.h functions

This avoids casting the argument to unsigned char, and to cast the
result of toupper/tolower back to char.
 1.138 11-Sep-2020  rillig make(1): add missing space in source code
 1.137 02-Sep-2020  rillig make(1): document the value restrictions for Boolean variables

The previous lenient rule came from the sprite.h header that was not
specific to make. To avoid confusion, only the expected values should
be stored in a Boolean variable. To help find obvious violations and
inconsistencies, there are different possibilities for the Boolean type,
during development.

In C there is no way to actually enforce this restriction at runtime.
It would be possible in C++, but the code is not ready to be compiled
with a C++ compiler.
 1.136 02-Sep-2020  rillig make(1): reduce number of stat fields returned by cached_stat

Only st_mtime and st_mode are actually filled, the remaining fields had
been set to zero. To prevent these from ever being accessed, a custom
struct make_stat replaces the previously used struct stat.

The fields in struct make_stat are intentionally named different from
the fields in struct stat because NetBSD and some other operating
systems define st_mtime as a macro, and that would not work in a field
declaration.
 1.135 02-Sep-2020  rillig make(1): use proper types in API of cached_stat and cached_lstat
 1.134 31-Aug-2020  rillig make(1): parenthesize macro arguments

Just in case anyone wants to use them for copy-and-paste.

The invocations of these macros are left cautious since the
system-provided definition of these macros may have forgotten the
parentheses as well.
 1.133 30-Aug-2020  rillig make(1): rename GNode.iParents to implicitParents

The i alone was too ambiguous. It could have meant ignore, implicit,
interactive, and probably many more.
 1.132 29-Aug-2020  rillig make(1): remove ReturnStatus, SUCCESS and FAILURE

These are used in so few places now that it is easier to use a simple
Boolean for them.
 1.131 29-Aug-2020  rillig make(1): add another Boolean variant to check during development
 1.130 29-Aug-2020  rillig make(1): allow for strict type checking for Boolean

Having Boolean aliased to int creates ambiguities since int is widely
used. Allow to occasionally compile make with -DUSE_DOUBLE_BOOLEAN to
check that the type definitions still agree.
 1.129 28-Aug-2020  rillig make(1): clean up targ.c

The main part is removing redundant or outdated information from
comments. In a few places, the expression cond ? TRUE : FALSE has been
simplified.
 1.128 28-Aug-2020  rillig make(1): print suffix flags in the standard way

This changes the output (it is now SUFF_NULL instead of just NULL), and
the order of the flags in the output is reversed.
 1.127 26-Aug-2020  rillig make(1): remove header sprite.h

Make is independent of the Sprite operating system.
 1.126 24-Aug-2020  rillig make(1): in debug mode, print GNode details in symbols

A string like OP_DEPENDS|OP_OPTIONAL|OP_PRECIOUS is much easier to read
and understand than the bit pattern 00000089.

The implementation in enum.h looks really bloated and ugly, but using
this API is as simple and natural as possible. That's the trade-off.

In enum.h, I thought about choosing the numbers in the macros such that
it is always possible to combine two of them in order to reach an
arbitrary number, because of the "part1, part2" in the ENUM__SPEC macro.
The powers of 2 are not these numbers, as 7 cannot be expressed as the
sum of two of them. Neither are the fibonacci numbers since 12 cannot
be expressed as the sum of 2 fibonacci numbers. I tried to find a
general pattern to generate these minimal 2-sum numbers, but failed.
 1.125 23-Aug-2020  rillig make(1): remove unused declarations from header files
 1.124 23-Aug-2020  rillig make(1): use proper data type for GNode.type

Theoretically this should show the enum constant names when displaying
the field in the debugger. This only happens for GNode.flags though,
but not for GNode.type. Not sure what the exact cause is.
 1.123 22-Aug-2020  rillig make(1): clean up headers

Remove redundant headers that are already included by "make.h".
Make <assert.h> available to all compilation units that use "make.h".
 1.122 22-Aug-2020  rillig make(1): remove wrong comment about possible Y2038 problem

The "time" that is mentioned is not clock time but a sequence number.
 1.121 22-Aug-2020  rillig make(1): remove unused variable jobServer
 1.120 22-Aug-2020  rillig make(1): convert GNode type constants to enum

This allows debuggers to print symbolic names for the type flags.

The names of these constants need to be revised. These flags probably
started as the 3 dependency operators (:, !, ::), and at that time, the
prefix OP_ made sense. The other flags are not related to the type of
the dependency operator and could have been placed in GNode.flags as
well.
 1.119 22-Aug-2020  rillig make(1): restructure GNode types and documentation

Having a numbered list above the type was not helpful since the numbers
didn't serve any purpose, they just consumed screen space.

Several of these list items didn't have an obvious relationship to the
struct fields. It's better to have just a rough introduction as the
type level documentation, leaving the details to the individual fields.

Converting the types and flags and other constants into separate types
and defining them outside the struct leaves more space to see the
relationship of the struct fields.

Limiting the documentation of each field to a single line, as suggested
by the end-of-line comments, reduces clarity since several of the fields
need way more documentation to be properly understood.
 1.118 20-Aug-2020  rillig make(1): remove unused function declarations
 1.117 20-Aug-2020  rillig make(1): fix wrong or outdated comments
 1.116 13-Aug-2020  rillig make(1): follow naming conventions for multiple-inclusion guards

This avoids undefined behavior.
 1.115 11-Aug-2020  rillig make(1): convert Suff.flags from #define to enum

This increases debugging support since the debugger can now display
symbolic names instead of an integer bit mask.
 1.114 10-Aug-2020  rillig make(1): fix parameter name of str_concat

The previous documentation mentioned Str_Concat, but str_concat has been
written in lowercase for years. The "flags" are not flags since they
cannot be combined, not even when they are written in hex.
 1.113 01-Aug-2020  rillig make(1): use enum for return values of Cond_Eval and friends
 1.112 31-Jul-2020  sjg Add -dL for LINT

When parsing variable assignments other than := and if
value contains '$' attempt Var_Subst the same as for :=,
if the value does not parse correctly, we get a fatal error
including file an line number.

This can greatly help with finding the cause of problems.

Reviewed by: christos
 1.111 21-Jul-2020  rillig make(1): clean up various things in var.c
 1.110 18-Jul-2020  sjg Add -dh for DEBUG_HASH

Allow tracking of max chain length, to see how well the hash
tables are working.
Pull the actual hash operation into a marco so it can be
easily changed - for experimenting.

The current hash, is pretty good.

Reviewed by: christos
 1.109 02-Jul-2020  rillig make(1): add more type safety for enums

There are several types of flags for variables, and these cannot be
mixed. To prevent accidental typos, these are defined in separate enum
types. Clang warns about direct assignments between distinct types, but
not about mixing distinct types in binary expressions like A | B. GCC
does not warn at all.
 1.108 19-Jun-2020  sjg Avoid unnecessary noise when sub-make or sibling dies

When analyzing a build log, the first 'stopped' output
from make, is the end of interesting output.

Normally when a build fails deep down in a parallel build
the log ends with many blockes of error output from make,
with all but the fist being unhelpful.

We add a function dieQuietly() which will return true
if we should supress the error output from make.
If the failing node was a sub-make, we want to die quietly.

Also when we read an abort token we call dieQuietly telling we
want to die quietly.

This behavior is suppressed by -dj or
setting .MAKE.DIE_QUIETLY=no

Reviewed by: christos
 1.107 03-Apr-2020  sjg Revert arraycount
 1.106 03-Apr-2020  sjg CHECK_VALID_META is too agressive for CMD check.

An empty CMD is perfectly valid.
So using CHECK_VALID_META results in too much rebuilding.
 1.105 30-Mar-2020  sjg make: fix -fno-common build

debug was declared extern, but debug_file was not; correct this and define
debug_file in main.c (as debug is) to fix the -fno-common build.

-fno-common will become the default with GCC10/LLVM11.

Patch from kevans at freebsd
 1.104 12-Feb-2018  sjg branches: 1.104.4; 1.104.6;
Do not treat .info as warning for -W

Reported by: lwhsu at FreeBSD.org
 1.103 20-Jul-2017  sjg Make compat.c handle SIGINT etc more like job.c

If there is a running child, pass the signal on, and
wait for it to exit before we self-terminate.

Reviewed by: christos
 1.102 07-Dec-2016  christos branches: 1.102.6;
Refactor and simplify objdir setting code.
 1.101 26-Aug-2016  dholland Add a .DELETE_ON_ERROR: magic target that causes *failed* targets as
well as *interrupted* targets to be deleted. The name and behavior of
the variable matches gmake.

Also fix a glitch in newline output on error in compat mode that I
discovered while doing it.

Closes PR 51376.
 1.100 07-Jun-2016  sjg branches: 1.100.2;
Extend the mtimes cache used by dir.c so it can be used by others.

We store both st_mtime and st_mode, since some callers care about the
later.

Reviewed by: christos
 1.99 03-Jun-2016  sjg Add cached_realpath()

realpath(3) is expensive, and meta mode at least uses it extensively.
We use cached_realpath() to save the result of successful calls to
realpath(3) in a private variable context.

This improves the worst case performance (eg examining libc with
nothing to do) by a factor of 4.

Reviewed by: christos
 1.98 18-Feb-2016  christos Collapse the 3 boolean parameter to 1 flags parameter. No functional change.
 1.97 17-Jan-2016  christos provide missing FD_CLOEXEC for the havenots.
 1.96 21-Sep-2015  pooka Add more compat defs for code compiled for !NetBSD targets.

At least GNU Hurd lacks MAXHOSTNAMELEN/MAXPATHLEN/PATH_MAX, so make sure
those have some arbitrary semi-sane values.

from Robert Millan in PR misc/50166, with some modifications from myself
 1.95 07-Sep-2014  joerg Revert all make changes except the unit tests to the state of three
weeks ago. Individual changes can be reapplied after review.
 1.94 23-Aug-2014  christos PR/46096: Jarmo Jaakkola: fix many problems with dependencies (PR 49086)

Quite extensive rewrite of the Suff module. Some ripple effects into
Parse and Targ modules too.

Dependency searches in general were made to honor explicit rules so
implicit and explicit sources are no longer applied on targets that
do not invoke a transformation rule.

Archive member dependency search was rewritten. Explicit rules now
work properly and $(.TARGET) is set correctly. POSIX semantics for
lib(member.o) and .s1.a rules are supported.

.SUFFIXES list maintenance was rewritten so that scanning of existing
rules works when suffixes are added and that clearing the suffix list
removes single suffix rules too. Transformation rule nodes are now
mixed with regular nodes so they are available as regular targets too
if needed (especially after the known suffixes are cleared).

The .NULL target was documented in the manual page, especially to
warn against using it when a single suffix rule would work.
A deprecation warning was also added to the manual and make also
warns the user if it encounters .NULL.

Search for suffix rules no longer allows the explicit dependencies
to override the selected transformation rule. A check is made in
the search that the transformation that would be tried does not
already exist in the chain. This prevents getting stuck in an infinite
loop under specific circumstances. Local variables are now set
before node's children are expanded so dynamic sources work in
multi-stage transformations. Make_HandleUse() no longer expands
the added children for transformation nodes, preventing triple
expansion and allowing the Suff module to properly postpone their
expansion until proper values are set for the local variables.

Directory prefix is no longer removed from $(.PREFIX) if the target
is found via directory search.

The last rule defined is now used instead of the first one (POSIX
requirement) in case a rule is defined multiple times. Everything
defined in the first instance is undone, but things added "globally"
are honored. To implement this, each node tracks attribute bits
which have been set by special targets (global) instead of special
sources (local). They also track dependencies that were added by
a rule with commands (local) instead of rule with no commands (global).

New attribute, OP_FROM_SYS_MK is introduced. It is set on all targets
found in system makefiles so that they are not eligible to become
the main target. We cannot just set OP_NOTMAIN because it is one of
the attributes inherited from transformation and .USE rules and would
make any eligible target that uses a built-in inference rule ineligible.

The $(.IMPSRC) local variable now works like in gmake: it is set to
the first prerequisite for explicit rules. For implicit rules it
is still the implied source.

The manual page is improved regarding the fixed features. Test cases
for the fixed problems are added.

Other improvements in the Suff module include:
- better debug messages for transformation rule search (length of
the chain is now visualized by indentation)
- Suff structures are created, destroyed and moved around by a set
of maintenance functions so their reference counts are easier
to track (this also gets rid of a lot of code duplication)
- some unreasonably long functions were split into smaller ones
- many local variables had their names changed to describe their
purpose instead of their type
 1.93 16-Jul-2014  christos PR/48367: David A. Holland: Mark possible submake nodes so that we can
avoid closing the job pipe on exec for them in order to make recursive
makes work in parallel.
 1.92 04-Sep-2013  sjg branches: 1.92.2;
Add VAR_INTERNAL as a context for variables set by make itself,
which should not override those set by makefiles.
Currently MAKEFILE is the only variable affected.

Reviewed by: christos
 1.91 18-Jun-2013  sjg Use a #define for the variable name we put in environment to pass .MAKE.LEVEL
in case we don't want to use gmake's MAKELEVEL in a different way.
 1.90 25-Feb-2013  dholland Fix obvious typo.
 1.89 12-Jun-2012  joerg branches: 1.89.2;
Replace __dead, __unused and the various printf format attributes
with versions prefixed by MAKE_ATTR_* to avoid modifying the
implementation namespace. Make sure they are available in all places
using nonints.h to fix bootstrap on Linux.
 1.88 04-Jun-2012  sjg Var_UnExport() and setenv() can both realloc environ.
Use a common variable (savedEnv) to track that to avoid wasting memory.
Also, if providing setenv and unsetenv, do getenv too to ensure a consistent
set.
 1.87 16-Sep-2011  joerg branches: 1.87.2;
Use __dead consistently. If it doesn't exist, define it away.
 1.86 04-May-2011  sjg Add .MAKE.META.BAILIWICK - to identify the scope of make's control.
meta_oodate: if a file that was written or linked within our bailiwick,
but outside of .OBJDIR is missing, add it to missingFiles.
If we get to the end of the .meta file without seeing it [re]moved,
then consider the target out-of-date.
 1.85 20-Feb-2011  joerg Use the current directory at start time for .PARSEDIR, if the filename
contains no /.
 1.84 25-Nov-2010  christos branches: 1.84.2;
Instead of keeping around the mtime of the youngest child, keep a pointer
to it, so that we can print it when we do the out of date determination.
 1.83 13-Sep-2010  sjg Add meta.c which implements "meta" mode for make.
In this mode, a .meta file is created for each target, capturing
the expanded commands used, any command output, and if filemon(9)
is available, a record of system calls which are of interest.
Not enabled unless USE_META=yes is set when building make.
Also, if FILEMON_H exists, meta.c will be compiled to use filemon(9).
 1.82 23-Apr-2010  sjg On darwin at least, vfork() fails in child of vfork().
It probably shouldn't work anyway, so avoid this.
We use the macro vFork() - a function seems to cause problems
and is unnecessary overhead.
 1.81 22-Apr-2010  sjg Just because $TMPDIR is set does not mean it is valid.
Add a central function for creating temp files so we have one place to
audit.

Reviewed by: dh
 1.80 07-Apr-2010  sjg Add:

.error "message"
.warning "message"
based on FreeBSD implementation.
add .info while were at it.

.ERROR: a target to run on error.
We pass the failing GNode to PrintOnError so it can set
.ERROR_TARGET.

.MAKE.MAKEFILE_PREFERENCE
As a means to control make's list of prefered makefile names.
(Default: "makefile Makefile")

.MAKE.DEPENDFILE
Names the file to read dependencies from
(Default ".depend")

.MAKE.MODE
Processed after all makefiles are read.
Can put make into "compat" mode (more to come).

Fix:

compat.c: Error code should not be sent to debug_file.
Make_DoAllVar: use DONE_ALLSRC to avoid processing a node multiple times.
ReadMakefile: we can simply use doing_depend to control setting MAKEFILE.
 1.79 08-Sep-2009  sjg Reviewed by: apb

Use .MAKE.LEVEL to track recursion.
The first instance of make will have .MAKE.LEVEL 0, which
can be handy for excluding rules which should not apply
in a sub-make.
gmake and freebsd's make have a similar mechanism, but each
uses a different variable to track it. Since we cannot be
compatible with both, we allow the makefiles to cope if they want
by handling the export of .MAKE.LEVEL+1 in Var_Set().
 1.78 24-Jan-2009  dsl Fixes to includes of make_malloc.h to that it actually builds when
USE_EMALLOC is undefined.
Fixes earlier fixes :-)
 1.77 24-Jan-2009  dsl Move the bmake_malloc() functions into their own .c and .h files.
Include instead of make.h in a few places.
 1.76 13-Dec-2008  dsl Use NULL instead of -1 cast to the relavant type (usually via NIL).
This was a suggestion from christos - so blame him if there is a deep
reason for using -1 :-)
 1.75 07-Dec-2008  christos add debug flag for cwd.
 1.74 15-Feb-2008  christos back all changes out until I fix it properly.
 1.73 14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.72 19-Jan-2008  sjg Implement -dl (aka LOUD) to override '@' at the start of script lines.
Based on supplied patch.

PR: 37202
 1.71 21-Dec-2007  dsl If make can't find a rule to create a file it needs to satisfy a rule
that came from .depend then just output a message and contine.
 1.70 08-Oct-2007  sjg Use .MAKE.MAKEFILES to track all the makefiles that have been read
so they can be used in dependency rules.
 1.69 05-Oct-2007  sjg Add the ability to .export variables to the environment.
 1.68 01-Oct-2007  sjg Add the ability to tweak the token output before targets in job mode.
Eg.
.MAKE.JOB.PREFIX=${.newline}---${.MAKE:T}[${.MAKE.PID}]
would produce
---make[1234] target ---
 1.67 01-Jan-2007  dsl branches: 1.67.4;
Remove the (now redundant) MAKE_BSIZE, BUF_DEF_SIZE from buf.c is used instead.
 1.66 20-Dec-2006  dsl Fix detection and reporting of dependency loops in parallel makes.
make's unit_tests should now run again.
 1.65 04-Dec-2006  dsl There really is no point calling estrdup() to get a copy of the makefile name
into every 'gnode' (aka target), instead just copy a pointer to the string
and avoid freeing the original name when we close the file.
I can't imagine any makefile set where this gives a larger footprint!
 1.64 17-Nov-2006  dsl branches: 1.64.2;
A rather large rototil in the way the parallel make code schedules jobs.
This gives a considerable speedup in the processing of .WAIT and .ORDER.
Both .WAIT and .ORDER stop both the commands of the node, and its dependant
nodes being built until the LH nodes are complete.
.WAIT only applies to the dependency line on which it appears, whereas
.ORDER applies globally between the two nodes.
In both cases dependant nodes can be built because other targets need them.
make now processes the target list left to right, scheduling child nodes
as they are needed to make other nodes (instead of attempting to generate
a bottom-up dependency graph at the start). This means that 'make -j1'
will tend to build in the same order as a non-parallel make.
Note that:
all: x y
x: a .WAIT b
y: b .WAIT a
does not generate a dependency loop.
But
x: y
.ORDER y x
does (unless something elswhere causes 'y' to be built).
 1.63 15-Oct-2006  dsl Output all debug trace output through 'debug_file' defaulting to 'stdout'.
(Almost all the debug output went there, but some went to stderr.)
Split the parsing of -d (debug flags) out into its own routine.
Allow the output filename to be changed by specifying -dF<file> to create
a log file, or -dF+<file> to append to it. <file> may be stdout or stderr.
Also change so that -d-<flags> acts on <flags> locally but doesn't copy
them to MAKEFLAGS so they aren't inherited by child makes.
I'm not 100% happy with the command line syntax for the above, so they are
currently undocumented.
 1.62 09-Oct-2006  dsl Rip out the code for the undocumented -P (don't use pipes for command
output) option. I'm sure it is baggage from the past.
 1.61 26-Aug-2006  christos Don't include <util.h> if we are not NetBSD. Other OS's don't have it.
 1.60 26-Aug-2006  christos More programs using efun.
 1.59 10-Mar-2006  christos PR/33049: OKANO Takayoshi: Fix the spelling of NetBSD RCS tags.
 1.58 26-Feb-2006  apb Make ".WAIT" apply recursively to all children of nodes on the right
hand side of the .WAIT, except when the recursive interpretation would
cause a cycle in the dependency graph.

Discussed in tech-toolchain. Reviewed by christos, sjg.
 1.57 22-Jan-2006  dsl Make .NOTPARALLEL stop the job engine issuing more than one token (instead
of trying to de-jobify the make.
You can now put .NOTPARALLEL in a submake of a recursive make (where it is
using a job-token pipe from the outer make and have it only run a single job.
You can also specify .NOTPARRALEL in the root makefile of a large recursive
make and have the submakes run multiple commands.
Add some diagnostics printfs (enabled with -dp) to the parser.
 1.56 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.55 17-Jun-2005  jmc Add new debugging option '-dn' which will leave the scripts fed into make on
-j jobs in /tmp for debugging purposes. Add a note to the man page that
this could cause problems if run a lot (due to the number of files created)
 1.54 08-May-2005  christos Now that dependencies in .BEGIN, .END, and .INTERRUPT work, allow them.
 1.53 01-May-2005  christos Don't accept dependencies for .BEGIN, .END, and .INTERRUPT since they
don't make sense or work anyway.
 1.52 15-Jul-2004  yamt define __GNUC_PREREQ__ if it isn't available on host.
 1.51 01-Jul-2004  jmc Change to use __unused instead and provide a compat definition in make.h if
not already defined from cdefs.h
 1.50 07-Dec-2003  dsl Add a -Dg3 which outputs the 'input graph' only on error exit.
Lets you see the wood for the trees...
 1.49 27-Sep-2003  sjg Implement :[] modifier to allow picking a range of words out of a variable.
Also :tW and a W flag to :C and :S to allow treating value as a single word.
Add unit tests for the above, and fix some corner cases.
Based on patches supplied by Alan Barrett <apb@cequrux.com>
 1.48 10-Sep-2003  jmmv Add the 'e' debug flag (i.e., '-d e'): when enabled, show the "target
failed" and "command failed" messages added recently. These introduce
too much noise when debugging some kind of problems, specially in pkgsrc.
 1.47 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.46 14-Jul-2003  christos Pass WARNS=3
 1.45 14-Mar-2003  thorpej Add a -X option, which prevents make(1) from putting variables
set on the command line into the environment individually. This
can be useful on systems which have a tight limit on the size
of the argument space.
 1.44 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.43 20-Mar-2002  pk Xref: parse.c, rev 1.46; make.c, rev 1.23

In these revisions `::' dependency handling was simplified by not linking
the cohort nodes into the dependency graph. This broke dependency checking
on all but the first instance of a `::' target since all of the cohort nodes
now just form a collection of disconnected dependency graphs.

Fix this by keeping a back-reference in each cohort to its leader (the
first instance of a :: node with the same name) and a count of the number
of cohorts that need to be made before dependent nodes are scheduled.

Classically, we'd need six centurions for cohort, but in this case one
suffices...
 1.42 18-Feb-2002  pk Make_HandleUse() no longer has a return value,
 1.41 04-Feb-2002  christos Remove OP_NOSUFF, fix OP_MADE in compat mode [from pk], and make the OP_MADE
comment reflect reality.
 1.40 03-Feb-2002  christos Bring down the number of stat(2) system calls from 682 to 294. This change
adds a .NOSUFF directive that has been applied to targets that have been
already made, and are not supposed to have suffix rules applied to them.
 1.39 31-Oct-2001  tv Overhaul the initialization and handling of .OBJDIR:

* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)

* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.

* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
 1.38 31-Oct-2001  tv Allow "-m" to be used in a .MAKEFLAGS: special target and get it to work.
(This splits out the "default system include paths" into its own Lst
variable, and uses it only if sysIncPath is empty. This allows sysIncPath
to be filled in by the Makefile itself.)
 1.37 16-Sep-2001  wiz Spell 'occurred' with two 'r's.
 1.36 03-Jul-2001  christos add .USEBEFORE Attribute
 1.35 09-Jun-2001  sjg Modify handling of command line variable assignments and their exporting
via MAKEFLAGS. Instead of appending them directly to .MAKEFLAGS, put
them in .MAKEOVERRIDES (and ensure they are quoted). This is now done
in Var_Set when it exports VAR_CMD's.
Use ExportMAKEFLAGS() to export MAKEFLAGS, using the combined content
of .MAKEFLAGS and .MAKEOVERRIDES (with duplicate supression).
If .MAKEFLAGS is assigned to in a Makefile, ExportMAKEFLAGS is called again.
This allows a line like:
.MAKEOVERRIDES=
to effectively stop the exporting of the command line vars in MAKEFLAGS.
 1.34 01-Jun-2001  sjg A number of semi-related changes.
1. make -dx turns on DEBUG_SHELL which causes sh -x to be used where
possible.
2. PrintOnError() is now called when make is stopping due to an error.
This routine reports the curdir and the value of any variables listed
in MAKE_PRINT_VAR_ON_ERROR.
3. Variables set via command line, are propagated to child-makes via
MAKEFLAGS. This behaviour appears to be necessary for POSIX (according
to the GNU folk anyway).
4. Do not reset MAKEFILE when reading ".depend" as this rather eliminates the
usefulness of ${MAKEFILE}.
5. Added ${.newline} as a simple means of being able to include \n in the
result of a :@ loop expansion.
6. Set ${MAKE_VERSION} if defined. Need to come up with a useful value.

Reviewed: christos
 1.33 14-Jan-2001  christos - make the second list of commands override the first like gmake does
- remember where the first command definition occured so that we can debug
things.
 1.32 10-Jan-2001  christos PR/11800: Chris Demetriou: Add -W flag to exit on parse warnings.
While I am here, s/make:.*"/%s:\1", progname/
 1.31 01-Jan-2001  sommerfeld Missing bit of last change
 1.30 30-Dec-2000  sommerfeld Add a token-passing scheme to allow a recursive make to successfully
use -j; all make's in a recursive build cooperate to limit the total
number of jobs, using a token-passing scheme.

The current token passing algorithm is similar to the one implemented
by gmake; there is a single pipe which is inherited through the entire
process hierarchy; tokens are obtained by reading a byte from the
"read end" of the pipe, and are returned by writing them to the "write
end". This exact algorithm is likely to change in the future.

Implementation details:
- Use the new trace facility to allow measurement of the
effectiveness of different token-passing schemes
- Get a token in MakeStartJobs(), return it in Make_Update()
- Eliminate Job_Full() and the jobFull global since they are
redundant with token system.
- Add an "internal" -J option (to pass the token pipe fd's down to
submakes) and a -T option for tracing.
- Change how compatMake is forced so that -j means something when
inherited by submakes.
- When waiting for a token, poll the token-passing pipe as well as
the output pipes of existing jobs.
 1.29 11-Jun-2000  mycroft Readd optimization last night. Problems earlier were partially due to the
arguments names on one function being swapped (by a previous author).

Do not do any duplicate suppression when a source list is created. Instead:
* OP_MADE protects against trying to make the source multiple times.
* A new OP_MARK flag is introduced to suppress duplicates while expanding
the .ALLSRC variable and .USE targets.
This turns the O(n^2) insertion into O(n) in most cases.

This is tested with a `make build' and some special test cases.
 1.28 10-Jun-2000  mycroft Back out last night's optimization for now.
 1.27 10-Jun-2000  mycroft Introduce an OP_MARK bit, and use it to suppress duplicates during .ALLSRC
and .USE expansion. Also, remove some more Lst_Member() checks that are now
redundant.
 1.26 01-Jun-2000  mycroft Create a `for' context, and substitute iteration variable from it using the
normal Var_Parse() path. This allows :R, etc. to work on iteration variables.
 1.25 04-May-2000  drochner branches: 1.25.2;
make cleaner C for more picky compilers
 1.24 20-Apr-2000  sjg Changes to make MAKEOBJDIRPREFIX useful.

Firstly, we ignore getenv("PWD") if MAKEOBJDIRPREFIX is set so that we always
get the same value for .CURDIR regardless of how make was invoked.

Second, when executing a command we check if it is ${.MAKE} or ${.MAKE:T}
without a preceeding chdir, if so we insert a chdir(${.CURDIR}) so that
the Makefile will be found by the child make. Note that this behaviour is
dissabled if MAKEOBJDIRPREFIX is not set or if NOCHECKMAKECHDIR is set.
See the comments in main.c for more detail.

With these two changes, one can successfully build usr/src using MAKEOBJDIRPREFIX
allowing the src to be mounted from a CD-ROM.
 1.23 16-Sep-1999  kim Make this compile on Solaris...
 1.22 15-Sep-1999  mycroft Replace the linear variable list in the GNode with a hash table. Gives a
small (~10% on my machine) speedup building libc.
Changes by: perry (+ bug fix and minor change by me)
Reviewed by: mycroft sommerfeld
 1.21 11-Nov-1998  christos This patch fixes the problem introduced in the previous commit where
parents would be get remade, even if children were not really updated
by the commands executed for them. It also makes all the children have
the real modification time set if possible, so it should fix some other
timing weirdnesses...

- collapse childMade and make fields into flags and convert them to bits
CHILDMADE and REMAKE
- introduce FORCE flag that gets set in all the parents of a child that
has no sources and does not exist.
- set oodate if the FORCE flag is set, and not if CHILDMADE
- centralize the RECHECK into Make_Recheck() and use this in make.c and compat.c
- use Make_TimeStamp for all child -> parent timestamp propagations
 1.20 18-Oct-1998  christos Only define const and volatile when __STDC__ is not defined (for BOOTSTRAP)
 1.19 21-May-1998  tv Make a MAKE_BOOTSTRAP case work on NetBSD, too, for cross-compile cases
 1.18 23-Sep-1997  fair fix some ints that should be "time_t" per PR#4139
 1.17 08-May-1997  gwr Add the new .NOPATH feature which can be used to disable .PATH search
for particular targets, i.e. .depend, objects, etc. (from Christos).
 1.16 02-May-1997  christos - Target searching addition:
Make used to only use the search path for nodes that were pure
sources (not targets of other sources). This has been corrected
and now gnu-autoconf generated Makefiles work in directories other
than the source one.

- Suffix transformation rescanning:
Suffix transformations (.c.o:; cc ...) were only recognized in
the past when both suffixes were members of the suffix list.
Thus a sequence like:
.z.b:
echo ${.TARGET}
.SUFFIXES: .z
would cause .z.b: to be inserted as a regular target (and the main
target in this case). Other make programs always add rules that
start with a period in the transformation list and never consider
them as targets. We cannot do that (consider .depend files) so we
resort to scanning the list of the current targets every time a
suffix gets added, and we mutate existing targets that are now
valid transformation rules into transformation rules. If the
transformed target was also the main target, we set the main target
to be the next target in the targets list.
 1.15 10-Mar-1997  christos Add a .MADE directive to indicated that the children of a target are
up-to-date, even when they are not. This is to simulate our current
make install behavior with proper dependencies.
 1.14 20-Feb-1997  christos Reported by cgd: fix .USE directive problems:
1. ${.*} variables did not get expanded in dependencies.
2. expanded ${.*} variables in .USE dependencies can cause tree
restructuring; handle it.
3. in compat mode, expand .USE before evaluating the list of targets,
instead of doing .USE expansions on demand, because they can cause
tree restructuring.
 1.13 31-Dec-1996  christos BSD did not traditionally have <sys/cdefs.h>; use BSD4_4 instead and include
<sys/param.h> to grab it.
 1.12 31-Dec-1996  christos define const and volatile for non __STDC__
 1.11 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.10 13-Aug-1996  christos Protect __P from being multiply defined (for systems that already define it)
 1.9 06-Mar-1996  christos branches: 1.9.4;
Fix PR/2118; apply sysincludes patch.
 1.8 04-Feb-1996  christos fix pr/1421 and pr/1997
 1.7 16-Dec-1995  christos - Added .WAIT to synchronize between sources like other pmake variants.
- Updated documentation to include .ORDER .PARALLEL .NO_PARALLEL .NONPARALLEL
 1.6 14-Jun-1995  christos - $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.5 09-May-1994  glass bootstrap improvements
 1.4 17-Apr-1994  glass bootstrap changes
 1.3 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9.4.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.25.2.1 23-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.64.2.2 05-Jun-2007  bouyer Apply patch (requested by tron in ticket #696):
usr.bin/make/compat.c patch
usr.bin/make/cond.c patch
usr.bin/make/dir.c patch
usr.bin/make/for.c patch
usr.bin/make/main.c patch
usr.bin/make/make.1 patch
usr.bin/make/make.c patch
usr.bin/make/make.h patch
usr.bin/make/nonints.h patch
usr.bin/make/parse.c patch
usr.bin/make/str.c patch
usr.bin/make/targ.c patch
usr.bin/make/util.c patch
usr.bin/make/var.c patch

Synchronize make(1) with HEAD branch to increase perfomance and
improve stability.
 1.64.2.1 20-Dec-2006  bouyer branches: 1.64.2.1.2;
Pull up following revision(s) (requested by dsl in ticket #285):
usr.bin/make/cond.c: revision 1.36
usr.bin/make/parse.c: revision 1.121-1.124
usr.bin/make/make.h: revision 1.65
usr.bin/make/targ.c: revision 1.46
usr.bin/make/main.c: revision 1.138-1.139
Simplify the code that processes .if lines.
It doesn't need a two-dimensional array to remember the states of .if lines.
It would be even simpler if we didn't try to detect .else and .elif lines
that follow .else lines.
Unfortunately this isn't the code that is stupendously slow...
Unknot this code slightly by avoiding 'break/return; else' and by putting
the short parts of some conditionals first.
First step towards speeding up the parsing of makefiles (esp. the unwanted
parts of .if clauses).
There should be no changes to the logic.
There really is no point calling estrdup() to get a copy of the makefile name
into every 'gnode' (aka target), instead just copy a pointer to the string
and avoid freeing the original name when we close the file.
I can't imagine any makefile set where this gives a larger footprint!
Add anewline to the end of the error message output when the debug log
file cannot be opened.
Put the big block of code that was common to ParseDoInclude() and
ParseTraditionalInclude() into a separate routine.
Fix the 'use after free' and 'free on item not malloced' that got added
to ParseTraditionalInclude() in Feb 2006 (rev 1.111).
Kill the 'PTR' struct and put both its members into IFile.
Remove the parameter from ParseEOF(), 1 of the 3 calls passed the wrong value!
Fortunately another test stopped anything nasty happening, we'll use that
test instead.
Revert part of a recent commit.
ParseEOF() shouldn't close the original file.
Some minor changes:
- Only test 'printVars' once.
Has side effect of not trying to find the 'main' target for '-V varname'.
- Only reap the single child process in Cmd_Exec(),
I think this is for 'xx != cmd' so probobably no other children should exist.
- Don't read and parse .depend if '-r' and '-V varname' are set.
I suspect that .depend shouldn't affect the output of any -V command...
 1.64.2.1.2.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.67.4.3 23-Mar-2008  matt sync with HEAD
 1.67.4.2 09-Jan-2008  matt sync with HEAD
 1.67.4.1 06-Nov-2007  matt sync with HEAD
 1.84.2.1 05-Mar-2011  bouyer Sync with HEAD
 1.87.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.87.2.1 30-Oct-2012  yamt sync with head
 1.89.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.89.2.1 23-Jun-2013  tls resync from head
 1.92.2.1 10-Aug-2014  tls Rebase.
 1.100.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.102.6.1 07-May-2021  martin Pull up following revision(s) (requested by mrg in ticket #1678):

bin/pax/options.c: revision 1.119
usr.bin/config/scan.l: revision 1.32
usr.bin/make/main.c: revision 1.274
bin/pax/extern.h: revision 1.60
usr.bin/config/defs.h: revision 1.106
usr.bin/make/make.h: revision 1.105
sbin/newfs_udf/udf_create.c: revision 1.27 (patch)
sbin/newfs_udf/newfs_udf.h: revision 1.7 (patch)
usr.bin/config/main.c: revision 1.100
usr.sbin/installboot/Makefile: revisions 1.53,1.54 (patch)
usr.sbin/installboot/installboot.h: revision 1.41 (patch)
usr.sbin/installboot/machines.c: revisisons 1.41,1.42 (patch)

Avoid depending on common symbols.
 1.104.6.1 30-Apr-2021  martin Pull up following revision(s) (requested by mrg in ticket #1263):

bin/pax/options.c: revision 1.119
usr.bin/config/scan.l: revision 1.32
usr.bin/make/main.c: revision 1.274
bin/pax/extern.h: revision 1.60
usr.bin/config/defs.h: revision 1.106
usr.bin/make/make.h: revision 1.105
sbin/newfs_udf/udf_create.c: revision 1.27 (patch)
sbin/newfs_udf/newfs_udf.h: revision 1.7 (patch)
usr.bin/config/main.c: revision 1.100

Avoid depending on common symbols.
 1.104.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.339.2.1 02-Aug-2025  perseant Sync with HEAD
 1.28 29-Jun-2025  rillig make: in cleanup mode, initialize freshly allocated memory

This helps during debugging.
 1.27 12-Jun-2025  rillig make: use a common style for unexpected error messages

In enomem, report the actual error instead of a fixed ENOMEM.
 1.26 07-Jan-2022  rillig branches: 1.26.4;
make: rename local variable in bmake_malloc

The length of a string does not include the trailing '\0'.

No binary change.
 1.25 19-Jan-2021  rillig make(1): remove do-not-format markers from comments

These markers had been used inconsistently. Furthermore the source code
had not been formatted automatically before 2020 at all, otherwise there
wouldn't have been any trailing whitespace left.
 1.24 07-Dec-2020  rillig make(1): remove duplicate code from bmake_strdup

Inlining is the job of the compiler, not of humans.
 1.23 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.22 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.21 03-Oct-2020  rillig make(1): clean up #include sections
 1.20 01-Oct-2020  rillig make(1): remove redundant function prototypes
 1.19 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.18 02-Sep-2020  rillig make(1): remove redundancy from comments in make_malloc.c
 1.17 29-Aug-2020  rillig make(1): fix build with -DUSE_EMALLOC
 1.16 29-Aug-2020  rillig make(1): add bmake_strsedup for duplicating a substring
 1.15 20-Aug-2020  rillig make(1): remove unreached code from bmake_strndup

The "at most" branch was never taken since all call sites in var.c only
ever need a substring, and the target buffer is not limited. Therefore
rename the function and make it simpler.

It's ok that bmake_strldup is defined as estrndup in case of USE_EMALLOC
since that function's implementation is compatible to the "copy
exactly", it just contains some extra null checks that will never match
since the variable values cannot (well, or should not) contain null
bytes. Theoretically they can, but the behavior then depends on the
exact implementation and is unreliable, therefore nobody does this.
After all, Makefiles are used for text processing, not for binary data.
 1.14 12-Aug-2020  rillig make(1): remove unnecessary test from bmake_strndup

The passed memory is never NULL.
 1.13 12-Aug-2020  rillig make(1): in bmake_strndup, only scan the relevant part of the string

Just in case the given str is not really a string.

The POSIX 2018 documentation on strndup does not specify as clearly as
possible whether s has to be a string or whether raw memory is
acceptable as well. It only indirectly calls the s parameter of strndup
a string.
 1.12 03-Jul-2020  rillig make(1): remove redundant parentheses around return values
 1.11 16-Apr-2017  dholland nowadays function specifiers go in declaration_specifiers
(not after the declarator)
 1.10 20-Jun-2012  sjg branches: 1.10.14; 1.10.18;
Do not include make_malloc.h or declare progname,
both are already done in make.h
 1.9 12-Jun-2012  joerg Replace __dead, __unused and the various printf format attributes
with versions prefixed by MAKE_ATTR_* to avoid modifying the
implementation namespace. Make sure they are available in all places
using nonints.h to fix bootstrap on Linux.
 1.8 10-Jun-2012  wiz Declare enomem __dead for clang.
 1.7 18-May-2012  sjg Avoid nested extern declaration warnings
 1.6 25-Dec-2010  dholland branches: 1.6.6;
Many C libraries don't set errno when malloc fails, so always use
strerror(ENOMEM).
 1.5 24-Jan-2009  dsl Fix sense of MAKE_NATICE test.
 1.4 24-Jan-2009  dsl Add #ifndef MAKE_NATIVE around __RCSID
 1.3 24-Jan-2009  dsl Fixes to includes of make_malloc.h to that it actually builds when
USE_EMALLOC is undefined.
Fixes earlier fixes :-)
 1.2 24-Jan-2009  cegger buildfixes for OSX:
- include <sys/types> for size_t
- progname is undeclared
- include <string.h> for string functions like strlen()
- include <errno.h> for errno
 1.1 24-Jan-2009  dsl Move the bmake_malloc() functions into their own .c and .h files.
Include instead of make.h in a few places.
 1.6.6.2 30-Oct-2012  yamt sync with head
 1.6.6.1 23-May-2012  yamt sync with head.
 1.10.18.1 21-Apr-2017  bouyer Sync with HEAD
 1.10.14.1 26-Apr-2017  pgoyette Sync with HEAD
 1.26.4.1 02-Aug-2025  perseant Sync with HEAD
 1.18 15-Dec-2021  rillig make: remove bmake_free

It was only used in 2 places, and in both these places, the pointer was
never null.
 1.17 15-Dec-2021  rillig make: mark several functions whose result must be used

Suggested by sjg, to catch more bugs like the memory leak in cond.c
1.303 from 2021-12-13.

No binary change.
 1.16 19-Jan-2021  rillig make(1): remove do-not-format markers from comments

These markers had been used inconsistently. Furthermore the source code
had not been formatted automatically before 2020 at all, otherwise there
wouldn't have been any trailing whitespace left.
 1.15 30-Dec-2020  rillig make(1): format multi-line comments
 1.14 15-Dec-2020  rillig make(1): indent hash.h and make_malloc.h with tabs instead of spaces
 1.13 10-Nov-2020  rillig make(1): use consistent definition for MAKE_INLINE
 1.12 19-Oct-2020  rillig make(1): clean up headers, no functional change
 1.11 13-Sep-2020  rillig make(1): fix position of MAKE_ATTR_UNUSED in inline functions

The attribute needs to be before the return type, otherwise GCC 5
complains that Hash_GetValue is defined but not used, when compiling
with USER_CPPFLAGS=-Dinline=. The other functions don't get any
warnings. It's probably because Hash_GetValue is the only inline
function that returns a pointer.
 1.10 29-Aug-2020  rillig make(1): fix build with -DUSE_EMALLOC
 1.9 29-Aug-2020  rillig make(1): add bmake_strsedup for duplicating a substring
 1.8 25-Aug-2020  rillig make(1): allow make to be compiled in C90 mode

Since the inline functions are the only C99 feature used by now, setting
USER_CFLAGS='-std=c90 -ansi -Dinline=' is enough for compiling make with
a C90 compiler.
 1.7 20-Aug-2020  rillig make(1): remove unreached code from bmake_strndup

The "at most" branch was never taken since all call sites in var.c only
ever need a substring, and the target buffer is not limited. Therefore
rename the function and make it simpler.

It's ok that bmake_strldup is defined as estrndup in case of USE_EMALLOC
since that function's implementation is compatible to the "copy
exactly", it just contains some extra null checks that will never match
since the variable values cannot (well, or should not) contain null
bytes. Theoretically they can, but the behavior then depends on the
exact implementation and is unreliable, therefore nobody does this.
After all, Makefiles are used for text processing, not for binary data.
 1.6 01-Aug-2020  rillig make(1): use consistent indentation in source code

Tabs for multiples of 8, then spaces.

The usage string has been kept as-is since the spaces there are
indentional and do influence the output.
 1.5 01-Aug-2020  rillig make(1): avoid calls to free(3) in the common case of a NULL pointer
 1.4 24-Jan-2009  dsl Fixes to includes of make_malloc.h to that it actually builds when
USE_EMALLOC is undefined.
Fixes earlier fixes :-)
 1.3 24-Jan-2009  cegger buildfixes for OSX:
- include <sys/types> for size_t
- progname is undeclared
- include <string.h> for string functions like strlen()
- include <errno.h> for errno
 1.2 24-Jan-2009  cegger buildfix: remove RCSID. It conflicts with the definition in the .c files.
 1.1 24-Jan-2009  dsl Move the bmake_malloc() functions into their own .c and .h files.
Include instead of make.h in a few places.
 1.219 04-Aug-2025  rillig make: fix signedness conversion compilation error

meta.c:1696:40: error: conversion to ‘size_t’ {aka ‘long unsigned int’}
from ‘ssize_t’ {aka ‘long int’} may change the sign of the result
[-Werror=sign-conversion]
 1.218 04-Aug-2025  sjg Always pass valid length to meta_job_output.
 1.217 04-Aug-2025  sjg meta_job_output() use size_t for len
 1.216 03-Aug-2025  sjg make: ensure output captured in meta file is accurate

In CollectOutput() a newline before the end of job->outBuf
results in a short write to stdout, but meta_job_output()
was recording the entire string in the meta file, so on
next call the left overs would be duplicated in the meta file.

Pass a length to meta_job_output() if it should only report part of
the data in meta file.
 1.215 13-Jun-2025  rillig make: do not discard empty lines in the output of a command
 1.214 13-Jun-2025  rillig make: omit redundant call to strlen during output of a parallel job
 1.213 12-Jun-2025  rillig make: use a common style for unexpected error messages

In enomem, report the actual error instead of a fixed ENOMEM.
 1.212 22-Apr-2025  rillig make: move struct Job from job.h to job.c

The content of this struct is an implementation detail, and other parts
of make only need to access very few parts of it.
 1.211 11-Apr-2025  rillig make: use "file:123" format in meta mode
 1.210 02-Jun-2024  rillig branches: 1.210.2;
make: sync VarEvalMode constant names with their debug log names
 1.209 25-May-2024  rillig make: replace magic numbers with POSIX FILENO constants

No binary change.
 1.208 27-Apr-2024  rillig make: simplify freeing of lists
 1.207 17-Dec-2023  rillig make: clean up unused return value of str2Lst_Append

No functional change.
 1.206 19-Aug-2023  sjg meta_ignore: check metaIgnorePaths on raw path

Some path prefixes can trigger automount, if we want to ignore them
it might be best to check metaIgnorePaths before we call realpath.
If the raw path does not match, check again after realpath.
 1.205 28-Mar-2023  rillig make: declare all common symbols in headers, unexport others

No functional change.
 1.204 28-Feb-2023  sjg Use inline function rather that macro BM
 1.203 25-Feb-2023  sjg meta.c: use macro to access job->bm

and if job is NULL use Mybm.

No functional change.
 1.202 14-Feb-2023  rillig make: clean up calls to Var_Subst

None of the calls to Var_Subst used the return value, and the return
value was always VPR_OK.

No functional change.
 1.201 28-Sep-2022  sjg Don't ignore return from snprintf or getcwd
 1.200 15-Apr-2022  rillig make: do not use __CONCAT and __STRING in meta_needed

Using __CONCAT for identifiers makes it impossible to find their usages
easily, as could be seen in targ.c 1.22 from 2001-07-03. It also
requires that the parts of the identifier are not macros themselves.

No binary change.
 1.199 04-Mar-2022  sjg Fix some unused warnings
 1.198 09-Feb-2022  rillig make: remove redundant conditions

A line starting with '======' is parsed as a variable assignment, with
an empty variable name and a value starting with '=====', making that
condition unreachable.

No functional change.
 1.197 08-Feb-2022  sjg Use a variable to store command line to be filtered.

This avoids any nasty side effects from content of command line.

Reviewed by: rillig
 1.196 04-Feb-2022  rillig make: use unsigned int for line numbers everywhere

Previously, some line numbers were stored as signed int while others
were stored as size_t. Since line numbers are never negative, use an
unsigned type. Since the maximum file size for makefiles is 1 GB (see
loadfile), unsigned int is large enough even on 64-bit platforms.

Using a single data types reduces the number of type conversions. Using
unsigned int improves compatibility with C90 (printf %u instead of %zu),
which is needed by bmake, which is derived from usr.bin/make.

No functional change.
 1.195 27-Jan-2022  sjg Allow local variable assignments in dependency lines

The variable is set in the context of the target.
This syntax has been supported by gmake for ~ever.
If necessary a makefile can set .MAKE.TARGET_LOCAL_VARIABLES=false
to disable this.

Expose GetBooleanExpr so parse.c can use it.
 1.194 26-Jan-2022  rillig make: clean up eat_dots for meta mode, part 2

At least on OpenBSD, "If the src and dst strings overlap, the behavior
is undefined" (since 2013-09-25), so rather use memmove instead.

Keep all other bugs for now, for example "/a/b//../" is reduced to
"/a/b/" instead of the correct "/a/", and for repeated "/././././" in
long paths, the performance is quadratic instead of linear.

Inline the two calls to eat_dots, turning the first into a two-liner.
 1.193 26-Jan-2022  rillig make: clean up eat_dots for meta mode

No binary change.
 1.192 15-Jan-2022  rillig make: replace Var_Value with Var_Exists where applicable

The latter function already existed in 1993, no idea why it was not
used.

No functional change.
 1.191 15-Jan-2022  rillig make: remove unnecessary functions for expanding variable names

In meta mode, the affected variable patterns do not contain a '$'.

Outside of meta mode, Global_SetExpand was only called a single time, so
inline that call.

No functional change.
 1.190 15-Jan-2022  rillig make: merge duplicate code for expanding variable expressions

No functional change.
 1.189 15-Jan-2022  rillig make: remove trailing whitespace in meta.c
 1.188 14-Jan-2022  sjg meta_cmd_cmp: use bool for once

Just use Buf_Init() some mallocs will be inevitable.
 1.187 13-Jan-2022  sjg meta.c: add .MAKE.META.CMP_FILTER

On rare occasions it is useful to be able to filter command lines
before comparison.
 1.186 13-Dec-2021  rillig make: fix indentation in meta.c
 1.185 27-Nov-2021  rillig make: remove CONSTCOND comments, lint no longer needs them
 1.184 24-Oct-2021  sjg Do not ignore write failures.

We should not ignore failure to write to cmdFILE,
meta files and filemon.

Reviewed by: rillig
 1.183 19-Aug-2021  rillig make: fix lint warning about strrchr discarding 'const'

No functional change.
 1.182 14-Aug-2021  rillig make: fix lint warning about strchr removing 'const'

No functional change.
 1.181 04-Apr-2021  rillig make: rename a few functions to be more descriptive

No functional change.
 1.180 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.179 15-Mar-2021  rillig make: replace enum bit-field with struct bit-field for VarEvalFlags

This makes the code easier to read, especially in var.c. It also makes
debugging sessions easier since some debuggers don't show enum
bit-fields symbolically as soon as more than one bit is set.

The code outside var.c is basically unchanged, except that instead of
passing the individual flags, there are 4 predefined evaluation modes.
These suffice for all practical use cases. Only in the implementation
deep inside var.c, the value of the flags keepDollar and keepUndef
differs.

There is no way of passing the struct to EnumFlags_ToString, which means
the ToString function has to be spelled out explicitly. This allows for
fine-tuning the representation in the debug log, to reduce the amount of
uppercae letters.

No functional change.
 1.178 22-Feb-2021  rillig make: remove freestanding freeIt variables

These variables all belong to a string variable. Connect them using
FStr, which reduces the number of variables to keep track of.

No functional change.
 1.177 05-Feb-2021  sjg Avoid strdup in mkTempFile

Require caller to pass a buffer and size if they
want the tempfile not unlinked.

Add Job_TempFile to handle blocking signals around
call to mkTempFile, so that meta_open_filemon can use it
in jobs mode.
 1.176 05-Feb-2021  rillig make: in the Var_ functions, move the scope to the front

This change provides for a more natural reading order in the code.
Placing the scope first makes it immediately clear in which context the
remaining parameters are interpreted.

No functional change.
 1.175 04-Feb-2021  rillig make: rename some VAR constants to SCOPE

The word "context" does not fit perfectly to the variables that are
associate with a GNode, as the context is usually something from the
outside and the variables are more like properties inherent to the
GNode.

The term "global context" fits even less. Since the thing where
variables are looked up is commonly named a scope, use that term
instead.

This commit only renames the global variables VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE, plus a few very closely related comments. These are:

GNode.vars (because of line breaks)
GNode_Free (dito)
varname-make_print_var_on_error.mk
varname-make_print_var_on_error-jobs.mk

The debug message in Var_Stats is left as-is since there is no unit test
for it yet.

The other renamings (variable names "context", "ctxt", as well as
further comments) will be done in a follow-up commit.
 1.174 03-Feb-2021  rillig make: rename Var_Delete to Var_DeleteExpand, Var_DeleteVar to Var_Delete

The function names now follow the naming scheme from the other functions
that handle variables.

There are several calls that remain syntactically unchanged but that
omit the call to strchr('$') now. Since all these calls use constant
variable names, there is no functional change.
 1.173 03-Feb-2021  rillig make: replace Global_AppendExpand with Global_Append

All callers with a variable name that is guaranteed to not contain a
dollar sign have been converted to call Global_Append instead of the
previous Global_AppendExpand. After that, Global_AppendExpand was
unused, therefore it was effectively just renamed.
 1.172 03-Feb-2021  rillig make: replace Global_SetExpand with Global_Set for constant names
 1.171 03-Feb-2021  rillig make: use shortcut functions Global_SetExpand and Global_AppendExpand

There are many places where global variables are set or appended to. To
reduce clutter and code size, encode the VAR_GLOBAL in the function
name.

The word Expand in the function names says that the variable name is
expanded. In most of the cases, this is not necessary, but there are no
corresponding functions Global_Set or Global_Append yet.

Encoding the information whether the name is expanded or not in the
function name will make inconsistencies obvious in future manual code
reviews. Letting the compiler check this by using different types for
unexpanded and expanded variable names is probably not worth the effort.
There are still a few bugs to be fixed, such as in SetVar, which expands
the variable name twice in a row.
 1.170 01-Feb-2021  rillig make: clean up comments
 1.169 16-Jan-2021  rillig make(1): fix a few inconsistencies for lint's strict bool mode
 1.168 10-Jan-2021  rillig make(1): consistently use boolean expressions in conditions

Most of the make code already followed the style of explicitly writing
(ptr != NULL) instead of the shorter (ptr) in conditions.

The remaining 50 instances have been found by an experimental,
unpublished check in lint(1) that treats bool expressions as
incompatible to any other scalar type, just as in Java, C#, Pascal and
several other languages.

The only unsafe operation on Boolean that is left over is (flags &
FLAG), for an enum implementing a bit set. If Boolean is an ordinary
integer type (the default), some high bits may get lost. But if Boolean
is the same as _Bool (by compiling with -DUSE_C99_BOOLEAN), C99 6.3.1.2
defines that a conversion from any scalar to the type _Bool acts as a
comparison to 0, which cannot lose any bits.
 1.167 09-Jan-2021  rillig make(1): fix lint warnings
 1.166 31-Dec-2020  rillig make(1): replace pointers in controlling conditions with booleans
 1.165 22-Dec-2020  rillig make(1): fix return type of macro DEBUG

This macro was supposed to return a boolean expression all the time, it
just hadn't been implemented this way. This resulted in wrong output
for the test sh-flags, in compilation modes -DUSE_UCHAR_BOOLEAN and
-DUSE_CHAR_BOOLEAN, since in ParseCommandFlags, the expression
DEBUG(LOUD) didn't fit into a boolean.
 1.164 20-Dec-2020  rillig make(1): fix undefined behavior in meta_oodate

Do not increment a null pointer.

Do not assign to a variable twice in the same statement. To be fair,
this may be safe because of the sequence point when the function is
called, but anyway, it looks too close to undefined behavior.
 1.163 20-Dec-2020  rillig make(1): reduce scope of cp in meta_oodate

That function is way too long (550 lines) and has too creative variable
names such as fname, fname1, fname2, fname3.
 1.162 20-Dec-2020  rillig make(1): fix declared variable type in printCMDs

No functional changes since StringListNode and GNodeListNode are both
typedefs of a simple generic ListNode.
 1.161 20-Dec-2020  rillig make(1): change return type of Var_Value to FStr
 1.160 13-Dec-2020  rillig make(1): replace %zu with %u in printf calls

This is needed to compile bmake with GCC 2.8.1 on SunOS 5.9.

To support ancient systems like this, the whole code of usr.bin/make is
supposed to use only ISO C90 features, except for filemon, which is not
used on these systems.
 1.159 13-Dec-2020  rillig make(1): add str_basename to reduce duplicate code

The function basename from POSIX has a few unfortunate properties, it is
allowed to return a pointer to static memory. This is too unreliable,
therefore this trivial own implementation.
 1.158 10-Dec-2020  rillig make(1): split JobFlags into separate fields

Having all these flags in a single bitmask makes it harder to see where
exactly they can possibly be used since their state could also be
modified using the unsuspicious job->flags = 0. Using individual names
just leaves the single memset, and that is only used during
initialization.
 1.157 05-Dec-2020  rillig make(1): remove unused parameter from meta_needed
 1.156 29-Nov-2020  rillig make(1): reduce memory allocation in meta_oodate
 1.155 29-Nov-2020  rillig make(1): reduce memory allocation in meta mode
 1.154 29-Nov-2020  rillig make(1): use space instead of tab for preprocessor directives
 1.153 28-Nov-2020  rillig make(1): remove pointer indirection from GNode.commands

Just to save a few memory allocations. No noticeable effect on the
performance though.
 1.152 28-Nov-2020  rillig make(1): rename parameter in meta_needed and meta_create

It conflicts with the global variable in dir.c when make is built in
all-in-one mode.
 1.151 28-Nov-2020  rillig make(1): fix local variable name in meta_create
 1.150 27-Nov-2020  rillig make(1): inline meta_file_t for printCMD

This struct had only been necessary as long as printCMD was a callback
to Lst_ForEach or Lst_ForEachUntil.
 1.149 27-Nov-2020  rillig make(1): inline Lst_ForEachUntil in meta mode

This means no more unnecessary void pointers in function signatures and
no more abstraction level at checking a single element of a list. In
most cases it is more appropriate to define a function that operates on
the list as a whole, thereby hiding implementation details like the
ListNode from the caller.
 1.148 23-Nov-2020  rillig make(1): remove redundant null check from meta_needed

The result of bmake_realloc can never be NULL.
 1.147 23-Nov-2020  rillig make(1): use comparisons in boolean expressions

The generated code stays exactly the same.
 1.146 23-Nov-2020  rillig make(1): use properly typed comparisons in boolean contexts
 1.145 23-Nov-2020  rillig make(1): align end-of-line comments with tabs
 1.144 15-Nov-2020  rillig make(1): clean up make.h, meta.c, parse.c, str.c

The main changes are in the comments, which have been shortened and
corrected.

Some local variables changed their names.

In ParseErrorInternal, the scope of va_start is now narrower.

In ParseDoDependency, the type of tOp has been fixed.

ParseGetLine doesn't take flags anymore but instead a parsing mode.
Previously, the flags had not been combined anyway.

At the beginning of Parse_File, fatals is already guaranteed to be 0, and
even if not, it would be wrong to just discard the fatal errors.
 1.143 14-Nov-2020  rillig make(1): remove redundant struct make_stat

In the cache for stat(2) and lstat(2), only one of the two timestamps
was ever used. To prevent a result from stat(2) leaking into the cache
for lstat(2), there have been two completely separate caches all the
time. Using different fields in the struct was therefore unnecessary.

By removing the redundant field, the internal struct in the cache is the
same as the external struct. This makes one of them redundant, thus
struct make_stat has been renamed to cached_stat, which better describes
its purpose, and the internal struct cache_st has been removed.

Just as before, the cache prevents any direct access to its internal
data. When passing it to the caller, it is copied.

Just as before, the field names of struct cached_stat cannot correspond
to those from struct stat, since the latter are often defined as macros.
Therefore they are prefixed with cst instead of st.

The redundancy had been added on 2020-06-05.
 1.142 14-Nov-2020  rillig make(1): remove redundant parameter from str2Lst_Append
 1.141 08-Nov-2020  rillig make(1): use strict typing in conditions of the form !var
 1.140 07-Nov-2020  rillig make(1): fix inconsistent indentation after #ifdef

Combining #ifdef with regular if-then-else calls for trouble.
 1.139 07-Nov-2020  rillig make(1): clean up code stylistically

* Replace character literal 0 with '\0'.
* Replace pointer literal 0 with NULL.
* Remove redundant parentheses.
* Parentheses in multi-line conditions are not redundant at the
beginning of a line.
* Replace a few !ptr with ptr == NULL.
* Replace a few ptr with ptr != NULL.
* Replace (expr & mask) == 0 with !(expr & mask).
* Remove redundant braces for blocks in cases where the generated code
stays the same. (Assertions further down in the code would get
different line numbers.)
* Rename parameters in CondParser_String to reflect the data flow.
* Replace #ifdef notdef with #if 0.

The generated code stays exactly the same, at least with GCC 5.5.0 on
NetBSD 8.0 amd64 using the default configuration.
 1.138 05-Nov-2020  rillig make(1): remove redundant parentheses from sizeof operator

The parentheses are only needed if the argument is a type, not an
expression.
 1.137 04-Nov-2020  rillig make(1): remove mistyped extern variable

Robust programs don't have extern variable declarations in .c files, as
that risks incomatible definitions that are not detected by the compiler
and invoke undefined behavior. Make make a little more robust.
 1.136 31-Oct-2020  rillig make(1): make memory allocation simpler in meta_create and meta_oodate

Since there is only a single variable left that needs to be freed at the
end (and probably never actually needs to be freed since nobody defines
an environment variable named .OBJDIR), there is no need to loop over
these variables.
 1.135 31-Oct-2020  rillig make(1): do not look up local variables like .TARGET anywhere else

Nobody defines a global variable named .TARGET since that would have
many unpredictable effects, applying to all targets at once.

Nobody defines an environment variable named .TARGET since that's
against the naming conventions for environment variables and would have
the same effect.

Because of this, there is no point looking up the variables that are
local to a GNode anywhere else. This means they cannot come from the
environment and thus their value doesn't need to be freed after use,
which makes the code simpler.

The newly added accessor functions in make.h refer to external
functions, but since that header is not used anywhere outside of
usr.bin/make, it doesn't matter. Between 2020-08-25 and 2020-10-30,
that header had been referenced by usr.bin/xinstall.
 1.134 31-Oct-2020  rillig make(1): fix indentation in source code
 1.133 30-Oct-2020  rillig make(1): change char * to void * in Var_Value

The only purpose of the parameter freeIt is to free the memory
associated with the return value. To do this, no pointer arithmetic is
needed. Therefore, change to a void pointer, to catch accidental use of
that pointer.
 1.132 30-Oct-2020  rillig make(1): fix indentation in source code
 1.131 25-Oct-2020  rillig make(1): add GNode_Path to access the path of a GNode
 1.130 24-Oct-2020  rillig make(1): inline Lst_Find in meta_oodate
 1.129 24-Oct-2020  rillig make(1): make Lst_RemoveIf simpler in meta_oodate

Using Lst_Find and Lst_FindFrom to implement Lst_RemoveIf was a bad
idea. It made the code much more complicated than necessary. There is
no predefined Lst_RemoveIf, but that can be implemented easily. By
inlining the list handling, path_match does not need void pointers
anymore.

Freeing the path from the missingFiles list had been implemented in a
surprisingly complicated way, intermangling it unnecessarily with the
list operations, even though these are completely independent.
 1.128 24-Oct-2020  rillig make(1): remove redundant parameter from meta_name
 1.127 19-Oct-2020  rillig make(1): inline simple Lst getters

The function call variant takes more screen space than the direct field
access. Having an abstract API is usually a good idea, in this case of
simple read-only member access it makes the code more difficult to read.

LstNode_Set has been kept as a function since it is not a read-only
accessor function.
 1.126 19-Oct-2020  rillig make(1): remove void pointers from printCMD
 1.125 18-Oct-2020  rillig make(1): rename Lst_Init to Lst_New

For the other types such as HashTable and Buffer, the Init function does
not allocate the memory for the structure itself, it only fills it.
 1.124 18-Oct-2020  rillig make(1): prepare for WARNS=6

The FD_* macros from sys/sys/fd_set.h use signed integers on NetBSD 8
and thus produce conversion errors. On NetBSD 9, these macros are fixed
to use 1U instead of 1.
 1.123 18-Oct-2020  rillig make(1): replace execError with execDie

All calls to this function were followed by _exit(1).
 1.122 28-Sep-2020  rillig make(1): make debug logging simpler

This avoids referring to the debug_file variable in many places where
this implementation detail is not necessary.
 1.121 28-Sep-2020  rillig make(1): make debugging code shorter
 1.120 26-Sep-2020  rillig make(1): inline and remove LstNode_Prev and LstNode_Next

These functions made the code larger than necessary. The prev and next
fields are published intentionally since navigating in a doubly-linked
list is simple to do and there is no need to wrap this in a layer of
function calls, not even syntactically. (On the execution level, the
function calls had been inlined anyway.)
 1.119 24-Sep-2020  rillig make(1): migrate printCMD in meta mode to Lst_ForEach
 1.118 24-Sep-2020  rillig make(1): rename Lst_ForEach to Lst_ForEachUntil

Since the callback function returns a terminating condition, this is not
really a foreach loop.

Many of the calls to Lst_ForEachUntil don't make use of the terminating
condition, and several don't modify the list structurally, which means
they don't need this complicated implementation.

In a follow-up commit, Lst_ForEach will be added back with a much
simpler implementation that iterates over the list naively, without a
terminating condition and without taking the iteration state from
Lst_Open/Lst_Next/Lst_Close into account. The migration to this simpler
implementation will be done step by step since each callback function
needs to be examined closely.
 1.117 22-Sep-2020  rillig make(1): prepare Var_Subst for proper error handling

Returning a VarParseResult instead of a string makes it possible to let
the error bubble up, until it reaches the main expression.
 1.116 22-Sep-2020  rillig make(1): use fine-grained type names for lists and their nodes

This is only intended to help the human reader. There is no additional
type safety yet.
 1.115 21-Sep-2020  rillig make(1): add specific typedefs for lists

These typedefs are only intended to help human readers, they do not
provide any type-safety. They also make the pointers explicit, which
had been hidden before by the typedef for Lst and LstNode. Typing a few
'*' is less work than finding out which of the many types are pointers
and which aren't.

In meta.c, the variable "ln" served two completely different purposes,
which have been split again. Register allocation is the job of the
compiler, not of the human source code reader.
 1.114 12-Sep-2020  rillig make(1): fix inconsistent code indentation
 1.113 02-Sep-2020  rillig make(1): reduce number of stat fields returned by cached_stat

Only st_mtime and st_mode are actually filled, the remaining fields had
been set to zero. To prevent these from ever being accessed, a custom
struct make_stat replaces the previously used struct stat.

The fields in struct make_stat are intentionally named different from
the fields in struct stat because NetBSD and some other operating
systems define st_mtime as a macro, and that would not work in a field
declaration.
 1.112 30-Aug-2020  rillig make(1): rename Lst_Datum to LstNode_Datum
 1.111 29-Aug-2020  rillig make(1): trust that Var_Subst never returns NULL

It really never does, and it doesn't even report errors. It just
returns the content of the buffer, up to the first parse error.
 1.110 29-Aug-2020  rillig make(1): rename LstNode functions to match their type
 1.109 29-Aug-2020  rillig make(1): rename Lst_FindB back to Lst_Find

The migration from "comparison function" to "match function" is done,
the "B" in the names is no longer needed.
 1.108 29-Aug-2020  rillig make(1): migrate remaining Lst_Find to Lst_FindB

While here, rename SuffSuffIsSuffix to SuffSuffGetSuffix since a
function named "is" should return a boolean, not a string pointer.
 1.107 28-Aug-2020  rillig make(1): fix the other assertion from Lst_FindFrom

When I migrated the Lst_FindFrom to the strict API variant, I forgot
that Lst_FindFrom requires both arguments (list and node) to be
non-null. I had only checked that the list is non-null.

There are only very few calls to Lst_FindFrom, and they are all ok now.
 1.106 28-Aug-2020  rillig make(1): remove trailing 'S' from names of Lst functions

The migration from null-passing Lst functions to argument-checking Lst
functions is completed.

There were 2 surprises: The targets list may be NULL, and in Dir_AddDir,
the path may be NULL. The latter case is especially surprising since
that function turns into an almost-nop in that case. This is another
case where probably 2 independent functions have been squeezed into a
single function. This may be improved in a follow-up commit.

All other lists were fine. They were always defined and thus didn't
need much work.
 1.105 28-Aug-2020  rillig make(1): migrate Lst_Find to Lst_FindS
 1.104 28-Aug-2020  rillig make(1): migrate Lst_First to Lst_FirstS
 1.103 27-Aug-2020  rillig make(1): migrate Lst_IsEmpty to Lst_IsEmptyS
 1.102 27-Aug-2020  rillig make(1): migrate Lst_Succ to Lst_SuccS
 1.101 27-Aug-2020  rillig make(1): migrate Lst_ForEach to Lst_ForEachS

Most lists are always valid. Only the "targets" variable may be null in
some cases, probably.
 1.100 26-Aug-2020  rillig make(1): add stricter variants for remaining Lst functions

In most cases the Lst functions are only called when the arguments are
indeed valid. It's not guaranteed though, therefore each function call
needs to be analyzed and converted individually.

While here, remove a few statements that were only useful when the Lst
functions handled circular lists.
 1.99 23-Aug-2020  rillig make(1): reverse order of the Lst_Find parameters

The other callbacks all have (function, param), only the Lst_Find had
(param, function), which was inconsistent.
 1.98 23-Aug-2020  rillig make(1): define aliases for function types in list processing

This makes the prototypes of the functions clearer.
 1.97 22-Aug-2020  rillig make(1): fix indentation
 1.96 22-Aug-2020  rillig make(1): replace Lst_Datum with non-null guaranteeing Lst_DatumS
 1.95 22-Aug-2020  rillig make(1): convert remaining Lst_AtEnd to the stricter Lst_Append

The general-purpose list library that is included in make allows to call
Lst_AtEnd for invalid lists, silently ignoring this programming error.
This is a flexibility that make doesn't need.

Another unneeded "feature" is that list items can theoretically be null
pointers. This doesn't make sense as well and is therefore not needed
by make.

These programming errors are now caught early by assertions.
 1.94 21-Aug-2020  rillig make(1): make list library code stricter

Up to now, the list library didn't distinguish between programming
mistakes (violations of invariants, illegal parameter values) and
actually interesting situations like "element not found in list".

The current code contains many branches for conditions that are neither
exercised by the unit tests nor by real-world usage. There is no point
in keeping this unnecessary code.

The list functions will be migrated from their lenient variants to the
stricter variants in small parts, each function getting the S suffix
when it is made strict, to avoid any confusion about how strict a
particular function is. When all functions have been migrated, they
will be renamed back to their original names.

While here, the comments of the functions are cleaned up since they
mention irrelevant implementation details in the API comments, as well
as "side effects" that are really main effects.
 1.93 21-Aug-2020  rillig make(1): remove unused code for circular lists

The list library had probably been imported from a general-purpose
library that also supported circular lists. These are not used by make
though.

After replacing Lst_Init(FALSE) with Lst_Init(), only a single call to
Lst_Init remained with a non-constant argument, and that was in
Lst_Concat, which was to be expected.
 1.92 03-Aug-2020  rillig make(1): no declaration-after-statement anymore

NetBSD make is intended to be maximally portable, therefore it uses only
C89. This was not declared in the Makefile before.

There are still a few places in parse.c and metachar.c that use
end-of-line comments. These will be fixed in a follow-up commit.
 1.91 01-Aug-2020  rillig make(1): avoid calls to free(3) in the common case of a NULL pointer
 1.90 01-Aug-2020  rillig make(1): let Var_Value return a const char *

The return value must not be modified anyway, so let the compiler check
this for free.
 1.89 28-Jul-2020  rillig make(1): remove dead code from Var_Subst

The first parameter from Var_Subst had been a literal NULL in all cases.
These have been fixed using this command:

sed -i 's|Var_Subst(NULL, |Var_Subst(|' *.c

The one remaining case was not found because the "NULL," was followed by
a line break instead of a space.

The removed code probably wouldn't have worked as expected anyway.
Expanding a single variable to a literal string would have led to
unexpected behavior for cases like ${VAR:M${pattern}}, in case pattern
would contain an unescaped ':' itself.
 1.88 19-Jul-2020  rillig make(1): clean up unnecessary snprintf and multi-line function calls
 1.87 19-Jul-2020  rillig make(1): rename Varf_Flags to VarEvalFlags

In var.c there are lots of different flag types. To make any accidental
mixture obvious, each flag group gets its own prefix.

The only flag group that is visible outside of var.c is concerned with
evaluating variables, therefore the "e", which replaces the former "f"
that probably just meant "flag".
 1.86 11-Jul-2020  sjg meta_oodate: if target is explicitly .META missing is oodate

If a .meta file is missing for a target marked .META
it is out-of-date
 1.85 03-Jul-2020  rillig make(1): remove trailing whitespace
 1.84 03-Jul-2020  rillig make(1): remove redundant parentheses around return values
 1.83 02-Jul-2020  rillig make(1): remove useless parameter from Var_Set

The enum corresponding to this int parameter is only defined in var.c,
which makes it impractical for the outside to set this parameter to
anything but 0.

On x86_64, this reduces the size of the resulting executable by 5 kB.
 1.82 25-Jun-2020  sjg filemon_read: report error if lseek fails

Reviewed by: riastradh
 1.81 03-Apr-2020  sjg CHECK_VALID_META is too agressive for CMD check.

An empty CMD is perfectly valid.
So using CHECK_VALID_META results in too much rebuilding.
 1.80 18-Mar-2020  sjg Check for meta file corruption earlier and more often.
 1.79 12-Feb-2020  sjg meta_compat_parent check for USE_FILEMON

patch from Soeren Tempel
 1.78 06-Feb-2020  sjg Fix meta_compat mode.

We need to call meta_job_output() from meta_compat_parent()
Also, the need for extra fds for meta mode only applies when
using filemon_ktrace.c.
Since we hope to see more interfaces like that, test for
USE_FILEMON_DEV being not defined.

Reviewed by: riastradh
 1.77 22-Jan-2020  sjg Check for filemon valid.

If meta_needed() returns FALSE, mfp and filemon will be NULL
in which case we should not call filemon_*().
 1.76 22-Jan-2020  sjg meta.c: report OODATE value if not empty

When a target is out-of-date per normal make rules
.OODATE will be non-empty, report this in .meta file
to help clarify why target was updated.
 1.75 19-Jan-2020  riastradh Per sjg's suggestion, split filemon API into separate back ends.

By default we use the ktrace back end, but the /dev/filemon back end
is available as a compile-time option, by setting USE_FILEMON=dev in
make. sjg raised concerns about ktrace performance and would like to
continue using /dev/filemon on FreeBSD (which has seen more
maintenance kernel-side) without forking make.
 1.74 19-Jan-2020  riastradh Reimplement make(1) meta mode without filemon(4).
 1.73 19-Dec-2019  maxv Revert the filemon removal in bmake, as pointed out by maya we do care
about not introducing divergence with FreeBSD, and the cost of unused
is acceptable here.
 1.72 18-Dec-2019  martin Fix the build
 1.71 18-Dec-2019  maxv Retire filemon, discussed on tech-kern@.
 1.70 13-Feb-2018  sjg branches: 1.70.4;
Avoid unused variable warning
 1.69 10-Aug-2017  sjg Avoid full path meta file names for subdir of .OBJDIR
 1.68 09-Jul-2017  sjg Ensure that command output is always followed by newline,
even when filemon is not being used.

Tweak MAKE_META_IGNORE_PATTERNS matching to avoid using path name
with :L as it does not handle ':' in path names.

fgetLine: an extra check to avoid shrinking the buffer.
 1.67 17-Aug-2016  sjg Refactor the handling of .MAKE.META.IGNORE_* to meta_ignore()
so that we can call it before adding paths to missingFiles.
Ie. do not track files we have been told to ignore.
 1.66 15-Aug-2016  sjg Add .MAKE.META.IGNORE_FILTER to allow more complicated filtering of filemon data.

The filter is applied to paths Read or Excuted, and if it expands to
nothing, the entry is skipped.

For example; dirdeps.mk can set this to:

.MAKE.META.IGNORE_FILTER = M*/${.MAKE.DEPENDFILE_PREFIX}*

when checking if DIRDEPS_CACHE is up to date, where only Makefile.depend*
are of interest.
 1.65 10-Aug-2016  sjg Use Lst_FindFrom and Lst_Succ(ln) to find next entry in missingFiles.
 1.64 10-Aug-2016  sjg Linux filemon only records D some/dir for rm -rf
rather than D entries for each file removed.
Thus we need a loop to remove all matching missingFiles entries
 1.63 29-Jun-2016  sjg meta_compat_parent: fflush each line
 1.62 14-Jun-2016  sjg meta_oodate: set needOODATE if oodate due to missing .meta file.
 1.61 07-Jun-2016  sjg Extend the mtimes cache used by dir.c so it can be used by others.

We store both st_mtime and st_mode, since some callers care about the
later.

Reviewed by: christos
 1.60 04-Jun-2016  sjg meta_oodate even when missing-meta is true, we do not make a target in
.CURDIR out of date just because of a missing meta file.

Also we can only be missing filemon data if we had a meta file.
 1.59 03-Jun-2016  sjg Add cached_realpath()

realpath(3) is expensive, and meta mode at least uses it extensively.
We use cached_realpath() to save the result of successful calls to
realpath(3) in a private variable context.

This improves the worst case performance (eg examining libc with
nothing to do) by a factor of 4.

Reviewed by: christos
 1.58 03-Jun-2016  sjg Refactor the logic for deciding when a .meta file is needed.

Both meta_create() and meta_oodate() now share meta_needed()
to indicate if a .meta file is needed.

This allows for deciding that missing .meta file is cause of out-of-date.
The new knob 'missing-meta' controlls this, and is off by default
since the side effect files of generators like yacc will typically need
.NOMETA to avoid problems.

This however makes it much easier for folk to switch back and forth
with meta mode (eg. FreeBSD's normal build can leverage meta mode for
improved reliablility without need to clean).

Also if .MAKE.MODE does not contain 'nofilemon', the knob
'missing-filemon' allows control as to whether missing filemon data
should cause the target to be out-of-date.
Again off by default.
 1.57 12-May-2016  sjg Propagate errors from filemon.

If we encounter errors producing a .meta file,
we should not consider the target completed successfully.
 1.56 10-May-2016  sjg Allow for ignoring paths that match a set of patterns.
This can be expensive, so use with caution.
 1.55 10-May-2016  sjg Apply realpath() to p before matching against metaIgnorePaths.
 1.54 11-Mar-2016  sjg Handle missing file for Read the same as for Write, since if it
is Deleted we don't care.

Patch from Bryan Drewery.
 1.53 07-Mar-2016  christos str2Lst_Append tokenizes the string and uses it in the list so we can't
free the string afterwards. Keep a copy of it and cleanup at the end.
 1.52 27-Feb-2016  christos CID 1025009: Fix wrong code (NULL deref)
 1.51 27-Feb-2016  christos CID 1025008: Free memory returned by Var_Subst
 1.50 27-Feb-2016  christos CID 1025007: Don't leak missingFiles
 1.49 27-Feb-2016  christos CID 1025006: pbm can't be NULL at this point.
 1.48 27-Feb-2016  sjg Let makefiles decide if depend file gets a meta file
 1.47 18-Feb-2016  sjg Adapt to changed Var_Subst()
 1.46 18-Feb-2016  sjg Actually FALSE as last arg to Var_Subst makes more sense
 1.45 18-Feb-2016  sjg Adapt to new Var_Subst prototype
 1.44 17-Jan-2016  christos remove free NULL checks (Tilman Sauerbeck)
 1.43 17-Jan-2016  christos provide missing FD_CLOEXEC for the havenots.
 1.42 17-Jan-2016  christos Use FD_CLOEXEC (Tilman Sauerbeck)
 1.41 30-Nov-2015  sjg Use lstat(2) if we have a link, incase it is a symlink.

Patch from bdrewery at FreeBSD.org
 1.40 11-Oct-2015  sjg Add Boolean wantit to Var_Parse and Var_Subst

wantit will be FALSE when we are just consuming to discard
in which case we skip "expensive" things like Cmd_Exec.

Reviewed by: christos
 1.39 10-Oct-2015  sjg Do not hard-code ingnoring of makeDependfile
 1.38 11-Apr-2015  sjg Use separate vars to track cwd and last dir a process read.
 1.37 01-Apr-2015  sjg Close child's reference to meta file.
 1.36 06-Nov-2014  sjg Ensure -- filemon is at start of line
 1.35 20-Oct-2014  sjg Use read and fwrite rather than fgets and printf when reading filemon data.
 1.34 18-Oct-2014  snj src is too big these days to tolerate superfluous apostrophes. It's
"its", people!
 1.33 01-Oct-2013  sjg meta_oodate: 'L'ink and 'M'ove entries need extra processing.
The src of a Link should be treated as a file Read
while the target a file Written.
The src of a Move is like a file Deleted
and the target like a file Written.
 1.32 25-Jun-2013  sjg Add .MAKE.META.IGNORE_PATHS to facilitate local additions to the paths
which should be ignored by meta_oodate().
 1.31 24-Jun-2013  sjg Ignore any files in /proc/
 1.30 16-May-2013  sjg New compiler doesn't like foo()
 1.29 31-Mar-2013  sjg Refine the effect of .OODATE on command comparison.
Rather than apply it to the whole script, just the current command line
is affected. This allows a trick like ${.OODATE:M.NOMETA_CMP}
to cause command comparison to be supressed for one command only.
 1.28 23-Mar-2013  sjg After removing an entry from missingFiles,
set ln=NULL after Lst_Remove() to make it clear we won't use it
after this point.
 1.27 23-Mar-2013  sjg If built with filemon support, set .MAKE.PATH_FILEMON to _PATH_FILEMON
so that makefiles can test for it.
 1.26 19-Jan-2013  sjg meta_oodate: rename ignoreOODATE to needOODATE.
if target uses ${.OODATE} in its script;
1. we canno compare commands
2. if we decide it is out-of-date .OODATE must not be empty.
The only option is to set it to .ALLSRC
 1.25 27-Jun-2012  sjg branches: 1.25.2;
gcc 4.2 doesn't like externs inside functions
 1.24 21-Sep-2011  christos branches: 1.24.2;
PR/45383: Henning Petersen: Swapped lseek args
 1.23 02-Sep-2011  sjg meta_oodate should ignore makeDependfile
 1.22 28-Aug-2011  sjg In meta mode, we create .meta files for most targets.
These capture all the interesting data - useful for debugging.
In such cases there is no need to replicate commands in the build log.
Rather than run the entire build .SILENT, allow meta mode to set that flag
per target iff a .meta file is created.
Normal behavior is retained for targets where no .meta file is created,
ensuring that no build data is lost.
 1.21 18-Aug-2011  sjg If a target is explicitly flagged .META,
a missing .meta file means it is out-of-date.
 1.20 22-Jun-2011  sjg After each strsep(&p) check that p is valid.
If not the .meta file is corrupted (build interrupted?)
issue a warning and declare target oodate.
 1.19 11-Jun-2011  sjg Use %zu rather than cast
 1.18 10-Jun-2011  sjg size_t on amd64 doesn't like %u, use a cast.
 1.17 04-May-2011  sjg branches: 1.17.2;
Add .MAKE.META.BAILIWICK - to identify the scope of make's control.
meta_oodate: if a file that was written or linked within our bailiwick,
but outside of .OBJDIR is missing, add it to missingFiles.
If we get to the end of the .meta file without seeing it [re]moved,
then consider the target out-of-date.
 1.16 31-Mar-2011  sjg Call meta_job_finish() from meta_job_error(), so that if
the .ERROR target copies the .meta file, it has been completed.
meta_job_finish() is safe to call again.
 1.15 30-Mar-2011  sjg Add NetBSD tags
 1.14 29-Mar-2011  sjg Check for extra commands as soon as we reach CWD,
so we return faster (if oodate) and give a more accurate debug message.
 1.13 27-Mar-2011  sjg Use curdirOk as the token
 1.12 27-Mar-2011  sjg When .MAKE.MODE inlcudes 'meta'; 'curdir=true' enables creating .meta
files in .CURDIR - such as when running make in .OBJDIR with a generated
makefile.
 1.11 06-Mar-2011  sjg Only need to getcwd() once
 1.10 06-Mar-2011  sjg CWD should be compared against cwd
 1.9 04-Mar-2011  sjg main.c now exports curdir[] so we can use it.
 1.8 13-Feb-2011  sjg When making a target that involves creating itermediate dirs,
realpath() will fail until after those dirs exist.
Try to ensure the same meta file name is used regardless.
 1.7 08-Feb-2011  sjg tmplen should be static
 1.6 15-Dec-2010  sjg branches: 1.6.2;
Invalidate meta_fname when we finish a job, so that in compat
mode, we do not report a previous .meta file as being involved
in an error.
 1.5 09-Dec-2010  sjg meta_oodate(): we should track 'latestdir' on a per process basis.
Also, only consider target out of date if a not-found file is outside
'CWD'. Ignore anything in "/tmp/" or tmpdir.
 1.4 27-Nov-2010  sjg When a source file moves, make will ignore the stale dependency,
but if the file in question is one that needs to be compiled (.c or .cc),
it still hands the bogus name to the compiler.

If Dir_MTime() cannot find such a file (gn->iParents is not empty),
see if the basename can be found via .PATH, and if so set gn->path to
the found file. This prevents the stale path being given to the
compiler.

In meta_oodate(), if a referenced file no longer exists, consider the
target out-of-date.

Also, if meta_oodate() decides a target is out-of-date, and it
it uses .OODATE in its commands, we need .OODATE recomputed.
Undo our call to Make_DoAllVar() so that the call from Make_OODate()
will do the right thing.
 1.3 13-Sep-2010  sjg tools/make/buildmake.sh compiles *.c, make sure meta.c does nothing
unless USE_META is defined.
 1.2 13-Sep-2010  sjg We do not need filemon(9) to have a .meta file
 1.1 13-Sep-2010  sjg Add meta.c which implements "meta" mode for make.
In this mode, a .meta file is created for each target, capturing
the expanded commands used, any command output, and if filemon(9)
is available, a record of system calls which are of interest.
Not enabled unless USE_META=yes is set when building make.
Also, if FILEMON_H exists, meta.c will be compiled to use filemon(9).
 1.6.2.3 05-Mar-2011  bouyer Sync with HEAD
 1.6.2.2 17-Feb-2011  bouyer Sync with HEAD
 1.6.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.17.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.24.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.24.2.2 23-Jan-2013  yamt sync with head
 1.24.2.1 30-Oct-2012  yamt sync with head
 1.25.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.25.2.2 23-Jun-2013  tls resync from head
 1.25.2.1 25-Feb-2013  tls resync with head
 1.70.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.210.2.1 02-Aug-2025  perseant Sync with HEAD
 1.15 04-Aug-2025  sjg meta_job_output() use size_t for len
 1.14 03-Aug-2025  sjg make: ensure output captured in meta file is accurate

In CollectOutput() a newline before the end of job->outBuf
results in a short write to stdout, but meta_job_output()
was recording the entire string in the meta file, so on
next call the left overs would be duplicated in the meta file.

Pass a length to meta_job_output() if it should only report part of
the data in meta file.
 1.13 13-Jun-2025  rillig make: do not discard empty lines in the output of a command
 1.12 13-Jun-2025  rillig make: omit redundant call to strlen during output of a parallel job
 1.11 15-Dec-2021  rillig branches: 1.11.4;
make: mark several functions whose result must be used

Suggested by sjg, to catch more bugs like the memory leak in cond.c
1.303 from 2021-12-13.

No binary change.
 1.10 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.9 10-Dec-2020  rillig make(1): split JobFlags into separate fields

Having all these flags in a single bitmask makes it harder to see where
exactly they can possibly be used since their state could also be
modified using the unsuspicious job->flags = 0. Using individual names
just leaves the single memset, and that is only used during
initialization.
 1.8 19-Oct-2020  rillig make(1): clean up headers, no functional change
 1.7 03-Jul-2020  rillig make(1): remove trailing whitespace
 1.6 19-Jan-2020  riastradh Reimplement make(1) meta mode without filemon(4).
 1.5 12-May-2016  sjg branches: 1.5.16;
Propagate errors from filemon.

If we encounter errors producing a .meta file,
we should not consider the target completed successfully.
 1.4 07-Mar-2016  christos str2Lst_Append tokenizes the string and uses it in the list so we can't
free the string afterwards. Keep a copy of it and cleanup at the end.
 1.3 23-Mar-2013  sjg If built with filemon support, set .MAKE.PATH_FILEMON to _PATH_FILEMON
so that makefiles can test for it.
 1.2 30-Mar-2011  sjg branches: 1.2.4; 1.2.10;
Add NetBSD tags
 1.1 13-Sep-2010  sjg Add meta.c which implements "meta" mode for make.
In this mode, a .meta file is created for each target, capturing
the expanded commands used, any command output, and if filemon(9)
is available, a record of system calls which are of interest.
Not enabled unless USE_META=yes is set when building make.
Also, if FILEMON_H exists, meta.c will be compiled to use filemon(9).
 1.2.10.1 23-Jun-2013  tls resync from head
 1.2.4.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.5.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.11.4.1 02-Aug-2025  perseant Sync with HEAD
 1.10 21-Jun-2021  rillig make: replace macro is_shell_metachar with inline function

No functional change.
 1.9 19-Jan-2021  rillig make(1): remove do-not-format markers from comments

These markers had been used inconsistently. Furthermore the source code
had not been formatted automatically before 2020 at all, otherwise there
wouldn't have been any trailing whitespace left.
 1.8 30-Oct-2020  rillig make(1): remove comment about adding is_shell_metachar to ctype.h

This function is so specialized that it would be wrong to have it in a
general-purpose C header.
 1.7 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.6 03-Aug-2020  rillig make(1): replace end-of-line comments with block comments

Just in case someone wants to port the current NetBSD make to an ancient
compiler that knows only C90.
 1.5 19-Jun-2015  mlelstv Adjust metachar handling to previous behaviour:
- space and tab are no shell metachars, remove them from generic
metachar function
- add space and tab as to-be-quoted characters for :Q modifier
- add = and : as characters that require command handling by the shell
 1.4 18-Jun-2015  christos grr too many different compilation options.
 1.3 18-Jun-2015  christos this is not buf.c
 1.2 18-Jun-2015  justin Fix non native build on metachar.c
 1.1 17-Jun-2015  christos centralize shell metachar handling.
 1.20 08-Jan-2022  rillig make: rename is_shell_metachar, fix character conversion warning

No binary change.
 1.19 15-Dec-2021  rillig make: remove redundant comments for multiple-inclusion guards
 1.18 15-Dec-2021  rillig make: mark several functions whose result must be used

Suggested by sjg, to catch more bugs like the memory leak in cond.c
1.303 from 2021-12-13.

No binary change.
 1.17 21-Jun-2021  rillig make: replace macro is_shell_metachar with inline function

No functional change.
 1.16 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.15 19-Jan-2021  rillig make(1): remove do-not-format markers from comments

These markers had been used inconsistently. Furthermore the source code
had not been formatted automatically before 2020 at all, otherwise there
wouldn't have been any trailing whitespace left.
 1.14 16-Jan-2021  rillig make(1): fix a few inconsistencies for lint's strict bool mode
 1.13 10-Jan-2021  rillig make(1): consistently use boolean expressions in conditions

Most of the make code already followed the style of explicitly writing
(ptr != NULL) instead of the shorter (ptr) in conditions.

The remaining 50 instances have been found by an experimental,
unpublished check in lint(1) that treats bool expressions as
incompatible to any other scalar type, just as in Java, C#, Pascal and
several other languages.

The only unsafe operation on Boolean that is left over is (flags &
FLAG), for an enum implementing a bit set. If Boolean is an ordinary
integer type (the default), some high bits may get lost. But if Boolean
is the same as _Bool (by compiling with -DUSE_C99_BOOLEAN), C99 6.3.1.2
defines that a conversion from any scalar to the type _Bool acts as a
comparison to 0, which cannot lose any bits.
 1.12 10-Nov-2020  rillig make(1): use consistent definition for MAKE_INLINE
 1.11 31-Oct-2020  rillig make(1): remove unused code from needshell

Since usr.bin/xinstall no longer uses this code, there is no need to
keep the second parameter.
 1.10 31-Oct-2020  rillig make(1): rename ismeta to is_shell_metachar

The old name was too broad.
 1.9 13-Sep-2020  rillig make(1): fix position of MAKE_ATTR_UNUSED in inline functions

The attribute needs to be before the return type, otherwise GCC 5
complains that Hash_GetValue is defined but not used, when compiling
with USER_CPPFLAGS=-Dinline=. The other functions don't get any
warnings. It's probably because Hash_GetValue is the only inline
function that returns a pointer.
 1.8 11-Sep-2020  rillig make(1): add wrappers around ctype.h functions

This avoids casting the argument to unsigned char, and to cast the
result of toupper/tolower back to char.
 1.7 25-Aug-2020  rillig make(1): allow make to be compiled in C90 mode

Since the inline functions are the only C99 feature used by now, setting
USER_CFLAGS='-std=c90 -ansi -Dinline=' is enough for compiling make with
a C90 compiler.
 1.6 23-Aug-2020  rillig make(1): remove unused declarations from header files
 1.5 13-Aug-2020  rillig make(1): follow naming conventions for multiple-inclusion guards

This avoids undefined behavior.
 1.4 21-Jun-2015  christos remove <sys/cdefs.h> for portability reasons
 1.3 19-Jun-2015  christos make needshell customizable, so that xinstall can use it.
 1.2 19-Jun-2015  christos create needshell so we don't scan the string multiple times.
 1.1 17-Jun-2015  christos centralize shell metachar handling.
 1.240 23-Jan-2022  rillig make: merge nonints.h into make.h

No functional change.
 1.239 15-Jan-2022  rillig make: remove unnecessary functions for expanding variable names

In meta mode, the affected variable patterns do not contain a '$'.

Outside of meta mode, Global_SetExpand was only called a single time, so
inline that call.

No functional change.
 1.238 15-Jan-2022  rillig make: merge duplicate code for expanding variable expressions

No functional change.
 1.237 09-Jan-2022  rillig make: in Cmd_Exec, return error message instead of format string

This change leaves only literal format strings in parse.c. It allows
for more detailed error messages than the current "non-zero status" or
"exited on a signal".

No functional change.
 1.236 09-Jan-2022  rillig make: fix use-after-free in -dp mode (since yesterday)

In a .for loop that contains an unclosed .if directive,
Cond_restore_depth generates an error message. If stack traces are
enabled using the option '-dp', the details of the .for loop are added
to the stack trace, but at that point, the ForLoop had already been
freed. To reproduce:

make-2022.01.09.00.33.57 -r -f unit-tests/directive-for.mk -dp
 1.235 08-Jan-2022  rillig make: add details about .for loop variables to stack traces

The stack traces are enabled with the debug logging option '-dp'.
 1.234 08-Jan-2022  rillig make: fix reported line numbers of continuation lines (since 2002)

Previously, multi-line directives like '.info' or '.error' reported the
line number of their last line instead of their first line, which is
more usual. This also affected the debug log from '-dp'.
 1.233 07-Jan-2022  rillig make: remove redundant function parameter in suffix handling

Now that mainNode is globally visible, there is no need to pass it
through function parameters.

No functional change.
 1.232 07-Jan-2022  rillig make: merge duplicate variables for the main target

No functional change.
 1.231 07-Jan-2022  rillig make: eliminate file-scope variable forLevel

No functional change.
 1.230 07-Jan-2022  rillig make: rename and inline Targ_Precious

No functional change.
 1.229 02-Jan-2022  rillig make: clean up handling of .for loops and .include directives

No functional change.
 1.228 01-Jan-2022  rillig make: remove unused parameter from Parse_PushInput

The parameter readMore was never NULL.

No functional change.
 1.227 31-Dec-2021  rillig make: unexport types VarAssignOp and VarAssign

These types are only needed in the parsing module.

No functional change.
 1.226 31-Dec-2021  rillig make: list VarAssignOp in the same order as in the manual page

No functional change.
 1.225 29-Dec-2021  rillig make: merge duplicate types CondEvalResult and CondResult

No binary change.
 1.224 29-Dec-2021  rillig make: remove redundant parameter for evaluating conditions

No functional change.
 1.223 28-Dec-2021  rillig make: constify cached_realpath

No binary change.
 1.222 27-Dec-2021  rillig make: rename eunlink to unlink_file

The name eunlink suggested a relation with the similarly named functions
emalloc or esnprintf, but that was misleading. Instead, unlink_file
works like unlink, except that it refuses to remove an empty directory.

No functional change.
 1.221 15-Dec-2021  rillig make: format comments according to /usr/share/misc/style

Assisted by indent(1), with manual corrections due to its many remaining
bugs.

No functional change.
 1.220 15-Dec-2021  rillig make: change return type of Compat_RunCommand from int to bool

The documentation was wrong before since status was not restricted to
only 0 or 1.

No functional change.
 1.219 15-Dec-2021  rillig make: mark several functions whose result must be used

Suggested by sjg, to catch more bugs like the memory leak in cond.c
1.303 from 2021-12-13.

No binary change.
 1.218 13-Dec-2021  rillig make: fix memory leak when evaluating ${.SUFFIX} (since yesterday)
 1.217 12-Dec-2021  sjg Add .SUFFIXES as read-only variable.

References to ${.SUFFIXES} are handled dynamically in
ParseVarnameLong by calling Suff_NamesStr.

The variable cannot be set normally.

Reviewed by: rillig
 1.216 12-Dec-2021  rillig make: rename Parse_SetInput to Parse_PushInput

The word 'set' sounded too much like it would replace the current file,
but instead the file is pushed to the stack, and the previous file is
continued later.

No functional change.
 1.215 12-Sep-2021  rillig make: fix lint warnings for strict bool mode

In strict bool mode, lint does not consider 'x & y' as having type bool,
if x and y have integer type, it only allows this for enums.

No functional change.
 1.214 14-Aug-2021  rillig make: rename variable and function for handling parse errors

The word 'fatals' was an unnecessary abbreviation.

No functional change.
 1.213 11-Apr-2021  rillig make: clean up remaining references to VarEvalFlags

VarEvalFlags has been replaced with VarEvalMode. There were some
comments and tests that still referred to the old names.

No functional change.
 1.212 11-Apr-2021  rillig make: add types Substring and LazyBuf

These will be used for making the string handling more efficient,
avoiding allocations, especially when evaluating variable expressions.

Since the string handling has grown quite a bit in the last months,
extract it into its own header file.

No functional change.
 1.211 04-Apr-2021  rillig make: convert VarEvalFlags back into an enum, but not a bit-set

As was apparent in VarEvalFlags_ToString, a bit-set was not the best
data type since most of the flags were not freely combinable. The two
flags that could be combined were keepDollar and keepUndef, but even
these have distinguished names in the debug log.

The downside of struct bit-fields is that they need extra helper
functions in C90 (see nonints.h). Exchange these for a few helper
functions in var.c, to keep the code outside var.c simple.

No functional change.
 1.210 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.209 04-Apr-2021  rillig make: rename a few functions to be more descriptive

No functional change.
 1.208 03-Apr-2021  rillig make: backport to C90

In the past few months I had accidentally used C99 features in the make
code. According to tools/README, tools that are used in the build
system should restrict themselves to C90.

This allows make to build with GCC's options "-pedantic
-Wno-system-headers -Dinline= -Wno-error=cast-qual".

I didn't notice anyone actively complaining though, I just wanted to see
how much work this backporting would be. The identifier __func__ is
still used, as in other tools.

No functional change.
 1.207 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.206 15-Mar-2021  rillig make: change debug log for variable evaluation flags to lowercase

This makes them easier distinguishable from variable names since the
latter are usually uppercase.

No functional change outside debug mode.
 1.205 15-Mar-2021  rillig make: replace enum bit-field with struct bit-field for VarEvalFlags

This makes the code easier to read, especially in var.c. It also makes
debugging sessions easier since some debuggers don't show enum
bit-fields symbolically as soon as more than one bit is set.

The code outside var.c is basically unchanged, except that instead of
passing the individual flags, there are 4 predefined evaluation modes.
These suffice for all practical use cases. Only in the implementation
deep inside var.c, the value of the flags keepDollar and keepUndef
differs.

There is no way of passing the struct to EnumFlags_ToString, which means
the ToString function has to be spelled out explicitly. This allows for
fine-tuning the representation in the debug log, to reduce the amount of
uppercae letters.

No functional change.
 1.204 15-Mar-2021  rillig make: rename VARE_NONE to VARE_PARSE_ONLY

The name 'NONE' described the bit pattern, which was not useful to
understand its meaning. Omitting VARE_WANTRES only parses the
expression, without evaluating any part of it.

No functional change, not even in debug mode since Enum_FlagsToString
always returns "none" for all-bits-unset.
 1.203 14-Feb-2021  rillig make: clean up FStr and MFStr memory in cleanup mode
 1.202 05-Feb-2021  rillig make: in the Var_ functions, move the scope to the front

This change provides for a more natural reading order in the code.
Placing the scope first makes it immediately clear in which context the
remaining parameters are interpreted.

No functional change.
 1.201 05-Feb-2021  rillig make: add shortcut Global_Delete for deleting a global variable
 1.200 04-Feb-2021  rillig make: rename Var_ValueDirect to GNode_ValueDirect
 1.199 04-Feb-2021  rillig make: group shortcuts for manipulating global variables

No functional change.
 1.198 04-Feb-2021  rillig make: rename Var_SetWithFlags to Var_SetExpandWithFlags

Add back Var_SetWithFlags for the one call that doesn't need to expand
the name.

Now one of the flags is encoded in the function name while the others
are encoded in VarSetFlags. This is inconsistent. Maybe there is a
better way to model the different variants of setting a variable.
 1.197 04-Feb-2021  rillig make: rename Var_Set to Var_SetExpand

After doing the textual renaming across all files, I added a new
function Var_Set that does not expand the variable name. I then undid
the renaming for all calls where the variable name cannot ever contain a
dollar sign. I omitted the word "Expand" from the textual references in
the unit tests and in the debug logging messages since the focus is
usually on the "Set" part, not on the "Expand".

No functional change.
 1.196 03-Feb-2021  rillig make: rename Var_Delete to Var_DeleteExpand, Var_DeleteVar to Var_Delete

The function names now follow the naming scheme from the other functions
that handle variables.

There are several calls that remain syntactically unchanged but that
omit the call to strchr('$') now. Since all these calls use constant
variable names, there is no functional change.
 1.195 03-Feb-2021  rillig make: split Var_Exists into plain Var_Exists and Var_ExistsExpand

Most previous calls to Var_Exists use constant variable names. Only the
two calls in parse.c need to expand the variable name.

It may be a good idea to expand the variable name once in VarAssign_Eval
instead of repeating the expansion in each of its special cases.

No functional change.
 1.194 03-Feb-2021  rillig make: replace Global_AppendExpand with Global_Append

All callers with a variable name that is guaranteed to not contain a
dollar sign have been converted to call Global_Append instead of the
previous Global_AppendExpand. After that, Global_AppendExpand was
unused, therefore it was effectively just renamed.
 1.193 03-Feb-2021  rillig make: split Var_Append into Var_Append and Var_AppendExpand

The plain Var_Append now does not expand the variable name anymore. It
is used in situations where the variable name is known to not contain a
dollar sign.

This is a preparation for adding Global_Append, corresponding to
Global_AppendExpand.
 1.192 03-Feb-2021  rillig make: replace Global_SetExpand with Global_Set for constant names
 1.191 03-Feb-2021  rillig make: use shortcut functions Global_SetExpand and Global_AppendExpand

There are many places where global variables are set or appended to. To
reduce clutter and code size, encode the VAR_GLOBAL in the function
name.

The word Expand in the function names says that the variable name is
expanded. In most of the cases, this is not necessary, but there are no
corresponding functions Global_Set or Global_Append yet.

Encoding the information whether the name is expanded or not in the
function name will make inconsistencies obvious in future manual code
reviews. Letting the compiler check this by using different types for
unexpanded and expanded variable names is probably not worth the effort.
There are still a few bugs to be fixed, such as in SetVar, which expands
the variable name twice in a row.
 1.190 02-Feb-2021  rillig make: remove overengineered Enum_ValueToString

For printing the status of a GNode, there was already made_name (now
renamed to GNodeMade_Name), which prints user-friendly text instead of
the bare enum constant names.

To do this change confidently, I first had to demonstrate that the
output really affects something other than just the word "UNMADE". There
had not been a test for that case before, and the test immediately
discovered a bug in the -dg2 and -dg3 options. This bug is one of the
oldest in make, dating back to at least 1993.
 1.189 01-Feb-2021  rillig make: remove outdated comment about VarEvalFlags

The previous variable preserveUndefined is now the flag VARE_KEEP_UNDEF.
 1.188 24-Jan-2021  rillig make(1): convert SearchPath to struct

This prepares for making dotLast a simple struct member instead of a
fake CachedDir, which is easier to understand.
 1.187 19-Jan-2021  rillig make(1): remove do-not-format markers from comments

These markers had been used inconsistently. Furthermore the source code
had not been formatted automatically before 2020 at all, otherwise there
wouldn't have been any trailing whitespace left.
 1.186 28-Dec-2020  rillig make(1): replace global preserveUndefined with VARE_KEEP_UNDEF

Controlling the expansion of variable expressions using a global
variable and a VARE flag was inconsistent.

Converting the global variable into a flag had to prerequisites:

1. The unintended duplicate variable assignment had to be fixed, as
done in parse.c 1.520 from 2020-12-27. Without this fix, it would have
been necessary to add more flags to Var_Exists and Var_SetWithFlags, and
this would have become too complex.

2. There had to be a unit test demonstrating that VARE_KEEP_DOLLAR only
applies to the top-level expression and is not passed to the
subexpressions, while VARE_KEEP_UNDEF applies to all subexpressions as
well. This test is in var-op-expand.mk 1.10 from 2020-12-28, at least
for the ':@word@' modifier. In ParseModifierPartSubst, VARE_KEEP_UNDEF
is not passed down either, in the same way.
 1.185 27-Dec-2020  rillig make(1): remove unnecessary VPR_ERR_SILENT
 1.184 27-Dec-2020  rillig make(1): clean up VarParseResult constants

The many constants were invented because at that time I didn't quite
understand the actual outcomes of Var_Parse that need to be
distinguished. There are only a few:

(1) Errors, whether they are parse errors, or evaluation errors or
undefined variables. The old constants VPR_PARSE_MSG and
VPR_UNDEF_MSG are merged into VPR_ERR.

(2) Undefined expressions in a situation in which they are allowed.
Previously the documentation for VPR_UNDEF_SILENT talked about
undefined expressions in situations where they were not allowed.
That case is fully covered by VPR_ERR instead.

(3) Errors that are silently ignored. These are probably bugs.

(4) Everything went fine, the expression has a defined value.
 1.183 27-Dec-2020  rillig make(1): remove unnecessary VPR_UNKNOWN for error handling

There is no sensible way for a caller of Var_Parse to deal with an error
state of "maybe successful, maybe not", therefore remove the constant
for it.
 1.182 27-Dec-2020  rillig make(1): align names of VarExportMode with the directives
 1.181 22-Dec-2020  rillig make(1): allow .undef to undefine multiple variables at once

Since make doesn't support variable names containing spaces, this edge
case is not enough reason to stop this feature. Having multiple
variable names as arguments nicely aligns with other directives such as
.for and .export.
 1.180 20-Dec-2020  rillig make(1): omit linear search for command in Compat_RunCommand
 1.179 20-Dec-2020  rillig make(1): remove constant parameter from MakeMode
 1.178 20-Dec-2020  rillig make(1): change return type of Var_Value to FStr
 1.177 20-Dec-2020  rillig make(1): return FStr from Var_Parse

This reduces the number of variable declarations at the call sites.
 1.176 20-Dec-2020  rillig make(1): export FStr and MFStr

These types are a replacement for the pattern "var + var_freeIt" that
enforces these two variables to be updated together.
 1.175 19-Dec-2020  rillig make(1): extract Var_DeleteVar from Var_Delete
 1.174 19-Dec-2020  rillig make(1): extract Var_Undef from ParseDirective
 1.173 18-Dec-2020  rillig make(1): constify Targ_FmtTime
 1.172 15-Dec-2020  rillig make(1): indent nonints.h and util.c with tabs instead of spaces
 1.171 13-Dec-2020  rillig make(1): add str_basename to reduce duplicate code

The function basename from POSIX has a few unfortunate properties, it is
allowed to return a pointer to static memory. This is too unreliable,
therefore this trivial own implementation.
 1.170 13-Dec-2020  rillig make(1): remove dead code from GetVarnamesToUnexport

Now that the parsing of the directives is unified and strict, there is
no need anymore for the dispatched functions to check for unknown
directives. These functions don't even get the information to decide
that since this decision is already done.
 1.169 13-Dec-2020  rillig make(1): clean up Var_Export
 1.168 12-Dec-2020  rillig make(1): eliminate boolean argument of Var_Export
 1.167 12-Dec-2020  rillig make(1): rename Var_ExportVars to Var_ReexportVars
 1.166 12-Dec-2020  rillig make(1): inline Targ_Ignore and Targ_Silent

Each of these functions was only used 2 times, and each of these calls
used a different part of the whole expression.
 1.165 06-Dec-2020  rillig make(1): rename IFile.nextbuf to readMore

The previous name sounded too much like a noun, which was too confusing.
See unit-tests/opt-file.mk for the history of this part of the code.
 1.164 29-Nov-2020  rillig make(1): reduce memory allocation for targets

This change moves the initialization and finalization of the list of
targets to the same function. They had been split before.
 1.163 28-Nov-2020  rillig make(1): replace Dir_Destroy with SearchPath_Free

The function Dir_Destroy is an implementation detail of the cached
directories, and it should not be exported to the other modules. The
search paths, on the other hand, are the high-level API that may be used
by the other modules, as the concept of search paths is documented in
the manual page.
 1.162 16-Nov-2020  rillig make(1): make some GNode functions const
 1.161 16-Nov-2020  rillig make(1): rename Targ_NewGN to GNode_New

This function is a classical constructor function, and if it weren't for
CLEANUP mode, it would have no dependencies on anything else besides the
memory allocator. Therefore it doesn't really matter which module
defines this function, and there is no need for the "Targ" to be part of
the function name.
 1.160 10-Nov-2020  rillig make(1): use consistent definition for MAKE_INLINE
 1.159 08-Nov-2020  rillig make(1): rename VARE_ASSIGN to VARE_KEEP_DOLLAR

The other flags in VarEvalFlags already describe their effects, not the
place where they are used. It's more important to know the effect.

Only a single unit test had to be adjusted. This probably means that
there are too few tests where the special effects of VARE_KEEP_DOLLAR
come into play. It could also mean that the effects are so simple and
obvious that they don't need any debug log, but that's not the case.
 1.158 08-Nov-2020  rillig make(1): change return type of Arch_MTime to void

This makes it easier to prove that Dir_MTime always returns gn->mtime,
without looking at the implementation of Arch_UpdateMTime.
 1.157 08-Nov-2020  rillig make(1): change return type of Arch_MemberMTime to void

This makes it easier to prove that Dir_MTime always returns gn->mtime,
without looking at the implementation of Arch_UpdateMemberMTime.
 1.156 07-Nov-2020  rillig make(1): fix type mismatch between int and VarSetFlags
 1.155 07-Nov-2020  rillig make(1): document the relation between VARE_ASSIGN and preserveUndefined
 1.154 07-Nov-2020  rillig make(1): clean up code stylistically

* Replace character literal 0 with '\0'.
* Replace pointer literal 0 with NULL.
* Remove redundant parentheses.
* Parentheses in multi-line conditions are not redundant at the
beginning of a line.
* Replace a few !ptr with ptr == NULL.
* Replace a few ptr with ptr != NULL.
* Replace (expr & mask) == 0 with !(expr & mask).
* Remove redundant braces for blocks in cases where the generated code
stays the same. (Assertions further down in the code would get
different line numbers.)
* Rename parameters in CondParser_String to reflect the data flow.
* Replace #ifdef notdef with #if 0.

The generated code stays exactly the same, at least with GCC 5.5.0 on
NetBSD 8.0 amd64 using the default configuration.
 1.153 07-Nov-2020  rillig make(1): rename Var_Set_with_flags to Var_SetWithFlags

Now that the function is exported from the var module, it should stick
to the naming conventions for public functions.
 1.152 07-Nov-2020  rillig make(1): rename VarSet_Flags to VarSetFlags

Most other types don't have an underscore as well.
 1.151 06-Nov-2020  rillig make(1): rename Arch_MemMTime to Arch_MemberMTime

The abbreviation Mem was ambiguous, it could have meant memory as well.
 1.150 06-Nov-2020  rillig make(1): rename getBoolean and s2Boolean
 1.149 01-Nov-2020  rillig make(1): in lint mode, exit with error status on errors

Calling Parse_Error during parsing has always led to a nonzero exit
status. Calling Parse_Error later, when expanding the shell commands,
has had no effect on the exit status. Neither had calling Error.

To make make a reliable tool, it has to report errors as they occur.
Enable this strict behavior in lint mode for now. Lint mode has to be
enabled explicitly, preserving the default behavior.
 1.148 31-Oct-2020  rillig make(1): do not look up local variables like .TARGET anywhere else

Nobody defines a global variable named .TARGET since that would have
many unpredictable effects, applying to all targets at once.

Nobody defines an environment variable named .TARGET since that's
against the naming conventions for environment variables and would have
the same effect.

Because of this, there is no point looking up the variables that are
local to a GNode anywhere else. This means they cannot come from the
environment and thus their value doesn't need to be freed after use,
which makes the code simpler.

The newly added accessor functions in make.h refer to external
functions, but since that header is not used anywhere outside of
usr.bin/make, it doesn't matter. Between 2020-08-25 and 2020-10-30,
that header had been referenced by usr.bin/xinstall.
 1.147 30-Oct-2020  rillig make(1): change char * to void * in Var_Value

The only purpose of the parameter freeIt is to free the memory
associated with the return value. To do this, no pointer arithmetic is
needed. Therefore, change to a void pointer, to catch accidental use of
that pointer.
 1.146 23-Oct-2020  rillig make(1): convert error level for Parse_Error to an enum
 1.145 19-Oct-2020  rillig make(1): clean up headers, no functional change
 1.144 18-Oct-2020  rillig make(1): remove redundant code for determining the assignment operator
 1.143 18-Oct-2020  rillig make(1): add tags to enum types

This allows IDEs to offer better type information than "anonymous enum".
 1.142 18-Oct-2020  rillig make(1): replace execError with execDie

All calls to this function were followed by _exit(1).
 1.141 17-Oct-2020  rillig make(1): normalize initialization and cleanup of the modules
 1.140 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.139 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.138 04-Oct-2020  rillig make(1): clean up parsing of variable assignments
 1.137 04-Oct-2020  rillig make(1): remove duplicate code for parsing a variable name
 1.136 04-Oct-2020  rillig make(1): don't modify the given line during Parse_DoVar

Placing null characters all over the line made the code hard to
understand. The null characters were placed for top-level whitespace as
well as the operator.

Working with a read-only line makes it easier to inspect the parsing
state during debugging.

This change involves an additional bmake_malloc for each variable name.
This will be compensated later by extending the API of the Var module to
also accept a pair of pointers (start, end) as the variable name.
 1.135 04-Oct-2020  rillig make(1): only use the VARE_ASSIGN flag if necessary

When checking the right-hand side of a variable assignment for syntax
errors, it does not matter whether a '$$' is expanded to '$' or kept as
'$$'.
 1.134 03-Oct-2020  rillig make(1): inline Str_FindSubstring in JobOutput
 1.133 01-Oct-2020  rillig make(1): add missing const for Parse_AddIncludeDir
 1.132 27-Sep-2020  rillig make(1): make parameter of Compat_RunCommand const
 1.131 26-Sep-2020  rillig make(1): inline Lst_ForEachUntil in Compat_Make
 1.130 26-Sep-2020  rillig make(1): clean up API for finding and creating GNodes

The previous API had complicated rules for the cases in which the single
function returned NULL or what it did. The flags for that function were
confusing since passing TARG_NOHASH would create a new node even though
TARG_CREATE was not included in that bit mask.

Splitting the function into 3 separate functions avoids this confusion.
It also reveals several places where the complicated API led to
unreachable code. Such code has been removed.
 1.129 25-Sep-2020  rillig make(1): declare strings for suff.c constant
 1.128 25-Sep-2020  rillig make(1): add tags to some of the unnamed structs

The tags prevent the structs from accidentally becoming compatible
types.

While here, remove a few typedefs for structs that are single-purpose,
since there is no point in abstracting from the actual representation of
these types.
 1.127 23-Sep-2020  rillig make(1): fix assertion failure in -j mode with .END node

There had been two separate global variables for the .END node, and in
parallel mode, only the one in jobs.c was initialized.

The code in JobRun heads over to Compat_Make without calling Compat_Run
first, which left the variable ENDNode uninitialized.
 1.126 22-Sep-2020  rillig make(1): prepare Var_Subst for proper error handling

Returning a VarParseResult instead of a string makes it possible to let
the error bubble up, until it reaches the main expression.
 1.125 22-Sep-2020  rillig make(1): rename VarParseErrors to VarParseResult

The name VPE_OK was confusing since it was not an error at all.
 1.124 22-Sep-2020  rillig make(1): use fine-grained type names for lists and their nodes

This is only intended to help the human reader. There is no additional
type safety yet.
 1.123 21-Sep-2020  rillig make(1): clean up VarParseErrors, for proper error handling

Having a pure bitset was wrong.

Instead, there are several alternatives (parse error, eval error, undef
error), and each of them can either have an error message printed (good)
or not (bad). In addition, there are VPE_OK for successful expression
evaluation and VPE_UNKNOWN (only used during migration to the correct
error handling scheme).
 1.122 13-Sep-2020  rillig make(1): fix documentation of VarParseErrors

It does not matter whether lint mode is enabled or not, Var_Parse must
reliably return whether an error message has been printed or not.

In the current phase where proper error handling is implemented only in
lint mode, this leads to code that looks a bit bloated since a few extra
branches are added, but that's ok. Eventually the SILENT constants will
all be removed, and then the number of different cases will shrink
again.
 1.121 13-Sep-2020  rillig make(1): suppress wrong "Malformed conditional" for undefined variables

This only has an effect in lint mode right now.
 1.120 13-Sep-2020  rillig make(1): make documentation of VarParseErrors more precise
 1.119 13-Sep-2020  rillig make(1): prepare Var_Parse for proper error handling and reporting

Right now, Var_Parse swallows many errors during parsing and evaluation.
Ideally, these errors should propagate from the deeply nested
expressions where they occur up to the top-level expressions. When such
an error occurs, the depending expressions should not be evaluated any
further. They may still be parsed, but side effects should be
minimized.

The goal is to prevent incomplete expressions like the "xy}" in
moderrs.exp:106 from being evaluated and eventually passed to the shell
for execution. This expression is a left-over from a parse error in the
mod-t-parse target in moderrs.mk:154.

This commit is a first step in analyzing and verifying the current state
of affairs. The modelling in VarParseErrors already looks complicated
but is expected to closely match reality.
 1.118 13-Sep-2020  rillig make(1): fix position of MAKE_ATTR_UNUSED in inline functions

The attribute needs to be before the return type, otherwise GCC 5
complains that Hash_GetValue is defined but not used, when compiling
with USER_CPPFLAGS=-Dinline=. The other functions don't get any
warnings. It's probably because Hash_GetValue is the only inline
function that returns a pointer.
 1.117 13-Sep-2020  rillig make(1): clean up API for evaluating conditions

There was no need to make struct If publicly visible.

There was no need to have parameters in the public API that were passed
the same constants all the time.

The former function names had not been distinctive.
 1.116 12-Sep-2020  rillig make(1): rename Var_ParsePP back to Var_Parse

The migration to the "parsing position" pointer has been done.
 1.115 12-Sep-2020  rillig make(1): migrate CondParser_String to Var_ParsePP
 1.114 12-Sep-2020  rillig make(1): add typedef for signal handler

Without this typedef, both the declaration and the definition of
bmake_signal were as unreadable as the declaration in the signal(3)
manual page.
 1.113 12-Sep-2020  rillig make(1): fix API of Targ_PrintNode

There was no need to export Targ_PrintNode at all. All the callers need
is a high-level API for printing a single node or a list of nodes. The
implementation detail that Targ_PrintNode was used as a callback to
Lst_ForEach should have never leaked into the API.
 1.112 12-Sep-2020  rillig make(1): fix API for Targ_PrintCmd

The previous API was too low-level and not strictly typed.
 1.111 12-Sep-2020  rillig make(1): fix prototype of Suff_EndTransform
 1.110 12-Sep-2020  rillig make(1): move PrintAddr to where it belongs
 1.109 12-Sep-2020  rillig make(1): fix prototype of Compat_Make
 1.108 12-Sep-2020  rillig make(1): fix name and prototype of Compat_RunCommand

By convention, exported identifiers are written with underscore.

The prototype of an exported function must not use void * just because
it is used in Lst_ForEach. This is an implementation detail and must
remain so.
 1.107 12-Sep-2020  rillig make(1): use proper return type for For_Accum
 1.106 06-Sep-2020  rillig make(1): add const for Parse_IsVar
 1.105 06-Sep-2020  rillig make(1): add const to For_Eval and For_Accum
 1.104 03-Sep-2020  rillig make(1): migrate Var_Parse API to parsing position

The ApplyModifier functions already use this pattern. For simplicity
and consistency Var_Parse should do the same. This saves a parameter to
be passed.

The migration takes place step by step, just like for the Lst functions
a few days ago.
 1.103 03-Sep-2020  rillig make(1): make parameter of Cond_Eval and Cond_EvalExpression const
 1.102 30-Aug-2020  rillig make(1): replace brk_string with Str_Words

The API is much simpler, and there is less detail that is exposed by
default and fewer punctuation to type on the caller's side. To see that
there is some memory to be freed, one would have to look into the
struct. Having part of the return value as the actual return value and
the rest in output parameters was unnecessarily asymmetrical.
 1.101 29-Aug-2020  rillig make(1): clean up comments in suff.c, small refactorings

In SuffParseTransform, the parameter names have been renamed to make the
"side effects" comment redundant.

In Suff_AddSuffix and Suff_AddLib, the parameter has been made const.

In SuffRemoveSrc, the unused variable has been removed, and the return
type has been fixed.
 1.100 29-Aug-2020  rillig make(1): allow for strict type checking for Boolean

Having Boolean aliased to int creates ambiguities since int is widely
used. Allow to occasionally compile make with -DUSE_DOUBLE_BOOLEAN to
check that the type definitions still agree.
 1.99 27-Aug-2020  rillig make(1): convert Arch_ParseArchive from ReturnStatus to Boolean

There are only few functions left that use the ReturnStatus. These will
be converted as well, to get rid of the additional typedef.
 1.98 23-Aug-2020  rillig make(1): make brk_string return size_t for the number of words
 1.97 23-Aug-2020  rillig make(1): fix assertion failure in debug output for read-only variables
 1.96 22-Aug-2020  sjg Add .SHELL as read-only variable

The .SHELL variable represents the shellPath used to run
scripts.

Reviewed by: rillig, christos
 1.95 21-Aug-2020  rillig make(1): remove function declarations without definitions
 1.94 11-Aug-2020  rillig make(1): add str_concat4 to make the other code simpler

There's no need for arch.c to call strlen when there is a high-level API
for the same purpose.
 1.93 10-Aug-2020  rillig make(1): replace str_concat with str_concat2 and str_concat3

The new functions have a simpler interface, and str_concat3 is even more
general-purpose, since the middle string is no longer required to be
exactly of length 1.
 1.92 10-Aug-2020  rillig make(1): fix parameter name of str_concat

The previous documentation mentioned Str_Concat, but str_concat has been
written in lowercase for years. The "flags" are not flags since they
cannot be combined, not even when they are written in hex.
 1.91 09-Aug-2020  rillig make(1): improve type signature of Var_Export
 1.90 08-Aug-2020  rillig make(1): clean up Var_UnExport

Mark the parameter as constant since it is not modified.

Remove tests for '\n' since these can never succeed.

newenv can never be NULL since neither of bmake_malloc or bmake_realloc
returns NULL.

Improve variable names: vlist was too unexpressive.

Add debug logging since unexporting variables is an uncommon operation
that directly affects the observable environment of the child processes.

Fix CRLF line endings in a few unit tests.
 1.89 01-Aug-2020  rillig make(1): use enum for return values of Cond_Eval and friends
 1.88 01-Aug-2020  rillig make(1): let Var_Value return a const char *

The return value must not be modified anyway, so let the compiler check
this for free.
 1.87 28-Jul-2020  rillig make(1): remove dead code from Var_Subst

The first parameter from Var_Subst had been a literal NULL in all cases.
These have been fixed using this command:

sed -i 's|Var_Subst(NULL, |Var_Subst(|' *.c

The one remaining case was not found because the "NULL," was followed by
a line break instead of a space.

The removed code probably wouldn't have worked as expected anyway.
Expanding a single variable to a literal string would have led to
unexpected behavior for cases like ${VAR:M${pattern}}, in case pattern
would contain an unescaped ':' itself.
 1.86 26-Jul-2020  rillig make(1): make return value of Var_Parse constant

This return value is not supposed to be modified since it can be a string
literal. The modifiable part is returned via freePtr, but only for
freeing, not for actually modifying anything.
 1.85 26-Jul-2020  rillig make(1): revert making Var_Parse return a const string

The dependencies between the C files and nonints.h are not declared
properly, which resulted in a successful partial build, but a full "make
clean && make" failed.
 1.84 26-Jul-2020  rillig make(1): mark result of Var_Parse as const

Var_Parse can return either a string literal or an allocated string. The
former must not be modified by the caller. If the string is allocated,
it is returned in freePtr as well, but only for freeing it after use.
 1.83 26-Jul-2020  rillig make(1): merge VARE_NOSUBST into VARE_WANTRES

The flag VARE_NOSUBST is only a few days old. It had grown out of the
VARP_NOSUBST and VAR_NOSUBST flags, not knowing at that time that it
meant the exact opposite of VARE_WANTRES.
 1.82 20-Jul-2020  rillig make(1): fix edge cases with $ at the end of the :@ modifier

In both parts of the :@ modifier, by passing &pflags to
ParseModifierPart, a final $ was interpreted as an anchor, which only
makes sense in the :S and :C modifiers.

This edge case is neither used by src nor by pkgsrc, except for the unit
tests that have been adjusted.
 1.81 20-Jul-2020  sjg Make DEBUG_HASH less of a fire-hose.

Reporting keys on every lookup is overkill unless
playing with a new HASH, so wrap in #ifdef DEBUG_HASH_LOOKUP
Also add some stats at the end so we can see
final size and max chain length - maxchain is a better
variable name than maxlen.
 1.80 19-Jul-2020  rillig make(1): rename Varf_Flags to VarEvalFlags

In var.c there are lots of different flag types. To make any accidental
mixture obvious, each flag group gets its own prefix.

The only flag group that is visible outside of var.c is concerned with
evaluating variables, therefore the "e", which replaces the former "f"
that probably just meant "flag".
 1.79 19-Jul-2020  rillig make(1): move SysV string matching to var.c

This kind of string matching is only used in variable modifiers, and only
if this feature is enabled by SYSVVARSUB.
 1.78 03-Jul-2020  rillig make(1): refactor Str_Match

- use shorter variable names to avoid line breaks
- eliminate c2 variable
- change return type to Boolean
 1.77 02-Jul-2020  rillig make(1): remove useless parameter from Var_Set

The enum corresponding to this int parameter is only defined in var.c,
which makes it impractical for the outside to set this parameter to
anything but 0.

On x86_64, this reduces the size of the resulting executable by 5 kB.
 1.76 02-Jul-2020  rillig make(1): add more type safety for enums

There are several types of flags for variables, and these cannot be
mixed. To prevent accidental typos, these are defined in separate enum
types. Clang warns about direct assignments between distinct types, but
not about mixing distinct types in binary expressions like A | B. GCC
does not warn at all.
 1.75 25-Apr-2020  christos - Percent on the rhs is special only if the lhs has one too.
- If the rhs does not have percent, but the lhs has, the result is the rhs
This behavior matches gmake
 1.74 05-Sep-2016  sevan Drop main() prototype.
 1.73 03-Jun-2016  sjg Add cached_realpath()

realpath(3) is expensive, and meta mode at least uses it extensively.
We use cached_realpath() to save the result of successful calls to
realpath(3) in a private variable context.

This improves the worst case performance (eg examining libc with
nothing to do) by a factor of 4.

Reviewed by: christos
 1.72 18-Feb-2016  sjg Add .export-literal to avoid the need for $$ dance when trying to put
unexpanded variables into environment.

Reviewed by: christos
 1.71 18-Feb-2016  christos Collapse the 3 boolean parameter to 1 flags parameter. No functional change.
 1.70 09-Jan-2016  christos Preserve $$ in := assignments..

FOO=\$$CRAP
BAR:=${FOO}

all:
echo ${FOO}
echo ${BAR}
 1.69 11-Oct-2015  sjg Add Boolean wantit to Var_Parse and Var_Subst

wantit will be FALSE when we are just consuming to discard
in which case we skip "expensive" things like Cmd_Exec.

Reviewed by: christos
 1.68 05-May-2015  sjg When evaluating condtionals from .if we want to require
that the lhs is a variable reference, a number or a quoted string.
This helps avoid subtle bugs caused by typos.

When conditionals are being evaluated during variable expansion
we cannot be as strict becuase lhs will already have been expanded.

We therefor pass a boolean to Cond_EvalExpression to tell it how
lhs should be treated.

Add unit-tests/cond2.mk to test the above

Reviewed by: christos, joerg
 1.67 07-Sep-2014  joerg Revert all make changes except the unit tests to the state of three
weeks ago. Individual changes can be reapplied after review.
 1.66 23-Aug-2014  christos PR/46096: Jarmo Jaakkola: fix many problems with dependencies (PR 49086)

Quite extensive rewrite of the Suff module. Some ripple effects into
Parse and Targ modules too.

Dependency searches in general were made to honor explicit rules so
implicit and explicit sources are no longer applied on targets that
do not invoke a transformation rule.

Archive member dependency search was rewritten. Explicit rules now
work properly and $(.TARGET) is set correctly. POSIX semantics for
lib(member.o) and .s1.a rules are supported.

.SUFFIXES list maintenance was rewritten so that scanning of existing
rules works when suffixes are added and that clearing the suffix list
removes single suffix rules too. Transformation rule nodes are now
mixed with regular nodes so they are available as regular targets too
if needed (especially after the known suffixes are cleared).

The .NULL target was documented in the manual page, especially to
warn against using it when a single suffix rule would work.
A deprecation warning was also added to the manual and make also
warns the user if it encounters .NULL.

Search for suffix rules no longer allows the explicit dependencies
to override the selected transformation rule. A check is made in
the search that the transformation that would be tried does not
already exist in the chain. This prevents getting stuck in an infinite
loop under specific circumstances. Local variables are now set
before node's children are expanded so dynamic sources work in
multi-stage transformations. Make_HandleUse() no longer expands
the added children for transformation nodes, preventing triple
expansion and allowing the Suff module to properly postpone their
expansion until proper values are set for the local variables.

Directory prefix is no longer removed from $(.PREFIX) if the target
is found via directory search.

The last rule defined is now used instead of the first one (POSIX
requirement) in case a rule is defined multiple times. Everything
defined in the first instance is undone, but things added "globally"
are honored. To implement this, each node tracks attribute bits
which have been set by special targets (global) instead of special
sources (local). They also track dependencies that were added by
a rule with commands (local) instead of rule with no commands (global).

New attribute, OP_FROM_SYS_MK is introduced. It is set on all targets
found in system makefiles so that they are not eligible to become
the main target. We cannot just set OP_NOTMAIN because it is one of
the attributes inherited from transformation and .USE rules and would
make any eligible target that uses a built-in inference rule ineligible.

The $(.IMPSRC) local variable now works like in gmake: it is set to
the first prerequisite for explicit rules. For implicit rules it
is still the implied source.

The manual page is improved regarding the fixed features. Test cases
for the fixed problems are added.

Other improvements in the Suff module include:
- better debug messages for transformation rule search (length of
the chain is now visualized by indentation)
- Suff structures are created, destroyed and moved around by a set
of maintenance functions so their reference counts are easier
to track (this also gets rid of a lot of code duplication)
- some unreasonably long functions were split into smaller ones
- many local variables had their names changed to describe their
purpose instead of their type
 1.65 30-Aug-2012  sjg Add a knob to control whether -V fully expands a plain variable by default.
The default retains the traditional NetBSD behavior, but the knob
can be set so that FreeBSD can retain their expected behavior.
This is a compromise to be sure.

Add a debug flag -dV to override the above, so that regardless of
the knob setting, the raw value of a variable can be easily seen.
 1.64 12-Jun-2012  joerg Replace __dead, __unused and the various printf format attributes
with versions prefixed by MAKE_ATTR_* to avoid modifying the
implementation namespace. Make sure they are available in all places
using nonints.h to fix bootstrap on Linux.
 1.63 16-Sep-2011  joerg branches: 1.63.2;
Use __dead consistently. If it doesn't exist, define it away.
 1.62 25-Dec-2010  dholland Begin cleanup of the make parser: separate out the logic for reading files
from the parsing goo. This will now use mmap for reading if it works and
fall back to read only for pipes and such. Step 1 of a cleanup program
proposed without objection on tech-toolchain.
 1.61 09-Dec-2010  sjg meta_oodate(): we should track 'latestdir' on a per process basis.
Also, only consider target out of date if a not-found file is outside
'CWD'. Ignore anything in "/tmp/" or tmpdir.
 1.60 07-Aug-2010  sjg wait[pid]() is called in several places.
If we encounter an error and run the .ERROR target, we may
reap a pid which jobs is waiting for. Ensure that we
cleanup so that make isn't left waiting for an already
deceased child.
 1.59 03-Jun-2010  sjg We have required sigaction() for quite a while.
Use bmake_signal() - a wrapper around sigaction()
rather than signal() to ensure that signals are handled
consistently.
 1.58 07-Apr-2010  sjg Add:

.error "message"
.warning "message"
based on FreeBSD implementation.
add .info while were at it.

.ERROR: a target to run on error.
We pass the failing GNode to PrintOnError so it can set
.ERROR_TARGET.

.MAKE.MAKEFILE_PREFERENCE
As a means to control make's list of prefered makefile names.
(Default: "makefile Makefile")

.MAKE.DEPENDFILE
Names the file to read dependencies from
(Default ".depend")

.MAKE.MODE
Processed after all makefiles are read.
Can put make into "compat" mode (more to come).

Fix:

compat.c: Error code should not be sent to debug_file.
Make_DoAllVar: use DONE_ALLSRC to avoid processing a node multiple times.
ReadMakefile: we can simply use doing_depend to control setting MAKEFILE.
 1.57 19-Nov-2009  sjg Add .unexport - the exact opposite of .export
and .unexport-env which unexport's all previously .export'd globals
as well as clearing environ[].
Allow's sys.mk near total controll.

Reviewed by: apb
 1.56 28-Jan-2009  dsl Allow for () in the argument to .ifdef et al.
Save/restore current values of global data across expression evaluation
to give ${foo:? ...} a change of working inside another .if.
 1.55 24-Jan-2009  dsl Move the bmake_malloc() functions into their own .c and .h files.
Include instead of make.h in a few places.
 1.54 23-Jan-2009  dsl Change 'ClientData' to 'void *' so that relevant parameters can
be made 'const void *'.
 1.53 17-Jan-2009  dsl Change 'Buffer' so that it is the actual struct, not a pointer to it.
Saves having to malloc/free a fixed size structure.
Buf_Init() now takes ptr to Buffer to initialiase.
Change Buf_Destroy() to return ptr to string when not freed.
Remove large number of casts to (Byte) and (Byte *) - 'Byte' is 'char' here.
Buf_AddByte[s] guarantees that the data is 0 termininated, so never add '\0'.
Keep 'count' not 'left' and 'inPtr', code is simplier with only one update.
Fix fallou, no functional change.
 1.52 13-Jan-2009  dsl Sprinkle a const. (arg of Main_ParseArgLine())
 1.51 11-Jan-2009  dsl Instead of stashing the body of every iteration of a .for loop, pass
Parse_SetInput() the name of a function to get the loop data blocks.
This should only be a change to the program logic.
 1.50 29-Nov-2008  dsl Split For_Eval() into two functions.
For_Eval() is now only called for the first line of a .for.
For_Accum() is called for the subsequent lines.
Stops any problems with forLevel being left invalid after an error.
Use a return value of -1 from For_Eval() to mean 'skip input line' to stop
a .for line with a syntax error being reparsed by make.
 1.49 06-Oct-2008  joerg Don't use emalloc and friends directly, but call them consistently
bmake_malloc and friends. Implement them via macros for the native case
and provide fallback implementations otherwise. Avoid polluting the
namespace by not defining enomem globally. Don't bother to provide
strdup and strndup, they were only used for the estrdup and estrndup
comapt code.

This addresses the presence of emalloc in system libraries on A/UX and
resulted strange issues as reported by Timothy E. Larson.
 1.48 15-Feb-2008  christos back all changes out until I fix it properly.
 1.47 14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.46 15-Oct-2007  sjg If we don't have emalloc, we won't have strndup either.
Allows building current make on 2.0.
 1.45 13-Oct-2007  apb * Convert all uses of strdup() to estrdup();
* Use estrndup() in a few cases where it simplifies the code;
* Provide compatibility definitions of strndup and estrndup;
 1.44 05-Oct-2007  sjg Add the ability to .export variables to the environment.
 1.43 04-Feb-2007  dsl branches: 1.43.4;
Add code to ensure that .if/.endif are correctly nested with .for/.endfor
and also include files don't have mismatched .if/.endif
It has been suggested that make used to have this test, but I can't
remember removing any code that might have performed it.
 1.42 16-Dec-2006  dsl Use open/read/close instead of stdio for makefiles.
Commons up the code for reading files and buffers, and allows a further
change where we don't copy the data out of the buffer when generating 'lines.
This will speed up makefile parsing (esp .if clauses).
 1.41 17-Nov-2006  dsl branches: 1.41.2; 1.41.4;
A rather large rototil in the way the parallel make code schedules jobs.
This gives a considerable speedup in the processing of .WAIT and .ORDER.
Both .WAIT and .ORDER stop both the commands of the node, and its dependant
nodes being built until the LH nodes are complete.
.WAIT only applies to the dependency line on which it appears, whereas
.ORDER applies globally between the two nodes.
In both cases dependant nodes can be built because other targets need them.
make now processes the target list left to right, scheduling child nodes
as they are needed to make other nodes (instead of attempting to generate
a bottom-up dependency graph at the start). This means that 'make -j1'
will tend to build in the same order as a non-parallel make.
Note that:
all: x y
x: a .WAIT b
y: b .WAIT a
does not generate a dependency loop.
But
x: y
.ORDER y x
does (unless something elswhere causes 'y' to be built).
 1.40 01-Nov-2006  sjg Use of libutil to provide emalloc et al, should be predicated on
a native NetBSD build using TOOLDIR etc.
Otherwise use the local versions.

Reviewed by: christos
 1.39 26-Aug-2006  christos Fix non-native build.
 1.38 26-Aug-2006  christos Don't include <util.h> if we are not NetBSD. Other OS's don't have it.
 1.37 26-Aug-2006  christos More programs using efun.
 1.36 31-Mar-2006  christos Add some coverity allocation comments, and change the way the allocator
functions work. When they allocate storage that needs to be freed, instead
of setting a boolean, set the pointer to be freed. Plug some more memory
leaks found by inspection.
 1.35 11-Feb-2006  dsl Debug trace all the targets we are actually intending making.
De-optimise the getting of a job token so we don't re-order the job
list when there are no tokens.
This might have helped etc/Makefile, but isn't enough.
 1.34 08-May-2005  christos Now that dependencies in .BEGIN, .END, and .INTERRUPT work, allow them.
 1.33 29-Dec-2004  christos Dir_MTime did not search for a file using the correct parh; i.e. it was
ignoring suffix-specific path search. So if a node was marked .MADE,
then suffix rules would not be applied to it, and we would look for
the file only in the default path, not the suffix-specific path.

XXX: Now that we looked for the suffix, we can save it in the GNode,
but we don't do this yet.
 1.32 07-May-2004  sjg Remove use of sh -e when running in compat mode.
Its not posix compliant and serves very little purpose.
With this change compat and jobs modes are consistent wrt how
they treat each line of a script.

Add support for the '+' command line prefix as required by posix.
Lines prefixed with '+' are executed even when -n is given.
[Actually posix says they should also be done for -q and -t]

PR:
Reviewed by: jmc
 1.31 07-May-2004  ross Simplify build, no functional changes.

Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().

It's now possible to build make on some hosts with: cc *.c */*.c
 1.30 06-Mar-2004  enami branches: 1.30.2;
Print useful line number on error while executing .for directive.
 1.29 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.28 14-Jul-2003  christos Pass WARNS=3
 1.27 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.26 14-Mar-2002  pk JobExec(): don't use Punt() in the child; it can't possibly DTRT, and will also
mess up the parents variables.

Instead, use execError() for all error paths in the child code.
 1.25 18-Jan-2002  thorpej Before we #define __attribute__ away, #undef it.
 1.24 18-Jan-2002  thorpej Make sure to eat __attribute__'s argument, too.
 1.23 17-Jan-2002  eeh __attribute__() if we're doing MAKE_BOOTSTRAP is a no-no.
 1.22 12-Jun-2001  sjg Add 4th arg (flags) to Var_Set so that VarLoopExpand can tell it not
to export interator variables when using context VAR_CMD.

Reviewed: christos
 1.21 29-May-2001  christos better error messages on exec* failures. From Simon Burge.
 1.20 03-Dec-2000  christos add noreturn attribute to the functions that need it.
 1.19 11-Oct-2000  is More format string cleanup by sommerfeld.
 1.18 15-Sep-1999  mycroft branches: 1.18.8;
Rework how :: dependencies are handled.
Build a list of `cohorts' as before, but do *not* link each one into all the
parent nodes; instead, copy the `cohort' lists into the stream of targets to
be built inside Make_ExpandUse(). Also do the attribute propagation as a
separate pass after parsing.
This eliminates several O(n^2) algorithms.
 1.17 18-Sep-1998  christos branches: 1.17.2;
Fix conditional variable expression parsing (reported by cgd)
 1.16 01-Apr-1998  christos Add conditional variable evaluation from Alistair Crooks.
 1.15 26-Mar-1998  christos PR/5210: Hauke Fath: make core dumps with .SHELL
Unfortunately this revealed a deeper problem with the brk_string code.
To fix it:
- remove sharing of the buffer between brk_string invocations
- change the semantics of brk_string so that the argument array
starts with 0, and return the buffer where the strings are
stored
 1.14 23-Sep-1997  fair branches: 1.14.2;
fix some ints that should be "time_t" per PR#4139
 1.13 02-May-1997  christos - Target searching addition:
Make used to only use the search path for nodes that were pure
sources (not targets of other sources). This has been corrected
and now gnu-autoconf generated Makefiles work in directories other
than the source one.

- Suffix transformation rescanning:
Suffix transformations (.c.o:; cc ...) were only recognized in
the past when both suffixes were members of the suffix list.
Thus a sequence like:
.z.b:
echo ${.TARGET}
.SUFFIXES: .z
would cause .z.b: to be inserted as a regular target (and the main
target in this case). Other make programs always add rules that
start with a period in the transformation list and never consider
them as targets. We cannot do that (consider .depend files) so we
resort to scanning the list of the current targets every time a
suffix gets added, and we mutate existing targets that are now
valid transformation rules into transformation rules. If the
transformed target was also the main target, we set the main target
to be the next target in the targets list.
 1.12 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.11 13-Aug-1996  christos Add estrdup(), a checked version of strdup and use it.
 1.10 28-May-1996  christos - Move -D flags from Makefile to config.h and explain what they do. Add
-Wall -Wno-unused to CFLAGS. Add new define SYSVVARSUB to enable SysV
style variable substitutions and enable them.
- Add SunOS style command substitutions via SUNSHCMD
- Fix core dump with '{variable = value'
 1.9 31-Mar-1996  christos branches: 1.9.4;
make emalloc and erealloc return void *; closes PR/2276
 1.8 29-Mar-1996  jtc Added erealloc() function that calls enomem() if the allocation fails
(this is like the existing emalloc() function). Changed all realloc()
calls to erealloc().
 1.7 02-Nov-1995  christos Minor:
- ${.PREFIX} should never contain a full pathname
- Fixed gcc -Wall warnings
Major:
- compatMake is now FALSE. This means that we are now running in
full pmake mode:
* rules on dependency lines can be executed in parallel and or
out of sequence:

foo: bar baz

can fire the rule for baz before the rule for bar is fired.
To enforce bar to be fired before baz, another rule needs to be
added. [bar: baz]
* adjacent shell commands in a target are now executed by a single
invocation of the shell, not one invocation of the shell per line
(compatMake can be turned off using the -B flag)
- The -j flag now works... I.e. make -j 4 will fork up to four jobs in
parallel when it can. The target name is printed before each burst
of output caused by the target execution as '--- target ---', when j > 1
- I have changed all the Makefiles so that they work with make -j N, and
I have tested the whole netbsd by:
'make -j 4 cleandir; make -j 4 depend; make -j 4; make -j 4 install'
- I have not compiled or tested this version of make with -DREMOTE.
 1.6 14-Jun-1995  christos - $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.5 16-Jun-1994  jtc Christos' fix for quoting variable extraction properly.
 1.4 06-Jun-1994  jtc Fixes from Christos Zoulas, who used purify, objectcenter and testcenter
to find memory leaks and illegal memory accesses.
 1.3 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9.4.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.14.2.1 08-May-1998  mycroft Sync with trunk, per request of christos.
 1.17.2.1 19-Oct-2000  he Pull up revision 1.19 (requested by he):
Format string cleanup.
 1.18.8.1 18-Oct-2000  tv Pullup usr.bin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.30.2.2 10-May-2004  tron Pull up revision 1.32 (requested by sjg in ticket #282):
Remove use of sh -e when running in compat mode.
Its not posix compliant and serves very little purpose.
With this change compat and jobs modes are consistent wrt how
they treat each line of a script.
Add support for the '+' command line prefix as required by posix.
Lines prefixed with '+' are executed even when -n is given.
[Actually posix says they should also be done for -q and -t]
PR:
Reviewed by: jmc
 1.30.2.1 10-May-2004  tron Pull up revision 1.31 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.41.4.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.41.2.1 05-Jun-2007  bouyer Apply patch (requested by tron in ticket #696):
usr.bin/make/compat.c patch
usr.bin/make/cond.c patch
usr.bin/make/dir.c patch
usr.bin/make/for.c patch
usr.bin/make/main.c patch
usr.bin/make/make.1 patch
usr.bin/make/make.c patch
usr.bin/make/make.h patch
usr.bin/make/nonints.h patch
usr.bin/make/parse.c patch
usr.bin/make/str.c patch
usr.bin/make/targ.c patch
usr.bin/make/util.c patch
usr.bin/make/var.c patch

Synchronize make(1) with HEAD branch to increase perfomance and
improve stability.
 1.43.4.1 06-Nov-2007  matt sync with HEAD
 1.63.2.1 30-Oct-2012  yamt sync with head
 1.753 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.752 16-Jun-2025  rillig make: in a warning without location information, print the stack trace

Without further context, a warning like the following is hard to track
back:

> nbmake[4]: warning: Invalid character " " in variable name
> "if ,"LSAN_OPTIONS=""
 1.751 13-Jun-2025  rillig make: skip inter-process stack trace when MAKE_STACK_TRACE=no

Previously, setting MAKE_STACK_TRACE to any other value than "yes"
accidentally generated almost-complete inter-process stack traces.
 1.750 13-Jun-2025  rillig make: add on-demand inter-process stack traces

When debugging a build that heavily uses nested calls to sub-makes, the
chain of calls is useful to quickly assess the situation. If explicitly
requested, include the actions from any parent processes in the stack
traces.

Reviewed by: sjg
 1.749 12-Jun-2025  rillig make: add program name to stack traces from sub-makes
 1.748 12-Jun-2025  rillig make: add quotes to "in directory" line in stack traces

The other lines in stack traces use quotes as well.
 1.747 12-Jun-2025  rillig make: use a common style for unexpected error messages

In enomem, report the actual error instead of a fixed ENOMEM.
 1.746 29-May-2025  sjg Ensure StackTrace is flushed
 1.745 26-May-2025  rillig make: prepare for inter-process stack traces

To understand how chains of sub-makes interact and how they are called,
it's useful to have stack traces that span multiple processes. To
implement this, a stack trace needs not only be printed but also stored
as a string.
 1.744 22-Apr-2025  rillig make: clean up

Replace 'unsigned int' with simply 'unsigned'.

In compat.c, skipping whitespace is not needed, as the loop above
already skips it.

In job.c, remove the unused header <sys/file.h>.

Inline the TMPPAT macro, as it is only needed in a single place.
 1.743 13-Apr-2025  rillig make: after entering POSIX mode, don't leave it again
 1.742 11-Apr-2025  rillig make: convert more messages to the "file:123" format
 1.741 30-Mar-2025  sjg make: POSIX mode, check for sysV style modifiers first

A POSIX compatible makefile should not be using any
of our native modifiers, so give preference to the sysV style modifier
and only check the others as a fallback.

Reviewed by: rillig
 1.740 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.739 29-Mar-2025  rillig make: in a stack trace with details and includes, list the current file
 1.738 14-Jan-2025  rillig make: simplify code for evaluating the '!=' variable assignment

An undefined variable evaluates to an empty string, without an error
message.
 1.737 14-Jan-2025  rillig make: simplify parsing of dependency lines

The evaluation modes that allow or deny undefined variables have the same
effect in this case, as Var_Subst does not return an error marker.
 1.736 31-Oct-2024  rillig make: in the debug log, always qualify line number with filename

Previously, to find out the filename corresponding to a line number from
a 'Parsing' line, it was necessary to find the preceding
'SetFilenameVars' line, which was unnecessarily time-consuming and
distracting.

The 'filename:line' format matches the one used in PrintStackTrace, and
it differs from the one used in PrintLocation, as the former format is
more common in other tools.

Most of the affected unit tests only use the 'Parsing' lines to give
additional context to their debug log, so no structural changes there.
 1.735 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.734 09-Jul-2024  rillig make: error out on parse/evaluation errors in shell commands

The expression ${VAR:X} has an unknown modifier ':X'. Previously, this
expression errored out when the expression was evaluated at parse time,
but not when the expression was evaluated when generating the commands
to bring a target up to date. The errors were previously reported, they
didn't affect the exit status, though.

Now, errors in expressions are handled in the same way, regardless of
the time at which they are evaluated.
 1.733 07-Jul-2024  rillig make: only generate code for cleanup functions in CLEANUP mode
 1.732 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.731 15-Jun-2024  rillig branches: 1.731.2;
make: in warnings, move the word "warning" to the front
 1.730 02-Jun-2024  rillig make: sync VarEvalMode constant names with their debug log names
 1.729 01-Jun-2024  sjg make: add .export-all

An explicit syntax for exporting all global variables is much safer
than allowing .export with no argument to do the same.

Add .export-all and have .export with no argument throw a warning saying
to use .export-all

Reviewed by: rillig
 1.728 31-May-2024  rillig make: clean up API for iterating over hash tables
 1.727 25-May-2024  rillig make: use fewer technical terms in debug message for dependency
 1.726 25-May-2024  rillig make: fix memory leak for command strings
 1.725 25-May-2024  rillig make: fix some more memory leaks
 1.724 25-May-2024  rillig make: fix a few more memory leaks
 1.723 19-May-2024  sjg make: use separate function to include makefiles.

Have Dir_FindFile and Dir_FindInclude call FindFile with a
bool flag to indicate whether .CURDIR should be be searched at all.
 1.722 27-Apr-2024  rillig make: simplify freeing of lists
 1.721 23-Apr-2024  rillig make: clean up comments, code and tests
 1.720 20-Apr-2024  rillig make: provide more context information for parse/evaluate errors
 1.719 14-Apr-2024  rillig make: add debug logging for .if and .for lines in -dp mode

This helps track down in which line a condition is evaluated.
 1.718 01-Apr-2024  rillig make: exit immediately after reading a null byte from a makefile

The chance of other garbage bytes in such a file is just too high.
 1.717 07-Feb-2024  rillig make: remove unneeded conditional-compilation toggles

The toggles INCLUDES, LIBRARIES, POSIX, SYSVINCLUDE, SYSVVARSUB,
GMAKEEXPORT and SUNSHCMD are no longer needed, they were unconditionally
set.

The toggle NO_REGEX was configurable from the command line, but
disabling it would result in various error messages about the unknown
':C' modifier.

OK sjg@.
 1.716 07-Jan-2024  rillig make: clean up comments, constify shell name
 1.715 05-Jan-2024  rillig make: miscellaneous cleanups
 1.714 03-Jan-2024  sjg make: do not add newline to an empty buffer

When LoadFile reads from /dev/null the buffer will be empty,
appending "\n" just results in an unnecessary extra call
to ParseRawLine.

Reviewed by: rillig
 1.713 29-Dec-2023  rillig make: unexport list memory management functions

They are only used in a single source file.

No functional change.
 1.712 19-Dec-2023  rillig make: clean up comments

No binary change, except for line numbers in assertions.
 1.711 17-Dec-2023  rillig make: clean up names of local variables

No binary change.
 1.710 19-Nov-2023  rillig make: replace 'variable expression' with 'expression' in comments

No binary change.
 1.709 02-Nov-2023  rillig make: miscellaneous cleanups

No functional change.
 1.708 02-Nov-2023  rillig make: clean up comments

No functional change.
 1.707 02-Nov-2023  rillig make: inline a single-line cross-file function

No functional change.
 1.706 19-Aug-2023  rillig make: show realistic invalid line in error message

Previously, the error message 'Invalid line' showed only the expanded
line, which might or might not show the actual problem. To be more
helpful, add the unexpanded line to the error message in case they
differ.

Remove the special handling of invalid lines that result from merge
conflicts. RCS is not commonly used anymore, and mentioning CVS was too
specific. By echoing the whole line, the patterns '<<<<<<' and '>>>>>>'
are clear enough to hint at the problem.
 1.705 19-Aug-2023  rillig make: add more details to error message about invalid lines
 1.704 23-Jun-2023  rillig make: sync a comment with reality

No binary change.
 1.703 21-Jun-2023  rillig make: skip a file protected by a multiple-inclusion guard more often

In practice, the common situation is that a file is first included,
defines its multiple-inclusion guard and is then skipped instead of
being included again.

The other way round is that the multiple-inclusion guard is defined when
the file is included first. In that case, the file is now regarded as
guarded as well.
 1.702 20-Jun-2023  rillig make: allow targets to be used as multiple-inclusion guards

This style is used by FreeBSD, among others.
 1.701 19-Jun-2023  rillig make: clean up code for skipping files with multiple-inclusion guard

No functional change.
 1.700 19-Jun-2023  rillig make: if a makefile is protected by a guard, only include it once

"looks reasonable" sjg@
 1.699 01-Jun-2023  rillig make: error out on a .break directive with arguments
 1.698 10-May-2023  rillig make: don't print null filename in stack traces

~~~makefile
!= printf '%s\n' '.include "2.mk"' > 1.mk
!= printf '%s\n' '!= rm 1.mk' '.info message' > 2.mk

.MAKEFLAGS: -dp
.include "1.mk"
.MAKEFLAGS: -d0

all:
~~~
 1.697 10-May-2023  rillig make: clean up comments
 1.696 15-Feb-2023  rillig make: inline macros for variable names

The variable name '.MAKEOVERRIDES' was already used in the non-macro
form.

No binary change.
 1.695 15-Feb-2023  rillig make: inline macro for variable name ".MAKE.EXPORTED"

The variable name is distinctive enough to be searched directly in the
code instead of having a named constant for it.

No binary change.
 1.694 14-Feb-2023  rillig make: clean up calls to Var_Subst

None of the calls to Var_Subst used the return value, and the return
value was always VPR_OK.

No functional change.
 1.693 14-Feb-2023  rillig make: reduce complexity of evaluating expressions

No functional change.
 1.692 24-Jan-2023  sjg make: .SYSPATH: to add dirs to sysIncPath

.SYSPATH: with no sources will clear sysIncPath
otherwise sources are added

Reviewed by: rillig
 1.691 23-Jan-2023  sjg make: .[NO]READONLY for control of read-only variables

Reviewed by: rillig
 1.690 03-Jan-2023  rillig make: add more details to warning 'Extra targets ignored'

Seen in binutils/zlib/Makefile.in:1283, which defines both '.MAKE' and
'.PHONY' in the same line.
 1.689 01-Oct-2022  rillig make: use consistent variable names in parser

No functional change.
 1.688 27-Sep-2022  rillig make: set WARNS to 6, from the default 5

No binary change on x86_64.
 1.687 24-Sep-2022  rillig make: clean up tracking of depth of nested .if directives

The variable cond_min_depth was redundant. It was only accessed while
parsing the makefiles. Merging it into struct IncludedFile removes the
possible confusion between cond_min_depth and including_cond_min_depth.

No functional change.
 1.686 24-Sep-2022  rillig make: only access the list of included files if it is non-empty
 1.685 24-Sep-2022  rillig make: fix variable and function names relating to .if nesting

The previous names were confusing since they suggested that cond_depth
instead of cond_min_depth would be saved and restored.

No functional change.
 1.684 23-Sep-2022  sjg Cond_reset_depth just use cond_min_depth

To avoid errors from unclosed conditionals on .break
it is sufficient to just set cond_depth = cond_min_depth.

Patch from rillig
 1.683 03-Sep-2022  rillig make: clean up handling of .break in .for loops

Move For_Break further up, as the functions in that file are sorted from
small to big. The cast from size_t to unsigned int is required by lint.

In parse.c, move the code into a separate function to keep
ParseDirective small. Its only job is to parse the directive and then
delegate to another function doing the actual work.

In the manual page, remove empty lines.

In the test, ensure that .break stops processing of the .for loop
immediately; anything after the .break is not processed anymore.
Replace ':=' with '=', as there is no need to evaluate '$i' early.
Check the expected value in the .mk file instead of the .exp file, to
keep the reading scope as small as possible.
 1.682 02-Sep-2022  sjg make: add .break to terminate .for loop early

When .break is encountered within a .for loop
it causes immediate termination.

Outside of a .for loop .break causes a parse error.

Reviewed by: christos
 1.681 24-Jul-2022  rillig make: fix out-of-bounds read when parsing an invalid line

Reported by Robert Morris in https://bugs.freebsd.org/265119.

Since 2021-12-14.
 1.680 12-Jun-2022  rillig make: reorganize Parse_Error

Determining the location where the error occurred is now done by
ParseVErrorInternal. This frees the remaining code from keeping the
filename and the line number together. It also makes Parse_Error short
enough that it might be worth providing a separate function for each of
the 3 log levels.

No functional change.
 1.679 11-Jun-2022  rillig make: fix memory leak in wildcard targets and sources

$ cat <<'EOF' > glob-leak.mk
all:
@pid=$$$$; \
ppid=$$(ps -o ppid -p "$$pid" | sed 1d); \
ps -o vsz,rsz -p $$ppid | sed 1d

.for _ in ${:U:${:Urange=$n}}
bin/*: source
.endfor
EOF

$ make.before -r -f glob-leak.mk n=1
19424 5280
$ make.before -r -f glob-leak.mk n=10
24220 10208
$ make.before -r -f glob-leak.mk n=100
71280 58504
$ make.before -r -f glob-leak.mk n=1000
556356 541620

$ make.after -r -f glob-leak.mk n=1
19208 5040
$ make.after -r -f glob-leak.mk n=10
22132 8092
$ make.after -r -f glob-leak.mk n=100
49040 35940
$ make.after -r -f glob-leak.mk n=1000
324160 314400

That's a saving of 40% already. The remaining 60% are suspicious as
well since after the first iteration of the .for loop, make's internal
state doesn't change conceptually, so there's no need to throw more
memory at it.
 1.678 11-Jun-2022  rillig make: separate cases in HandleDependencyTargetMundane

Most targets do not use wildcards, so there is no need to put the single
item into a list.

No functional change.
 1.677 11-Jun-2022  rillig make: extract HandleSingleDependencyTargetMundane

No functional change.
 1.676 11-Jun-2022  rillig make: remove redundant include for stdint.h

No functional change.
 1.675 10-Jun-2022  rillig make: rename loadfile to LoadFile

It was the only function in parse.c that had a lowercase name.

No functional change.
 1.674 10-Jun-2022  rillig make: split IncludeFile into separate functions

No functional change.
 1.673 10-Jun-2022  rillig make: extract half of IncludeFile into a separate function

No functional change.
 1.672 10-Jun-2022  rillig make: condense code for searching a file in the paths

No functional change.
 1.671 07-May-2022  rillig make: fix off-by-one error in buffer for .WAIT nodes

Strangely, GCC didn't warn about this error. For the buffer overflow to
actually happen, there would have to be a billion .WAIT nodes.
 1.670 18-Apr-2022  sjg Comment on interaction of posix.mk with[out] -r
 1.669 18-Apr-2022  rillig make: only switch to POSIX mode if '.POSIX:' is the first line

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html
says that in order to make a makefile POSIX-conforming, its first
non-comment line must be the special dependency line '.POSIX:' without
any source dependencies.

Previously, make switched to POSIX mode even if such a line occurred
anywhere else, which was allowed by POSIX but was deep in the
"unspecified behavior" area. For NetBSD make, there is no big
difference since it doesn't ship any <posix.mk> file, this change mainly
affects the bmake distribution.

Previously, makefiles that contain '.POSIX:' somewhere in the middle
could fail due to <posix.mk> resetting .SUFFIXES, among other things.

Suggested by Simon J. Gerraty, who also reviewed an earlier version of
this change.
 1.668 25-Mar-2022  sjg Include posix.mk when .POSIX: first encountered

Since .POSIX: is required to be the first non-comment line
in a Makefile, including ${MAKE_POSIX_MK} or whatever _PATH_POSIX_MK is
set to at this point is equivalent to an extension of sys.mk

This is a minimal change that can allow a better approximation of
POSIX compliance

Reviewed by: rillig
 1.667 03-Mar-2022  rillig make: improve comments and a parameter name

No binary change.
 1.666 09-Feb-2022  rillig make: remove redundant conditions

A line starting with '======' is parsed as a variable assignment, with
an empty variable name and a value starting with '=====', making that
condition unreachable.

No functional change.
 1.665 09-Feb-2022  rillig make: fix mistakes, spelling and typos in comments and manual page

No binary change for -DNDEBUG.
 1.664 09-Feb-2022  rillig make: clean up variable names

No binary change.
 1.663 07-Feb-2022  rillig make: remove stray empty line

No functional change.
 1.662 05-Feb-2022  sjg Ensure Parse_IsVar does not step off the end of input string.
 1.661 04-Feb-2022  rillig make: use unsigned int for line numbers everywhere

Previously, some line numbers were stored as signed int while others
were stored as size_t. Since line numbers are never negative, use an
unsigned type. Since the maximum file size for makefiles is 1 GB (see
loadfile), unsigned int is large enough even on 64-bit platforms.

Using a single data types reduces the number of type conversions. Using
unsigned int improves compatibility with C90 (printf %u instead of %zu),
which is needed by bmake, which is derived from usr.bin/make.

No functional change.
 1.660 29-Jan-2022  rillig make: for recursive variables in commands, print location

Print the approximate location based on the last command that has been
defined for the target. It would be possible to get more detailed
location information by counting the number of commands of the target,
but that would get messy due to .USEBEFORE, .USE and .DEFAULT, and
still, this is an edge case, so don't waste too much code for it now.
Having this hint about the location is more helpful than just a plain
"Variable X is recursive" without any further details.
 1.659 29-Jan-2022  rillig make: print stack trace on fatal errors

The only fatal error that occurs while the makefiles are read in is the
one about recursive variables, which didn't give any hint about the
location before.

If a recursive variable is detected while evaluating the commands of a
target to be made, there is no location information, as before.
 1.658 29-Jan-2022  rillig make: inline functions that have a single call site

No functional change.
 1.657 27-Jan-2022  rillig make: remove trailing whitespace, break lines

No binary change, except for assertion line numbers.
 1.656 27-Jan-2022  sjg Allow local variable assignments in dependency lines

The variable is set in the context of the target.
This syntax has been supported by gmake for ~ever.
If necessary a makefile can set .MAKE.TARGET_LOCAL_VARIABLES=false
to disable this.

Expose GetBooleanExpr so parse.c can use it.
 1.655 22-Jan-2022  rillig make: add missing newline after "cannot continue" message

It was wrong of Parse_File to output an unfinished line and hope for
some other code to finish it. As demonstrated in the test, PrintOnError
did not do that in the case of additional debug output.

To keep the overall behavior as close as possible to before, the other
callers of PrintOnError now have to pass the newline themselves. Passing
strings that start with newlines but don't end with them looked
suspicious anyway.
 1.654 22-Jan-2022  rillig make: clean up comments
 1.653 20-Jan-2022  rillig make: fix filename in warning about duplicate script (since 2018-12-22)
 1.652 16-Jan-2022  rillig make: condense code in Parse_IsVar

No functional change.
 1.651 15-Jan-2022  rillig make: use islower for parsing directives

None of the directives has an uppercase letter, so there is no need to
test for it.

No functional change.
 1.650 15-Jan-2022  rillig make: merge duplicate code for expanding variable expressions

No functional change.
 1.649 09-Jan-2022  rillig make: add missing printflike annotations to parse.c

Clang is stricter than GCC in checking format string inconsistencies.
Reported by Tobias Nygren.
 1.648 09-Jan-2022  rillig make: in Cmd_Exec, return error message instead of format string

This change leaves only literal format strings in parse.c. It allows
for more detailed error messages than the current "non-zero status" or
"exited on a signal".

No functional change.
 1.647 09-Jan-2022  rillig make: fix use-after-free in -dp mode (since yesterday)

In a .for loop that contains an unclosed .if directive,
Cond_restore_depth generates an error message. If stack traces are
enabled using the option '-dp', the details of the .for loop are added
to the stack trace, but at that point, the ForLoop had already been
freed. To reproduce:

make-2022.01.09.00.33.57 -r -f unit-tests/directive-for.mk -dp
 1.646 09-Jan-2022  rillig make: remove redundant lines from stack traces

These lines repeated the information from the .for loop line above them.
 1.645 09-Jan-2022  rillig make: in ApplyDependencySourceWait, align variable type with %u

No binary change.
 1.644 08-Jan-2022  rillig make: add details about .for loop variables to stack traces

The stack traces are enabled with the debug logging option '-dp'.
 1.643 08-Jan-2022  rillig make: fix stack traces in -dp mode (since 2021-01-26)

Previously, the stack traces omitted some lines that seemed to be
redundant. As a result, the stack traces contained confusing line
numbers.
 1.642 08-Jan-2022  rillig make: reduce confusing code in ParseForLoop

The previous version of the code gave the wrong impression that For_Eval
would modify CurFile. That happens only later, in For_Run.

No functional change.
 1.641 08-Jan-2022  rillig make: fix line number in debug log after returning from a file

The parser returns to the next line, not to the current line.
 1.640 08-Jan-2022  rillig make: return early from SkipIrrelevantBranches

No functional change.
 1.639 08-Jan-2022  rillig make: fix reported line numbers of continuation lines (since 2002)

Previously, multi-line directives like '.info' or '.error' reported the
line number of their last line instead of their first line, which is
more usual. This also affected the debug log from '-dp'.
 1.638 08-Jan-2022  rillig make: constify UnescapeBackslash, fix typo in comment

No binary change.
 1.637 07-Jan-2022  rillig make: remove redundant condition in ParseRawLine

The input buffer is guaranteed to be terminated by '\n'. This means
that after a '\\', there is no need to check for the end of that buffer.

While here, condense ReadLowLevelLine.

No functional change.
 1.636 07-Jan-2022  rillig make: rename local variable in ParseRawLine

The previous variable name suggested that the variable would point to
the first '#' character of the line, instead it points to the whitespace
before the first '#'.

No functional change.
 1.635 07-Jan-2022  rillig make: condense UnescapeBackslash

No functional change.
 1.634 07-Jan-2022  rillig make: in loadfile, use simpler magic numbers

No functional change.
 1.633 07-Jan-2022  rillig make: have as few statements as possible between va_start and va_end

No functional change.
 1.632 07-Jan-2022  rillig make: remove redundant function parameter in suffix handling

Now that mainNode is globally visible, there is no need to pass it
through function parameters.

No functional change.
 1.631 07-Jan-2022  rillig make: merge duplicate variables for the main target

No functional change.
 1.630 07-Jan-2022  rillig make: clean up comments, variable names, function names

The comment in ApplyDependencySourceOther repeated the code, its second
half didn't match any current code.

The comment above ParseDependencySourcesEmpty repeated the code.

No binary change, except for assertion line numbers.
 1.629 07-Jan-2022  rillig make: eliminate file-scope variable forLevel

No functional change.
 1.628 07-Jan-2022  rillig make: clean up comments and names in parse.c

No binary change except for assertion line numbers.
 1.627 07-Jan-2022  rillig make: rename IFile and its fields to match their actual content

For lines that use backslash continuation, the human-readable line
number does not equal the number of raw lines that have been read from
the file.

The big comment in PrintStackTrace has become outdated, it still
referred to first_lineno. Due to the bugs documented in
opt-debug-parse.mk, that function needs to be redone completely.

No functional change.
 1.626 07-Jan-2022  rillig make: clean up ParseDependencySources

It is not necessary anymore to modify the passed-in line. It had been
necessary when the parsing function was several hundred lines long, to
avoid gotos.

No functional change.
 1.625 07-Jan-2022  rillig make: clean up local variables in ParseDependencyTargets

Having only a single moving pointer is less confusing than the previous
copying between tgt and cp. For example, it did not make sense that the
target would start with '!'.

No functional change.
 1.624 07-Jan-2022  rillig make: remove redundant variable in ParseDependencyTargetWord

No functional change.
 1.623 07-Jan-2022  rillig make: clean up function argument names and comments

No binary change except for assertion line numbers.
 1.622 07-Jan-2022  rillig make: clean up nitpicks in parse.c

In PrintLocation, fname is not an iterator, so prefer fname[0] over
*fname.

List stdout and stderr in this order, for consistency with main.c.

No functional change.
 1.621 07-Jan-2022  rillig make: reduce negations in ParseVErrorInternal

No functional change.
 1.620 07-Jan-2022  rillig make: fix null pointer when including empty file (since 2022-01-01)

Calling malloc(0) may return a null pointer, but callers of bmake_malloc
do not expect that.

Reported by Chris Pinnock, found by cross-compiling NetBSD on OpenBSD,
where tools/groff creates Makefile.dep files of size 0.
 1.619 02-Jan-2022  rillig make: clean up nitpicks

In ParseWord, the expressions '*p' and 'ch' are the same.

In ParseDependencyTargetWord, clean up a wordy comment and join two
conditions.

In the test cond-token-number, clarify that make doesn't convert from
hex to decimal but only from hex to internal representation.

No functional change.
 1.618 02-Jan-2022  rillig make: clean up parsing of makefiles

Remove redundant comments.

Rename IFile.first_lineno to forBodyLineno since it only contains a
useful value in .for loops but not in .include files. Also clarify that
this line number is the start of the loop body, since in PrintStackTrace
this line is used as a human-readable line number. For a .for loop in
which the loop head spans multiple lines, this line number is wrong
anyway.

No functional change.
 1.617 02-Jan-2022  rillig make: remove redundant IFile.fromForLoop

No functional change.
 1.616 02-Jan-2022  rillig make: clean up handling of .for loops and .include directives

No functional change.
 1.615 02-Jan-2022  rillig make: fix line number in error message about open conditionals
 1.614 01-Jan-2022  rillig make: remove unused parameter from Parse_PushInput

The parameter readMore was never NULL.

No functional change.
 1.613 01-Jan-2022  rillig make: fix error message when reading more than 1 GB from stdin

Previously, the error message was:
make: (null): file too large
Now it is:
make: (stdin): file too large
 1.612 01-Jan-2022  rillig make: clean up loadfile

Do not reserve extra space "just in case a makefile does not end in
'\n'" since that doesn't happen often.

The assertion for 'buf.len <= buf.cap' was redundant.

No functional change.
 1.611 01-Jan-2022  rillig make: convert do-while into while in FindKeyword

GCC generates more efficient code; previously it wasn't aware that (end
- start) was always positive, thus allowing to omit the code for
dividing a negative number by 2.

No functional change.
 1.610 01-Jan-2022  rillig make: remove redundant comments from ParseDependencySourceSpecial
 1.609 31-Dec-2021  rillig make: sync API documentation of parse.c with latest changes
 1.608 31-Dec-2021  rillig make: prevent out-of-bounds pointer in AdjustVarassignOp

It's a rather theoretical case that 'name' would point at the very end
of the address space and the string there would be "V=", but in that
case, the expression 'name + 3' would wrap around.
 1.607 31-Dec-2021  rillig make: merge duplicate code in Parse_IsVar

No functional change.
 1.606 31-Dec-2021  rillig make: eliminate type VarAssignParsed

No functional change.
 1.605 31-Dec-2021  rillig make: unexport types VarAssignOp and VarAssign

These types are only needed in the parsing module.

No functional change.
 1.604 29-Dec-2021  rillig make: merge duplicate enum constants for CondEvalResult and CondResult

No binary change.
 1.603 28-Dec-2021  rillig make: rename and constify SkipExtraTargets

No binary change.
 1.602 28-Dec-2021  rillig make: clean up function names in parse.c, remove redundant comments

No functional change.
 1.601 28-Dec-2021  rillig make: extract the non-parsing part from ParseDependencyTargets

No functional change.
 1.600 28-Dec-2021  rillig make: clean up ParseDependency

No functional change.
 1.599 28-Dec-2021  rillig make: remove redundant variable in ParseDependencyTargets

The idea of that variable was to work on constant strings as far as
possible. For now it just blew up the code unnecessarily.

No binary change.
 1.598 28-Dec-2021  rillig make: remove redundant parameter from ParseDependencyTargets

No functional change.
 1.597 28-Dec-2021  rillig make: remove redundant parameters in dependency parsing functions

Before 2020, there had been a huge function for parsing a dependency
line, with lots of local variables that were reused for different
purposes. When that function was split up into smaller functions, that
was done mechanically, without eliminating redundant variables.

No functional change.
 1.596 28-Dec-2021  rillig make: remove redundant comments from ParseDependencyTargets

The large comment is already explained in the archive module.
 1.595 28-Dec-2021  rillig make: reduce scope of the list of wildcard target names

The list is only used when a single target name is parsed, in case the
name contains wildcards. There is no need to keep it any longer or
reuse it.

Clean up outdated and redundant comments.

No functional change.
 1.594 28-Dec-2021  rillig make: make ParseIsEscape simpler

No functional change.
 1.593 28-Dec-2021  rillig make: rename functions for handling dependency lines

The prefix 'Parse' was ambiguous since it was both the module name and a
verb. Rename those functions that don't actually parse anything.

No functional change.
 1.592 28-Dec-2021  rillig make: make debug logging for .ORDER more human-friendly

The interesting part of the .ORDER constraint is what is made before
what, so reveal this information in the debug log.

The debug output from the test looks a bit strange since it forces
'three' to be made before 'one', but that's because the test exercises
the edge case of introducing a circular dependency.
 1.591 28-Dec-2021  rillig make: make debug logging a bit more human-friendly

The previous log format "ParseReadLine (%d): '%s'" focused on the
implementation, it was not immediately obvious to a casual reader that
the number in parentheses was the line number. Additionally, having
both a colon and quotes in a log message is uncommon. The quotes have
been added in parse.c 1.127 from 2007-01-01.

The new log format "Parsing line %d: %s" is meant to be easier readable
by humans. The quotes are not needed since ParseReadLine always strips
trailing whitespace, leaving no room for ambiguities. The other log
messages follow common punctuation rules, which makes the beginning of
the line equally unambiguous. Before var.c 1.911 from 2021-04-05,
variable assignments were logged with the format "%s:%s = %s", without a
space after the colon.
 1.590 28-Dec-2021  rillig make: clean up variable names for parsing dependency lines

Rename 'spec' to 'special', for consistency with the previous commits.

Rename 'tOp' to 'targetAttr' since it is not an dependency operator like
':', it's an attribute like '.SILENT'.

No binary change, except for the line number of the assertion in line
1618.
 1.589 28-Dec-2021  rillig make: extract OP_NOTARGET into separate function

No binary change, except for line numbers in assertions.
 1.588 28-Dec-2021  rillig make: remove redundant local variable

The variable name 'end' suggested pointing to the end of the string, but
instead it pointed to the last possible starting position of the word to
be searched. Remove this possible misunderstanding.

No functional change.
 1.587 27-Dec-2021  rillig make: rename local variables to be simpler

No binary change.
 1.586 27-Dec-2021  rillig make: replace __func__ with actual strings

Make is supposed to be C90-compatible, and __func__ is from C99.

No functional change.
 1.585 27-Dec-2021  rillig make: clean up comments
 1.584 27-Dec-2021  rillig make: remove unnecessary words from command line options

Several years ago, the command line options were individual global
variables. The global variable could therefore not be named 'silent'
since that would have conflicted with local variables of the same name.
After moving the global variable to the namespace 'struct CmdOpts',
there is no conflict anymore.

There doesn't seem to be any risk of naming collisions for the names
'touch' and 'query'.

No functional change.
 1.583 15-Dec-2021  rillig make: format comments according to /usr/share/misc/style

Assisted by indent(1), with manual corrections due to its many remaining
bugs.

No functional change.
 1.582 15-Dec-2021  rillig make: in ParseDependencyCheckSpec, move default branch to the bottom

No functional change.
 1.581 14-Dec-2021  rillig make: condense repetetive code in ParseDirective

No functional change.
 1.580 14-Dec-2021  rillig make: remove dead code for handling traditional include directives

This code is not reached, a line containing only the word "include" is
categorized as error before.

No functional change.
 1.579 14-Dec-2021  rillig make: clean up parsing of variable assignments

Assign pairs of variables in a consistent order, as far as possible.

Use string functions instead of raw byte access, to make the code more
human-readable. GCC 10 optimizes the code reasonably.

No functional change.
 1.578 14-Dec-2021  rillig make: remove unreachable code for parsing the dependency operator

At the point where ParseDependencyOp is called, cp is guaranteed to
point to either ':' or '!'.

No functional change.
 1.577 13-Dec-2021  rillig make: clean up loading of files

The call to Buf_DoneData was useless since ownership of the buffer data
has already been passwed on to loadedfile_create and the local variable
'buf' goes out of scope after that statement.

Except for cleaning up in debug mode, there is no reason to call
Buf_DoneData and then discard the returned value.

No functional change.
 1.576 13-Dec-2021  rillig make: fix memory leak for filenames in .for loops (since 2013-06-18)

Previously, each time a .for directive pushed its buffer on the input
file stack, the current filename was duplicated. This was a waste of
memory.

The name of a file is typically only used while it is read in. There is
one situation when the filename is needed for longer, which is when a
target is defined.

Since .for loops are implemented as a special form of included files,
each .for loop duplicated the current filename as well.

$ cat << EOF > for.mk
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.endfor
.endfor
.endfor
.endfor
.endfor
.endfor
.endfor

all:
@ps -o rsz -p ${.MAKE.PID}
EOF

$ make-2021.12.13.03.55.16 -r -f for.mk
RSZ
10720

$ ./make -r -f for.mk
RSZ
1716

The difference is 8 MB, which amounts to 1 million .for loops.
 1.575 13-Dec-2021  rillig make: fix memory leak in IncludeFile

Previously, each .include leaked a copy of the file name.
 1.574 12-Dec-2021  rillig make: rename Parse_SetInput to Parse_PushInput

The word 'set' sounded too much like it would replace the current file,
but instead the file is pushed to the stack, and the previous file is
continued later.

No functional change.
 1.573 12-Dec-2021  rillig make: remove unused loadedfile.path
 1.572 09-Dec-2021  rillig make: remove period from end of error messages and warnings

The majority of the existing error messages and warnings does not
include a period at the end. Follow this style consistently.
 1.571 07-Dec-2021  rillig make: document that the input buffer is not null-terminated
 1.570 07-Dec-2021  rillig make: inline common subexpression in ParseRawLine

There is no need to load the buf_end from memory each time a character
from a makefile is processed. The end of the buffer only changes when
the file changes, not while reading a single line.

No functional change.
 1.569 04-Dec-2021  rillig make: merge duplicate code in ParseDirective

No functional change.
 1.568 03-Dec-2021  rillig make: do not try to expand fixed variable names

The function SetFilenameVars is only called with fixed variable names,
none of which contains a '$', so take a shortcut.

No functional change.
 1.567 03-Dec-2021  rillig make: only allocate the name of an included file if necessary

The string passed to IncludeFile is only used during that function call,
it is not stored anywhere.

No functional change.
 1.566 03-Dec-2021  rillig make: clean up ParseInclude

It was confusing to let the variable 'file' point to the '<' of the
.include directive. In each parsing function, there should only be a
single moving pointer, typically named 'p' or historically 'cp', even
though the 'c' is redundant.

No functional change.
 1.565 21-Sep-2021  rillig make: reduce relocations, thereby reducing .text size

No functional change.
 1.564 21-Sep-2021  rillig make: remove unnecessary const from parameters

These were leftovers from earlier refactorings, when extracting code to
separate functions.

No functional change.
 1.563 14-Aug-2021  rillig make: fix spelling of CVS and RCS in error message
 1.562 14-Aug-2021  rillig make: rename ParseMark to be more expressive

No functional change.
 1.561 14-Aug-2021  rillig make: rename variable and function for handling parse errors

The word 'fatals' was an unnecessary abbreviation.

No functional change.
 1.560 21-Jun-2021  rillig make: document ParseDependencyOp
 1.559 21-Jun-2021  rillig make: document where to find tests for the dependency lines
 1.558 21-Jun-2021  rillig make: extract ParseDependencySources from ParseDependency

No functional change.
 1.557 04-Apr-2021  rillig make: convert VarEvalFlags back into an enum, but not a bit-set

As was apparent in VarEvalFlags_ToString, a bit-set was not the best
data type since most of the flags were not freely combinable. The two
flags that could be combined were keepDollar and keepUndef, but even
these have distinguished names in the debug log.

The downside of struct bit-fields is that they need extra helper
functions in C90 (see nonints.h). Exchange these for a few helper
functions in var.c, to keep the code outside var.c simple.

No functional change.
 1.556 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.555 04-Apr-2021  rillig make: rename ambiguous functions

These two functions have counterparts that include the word 'Do' in
their name, which is confusing.

No functional change.
 1.554 03-Apr-2021  rillig make: rename function parameters to match boolean constants

No functional change.
 1.553 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.552 15-Mar-2021  rillig make: replace enum bit-field with struct bit-field for VarEvalFlags

This makes the code easier to read, especially in var.c. It also makes
debugging sessions easier since some debuggers don't show enum
bit-fields symbolically as soon as more than one bit is set.

The code outside var.c is basically unchanged, except that instead of
passing the individual flags, there are 4 predefined evaluation modes.
These suffice for all practical use cases. Only in the implementation
deep inside var.c, the value of the flags keepDollar and keepUndef
differs.

There is no way of passing the struct to EnumFlags_ToString, which means
the ToString function has to be spelled out explicitly. This allows for
fine-tuning the representation in the debug log, to reduce the amount of
uppercae letters.

No functional change.
 1.551 15-Mar-2021  rillig make: rename VARE_NONE to VARE_PARSE_ONLY

The name 'NONE' described the bit pattern, which was not useful to
understand its meaning. Omitting VARE_WANTRES only parses the
expression, without evaluating any part of it.

No functional change, not even in debug mode since Enum_FlagsToString
always returns "none" for all-bits-unset.
 1.550 22-Feb-2021  rillig make: remove freestanding freeIt variables

These variables all belong to a string variable. Connect them using
FStr, which reduces the number of variables to keep track of.

No functional change.
 1.549 05-Feb-2021  rillig make: clean up a few comments in parse.c
 1.548 05-Feb-2021  rillig make: in the Var_ functions, move the scope to the front

This change provides for a more natural reading order in the code.
Placing the scope first makes it immediately clear in which context the
remaining parameters are interpreted.

No functional change.
 1.547 05-Feb-2021  rillig make: add shortcut Global_Delete for deleting a global variable
 1.546 04-Feb-2021  rillig make: rename context and ctxt to scope

This continues the previous commit, in which VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE were renamed.

Renaming the variable 'ctxt' was trivial since that word is used nowhere
else. In the comments though, each occurrence of the word 'context' had
to be checked individually since the word 'context' was not only used
for referring to a variable scope. It is also used to distinguish
different situations where characters are escaped in a certain way
('parsing context') and in a few other expressions.
 1.545 04-Feb-2021  rillig make: rename some VAR constants to SCOPE

The word "context" does not fit perfectly to the variables that are
associate with a GNode, as the context is usually something from the
outside and the variables are more like properties inherent to the
GNode.

The term "global context" fits even less. Since the thing where
variables are looked up is commonly named a scope, use that term
instead.

This commit only renames the global variables VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE, plus a few very closely related comments. These are:

GNode.vars (because of line breaks)
GNode_Free (dito)
varname-make_print_var_on_error.mk
varname-make_print_var_on_error-jobs.mk

The debug message in Var_Stats is left as-is since there is no unit test
for it yet.

The other renamings (variable names "context", "ctxt", as well as
further comments) will be done in a follow-up commit.
 1.544 04-Feb-2021  rillig make: rename Var_Set to Var_SetExpand

After doing the textual renaming across all files, I added a new
function Var_Set that does not expand the variable name. I then undid
the renaming for all calls where the variable name cannot ever contain a
dollar sign. I omitted the word "Expand" from the textual references in
the unit tests and in the debug logging messages since the focus is
usually on the "Set" part, not on the "Expand".

No functional change.
 1.543 03-Feb-2021  rillig make: split Var_Exists into plain Var_Exists and Var_ExistsExpand

Most previous calls to Var_Exists use constant variable names. Only the
two calls in parse.c need to expand the variable name.

It may be a good idea to expand the variable name once in VarAssign_Eval
instead of repeating the expansion in each of its special cases.

No functional change.
 1.542 03-Feb-2021  rillig make: replace Global_AppendExpand with Global_Append

All callers with a variable name that is guaranteed to not contain a
dollar sign have been converted to call Global_Append instead of the
previous Global_AppendExpand. After that, Global_AppendExpand was
unused, therefore it was effectively just renamed.
 1.541 03-Feb-2021  rillig make: split Var_Append into Var_Append and Var_AppendExpand

The plain Var_Append now does not expand the variable name anymore. It
is used in situations where the variable name is known to not contain a
dollar sign.

This is a preparation for adding Global_Append, corresponding to
Global_AppendExpand.
 1.540 03-Feb-2021  rillig make: replace Global_SetExpand with Global_Set for constant names
 1.539 03-Feb-2021  rillig make: use shortcut functions Global_SetExpand and Global_AppendExpand

There are many places where global variables are set or appended to. To
reduce clutter and code size, encode the VAR_GLOBAL in the function
name.

The word Expand in the function names says that the variable name is
expanded. In most of the cases, this is not necessary, but there are no
corresponding functions Global_Set or Global_Append yet.

Encoding the information whether the name is expanded or not in the
function name will make inconsistencies obvious in future manual code
reviews. Letting the compiler check this by using different types for
unexpanded and expanded variable names is probably not worth the effort.
There are still a few bugs to be fixed, such as in SetVar, which expands
the variable name twice in a row.
 1.538 01-Feb-2021  rillig make: clean up comments in parse.c
 1.537 01-Feb-2021  rillig make: rename Parse_include_file to IncludeFile
 1.536 01-Feb-2021  rillig make: simplify VarAssign_EvalSubst

No functional change.
 1.535 01-Feb-2021  rillig make: replace parse error "Need an operator" with better message

The previous error message is not easily understandable since it is
missing a crucial detail, the column where the operator is needed.
Without this information, the author of the makefile gets no useful
hint. Furthermore, there are several types of operators in makefiles:

the dependency operators ':', '!', '::',
the variable assignment operators '=', '!=', '+=', '?=', ':=',
the conditional operators '&&', '||', '!',
the comparison operators '==', '!=', '>', '>=', '<', '<='.

This leaves too much ambiguity.

Replace this error message with "Invalid line type", which is more
generic, more accurate and thus less misleading.
 1.534 30-Jan-2021  rillig make(1): split Buf_Destroy into Buf_Done and Buf_DoneData

In all cases except one, the boolean argument to Buf_Destroy was
constant. Removing that argument by splitting the function into two
separate functions makes the intention clearer on the call site. It
also removes the possibility for using the return value of Buf_Done,
which would have made no sense.

The function Buf_Done now pairs with Buf_Init, just as in HashTable and
Lst.

Even though Buf_Done is essentially a no-op, it is kept as a function,
both for symmetry with Buf_Init and for clearing the Buffer members
after use (this will be done only in CLEANUP mode, in a follow-up
commit).
 1.533 27-Jan-2021  rillig make(1): fix irrelevant message in -W mode
 1.532 26-Jan-2021  rillig make(1): in -dp mode, print stack trace with each diagnostic

This makes it easier to track down where a warning or an error
originated from. This information could be further enriched for .for
loops, to also include the variable names and their values. For now,
it's good enough to replace the large comment describing how a stack
trace _could_ be generated with actual code that implements that idea.

The syntax of the locations is <filename>:<lineno>, which intentionally
differs from the traditional "<filename>" line <lineno>, since the
former is more widely supported by editors and IDEs.

Having this stacktrace information is especially intended for
complicated systems built upon make, such as pkgsrc.
 1.531 24-Jan-2021  rillig make(1): convert SearchPath to struct

This prepares for making dotLast a simple struct member instead of a
fake CachedDir, which is easier to understand.
 1.530 23-Jan-2021  rillig make(1): improve variable names when parsing directives
 1.529 23-Jan-2021  rillig make(1): rename Dir_AddDir, reorder parameters of SearchPath_ToFlags
 1.528 23-Jan-2021  rillig make(1): rename Dir_Expand to SearchPath_Expand

The main subject of this function is the search path. In this search
path the pattern is expanded.
 1.527 21-Jan-2021  rillig make(1): merge duplicate code in Parse_MainName
 1.526 10-Jan-2021  rillig make(1): consistently use boolean expressions in conditions

Most of the make code already followed the style of explicitly writing
(ptr != NULL) instead of the shorter (ptr) in conditions.

The remaining 50 instances have been found by an experimental,
unpublished check in lint(1) that treats bool expressions as
incompatible to any other scalar type, just as in Java, C#, Pascal and
several other languages.

The only unsafe operation on Boolean that is left over is (flags &
FLAG), for an enum implementing a bit set. If Boolean is an ordinary
integer type (the default), some high bits may get lost. But if Boolean
is the same as _Bool (by compiling with -DUSE_C99_BOOLEAN), C99 6.3.1.2
defines that a conversion from any scalar to the type _Bool acts as a
comparison to 0, which cannot lose any bits.
 1.525 31-Dec-2020  rillig make(1): replace pointers in controlling conditions with booleans
 1.524 30-Dec-2020  rillig make(1): format multi-line comments
 1.523 28-Dec-2020  rillig make(1): rename Buf_Expand_1 to Buf_Expand
 1.522 28-Dec-2020  rillig make(1): remove mmap for loading files, only allow files < 1 GiB

Using mmap is beneficial if the loaded data is read-only, or if it is
accessed in random order. Neither of these applies here. When loading
a file, make reads it strictly from top to bottom, once. During
parsing, the loaded data is modified in-place to insert '\0' and '\n'
for terminating strings and lines. Because of all of this, there is no
benefit in using mmap.

Reading the file using 2 calls to read(2) (one for the data, one for
checking for EOF) loads the data in a single pass, instead of producing
a page fault whenever the parser passes another page boundary.

Use a Buffer for loading the file data, to avoid calling bmake_realloc
directly.

Do not resize the loaded buffer at the end. Each loaded file is
short-lived anyway, and only a few files are loaded at the same time, so
there is no point in optimizing this part for low memory usage.
 1.521 28-Dec-2020  rillig make(1): replace global preserveUndefined with VARE_KEEP_UNDEF

Controlling the expansion of variable expressions using a global
variable and a VARE flag was inconsistent.

Converting the global variable into a flag had to prerequisites:

1. The unintended duplicate variable assignment had to be fixed, as
done in parse.c 1.520 from 2020-12-27. Without this fix, it would have
been necessary to add more flags to Var_Exists and Var_SetWithFlags, and
this would have become too complex.

2. There had to be a unit test demonstrating that VARE_KEEP_DOLLAR only
applies to the top-level expression and is not passed to the
subexpressions, while VARE_KEEP_UNDEF applies to all subexpressions as
well. This test is in var-op-expand.mk 1.10 from 2020-12-28, at least
for the ':@word@' modifier. In ParseModifierPartSubst, VARE_KEEP_UNDEF
is not passed down either, in the same way.
 1.520 27-Dec-2020  rillig make(1): fix edge case in := with undefined in variable name

Previously, the assignment "VAR${UNDEF} := value" actually assigned to 2
variables. See var-op-expand.mk for details.
 1.519 27-Dec-2020  rillig make(1): skip variable expansion in ParseDependencyTargetWord

The goal of the code is just to skip over the variable expression, thus
there is no need to evaluate it.
 1.518 27-Dec-2020  rillig make(1): exit 2 on technical errors

This allows the -q option to distinguish errors from out-of-date
targets. Granted, it's an edge case but it should be solved
consistently anyway.

The majority of cases in which make exits with exit status 1, even in -q
mode, is when there are parse errors. These have been kept as-is for
now as they affect many of the unit tests.

The technical errors, on the other hand, occur so rarely that it's hard
to write reliable tests for them that fail consistently on all platforms
supported by make.
 1.517 27-Dec-2020  rillig make(1): align names of VarExportMode with the directives
 1.516 23-Dec-2020  rillig make(1): fix a few lint warnings
 1.515 23-Dec-2020  rillig make(1): rename CmdOpts.lint to strict

When running lint(1) on the code, it defines the preprocessor macro
"lint" to 1, which generated a syntax error in the declaration "Boolean
lint", as that became "Boolean 1".
 1.514 22-Dec-2020  rillig make(1): re-add improved assertion in ParseGetLine
 1.513 22-Dec-2020  rillig make(1): remove assertion about lines ending with '\n'

It fails the NetBSD build.sh.
 1.512 22-Dec-2020  rillig make(1): remove needless assignment to line_end in ParseGetLine
 1.511 22-Dec-2020  rillig make(1): fix assertion failure for files without trailing newline

Previously, mmapped files didn't always have the final newline added.
Only those that ended at a page boundary did.

This confused ParseRawLine, which assumed (and since parse.c 1.510 from
moments ago also asserted) that every line ends with a newline, which
allows the code to assume that after a backslash, there is at least one
other character in the buffer, thereby preventing an out-of-bounds read.

This bug had been there at least since parse.c 1.170 from 2010-12-25
04:57:07, maybe even earlier, I didn't check.

Now line_end always points to the trailing newline, which allows
ParseGetLine to overwrite that character to end the string.
 1.510 22-Dec-2020  rillig make(1): prevent undefined behavior in loadfile_mmap

Reading a file without a trailing newline had resulted in an
out-of-bounds write, in the common case where the file is loaded via
mmap.
 1.509 21-Dec-2020  rillig make(1): fix garbled output for failed shell command (since 2020-12-20)

Passing a struct as printf argument for the %s conversion doesn't work.
On NetBSD-8.0-x86_64, the output looks normal, but on SunOS-5.9, the
output is garbled, containing bytes 0xFF and 0xFE.

This bug had been introduced in parse.c 1.507 from 2020-12-20 14:52:16.

Thanks to sjg for finding this bug so quickly.
 1.508 20-Dec-2020  rillig make(1): remove redundant const declarations for parameters
 1.507 20-Dec-2020  rillig make(1): clean up memory handling in VarAssign_EvalShell
 1.506 20-Dec-2020  rillig make(1): clean up memory handling in Parse_DoVar
 1.505 20-Dec-2020  rillig make(1): change return type of Var_Value to FStr
 1.504 20-Dec-2020  rillig make(1): return FStr from Var_Parse

This reduces the number of variable declarations at the call sites.
 1.503 19-Dec-2020  rillig make(1): fix error message for .info/.warning/.error without argument

Previously, the error message was "Unknown directive", which was
obviously wrong. The new error message is "Missing argument".
 1.502 19-Dec-2020  rillig make(1): extract Var_Undef from ParseDirective
 1.501 19-Dec-2020  rillig make(1): extract ParseSkippedBranches from ParseReadLine
 1.500 19-Dec-2020  rillig make(1): extract ParseForLoop from ParseReadLine
 1.499 19-Dec-2020  rillig make(1): rename mode constants for ParseGetLine to be more expressive
 1.498 19-Dec-2020  rillig make(1): fix documentation of GetLineMode

ParseGetLine always returns a logical line, even for PARSE_RAW.
 1.497 19-Dec-2020  rillig make(1): reduce debugging details in Parse_SetInput

The address of readMoreArg is hardly useful when stepping through this
part of the code, therefore omit it. Instead of mentioning the exact
function names of the data source, describe them in words, which helps
especially in the case of .for loops.
 1.496 19-Dec-2020  rillig make(1): rename parameter line to lineno
 1.495 19-Dec-2020  rillig make(1): document enum GetLineMode
 1.494 19-Dec-2020  rillig make(1): fix line numbers in .for loops (since 2007-01-01)
 1.493 19-Dec-2020  rillig make(1): merge parameter of ParseRawLine into return value
 1.492 19-Dec-2020  rillig make(1): clean up variable names in ParseGetLine and ParseRawLine
 1.491 19-Dec-2020  rillig make(1): fix variable names in UnescapeBackslash

The previous variable names had been chosen at a time when compilers
didn't merge variables into the same registers. Luckily, these times
are gone, and it's no longer necessary to use a variable for 2 or more
completely unrelated purposes.
 1.490 19-Dec-2020  rillig make(1): clean up ParseRawLine
 1.489 19-Dec-2020  rillig make(1): extract ParseRawLine from ParseGetLine
 1.488 19-Dec-2020  rillig make(1): clean up another local variable in ParseGetLine
 1.487 18-Dec-2020  rillig make(1): clean up UnescapeBackslash
 1.486 18-Dec-2020  rillig make(1): remove unused parameter from UnescapeBackslash
 1.485 18-Dec-2020  rillig make(1): split ParseGetLine into separate functions
 1.484 18-Dec-2020  rillig make(1): separate ParseGetLine into paragraphs
 1.483 15-Dec-2020  rillig make(1): document how to detect typos in .elif directives
 1.482 14-Dec-2020  rillig make(1): clean up ParseReadLine

In function names, the word "get" was not used consistently to look up
or compute data, in several cases "get" was a synonym for "read", just
like in the standard C library (fgetc).

The really confusing part is that there are two functions now, called
ParseGetLine and ParseReadLine, and both were underdocumented.
 1.481 13-Dec-2020  rillig make(1): replace %zu with %u in printf calls

This is needed to compile bmake with GCC 2.8.1 on SunOS 5.9.

To support ancient systems like this, the whole code of usr.bin/make is
supposed to use only ISO C90 features, except for filemon, which is not
used on these systems.
 1.480 13-Dec-2020  rillig make(1): add str_basename to reduce duplicate code

The function basename from POSIX has a few unfortunate properties, it is
allowed to return a pointer to static memory. This is too unreliable,
therefore this trivial own implementation.
 1.479 13-Dec-2020  rillig make(1): remove dead code from GetVarnamesToUnexport

Now that the parsing of the directives is unified and strict, there is
no need anymore for the dispatched functions to check for unknown
directives. These functions don't even get the information to decide
that since this decision is already done.
 1.478 13-Dec-2020  rillig make(1): replace *line with line[0]

Since a line is not an iterator and since the expression *line typically
means "the current element", not "the first character", replacing *line
with line[0] more directly expresses the idea of accessing the first
character of a string.
 1.477 13-Dec-2020  rillig make(1): clean up comment for ParseDirective
 1.476 13-Dec-2020  rillig make(1): clean up Var_Export
 1.475 13-Dec-2020  rillig make(1): error out on misspelled directives

Before, make accepted misspellings like .warnings, .export-literally and
a few others, all of which are unlikely to occur in practice. See the
test directive-misspellings.mk for further details.
 1.474 12-Dec-2020  rillig make(1): reduce indentation of ParseDirective
 1.473 12-Dec-2020  rillig make(1): eliminate boolean argument of Var_Export
 1.472 06-Dec-2020  rillig make(1): error out on null bytes in makefiles

Makefiles are text files, they must not contain null bytes.

The previous code in this area was rotten anyway. It assumed that
buf_end could be NULL even if buf_ptr was a valid pointer, which is no
longer true, probably since a few years already.

Continuing parsing after a null byte does not make sense. If there's a
null byte in a text file, that file is corrupted, and parsing it leads
to unintended effects easily. Therefore the only sensible action is to
stop parsing immediately.

The check whether cf->readMore could be null was outdated as well, which
previously made the fatal error impossible to reach. Because of the
missing unit tests, nobody noticed this though.

The "exit status 0" in opt-file.exp is worring but that's due to another
bug and will be fixed in a follow-up commit.
 1.471 06-Dec-2020  rillig make(1): rename IFile.nextbuf to readMore

The previous name sounded too much like a noun, which was too confusing.
See unit-tests/opt-file.mk for the history of this part of the code.
 1.470 06-Dec-2020  rillig make(1): fix undefined behavior in ParseEOF

Adding a number to a null pointer should have been caught by any
Undefined Behavior Sanitizer, but apparently neither GCC nor Clang do
this.
 1.469 05-Dec-2020  rillig make(1): indent parse.c with tabs instead of spaces
 1.468 05-Dec-2020  rillig make(1): reduce indentation in ParseDependencySourceKeyword
 1.467 05-Dec-2020  rillig make(1): extract ParseDependencySourceWait
 1.466 05-Dec-2020  rillig make(1): define constants for enum zero-values
 1.465 05-Dec-2020  rillig make(1): remove redundant assignments
 1.464 04-Dec-2020  rillig make(1): rename parse functions

The word "Do" was not necessary.
 1.463 29-Nov-2020  rillig make(1): reduce memory allocation for dirSearchPath
 1.462 29-Nov-2020  rillig make(1): reduce memory allocations for parsing dependencies
 1.461 29-Nov-2020  rillig make(1): reduce memory allocation for targets

This change moves the initialization and finalization of the list of
targets to the same function. They had been split before.
 1.460 28-Nov-2020  rillig make(1): reduce memory allocation for CmdOpts.create
 1.459 28-Nov-2020  rillig make(1): replace Dir_Destroy with SearchPath_Free

The function Dir_Destroy is an implementation detail of the cached
directories, and it should not be exported to the other modules. The
search paths, on the other hand, are the high-level API that may be used
by the other modules, as the concept of search paths is documented in
the manual page.
 1.458 28-Nov-2020  rillig make(1): rename some Dir functions to SearchPath

These functions have the search path as their main subject.
 1.457 28-Nov-2020  rillig make(1): reduce pointer indirection for GNode.cohorts
 1.456 28-Nov-2020  rillig make(1): reduce pointer indirection for GNode.order_pred and order_succ
 1.455 28-Nov-2020  rillig make(1): reduce memory allocation for GNode.parents and GNode.children
 1.454 28-Nov-2020  rillig make(1): remove pointer indirection from GNode.commands

Just to save a few memory allocations. No noticeable effect on the
performance though.
 1.453 28-Nov-2020  rillig make(1): fix type of local variable in ParseMessage
 1.452 28-Nov-2020  rillig make(1): rename local variable in ParseFindKeyword

It conflicts with the global 'cur'.
 1.451 23-Nov-2020  rillig make(1): use comparisons in boolean expressions

The generated code stays exactly the same.
 1.450 23-Nov-2020  rillig make(1): use properly typed comparisons in boolean contexts
 1.449 23-Nov-2020  rillig make(1): align end-of-line comments with tabs
 1.448 22-Nov-2020  rillig make(1): add another unit test for suffix handling
 1.447 22-Nov-2020  rillig make(1): add debug logging for setting and resetting the main target

The suffix code still doesn't behave as expected. Make sure that at
least setting the main target works as expected. It does, and the added
debug logging provides further hints for debugging the suffix handling
code.
 1.446 22-Nov-2020  rillig make(1): use canonical character comparison in ParseDoDependencyTargets
 1.445 20-Nov-2020  rillig make(1): make string iterator in ParseDependencyTargetWord const
 1.444 20-Nov-2020  rillig make(1): fix local variable name in ParseDoDependencyTargets
 1.443 16-Nov-2020  rillig make(1): rename Targ_NewGN to GNode_New

This function is a classical constructor function, and if it weren't for
CLEANUP mode, it would have no dependencies on anything else besides the
memory allocator. Therefore it doesn't really matter which module
defines this function, and there is no need for the "Targ" to be part of
the function name.
 1.442 15-Nov-2020  rillig make(1): clean up coding style in compat, parse, suff
 1.441 15-Nov-2020  rillig make(1): clean up make.h, meta.c, parse.c, str.c

The main changes are in the comments, which have been shortened and
corrected.

Some local variables changed their names.

In ParseErrorInternal, the scope of va_start is now narrower.

In ParseDoDependency, the type of tOp has been fixed.

ParseGetLine doesn't take flags anymore but instead a parsing mode.
Previously, the flags had not been combined anyway.

At the beginning of Parse_File, fatals is already guaranteed to be 0, and
even if not, it would be wrong to just discard the fatal errors.
 1.440 14-Nov-2020  rillig make(1): clean up comment above ParseDoDependencyTargetSpecial
 1.439 14-Nov-2020  rillig make(1): rename DEFAULT to defaultNode

In C, uppercase names are typically used for constants, and this is not
a constant.
 1.438 12-Nov-2020  sjg Pass a writable flag to Main_SetObjdir to control writable check

For curdir and an explicit .OBJDIR target, we allow for
the directory to be read-only.
During InitObjdir we otherwise default to requiring objdir to be
writable - this can be controlled by env variable
MAKE_OBJDIR_CHECK_WRITABLE

Add unit-tests/objdir-writable

Reviewed by: christos rillig
 1.437 08-Nov-2020  rillig make(1): move lint option away from the debug flags

The lint option affects much more than a typical debug flag. Not only
does it produce additional diagnostics, it also changes the control flow
and fixes the traditional error handling in a few places.

No functional change.
 1.436 08-Nov-2020  rillig make(1): clean up code related to VarEvalFlags

Mention VARE_WANTRES before VARE_UNDEFERR since the latter depends on
the former.

In ApplyModifier_Assign, VARE_KEEP_DOLLAR doesn't have to be removed
from eflags since ParseModifierPart does this already.

In EvalUndefined, testing for VARE_WANTRES is redundant if VARE_UNDEFERR
is already set.
 1.435 08-Nov-2020  rillig make(1): rename VARE_ASSIGN to VARE_KEEP_DOLLAR

The other flags in VarEvalFlags already describe their effects, not the
place where they are used. It's more important to know the effect.

Only a single unit test had to be adjusted. This probably means that
there are too few tests where the special effects of VARE_KEEP_DOLLAR
come into play. It could also mean that the effects are so simple and
obvious that they don't need any debug log, but that's not the case.
 1.434 08-Nov-2020  rillig make(1): use strict typing in conditions of the form !var
 1.433 08-Nov-2020  rillig make(1): inline strncmp in Parse_IsVar

The usual compilers don't do this themselves.
 1.432 07-Nov-2020  rillig make(1): replace strstr in ParseMaybeSubMake with optimized code

This code is called for each command that is parsed. Calling strstr with
4 strings that all start with the same character is unnecessary work.
Therefore, replace strstr with manually optimized code. Neither GCC
5.5.0 nor GCC 10 inlines strncmp like this, otherwise I would have used
that.

Change in behavior: previously, a${MAKE}b would not be considered to be a
sub-make command, which is probably correct but does not occur in
practice. The check for non-alphanumeric characters around the found
string was probably meant only for the plain word "make".
 1.431 07-Nov-2020  rillig make(1): remove redundant empty lines from parse.c
 1.430 07-Nov-2020  rillig make(1): clean up parse.c

The generated code stays exactly the same. The only changes will be the
line numbers of assertions. To preserve them, the removed lines have
been filled up with comments and will be removed in the follow-up commit.
 1.429 07-Nov-2020  rillig make(1): add pp_skip_hspace to skip horizontal whitespace during parsing
 1.428 07-Nov-2020  rillig make(1): clean up code stylistically

* Replace character literal 0 with '\0'.
* Replace pointer literal 0 with NULL.
* Remove redundant parentheses.
* Parentheses in multi-line conditions are not redundant at the
beginning of a line.
* Replace a few !ptr with ptr == NULL.
* Replace a few ptr with ptr != NULL.
* Replace (expr & mask) == 0 with !(expr & mask).
* Remove redundant braces for blocks in cases where the generated code
stays the same. (Assertions further down in the code would get
different line numbers.)
* Rename parameters in CondParser_String to reflect the data flow.
* Replace #ifdef notdef with #if 0.

The generated code stays exactly the same, at least with GCC 5.5.0 on
NetBSD 8.0 amd64 using the default configuration.
 1.427 05-Nov-2020  rillig make(1): remove redundant parentheses from sizeof operator

The parentheses are only needed if the argument is a type, not an
expression.
 1.426 04-Nov-2020  rillig make(1): align comments on a few commonly used variables
 1.425 04-Nov-2020  rillig make(1): fix indentation in parse.c
 1.424 04-Nov-2020  rillig make(1): negate discardUndefined to preserveUndefined
 1.423 04-Nov-2020  rillig make(1): rename oldVars to discardUndefined

While here, moved all the documentation about this variable into a
single place.
 1.422 02-Nov-2020  rillig make(1): fix undefined behavior in Parse_IsVar

Even though the pointer was out-of-bounds, a crash was unlikely in
practice, since typical C compilers don't check the pointers for invalid
values after each modification. The memory it pointed to was not
accessed though.
 1.421 02-Nov-2020  rillig make(1): document undefined behavior in Parse_IsVar

Sigh. If only C could be compiled in strict mode that detects these
out-of-bounds memory accesses.
 1.420 01-Nov-2020  rillig make(1): in lint mode, exit with error status on errors

Calling Parse_Error during parsing has always led to a nonzero exit
status. Calling Parse_Error later, when expanding the shell commands,
has had no effect on the exit status. Neither had calling Error.

To make make a reliable tool, it has to report errors as they occur.
Enable this strict behavior in lint mode for now. Lint mode has to be
enabled explicitly, preserving the default behavior.
 1.419 31-Oct-2020  rillig make(1): clean up StrContainsWord
 1.418 31-Oct-2020  rillig make(1): fix out-of-bounds pointer in ParseTrackInput
 1.417 31-Oct-2020  rillig make(1): improve local variable name in ParseTrackInput

By the way, the Address Sanitizer that ran over this code on 2015-11-26
didn't find the other out-of-bounds bug. Most probably the Address
Sanitizer only detected obvious bugs in the actual test data, and there
was no test case in which .MAKE.MAKEFILES was shorter than the newly
added makefile.
 1.416 31-Oct-2020  rillig make(1): fix off-by-one bug in ParseTrackInput (since 2015-11-26)
 1.415 31-Oct-2020  rillig make(1): document local variable in parse.c more precisely
 1.414 31-Oct-2020  rillig make(1): extract loadedfile_mmap from loadfile
 1.413 30-Oct-2020  rillig make(1): change char * to void * in Var_Value

The only purpose of the parameter freeIt is to free the memory
associated with the return value. To do this, no pointer arithmetic is
needed. Therefore, change to a void pointer, to catch accidental use of
that pointer.
 1.412 30-Oct-2020  rillig make(1): fix indentation in source code
 1.411 30-Oct-2020  rillig make(1): rename VAR_CMD to VAR_CMDLINE

Since make has to do with both the command line and child commands, the
former name was confusing.
 1.410 29-Oct-2020  rillig make(1): move comment from Parse_DoVar to Parse_IsVar
 1.409 28-Oct-2020  rillig make(1): rename defIncPath to defSysIncPath

There are two variables, parseIncPath and sysIncPath, which made the
name defIncPath ambiguous.
 1.408 28-Oct-2020  rillig make(1): merge curFile into includes

This makes GetActuallyIncludingFile simpler since it no longer needs the
special case for curFile.

The type of 'includes' has changed from Vector<IFile *> to
Vector<IFile>, to avoid a few extra memory allocations and because
Vector is easier to use with structs than with pointers (see
GetInclude).
 1.407 28-Oct-2020  rillig make(1): rename predecessor to order_pred

The new name aligns nicely with the GNode field of the same name.
 1.406 28-Oct-2020  rillig make(1): sort ParseSpecial alphabetically
 1.405 28-Oct-2020  rillig make(1): remove unused, undocumented .NOEXPORT
 1.404 28-Oct-2020  rillig make(1): rename ParseSpecial enum values consistently

The previous naming scheme was inconsistent in that dotError started
with a lowercase character and ExObjdir and ExPath had a distracting
prefix.
 1.403 28-Oct-2020  rillig make(1): rename some fields of struct IFile

The initial "P_" of these field names didn't match anything else. The
documentation was missing the purpose of the buffer. The start of the
buffer is only needed to free it later, so reflect that in the variable
name.
 1.402 28-Oct-2020  rillig make(1): clean up API comment in parse.c
 1.401 26-Oct-2020  rillig make(1): group the command line options and arguments

By having a single struct that holds all command line options and
arguments, it is easy to see in the code when such a command line
argument is modified. It also cleans up the namespace since the command
line options don't follow a common naming style. Having them in a
struct also means that there is a single place for putting the
documentation, not two as before.

The struct also suggests to extract the initialization code out of main,
which is still too large, having more than 400 lines of code and
covering far too many topics.
 1.400 25-Oct-2020  rillig make(1): replace PtrVector with Vector, which can contain any type
 1.399 25-Oct-2020  rillig make(1): rename type Vector to PtrVector

This allows the name Vector to be used for a more generic vector type,
which will be added soon.
 1.398 23-Oct-2020  rillig make(1): convert error level for Parse_Error to an enum
 1.397 23-Oct-2020  rillig make(1): negate OP_NOP and rename it to GNode_IsTarget
 1.396 22-Oct-2020  rillig make(1): remove redundant type casts

This mainly affects the void pointers in callback functions for lists.
These had been necessary once when the parameter type was still
ClientData instead of void pointer.
 1.395 20-Oct-2020  rillig make(1): clean up parsing code for dependency lines

The variable names "line" and "cp" were not appropriate for some of the
functions where they point to a single word, not to the whole line.

The const parameters were only necessary during refactoring, to make
sure that no unintended aliasing happens between the local variables.
This kind of bugs has already happened a few times in the last months,
and it requires full test coverage of all edge cases, which is not
achieved yet.

In ParseErrorNoDependency, lstart was always the same as line.
 1.394 19-Oct-2020  rillig make(1): inline simple Lst getters

The function call variant takes more screen space than the direct field
access. Having an abstract API is usually a good idea, in this case of
simple read-only member access it makes the code more difficult to read.

LstNode_Set has been kept as a function since it is not a read-only
accessor function.
 1.393 19-Oct-2020  rillig make(1): remove void pointers from ParseAddDir
 1.392 19-Oct-2020  rillig make(1): remove void pointers from ParseClearPath
 1.391 18-Oct-2020  rillig make(1): clean up and document VarAssign_Eval

In the previous commit, out_avalue_freeIt had been passed to
VarAssign_EvalSubst, which created a memory leak. Other than that, the
code changes are purely cosmetic.
 1.390 18-Oct-2020  rillig make(1): split VarAssign_Eval into smaller functions
 1.389 18-Oct-2020  rillig make(1): remove redundant code for determining the assignment operator
 1.388 18-Oct-2020  rillig make(1): move ParseVarassignOp further up
 1.387 18-Oct-2020  rillig make(1): fix GCC warning about small buffer for cohort_num

Since unmade_cohorts is a signed number (the code contains an underflow
check), the result of the '%' operator could be negative and result in
"#-999999", which would overflow the buffer, truncating the last digit.
 1.386 18-Oct-2020  rillig make(1): add tags to enum types

This allows IDEs to offer better type information than "anonymous enum".
 1.385 18-Oct-2020  rillig make(1): rename Lst_Init to Lst_New

For the other types such as HashTable and Buffer, the Init function does
not allocate the memory for the structure itself, it only fills it.
 1.384 18-Oct-2020  rillig make(1): rename Stack to Vector

Both Var_Dump and GetActuallyIncludingFile access more than only the top
item of the stack, therefore it is more honest to rename the data type.
 1.383 17-Oct-2020  rillig make(1): normalize initialization and cleanup of the modules
 1.382 17-Oct-2020  rillig make(1): remove struct ParseLinkSrcArgs

Inlining Lst_ForEach removes the need for the void pointers and the
additional parameter struct.
 1.381 17-Oct-2020  rillig make(1): extract ParseLine from Parse_File
 1.380 17-Oct-2020  rillig make(1): extract FindSemicolon from ParseDependency
 1.379 17-Oct-2020  rillig make(1): split Parse_File into smaller functions
 1.378 17-Oct-2020  rillig make(1): remove dead and broken warning for novices

In non-POSIX mode (which can only be enabled by editing config.h),
having a shell command indented by spaces instead of tabs would generate
a warning, and then, contrary to the comment above the code, no command
would be added to the current targets, since *cp == '\0'.

This had been broken since parse.c 1.133 on 2007-02-24, therefore it
seems unnecessary to even try to fix this code.
 1.377 17-Oct-2020  rillig make(1): clean up ParseMessage

Since there is no code path that would lead to the "invalid syntax"
message, it has been removed.

The switch statement for choosing the log level was overly bloated.
 1.376 17-Oct-2020  rillig make(1): remove redundant macros from ParseEOF and Parse_File
 1.375 17-Oct-2020  rillig make(1): fix stylistic issues in parse.c
 1.374 17-Oct-2020  rillig make(1): normalize spacing in parse.c
 1.373 17-Oct-2020  rillig make(1): fix indentation
 1.372 17-Oct-2020  rillig make(1): document the purpose of targCmds
 1.371 17-Oct-2020  rillig make(1): inline ParseHasCommands and ParseHasCommands
 1.370 05-Oct-2020  rillig make(1): enable format string truncation warnings for parse.c

No node is ever going to have a million or more cohorts. And even if
there were, this name is only used for printing informational messages.
 1.369 05-Oct-2020  rillig make(1): prepare job.c, main.c, parse.c, suff.c for WARNS=6

In job.c, GCC 5 complains about the macro FILENO that it has type
unsigned int, which is then passed as the argument of dup2, which
expects a simple int. Maybe this workaround from 1995 is not necessary
anymore, or maybe it is but can be restricted to the few affected
platforms.

This leaves meta.c and the filemon files to be converted. I didn't do
them since they are not well covered by the unit tests.
 1.368 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.367 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.366 05-Oct-2020  rillig make(1): extract parsing of sources from ParseDoDependency
 1.365 05-Oct-2020  rillig make(1): extract the target parsing from ParseDoDependency
 1.364 05-Oct-2020  rillig make(1): split ParseDoDependency into several smaller functions
 1.363 05-Oct-2020  rillig make(1): split ParseDoSrc into smaller functions
 1.362 04-Oct-2020  rillig make(1): fix assignment to .CURDIR via the shell assignment operator

This is probably an edge case that nobody will ever stumble upon, since
.CURDIR is usually regarded as a read-only variable.

The other variable that is affected by this code path is .MAKE.EXPORTED,
and for this variable as well, it would be unusual to assign it a value
from a shell command.
 1.361 04-Oct-2020  rillig make(1): rename local variable in VarAssign_Eval

The value to be freed is not always evalue. In the case of VAR_SUBST,
it will be the output of the command, not the command itself.
 1.360 04-Oct-2020  rillig make(1): hide some more implementation details from Parse_DoVar
 1.359 04-Oct-2020  rillig make(1): clean up remaining details in variable assignment parser
 1.358 04-Oct-2020  rillig make(1): clean up code for parsing ?= variable assignments

There is no need to handle the ?= operator in ParseVarassignOp already,
when all other operators are handled later.
 1.357 04-Oct-2020  rillig make(1): clean up parsing of variable assignments
 1.356 04-Oct-2020  rillig make(1): remove duplicate code for parsing a variable name
 1.355 04-Oct-2020  rillig make(1): rename parameter of Parse_IsVar
 1.354 04-Oct-2020  rillig make(1): split Parse_DoVar into manageable pieces

This makes it easier to eliminate duplicate code, for example in
Parse_IsVar and Parse_DoVar.
 1.353 04-Oct-2020  rillig make(1): don't modify the given line during Parse_DoVar

Placing null characters all over the line made the code hard to
understand. The null characters were placed for top-level whitespace as
well as the operator.

Working with a read-only line makes it easier to inspect the parsing
state during debugging.

This change involves an additional bmake_malloc for each variable name.
This will be compensated later by extending the API of the Var module to
also accept a pair of pointers (start, end) as the variable name.
 1.352 04-Oct-2020  rillig make(1): clean up local variables in Parse_DoVar

The variable "line" was misnamed since it turned from the beginning of
the line to the variable name. The variable "cp" was named too broadly.
Having two moving pointers in a single parsing function was too much.

Now p is the only moving pointer. From it, the variable name and value
are extracted as the pointer flies by. These more specific names make
the lower half of the function more readable since Var_Set(name, value)
sounds more correct and to the point than Var_Set(line, cp).

Memory management for the possibly expanded variable value is now
simpler as there may or may not be an expanded value, and that is freed
in every case. No need for another Boolean variable called freeCp
anymore. Distinguishing between the unexpanded value and the actual
value highlights the data flow.

Using const pointers is a step into the direction of having a parser
that operates on a read-only string. Right now the string is destroyed
upon parsing.
 1.351 04-Oct-2020  rillig make(1): fix out-of-bounds memory access in Parse_DoVar

When a line starts with "=value", this is interpreted as a variable
assignment, with an empty variable name. In that case, there is no
"previous character" from the '='. Accessing that character therefore
was an out-of-bounds read access.

If a whole file starts with "=value", instead of just a single line,
this out-of-bounds access can actually lead to a segmentation fault.
This depends on the memory allocator though.
 1.350 04-Oct-2020  rillig make(1): only use the VARE_ASSIGN flag if necessary

When checking the right-hand side of a variable assignment for syntax
errors, it does not matter whether a '$$' is expanded to '$' or kept as
'$$'.
 1.349 04-Oct-2020  rillig make(1): fix parsing of the :sh assignment operator modifier
 1.348 03-Oct-2020  rillig make(1): clean up #include sections
 1.347 03-Oct-2020  rillig make(1): remove dead store in ParseGetLine

GCC 5 didn't dare to optimize this by itself.
 1.346 03-Oct-2020  rillig make(1): inline macro ISEQOPERATOR

The name of the macro was wrong. These characters are not used in an
equality operator, it's an assignment operator.
 1.345 03-Oct-2020  rillig make(1): use consistent pattern for parsing whitespace

The pp and cpp in the function names stand for "parsing position" and
"const parsing position".
 1.344 01-Oct-2020  rillig make(1): add missing const for Parse_AddIncludeDir
 1.343 28-Sep-2020  rillig make(1): replace += 1 with ++ and -= 1 with --

Just for visual consistency. The generated code stays exactly the same.
 1.342 28-Sep-2020  rillig make(1): make debug logging simpler

This avoids referring to the debug_file variable in many places where
this implementation detail is not necessary.
 1.341 28-Sep-2020  rillig make(1): make debugging code shorter
 1.340 28-Sep-2020  sjg Remove unnecessary dieQuietly calls
 1.339 28-Sep-2020  sjg Ensure that parse errors report 'stopped in'
 1.338 27-Sep-2020  rillig make(1): normalize whitespace in source code

There is no more space tab. Either only tabs or only spaces or tabs
followed by spaces, but not spaces followed by tabs.
 1.337 27-Sep-2020  rillig make(1): inline Lst_ForEachUntil when parsing dependency lines

This avoids a few operations on void pointers.
 1.336 27-Sep-2020  rillig make(1): remove redundant null checks for the active targets

Before August 2020, the Lst library passed null pointers through. This
was a confusing design pattern that has been removed since. Now the Lst
functions fail fast on null pointers.

The 'targets' list is one of the few places where there is indeed an
optional list that may sometimes be null. Back then, there was not
enough inline documentation to understand when the targets list was null
and when it wasn't.

Now that the documentation is there, the redundant and thereby
misleading null checks are no longer useful.
 1.335 27-Sep-2020  rillig make(1): inline Lst_ForEachUntil in ParseDoDependency
 1.334 26-Sep-2020  rillig make(1): revert migration from Lst_ForEachUntil to Lst_ForEach

There is a crucial difference between these functions, in that
Lst_ForEachUntil can cope with a few concurrent modifications while
iterating over the list. This is something that Lst_ForEach doesn't do.

This difference led to a crash very early in NetBSD's build.sh.
 1.333 26-Sep-2020  rillig make(1): replace a few Lst_ForEachUntil with simpler Lst_ForEach
 1.332 26-Sep-2020  rillig make(1): clean up API for finding and creating GNodes

The previous API had complicated rules for the cases in which the single
function returned NULL or what it did. The flags for that function were
confusing since passing TARG_NOHASH would create a new node even though
TARG_CREATE was not included in that bit mask.

Splitting the function into 3 separate functions avoids this confusion.
It also reveals several places where the complicated API led to
unreachable code. Such code has been removed.
 1.331 26-Sep-2020  rillig make(1): replace a few Lst_ForEachUntil with simpler Lst_ForEach
 1.330 25-Sep-2020  rillig make(1): remove redundant variable inLine from parse.c

This variable has served at least 27 years bringing unnecessary
redundancy to the code. It was already redundant at 1993-03-21, when
the code was imported to NetBSD.
 1.329 25-Sep-2020  rillig make(1): rename ParseFinishLine to FinishDependencyGroup

Even after 27 or more years, it's not too late to fix bad function
names. This one for example does not finish a line but a dependency
group.
 1.328 25-Sep-2020  rillig make(1): fix missing check for duplicate commands in Parse_File
 1.327 25-Sep-2020  rillig make(1): inline Lst_ForEachUntil in ParseLine_ShellCommand
 1.326 25-Sep-2020  rillig make(1): extract ParseLine_ShellCommand from Parse_File

Parsing a single shell command from a line does not belong in
Parse_File, its proper place is in Parse_Line. Having the whole
detailed code inline in Parse_File is even more confusing.
 1.325 25-Sep-2020  rillig make(1): rename variables cp2 to be more expressive
 1.324 24-Sep-2020  rillig make(1): rename Lst_ForEach to Lst_ForEachUntil

Since the callback function returns a terminating condition, this is not
really a foreach loop.

Many of the calls to Lst_ForEachUntil don't make use of the terminating
condition, and several don't modify the list structurally, which means
they don't need this complicated implementation.

In a follow-up commit, Lst_ForEach will be added back with a much
simpler implementation that iterates over the list naively, without a
terminating condition and without taking the iteration state from
Lst_Open/Lst_Next/Lst_Close into account. The migration to this simpler
implementation will be done step by step since each callback function
needs to be examined closely.
 1.323 22-Sep-2020  rillig make(1): prepare Var_Subst for proper error handling

Returning a VarParseResult instead of a string makes it possible to let
the error bubble up, until it reaches the main expression.
 1.322 22-Sep-2020  rillig make(1): use fine-grained type names for lists and their nodes

This is only intended to help the human reader. There is no additional
type safety yet.
 1.321 22-Sep-2020  rillig make(1): rename type Path to CachedDir

The word "path" is commonly used either as an abbreviation for pathname
(a string consisting of several directory or file names) or as an
abbreviation for search path (a list of directory names used for
searching files), but not for a single directory.
 1.320 14-Sep-2020  rillig make(1): in lint mode, allow undefined variables in dependency lines

This is needed to get past the first few seconds in a src/build.sh run.

The nest obstacle is src/tools/Makefile.gnuhost:30, where the variable
MODULE is undefined even though that file says in line 3 that MODULE is
expected to be set. It has been saying this since 2001, but since make
didn't have the corresponding check enabled, this didn't break the
build.
 1.319 14-Sep-2020  rillig make(1): describe how Parse_Error might print stack traces

In deeply nested include chains and .for loops this may be a useful
feature. It's a little tricky to generate an intuitive stack trace,
though not impossible. This explanation also serves as a detailed
documentation about how the .include and .for directives are
implemented.
 1.318 14-Sep-2020  rillig make(1): add test for the global variable 'targets' in parse.c
 1.317 14-Sep-2020  rillig make(1): fix documentation of ParseLinkSrcArgs.specType

That code is never called for .SUFFIXES, but for .END.
 1.316 14-Sep-2020  rillig make(1): clean up documentation and code of ParseLinkSrc

The previous documentation was focused on the implementation details,
which are already clear from the code. Add some high-level
documentation to help readers understand how this function fits into the
overall picture.
 1.315 14-Sep-2020  rillig make(1): eliminate the global variable specType

This variable didn't have an intended lifetype of "whole application",
therefore it is better implemented as a local variable that is passed
around the few functions that really need it. It's the same pattern as
in the ModifyWord functions in var.c, only this time without a typedef.
 1.314 14-Sep-2020  rillig make(1): extract ParseDependencyTargetWord from ParseDoDependency
 1.313 14-Sep-2020  rillig make(1): split "general GNode *" in ParseDoDepends
 1.312 14-Sep-2020  rillig make(1): fix type of parseKeywords.op
 1.311 14-Sep-2020  rillig make(1): extract some code out of ParseDoDependency

With its almost 600 lines, that function is way too long.
 1.310 14-Sep-2020  rillig make(1): inline LPAREN in parse.c

It's shorter and more readable, and the other characters don't have
named constants as well.
 1.309 14-Sep-2020  rillig make(1): flip conditions in ParseDoDependency

In the usual case where the character is a letter or another ordinary
character, each of the terminal conditions has to be evaluated,
therefore from the compiler's view the order doesn't matter. For
humans, "a unless b" is easier to grasp and more common than "not b but
a", therefore switch to the common pattern.
 1.308 14-Sep-2020  rillig make(1): split complicated condition in ParseDoDependency
 1.307 14-Sep-2020  rillig make(1): split confusing condition in ParseDoDependency

A while loop is easier to understand than a do-while loop.

An if statement of the form if-something-then-do-something is easier to
understand than if-complicated-condition-then-continue-doing-something.
 1.306 14-Sep-2020  rillig make(1): clean up documentation of ParseDoDependency

The documentation was too low-level in parts, essentially repeating the
code in prose. Instead, add more examples and high-level context
information since that is something that the code cannot do.
 1.305 13-Sep-2020  rillig make(1): rename local variables in PrintLocation

For PrintLocation, there is no "current" filename or line number,
therefore the "c" in the variable names was confusing.
 1.304 13-Sep-2020  rillig make(1): prepare Var_Parse for proper error handling and reporting

Right now, Var_Parse swallows many errors during parsing and evaluation.
Ideally, these errors should propagate from the deeply nested
expressions where they occur up to the top-level expressions. When such
an error occurs, the depending expressions should not be evaluated any
further. They may still be parsed, but side effects should be
minimized.

The goal is to prevent incomplete expressions like the "xy}" in
moderrs.exp:106 from being evaluated and eventually passed to the shell
for execution. This expression is a left-over from a parse error in the
mod-t-parse target in moderrs.mk:154.

This commit is a first step in analyzing and verifying the current state
of affairs. The modelling in VarParseErrors already looks complicated
but is expected to closely match reality.
 1.303 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.302 13-Sep-2020  rillig make(1): clean up API for evaluating conditions

There was no need to make struct If publicly visible.

There was no need to have parameters in the public API that were passed
the same constants all the time.

The former function names had not been distinctive.
 1.301 13-Sep-2020  rillig make(1): clean up comments for ParseErrorInternal and ParseMessage
 1.300 13-Sep-2020  rillig make(1): fix comment for ParseVErrorInternal
 1.299 13-Sep-2020  rillig make(1): reduce complexity of PrintLocation

Analyzing a printf statement that is split into several small pieces is
harder than necessary in this case. Joing the printf statements into
simple strings. While here, remove the needless casts to int and add a
few empty lines for visual guidance.
 1.298 13-Sep-2020  rillig make(1): inline strchr call in IsInclude
 1.297 13-Sep-2020  rillig make(1): clean up the documentation for Parse_File
 1.296 13-Sep-2020  rillig make(1): remove redundant VARARGS comments

These had been necessary at a time when the functions were declared with
"unknown parameter types".

On 1994-03-05, conditional support for function prototypes was added,
for those compilers that already supported this feature.

On 2002-06-15, the prototypes were made mandatory, and since then the
VARARGS comments had been completely redundant, or worse, simply wrong
(for ParseVErrorInternal).
 1.295 12-Sep-2020  rillig make(1): reword variable invocation to variable expression

Variables are a passive thing. They cannot be invoked, they can only be
evaluated.
 1.294 12-Sep-2020  rillig make(1): rename Var_ParsePP back to Var_Parse

The migration to the "parsing position" pointer has been done.
 1.293 12-Sep-2020  rillig make(1): fix prototype of Suff_EndTransform
 1.292 12-Sep-2020  rillig make(1): fix inconsistent code indentation
 1.291 12-Sep-2020  rillig make(1): split ParseVErrorInternal into 2 functions
 1.290 11-Sep-2020  rillig make(1): add wrappers around ctype.h functions

This avoids casting the argument to unsigned char, and to cast the
result of toupper/tolower back to char.
 1.289 08-Sep-2020  rillig make(1): fix off-by-one error in SuffExpandChildren

In suff.c r1.144 from yesterday, in the line "cp += nested_p - cp", I
accidentally removed the "- 1". Since these "- 1" lines lead to slow
execution, each branch now increments the pointer separately by the
actually needed amount.

Fixing this bug posed way more new questions than it answered, and it
revealed an inconsistency in the parser about how characters are to be
escaped, and missing details in the documentation of Var_Parse, as well
as a parse error that unexpectedly doesn't stop make from continuing.
 1.288 07-Sep-2020  rillig make(1): with -dp, print name of the function instead of its address

This makes the output a bit more reproducible. There are still the file
descriptors, which may differ between different runs, but at least the
nextbuf function is printed using a symbolic name instead of a meaningless address.
Besides loadedfile_nextbuf, the only other function is ForIterate.
 1.287 07-Sep-2020  rillig make(1): migrate Var_Parse to Var_ParsePP in ParseDoDependency
 1.286 06-Sep-2020  rillig make(1): add const for Parse_IsVar
 1.285 05-Sep-2020  rillig make(1): replay the changes from v1.283

I accidentally reverted them in v1.284.
 1.284 05-Sep-2020  rillig make(1): clean up comments about parsing
 1.283 05-Sep-2020  rillig make(1): fix comments about setting .PARSEDIR and .PARSEFILE
 1.282 05-Sep-2020  rillig make(1): make GetActuallyIncludingFile faster

In deeply nested includes, starting the search from the inner end is
faster since it needs fewer comparisons.
 1.281 05-Sep-2020  rillig make(1): fix .INCLUDEDFROMDIR/.INCLUDEDFROMFILE
 1.280 05-Sep-2020  rillig make(1): fix local variable type in ParseIsEscaped
 1.279 05-Sep-2020  rillig make(1): fix return type of ParseIsEscaped
 1.278 05-Sep-2020  rillig make(1): remove redundant prototype for ParseMark
 1.277 05-Sep-2020  rillig make(1): remove redundant prototypes for local functions from parse.c
 1.276 04-Sep-2020  rillig make(1): use a stack instead of a list for the nested include path

By using a Stack instead of a Lst, the available API is reduced to the
very few functions that are really needed for a stack. This prevents
accidental misuse (such as confusing Lst_Append with Lst_Prepend) and
clearly communicates what the expected behavior is.

A stack also needs fewer calls to bmake_malloc than an equally-sized
list, and the memory is contiguous. For the nested include path, all
this doesn't matter, but the type is so generic that it may be used in
other places as well.
 1.275 01-Sep-2020  rillig make(1): clean up documentation in buf.h, and redundant include files
 1.274 30-Aug-2020  rillig make(1): rename Lst_Datum to LstNode_Datum
 1.273 29-Aug-2020  rillig make(1): trust that Var_Parse never returns NULL

That function is quite long, but all its return paths lead either to the
expanded variable expression, or to var_Error or varNoError.
 1.272 29-Aug-2020  rillig make(1): remove ReturnStatus, SUCCESS and FAILURE

These are used in so few places now that it is easier to use a simple
Boolean for them.
 1.271 29-Aug-2020  rillig make(1): add bmake_strsedup for duplicating a substring
 1.270 29-Aug-2020  rillig make(1): merge duplicate code for bmake_strldup
 1.269 29-Aug-2020  rillig make(1): allow for strict type checking for Boolean

Having Boolean aliased to int creates ambiguities since int is widely
used. Allow to occasionally compile make with -DUSE_DOUBLE_BOOLEAN to
check that the type definitions still agree.
 1.268 28-Aug-2020  rillig make(1): remove trailing 'S' from names of Lst functions

The migration from null-passing Lst functions to argument-checking Lst
functions is completed.

There were 2 surprises: The targets list may be NULL, and in Dir_AddDir,
the path may be NULL. The latter case is especially surprising since
that function turns into an almost-nop in that case. This is another
case where probably 2 independent functions have been squeezed into a
single function. This may be improved in a follow-up commit.

All other lists were fine. They were always defined and thus didn't
need much work.
 1.267 27-Aug-2020  rillig make(1): migrate Lst_IsEmpty to Lst_IsEmptyS
 1.266 27-Aug-2020  rillig make(1): migrate Lst_Last to Lst_LastS
 1.265 27-Aug-2020  rillig make(1): migrate Lst_ForEach to Lst_ForEachS

Most lists are always valid. Only the "targets" variable may be null in
some cases, probably.
 1.264 27-Aug-2020  rillig make(1): convert Arch_ParseArchive from ReturnStatus to Boolean

There are only few functions left that use the ReturnStatus. These will
be converted as well, to get rid of the additional typedef.
 1.263 26-Aug-2020  rillig make(1): add stricter variants for remaining Lst functions

In most cases the Lst functions are only called when the arguments are
indeed valid. It's not guaranteed though, therefore each function call
needs to be analyzed and converted individually.

While here, remove a few statements that were only useful when the Lst
functions handled circular lists.
 1.262 25-Aug-2020  rillig make(1): fix obvious bugs in -DCLEANUP mode

The outdated type name FreeProc had been renamed to LstFreeProc.
Casting the function free to it is not necessary since the type of this
function is already exactly the correct type. Anything else would be
undefined behavior anyway.

The uninitialized sufflist in Suff_ClearSuffixes was ok until now
because the Lst functions had silently skipped any calls with invalid
arguments. This silent skipping is a good argument to have strict
argument validation since it detects these unintended control flows.
 1.261 22-Aug-2020  rillig make(1): make moving and copying lists simpler

Instead of the two-in-one Lst_Concat, having two separate functions is
easier to understand. There is no need for a long API comment anymore
since the new functions have a single purpose that is accurately
described by their name.

The long comment inside Lst_Concat has been removed since it only
repeated the exact code, only in more words.

The comments in make.c about appending the cohorts had been wrong. They
were not appended but prepended. Once more, the function name expresses
everything that the comment said, making the comment redundant. There
is no need to test whether the cohorts list is empty, doing nothing is
implied by the word All in Lst_PrependAllS.
 1.260 22-Aug-2020  rillig make(1): clean up headers

Remove redundant headers that are already included by "make.h".
Make <assert.h> available to all compilation units that use "make.h".
 1.259 22-Aug-2020  rillig make(1): fix undefined behavior when assigning to variable ""

Using a programming language with built-in array bounds checks would
have prevented this bug, and many others as well.
 1.258 22-Aug-2020  rillig make(1): fix indentation
 1.257 22-Aug-2020  rillig make(1): replace Lst_Datum with non-null guaranteeing Lst_DatumS
 1.256 22-Aug-2020  rillig make(1): convert Lst_Enqueue and Lst_Dequeue to nonnull variants

Except for once instance in parse.c, the usage pattern for Lst_Dequeue
was to first test whether the list is empty. This pattern allowed the
implementation of Lst_Dequeue to become simpler since the null check is
not needed anymore.

The calls to Lst_Enqueue never pass an invalid list or a null pointer,
therefore making them strict was trivial.
 1.255 22-Aug-2020  rillig make(1): replace two instances of Lst_AtFront with Lst_Prepend

In these cases, the list is guaranteed to be valid, therefore no
assertion is expected.

For comparison, the Lst_AtFront in dir.c needs to be kept since the path
may be null there.
 1.254 22-Aug-2020  rillig make(1): convert remaining Lst_AtEnd to the stricter Lst_Append

The general-purpose list library that is included in make allows to call
Lst_AtEnd for invalid lists, silently ignoring this programming error.
This is a flexibility that make doesn't need.

Another unneeded "feature" is that list items can theoretically be null
pointers. This doesn't make sense as well and is therefore not needed
by make.

These programming errors are now caught early by assertions.
 1.253 22-Aug-2020  rillig make(1): replace "(void)Lst_AtEnd" with stricter "Lst_AppendS"

This change ensures that there is actually something added to the list.
Lst_AtEnd had silently skipped the addition if the list was invalid
(null pointer), which was not intended in these cases. The "(void)" is
assumed to mean "I know that this cannot fail", while it could also mean
"I don't care whether something actually happened".

Running "./build.sh -j6 tools" still succeeds after this change,
therefore chances are very low that this change breaks anything. If
there is any change, it's an obvious assertion failure. There is no
silent change in behavior though.
 1.252 21-Aug-2020  rillig make(1): remove unused code for circular lists

The list library had probably been imported from a general-purpose
library that also supported circular lists. These are not used by make
though.

After replacing Lst_Init(FALSE) with Lst_Init(), only a single call to
Lst_Init remained with a non-constant argument, and that was in
Lst_Concat, which was to be expected.
 1.251 10-Aug-2020  rillig make(1): replace str_concat with str_concat2 and str_concat3

The new functions have a simpler interface, and str_concat3 is even more
general-purpose, since the middle string is no longer required to be
exactly of length 1.
 1.250 09-Aug-2020  rillig make(1): improve type signature of Var_Export
 1.249 06-Aug-2020  sjg Remove VARE_WANTRES for LINT

We need the parsing checked.
I might make sense to add a VARE_LINT flag for corner cases.
Time will tell.

Reviewed by: rillig
 1.248 03-Aug-2020  rillig make(1): replace end-of-line comments with block comments

Just in case someone wants to port the current NetBSD make to an ancient
compiler that knows only C90.
 1.247 03-Aug-2020  rillig make(1): no declaration-after-statement anymore

NetBSD make is intended to be maximally portable, therefore it uses only
C89. This was not declared in the Makefile before.

There are still a few places in parse.c and metachar.c that use
end-of-line comments. These will be fixed in a follow-up commit.
 1.246 01-Aug-2020  rillig make(1): use consistent indentation in source code

Tabs for multiples of 8, then spaces.

The usage string has been kept as-is since the spaces there are
indentional and do influence the output.
 1.245 01-Aug-2020  rillig make(1): avoid calls to free(3) in the common case of a NULL pointer
 1.244 01-Aug-2020  rillig make(1): let Var_Value return a const char *

The return value must not be modified anyway, so let the compiler check
this for free.
 1.243 31-Jul-2020  sjg Add -dL for LINT

When parsing variable assignments other than := and if
value contains '$' attempt Var_Subst the same as for :=,
if the value does not parse correctly, we get a fatal error
including file an line number.

This can greatly help with finding the cause of problems.

Reviewed by: christos
 1.242 28-Jul-2020  rillig make(1): remove unnecessary parentheses in obvious cases
 1.241 28-Jul-2020  rillig make(1): remove dead code in parse error handling
 1.240 28-Jul-2020  rillig make(1): when parsing an unknown directive, print the directive name
 1.239 28-Jul-2020  rillig make(1): remove dead code from Var_Subst

The first parameter from Var_Subst had been a literal NULL in all cases.
These have been fixed using this command:

sed -i 's|Var_Subst(NULL, |Var_Subst(|' *.c

The one remaining case was not found because the "NULL," was followed by
a line break instead of a space.

The removed code probably wouldn't have worked as expected anyway.
Expanding a single variable to a literal string would have led to
unexpected behavior for cases like ${VAR:M${pattern}}, in case pattern
would contain an unescaped ':' itself.
 1.238 20-Jul-2020  rillig make(1): make modifier handling simpler

Implementing a modifier such as :S or :M should not be concerned with
separating the words of the resulting string. Ideally this should be
done in the same way by all modifiers.

Before, the :R (filename root) modifier added a separator even if the
resulting filename root was an empty string. The chances that this
change in behavior breaks anything are epsilon.

The :@ modifier, if it appeared after a :ts modifier, did not use the
word separator from the :ts modifier (which all other modifiers do) but
always added a space. This behavior has been preserved for now. It's an
unnecessary inconsistency though.

In contrast to Buffer, the newly added SepBuf uses size_t for memory
sizes and also uses the conventional parameter order (mem, memsize)
instead of the unusual (memsize, mem).
 1.237 19-Jul-2020  rillig make(1): rename Varf_Flags to VarEvalFlags

In var.c there are lots of different flag types. To make any accidental
mixture obvious, each flag group gets its own prefix.

The only flag group that is visible outside of var.c is concerned with
evaluating variables, therefore the "e", which replaces the former "f"
that probably just meant "flag".
 1.236 03-Jul-2020  rillig make(1): remove trailing whitespace
 1.235 03-Jul-2020  rillig make(1): remove redundant parentheses around return values
 1.234 02-Jul-2020  rillig make(1): remove useless parameter from Var_Set

The enum corresponding to this int parameter is only defined in var.c,
which makes it impractical for the outside to set this parameter to
anything but 0.

On x86_64, this reduces the size of the resulting executable by 5 kB.
 1.233 26-Sep-2019  sjg Do not assume safe to pass NULL to realpath(3).

PR: 54574
Reviewed by: buhrow
 1.232 09-Apr-2019  sjg ParseDoDependency: free paths rather than assert

PR: 52737
Reviewed by: christos
 1.231 22-Dec-2018  sjg ParseVErrorInternal: use .PARSEDIR and
apply realpath(3) if not absolute,
and use .PARSEFILE for consitent results.

Reviewed by: christos
 1.230 17-Dec-2018  christos PR/53796: Valery Ushakov: make prints wrong makefile path in an error message
Use ${.CURDIR} if ${.PARSEDIR} is not absolute.
 1.229 05-Apr-2018  christos branches: 1.229.2;
Appease the compiler gods; yes I know what I am doing adding to a literal
string.
 1.228 05-Apr-2018  christos Be more selective about detecting a SYSV include as opposed to a dependency
line. Dependency lines should contain a '::' operator or ':<space>'.
 1.227 22-Feb-2018  sjg branches: 1.227.2;
Avoid calling sysconf for every file loaded.
At start of a meta build this can be measurable overhead.

Patch from bdrewery at freebsd.org
 1.226 12-Feb-2018  sjg Do not treat .info as warning for -W

Reported by: lwhsu at FreeBSD.org
 1.225 17-Apr-2017  maya Use correct header for SIZE_MAX. from a.rin
 1.224 16-Apr-2017  riastradh Plug memory leak in ParseTraditionalInclude.
 1.223 16-Apr-2017  riastradh Plug memory leak.

CID 978370
 1.222 16-Apr-2017  riastradh Make it clearer that this is not a memory leak.

CID 978369
 1.221 16-Apr-2017  riastradh Guarantee no arithmetic overflow.
 1.220 16-Apr-2017  maya Use bmake_malloc where we don't test the return value of malloc currently.

Appeases coverity.
 1.219 16-Apr-2017  riastradh Use, don't kludge, MAKE_ATTR_UNUSED.

CID 1300234
CID 1300237
CID 1300238
CID 1300245
CID 1300255
CID 1300267
CID 1300284
 1.218 01-Mar-2017  sjg loadfile: in the mmap case ensures that the buffer ends with \n
do the same for the non-mmap case - avoids core dump.
 1.217 09-Dec-2016  sjg branches: 1.217.2;
Avoid coredump for

(FOO) = fu

reported by Ori Bernstein
 1.216 07-Dec-2016  christos Refactor and simplify objdir setting code.
 1.215 26-Aug-2016  dholland Add a .DELETE_ON_ERROR: magic target that causes *failed* targets as
well as *interrupted* targets to be deleted. The name and behavior of
the variable matches gmake.

Also fix a glitch in newline output on error in compat mode that I
discovered while doing it.

Closes PR 51376.
 1.214 06-Apr-2016  gson branches: 1.214.2;
Fully avoid the nonstandard types u_char, u_int, and u_long, which
were only used inconsistently in a few places anyway.
 1.213 11-Mar-2016  matthias make parsing of library member targets work. So

lib.a(member.o): something
cp something member.o
ar r lib.a member.o
rm member.o

will work now.
 1.212 19-Feb-2016  sjg Initialize curFile->depending in Parse_SetInput.
 1.211 18-Feb-2016  christos Collapse the 3 boolean parameter to 1 flags parameter. No functional change.
 1.210 18-Feb-2016  sjg Add support for .dinclude

Like .sinclude missing file will be ignored.
Like .depend stale dependencies will be ignored.
Allows better implementation of auto depend.

Reviewed by: christos
Requested by: Bryan Drewery at FreeBSD.
 1.209 17-Jan-2016  christos remove free NULL checks (Tilman Sauerbeck)
 1.208 17-Jan-2016  christos provide missing FD_CLOEXEC for the havenots.
 1.207 09-Jan-2016  christos Preserve $$ in := assignments..

FOO=\$$CRAP
BAR:=${FOO}

all:
echo ${FOO}
echo ${BAR}
 1.206 26-Nov-2015  sjg ParseTrackInput: do not access beyond end of buffer.

Detected by Address Sanitizer - dim at FreeBSD.org
 1.205 11-Oct-2015  sjg Add Boolean wantit to Var_Parse and Var_Subst

wantit will be FALSE when we are just consuming to discard
in which case we skip "expensive" things like Cmd_Exec.

Reviewed by: christos
 1.204 18-Sep-2014  dholland Comments, and one very minor tidyup.
 1.203 07-Sep-2014  joerg Revert all make changes except the unit tests to the state of three
weeks ago. Individual changes can be reapplied after review.
 1.202 29-Aug-2014  christos undo eating the trailing backslash now that the shell has been fixed.
 1.201 28-Aug-2014  christos don't leave trailing backlashes on commands, just like gmake does. What does
POSIX have to say?
 1.200 23-Aug-2014  christos PR/46096: Jarmo Jaakkola: fix many problems with dependencies (PR 49086)

Quite extensive rewrite of the Suff module. Some ripple effects into
Parse and Targ modules too.

Dependency searches in general were made to honor explicit rules so
implicit and explicit sources are no longer applied on targets that
do not invoke a transformation rule.

Archive member dependency search was rewritten. Explicit rules now
work properly and $(.TARGET) is set correctly. POSIX semantics for
lib(member.o) and .s1.a rules are supported.

.SUFFIXES list maintenance was rewritten so that scanning of existing
rules works when suffixes are added and that clearing the suffix list
removes single suffix rules too. Transformation rule nodes are now
mixed with regular nodes so they are available as regular targets too
if needed (especially after the known suffixes are cleared).

The .NULL target was documented in the manual page, especially to
warn against using it when a single suffix rule would work.
A deprecation warning was also added to the manual and make also
warns the user if it encounters .NULL.

Search for suffix rules no longer allows the explicit dependencies
to override the selected transformation rule. A check is made in
the search that the transformation that would be tried does not
already exist in the chain. This prevents getting stuck in an infinite
loop under specific circumstances. Local variables are now set
before node's children are expanded so dynamic sources work in
multi-stage transformations. Make_HandleUse() no longer expands
the added children for transformation nodes, preventing triple
expansion and allowing the Suff module to properly postpone their
expansion until proper values are set for the local variables.

Directory prefix is no longer removed from $(.PREFIX) if the target
is found via directory search.

The last rule defined is now used instead of the first one (POSIX
requirement) in case a rule is defined multiple times. Everything
defined in the first instance is undone, but things added "globally"
are honored. To implement this, each node tracks attribute bits
which have been set by special targets (global) instead of special
sources (local). They also track dependencies that were added by
a rule with commands (local) instead of rule with no commands (global).

New attribute, OP_FROM_SYS_MK is introduced. It is set on all targets
found in system makefiles so that they are not eligible to become
the main target. We cannot just set OP_NOTMAIN because it is one of
the attributes inherited from transformation and .USE rules and would
make any eligible target that uses a built-in inference rule ineligible.

The $(.IMPSRC) local variable now works like in gmake: it is set to
the first prerequisite for explicit rules. For implicit rules it
is still the implied source.

The manual page is improved regarding the fixed features. Test cases
for the fixed problems are added.

Other improvements in the Suff module include:
- better debug messages for transformation rule search (length of
the chain is now visualized by indentation)
- Suff structures are created, destroyed and moved around by a set
of maintenance functions so their reference counts are easier
to track (this also gets rid of a lot of code duplication)
- some unreasonably long functions were split into smaller ones
- many local variables had their names changed to describe their
purpose instead of their type
 1.199 23-Aug-2014  christos PR/49085: Jarmo Jaakkola: fix several parsing errors

Don't exit from var.c:Var_Parse() before possible modifiers are handled
on D and F modified versions of local variables. Properly expand $(?D)
and $(?F) too.

Make line continuations in rule's commands POSIX compliant.

Fix the syntax error caused by lib(member) as the last target before
a dependency operator.

Document the line continuation change in the manual page. Also talk
more about the POSIX style local variables and their modifiers.

Add tests covering the fixed problems into d_posix.mk. The test is
a known failure at the moment because of PR 49086 and PR 49092.

[XXX: unconverted tests]
 1.198 16-Jul-2014  justin Avoid use of __arraycount in tools as not portable
 1.197 16-Jul-2014  justin Remove an accidental C99-ism in tools which needs to be portable
 1.196 16-Jul-2014  christos remove debugging
 1.195 16-Jul-2014  christos PR/48367: David A. Holland: Mark possible submake nodes so that we can
avoid closing the job pipe on exec for them in order to make recursive
makes work in parallel.
 1.194 15-Feb-2014  christos branches: 1.194.2;
delete the correct variables on eof
fix typo in comment (from sjg)
 1.193 10-Jan-2014  christos add .INCLUDEDFROM{FILE,DIR}
 1.192 18-Oct-2013  christos fix unused variable warnings
 1.191 28-Aug-2013  sjg Fix parsing of SUNSHCMD style :sh = assigments.

Submitted by: Will Andrews at freebsd.org
 1.190 10-Aug-2013  sjg ParseGetLine: don't treat a zero byte as end of buffer if P_end says it isn't.
Consume up to next newline, and issue a parse warning.
If no newline found before P_end, carry on as before.
 1.189 18-Jun-2013  sjg Fix use after free bug.
Parse_SetInput:
curFile->fname was using the buffer passed to it - which ReadMakefile frees.
This change makes the comment in ParseEOF about leaking curFile->fname true.
 1.188 22-Mar-2013  sjg ParseGmakeExport: terminate variable at '=', or setenv(3) will fail
on some systems.
 1.187 05-Mar-2013  christos Add a .STALE special target that gets invoked when dependency files contain
stail entries.
 1.186 05-Mar-2013  christos Keep track of the location where a dependency is defined, so we can report
about it.
 1.185 12-Jun-2012  joerg branches: 1.185.2;
Replace __dead, __unused and the various printf format attributes
with versions prefixed by MAKE_ATTR_* to avoid modifying the
implementation namespace. Make sure they are available in all places
using nonints.h to fix bootstrap on Linux.
 1.184 24-Apr-2012  sjg Restore previous behavior - supressing duplicate entries in
.MAKE.MAKEFILES - it is more efficient.
 1.183 20-Apr-2012  sjg Fix some typos in/around ParseGmakeExport.
Remove the suppresssion of duplicate entries in .MAKE.MAKEFILES
 1.182 31-Mar-2012  christos Add a gmake inspired export command
 1.181 24-Mar-2012  sjg Avoid the need to escape the # in :[#] when parsing conditionals.
 1.180 06-Nov-2011  christos add debugging for parsedir and parsefile
 1.179 31-Aug-2011  plunky branches: 1.179.2;
NULL does not need a cast
 1.178 17-May-2011  dsl If a makefile if a multiple of the page size and doesn't end with a
newline, then it all goes horribly wrong when make tries to terminate
the last input line.
This was all ok before the mmap changes (rev 1.169) because the last
32 bytes of the input buffer were never read into.
The non-mmap case has a similar problem.
Bug found because my .depend files don't have a newline at the end of
the .OPTIO|NAL line (don't know if that is a local change).
 1.177 03-Mar-2011  nakayama Fix build on Solaris 10.
 1.176 20-Feb-2011  joerg Use the current directory at start time for .PARSEDIR, if the filename
contains no /.
 1.175 20-Feb-2011  dholland Remove the extra blank line after "Fatal errors encountered -- cannot
continue". This has been there since 1.1 but I don't think it was
intentional. If anyone actually cares about the blank line being there
for some reason, go ahead and revert this change...
 1.174 20-Feb-2011  dholland Remove stray extra newline in error message.
 1.173 25-Dec-2010  dholland branches: 1.173.2;
erm. fix previous...
 1.172 25-Dec-2010  dholland Maybe fix a problem that appeared on loonix.
 1.171 25-Dec-2010  dholland Uses stat; needs sys/stat.h. No idea what's pulling it in implicitly on
NetBSD so I didn't notice. Woops. Noted by Kurt Schreiner on current-users.
 1.170 25-Dec-2010  dholland Begin cleanup of the make parser: separate out the logic for reading files
from the parsing goo. This will now use mmap for reading if it works and
fall back to read only for pipes and such. Step 1 of a cleanup program
proposed without objection on tech-toolchain.
 1.169 13-Dec-2010  dholland typo in comment
 1.168 13-Dec-2010  dholland Tables used by parser logic should be const.
 1.167 13-Dec-2010  dholland Remove stray extern definition that's already in jobs.h.
 1.166 13-Dec-2010  dholland Cosmetic: declare types before variables, group variables by role,
update some comments, format comments properly, etc. No functional
change intended.
 1.165 13-Sep-2010  sjg Add meta.c which implements "meta" mode for make.
In this mode, a .meta file is created for each target, capturing
the expanded commands used, any command output, and if filemon(9)
is available, a record of system calls which are of interest.
Not enabled unless USE_META=yes is set when building make.
Also, if FILEMON_H exists, meta.c will be compiled to use filemon(9).
 1.164 24-May-2010  sjg Don't missinterpret targets that start with .info
 1.163 29-Apr-2010  sjg fflush stdout, before writing to stderr.
 1.162 08-Apr-2010  sjg Process .ERROR the same as .BEGIN, .END etc
so that it cannot be the default target.
Add unit-tests for .info - .error, and .ERROR.
 1.161 07-Apr-2010  sjg Add:

.error "message"
.warning "message"
based on FreeBSD implementation.
add .info while were at it.

.ERROR: a target to run on error.
We pass the failing GNode to PrintOnError so it can set
.ERROR_TARGET.

.MAKE.MAKEFILE_PREFERENCE
As a means to control make's list of prefered makefile names.
(Default: "makefile Makefile")

.MAKE.DEPENDFILE
Names the file to read dependencies from
(Default ".depend")

.MAKE.MODE
Processed after all makefiles are read.
Can put make into "compat" mode (more to come).

Fix:

compat.c: Error code should not be sent to debug_file.
Make_DoAllVar: use DONE_ALLSRC to avoid processing a node multiple times.
ReadMakefile: we can simply use doing_depend to control setting MAKEFILE.
 1.160 19-Nov-2009  sjg Add .unexport - the exact opposite of .export
and .unexport-env which unexport's all previously .export'd globals
as well as clearing environ[].
Allow's sys.mk near total controll.

Reviewed by: apb
 1.159 06-Nov-2009  dsl Report lines that ought to contain a ':' operator but start with a '.'
as "Unknown directive" sinze they are more likely to be .elseif (etc).
Lets me close PR/37222!
 1.158 07-Oct-2009  sjg The parser used to break dependency lines at ';' without regard
for substitution patterns. This (perhaps coupled with the
new handling of .for variables in ${:U<value>...) caused interesting
results for lines like:

.for file in ${LIST}
for-subst: ${file:S;^;${here}/;g}

add a unit-test to keep an eye on this.
 1.157 23-Jan-2009  dsl Change 'ClientData' to 'void *' so that relevant parameters can
be made 'const void *'.
 1.156 16-Jan-2009  dsl Parse_Error() really doesn't need to cruft up a dummy structure for curFile.
It only needs the 'fname' and 'lineno' fields - so just use NULL/0 when
curFile is NULL.
 1.155 11-Jan-2009  dsl Instead of stashing the body of every iteration of a .for loop, pass
Parse_SetInput() the name of a function to get the loop data blocks.
This should only be a change to the program logic.
 1.154 08-Jan-2009  dsl Fix PR bin/1443 properly!
Ignore '=' and ' ' inside {} and () when looking for an assignment operator.
Also require the operator be immediately after any whitespace.
XXX mismatched (){} in variable modifiers will not DTRT.
 1.153 04-Jan-2009  dsl Count () and {} when looking to the '=' that terminates the variable being
assigned to.
Should fix: A.${B:S/=//} = c
 1.152 13-Dec-2008  dsl Use NULL instead of -1 cast to the relavant type (usually via NIL).
This was a suggestion from christos - so blame him if there is a deep
reason for using -1 :-)
 1.151 29-Nov-2008  dsl Split For_Eval() into two functions.
For_Eval() is now only called for the first line of a .for.
For_Accum() is called for the subsequent lines.
Stops any problems with forLevel being left invalid after an error.
Use a return value of -1 from For_Eval() to mean 'skip input line' to stop
a .for line with a syntax error being reparsed by make.
 1.150 12-Nov-2008  apb intFile.fd should be initialised to -1, not 0.
 1.149 12-Nov-2008  christos avoid using c99 struct named initializers because this is a host tool and
needs to be compiled by a host compiler which might not be c99 compliant.
 1.148 29-Oct-2008  sjg branches: 1.148.2;
If Parse_Error is called after curFile is invalid, set it to a dummy
to avoid seg-fault. Also the NULL filename will cause ParseVErrorInternal
to skip trying to report file and line number info.

If CondToken is called outside the context of a .if etc, variables in
the expression being parsed will already be expanded, so allow for
an unqouted number to jump us back into the compare logic.
This allows ${${SomeNumber:U42} > 0:?True:False} to work anywhere.

Job_Finish should process postCommands if it has commands or children.
 1.147 06-Oct-2008  joerg Don't use emalloc and friends directly, but call them consistently
bmake_malloc and friends. Implement them via macros for the native case
and provide fallback implementations otherwise. Avoid polluting the
namespace by not defining enomem globally. Don't bother to provide
strdup and strndup, they were only used for the estrdup and estrndup
comapt code.

This addresses the presence of emalloc in system libraries on A/UX and
resulted strange issues as reported by Timothy E. Larson.
 1.146 03-Jun-2008  christos PR/38840: Pierre Pronchery: make crashes while parsing long lines in Makefiles
 1.145 15-Feb-2008  christos branches: 1.145.4; 1.145.6;
back all changes out until I fix it properly.
 1.144 14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.143 03-Jan-2008  dsl When we extend the buffer used to read makefiles (in order to read lines
longer than 32k) remember the new length so we DTRT for lines longer than 64k.
Should fix PR/37684
 1.142 22-Oct-2007  sjg Allow .PATH<suffix> to be used for .include "".
 1.141 13-Oct-2007  christos strlen returns size_t
 1.140 13-Oct-2007  dsl When processing .include "../../foo.mk" lexically process the leading ../
against the directory name of the makefile being processed.
Shortens a lot of pathnames (especially in pkgsrc) and significantly
reduces the number of duplicate entries in .MAKE.MAKEFILES
 1.139 12-Oct-2007  dsl If we are going to save the names of all opened makefiles, do so when files
are first processed, not for every line of every loop inside the file.
When (attempting) to check for duplicate names, use the spaces between names
as separators rather than using strstr() - which is slow and wont find
duplicates after an incorect early match.
However the duplicate check is rather broken (especially for pkgsrc) where
names like ../../devel/atk/../../devel/glib2/../../devel/gettext-lib/ \
../../devel/gettext-lib/../../mk/buildlink3/../../mk/bsd.prefs.mk
which need (some form of) realpath() processing.
'cd pkgsrc/xaa/gtk2; make show-var VARNAME=.MAKE.MAKEFILES' shows the problem.
 1.138 12-Oct-2007  christos static a const string.
 1.137 08-Oct-2007  sjg Use .MAKE.MAKEFILES to track all the makefiles that have been read
so they can be used in dependency rules.
 1.136 05-Oct-2007  sjg Add the ability to .export variables to the environment.
 1.135 01-Oct-2007  sjg Add the ability to tweak the token output before targets in job mode.
Eg.
.MAKE.JOB.PREFIX=${.newline}---${.MAKE:T}[${.MAKE.PID}]
would produce
---make[1234] target ---
 1.134 23-May-2007  dsl branches: 1.134.4;
Delete some comments that refer to long-extinct code.
 1.133 24-Feb-2007  dsl Don't increment 'cp' twice when looking for commands following ';' on a
dependency line.
This makes the line "foo:;echo bar" not try to execute "cho bar", and the
line "baz:;" not treat the rest of the makefile as commands.
Pointed out by Takahiro Kambe on current-users.
 1.132 04-Feb-2007  dsl Add code to ensure that .if/.endif are correctly nested with .for/.endfor
and also include files don't have mismatched .if/.endif
It has been suggested that make used to have this test, but I can't
remember removing any code that might have performed it.
 1.131 24-Jan-2007  dsl Check of open conditionals before we trash 'curFile' - so we can actually
report the filename of the error (without core dumping!).
Also fix tests for reporting errors to the debug_file, and don't add $PWD
to (stdin).
 1.130 18-Jan-2007  dsl Don't delete '\' from before '#' in shell command lines.
Probably fixes build of pkgsrc:editors/xemacs.
Pointed out by Richard Earnshaw.
 1.129 15-Jan-2007  christos Avoid coredumping. Found by accidentally running make instead of gmake
in java's control/make directory.
 1.128 02-Jan-2007  dsl Don't delete whitespace before a "\\\n" sequence. Somewhere I'd misread
the required behaviour and replaced it with something more sensible - except
for makefiles that contain "\n\t\\\n shell command"...
 1.127 01-Jan-2007  dsl Rework the code that separates the makefile into lines.
Instead of copying the file byte by byte into an expanding line buffer, just
scan the file buffer for (unescaped) newlines.
Escaped newlines (etc) are processed by modifying the file buffer later.
Speeds up 'nbmake obj' by a factor of 2.
I suspect it will do wonders for parts of pkgsrc as well, since it largely
eliminates cpu cycles from the false part of .ifs.
 1.126 18-Dec-2006  christos From Anon Ymous:
Removed two "(void)&" constructs as there is no setjmp() or vfork() insight.
Flagged a few parameters __unused so this will compile with -Wextra now.
 1.125 16-Dec-2006  dsl Use open/read/close instead of stdio for makefiles.
Commons up the code for reading files and buffers, and allows a further
change where we don't copy the data out of the buffer when generating 'lines.
This will speed up makefile parsing (esp .if clauses).
 1.124 07-Dec-2006  dsl Revert part of a recent commit.
ParseEOF() shouldn't close the original file.
 1.123 07-Dec-2006  dsl Put the big block of code that was common to ParseDoInclude() and
ParseTraditionalInclude() into a separate routine.
Fix the 'use after free' and 'free on item not malloced' that got added
to ParseTraditionalInclude() in Feb 2006 (rev 1.111).
Kill the 'PTR' struct and put both its members into IFile.
Remove the parameter from ParseEOF(), 1 of the 3 calls passed the wrong value!
Fortunately another test stopped anything nasty happening, we'll use that
test instead.
 1.122 04-Dec-2006  dsl There really is no point calling estrdup() to get a copy of the makefile name
into every 'gnode' (aka target), instead just copy a pointer to the string
and avoid freeing the original name when we close the file.
I can't imagine any makefile set where this gives a larger footprint!
 1.121 03-Dec-2006  dsl Unknot this code slightly by avoiding 'break/return; else' and by putting
the short parts of some conditionals first.
First step towards speeding up the parsing of makefiles (esp. the unwanted
parts of .if clauses).
There should be no changes to the logic.
 1.120 17-Nov-2006  dsl branches: 1.120.2;
A rather large rototil in the way the parallel make code schedules jobs.
This gives a considerable speedup in the processing of .WAIT and .ORDER.
Both .WAIT and .ORDER stop both the commands of the node, and its dependant
nodes being built until the LH nodes are complete.
.WAIT only applies to the dependency line on which it appears, whereas
.ORDER applies globally between the two nodes.
In both cases dependant nodes can be built because other targets need them.
make now processes the target list left to right, scheduling child nodes
as they are needed to make other nodes (instead of attempting to generate
a bottom-up dependency graph at the start). This means that 'make -j1'
will tend to build in the same order as a non-parallel make.
Note that:
all: x y
x: a .WAIT b
y: b .WAIT a
does not generate a dependency loop.
But
x: y
.ORDER y x
does (unless something elswhere causes 'y' to be built).
 1.119 27-Oct-2006  dsl Since 'ClientData' is 'void *', nuke almost all the (ClientData) casts.
 1.118 15-Oct-2006  dsl Add some more explanitory comments.
Rename 'allsrc' to 'curSrcs' so that the variable passed to ParseDoSrc (etc)
has the same name as the local in the calling routine, rather than a name
that seems to imply a more global and persistent list.
 1.117 15-Oct-2006  dsl Change a 'while' loop to a 'for' loop so we can add 'free(line)' into the
loop continue part. Remove the 'free(line)' from teh end of the loop body,
change the gotos into continues and collapse out some 'else if's.
All in the name of code transparency. No functional changes.
 1.116 15-Oct-2006  dsl Output all debug trace output through 'debug_file' defaulting to 'stdout'.
(Almost all the debug output went there, but some went to stderr.)
Split the parsing of -d (debug flags) out into its own routine.
Allow the output filename to be changed by specifying -dF<file> to create
a log file, or -dF+<file> to append to it. <file> may be stdout or stderr.
Also change so that -d-<flags> acts on <flags> locally but doesn't copy
them to MAKEFLAGS so they aren't inherited by child makes.
I'm not 100% happy with the command line syntax for the above, so they are
currently undocumented.
 1.115 26-Aug-2006  christos More programs using efun.
 1.114 31-Mar-2006  christos Add some coverity allocation comments, and change the way the allocator
functions work. When they allocate storage that needs to be freed, instead
of setting a boolean, set the pointer to be freed. Plug some more memory
leaks found by inspection.
 1.113 31-Mar-2006  dsl There is no need to count jobs and job tokens.
If we don't create the job pipe, use the '-j n' option to limit the number
of tokens we will remove from the pipe.
 1.112 31-Mar-2006  christos Coverity CID 544: Fix memory leak.
 1.111 28-Mar-2006  ginsbach - Change where variable substitution is done when processing traditional
include statements so that if a variable expands to more than one file
name make will "do the right thing".
- Add additional debug print

Reviewed by christos.
 1.110 26-Feb-2006  apb Make ".WAIT" apply recursively to all children of nodes on the right
hand side of the .WAIT, except when the recursive interpretation would
cause a cycle in the dependency graph.

Discussed in tech-toolchain. Reviewed by christos, sjg.
 1.109 11-Feb-2006  dsl Add some more debug prints.
 1.108 22-Jan-2006  dsl Make .NOTPARALLEL stop the job engine issuing more than one token (instead
of trying to de-jobify the make.
You can now put .NOTPARALLEL in a submake of a recursive make (where it is
using a job-token pipe from the outer make and have it only run a single job.
You can also specify .NOTPARRALEL in the root makefile of a large recursive
make and have the submakes run multiple commands.
Add some diagnostics printfs (enabled with -dp) to the parser.
 1.107 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.106 09-Aug-2005  christos Add typedefs for DuplicateProc and FreeProc from Max Okumoto.
 1.105 08-Aug-2005  christos From Max Okumoto:
- Remove casts to NULL.
- Remove space between cast and object.
 1.104 05-Aug-2005  christos More KNF cleanups from Max Okumoto
 1.103 25-Jul-2005  christos Whitespace KNF cleanup from Max Okumoto
 1.102 18-Jun-2005  rpaulo PR standards/17732: make doesn't honour escaped comment lines. Now with
a real fix.
Ok'ed by sjg and hubertf.
 1.101 16-Jun-2005  rpaulo Back it out while I'm working on a real fix without introducing new bugs.
 1.100 15-Jun-2005  rpaulo PR bin/17732: Allow make to understand escaped comments.
Approved by sjg, christos and hubertf.
 1.99 08-May-2005  christos Now that dependencies in .BEGIN, .END, and .INTERRUPT work, allow them.
 1.98 01-May-2005  christos Don't accept dependencies for .BEGIN, .END, and .INTERRUPT since they
don't make sense or work anyway.
 1.97 16-Feb-2005  christos branches: 1.97.2;
PR/29203, PR/29204: Max Okumoto: KNF changes to make [no functional changes]
 1.96 07-May-2004  ross Simplify build, no functional changes.

Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().

It's now possible to build make on some hosts with: cc *.c */*.c
 1.95 06-Mar-2004  enami branches: 1.95.2;
Print useful line number on error while executing .for directive.
 1.94 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.93 14-Jul-2003  christos Pass WARNS=3
 1.92 23-Mar-2003  sjg Comment in ParseDoSrc was no longer accurate.
Explain the difference between handling of src node
in ParseDoSpecialSrc cf. ParseDoSrc.
 1.91 23-Mar-2003  sjg We are supposed to pass the node for our expanded src to ParseAddDep
for each entry in allsrc. Just like ParseDoSrc. The only difference
in handling these special expanded srcs in in the call to ParseLinkSrc.
 1.90 22-Mar-2003  sjg ParseDoSpecialSrc: since we're already being called for each target
make it depend only on the expansion of src that matches.
Otherwise given:

a b c: ${.TARGET}.x

a b and c will each depend on a.x, b.x and c.x

Further, we only _need_ to do ParseDoSpecialSrc if a .WAIT appears
in the source list - so establish that up front.
 1.89 21-Mar-2003  christos don't mess with suffix rules.
 1.88 21-Mar-2003  sjg Missed a s/tn->name/pref/
 1.87 21-Mar-2003  sjg Add ParseDoSpecialSrc() to handle srcs that refer to ${.TARGET} etc.
These are expanded for each target (set in its own context) and
ParseDoSrc() is then called for the expanded src.

PR: 20828
Reviewed by: christos
 1.86 01-Dec-2002  sjg Parse_DoVar: don't free cp until we are done with it!

Reviewed by: hannken
 1.85 26-Nov-2002  sjg Whenever we update .PATH, set the variable ${.PATH} to reflect the
search list that will be used. Thus 'dot' and 'cur' will appear in
${.PATH} either at the start or end depending on .DOTLAST even though
they are not strictly in dirSearchPath.

When .CURDIR is assigned to - re-set the 'cur' Path.

Finally, when checking subdirs, look in 'dot' and 'cur' (first or last
depending on .DOTLAST) just as we do in other situations.
 1.84 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.83 20-Mar-2002  pk Xref: parse.c, rev 1.46; make.c, rev 1.23

In these revisions `::' dependency handling was simplified by not linking
the cohort nodes into the dependency graph. This broke dependency checking
on all but the first instance of a `::' target since all of the cohort nodes
now just form a collection of disconnected dependency graphs.

Fix this by keeping a back-reference in each cohort to its leader (the
first instance of a :: node with the same name) and a count of the number
of cohorts that need to be made before dependent nodes are scheduled.

Classically, we'd need six centurions for cohort, but in this case one
suffices...
 1.82 21-Feb-2002  reinoud Pull every file parsing context into one structure instead of using a few
file global variables... adding an extra context variable is thus allmost
trivial now.
 1.81 17-Feb-2002  pk Add the default main target to the ${.TARGETS} variable, too.
 1.80 04-Feb-2002  christos Remove OP_NOSUFF, fix OP_MADE in compat mode [from pk], and make the OP_MADE
comment reflect reality.
 1.79 03-Feb-2002  christos Bring down the number of stat(2) system calls from 682 to 294. This change
adds a .NOSUFF directive that has been applied to targets that have been
already made, and are not supposed to have suffix rules applied to them.
 1.78 27-Jan-2002  reinoud Fix major bug in make(1) ... due to shadowing of the dotLast path used for
the .DOTLAST primitive by a boolean variable with the same name, this whole
mechanism was broken ... it doesn't save much stat calls but it was wrong.

Thanks to Jason Thorpe for the other shadow-variable fixing patches he
made.
 1.77 26-Jan-2002  christos Process escaped characters properly. Now:

foo\:bar:
touch $@

works. Of course I am lazy right now, and I am not removing the '\' escapes
so the output looks fine, but it is functionally correct.
 1.76 24-Jan-2002  reinoud Small update to make(1) to let it follow more its own guidelines ! ... This
patch makes sure that files included using ".include <bsd.own.mk>" are
really looked for in the system make file directory or in the specified -m
paths instead of allways looking in the other -I and .PATH specified paths
... This speeds up the make a few procents at times for all the system make
files are now found directly instead of searching several paths, saving a
lot of stat() calls.

The number of stat calls is still exorbirant hight though... 910 or so for
making `make' alone ....
 1.75 31-Oct-2001  tv Overhaul the initialization and handling of .OBJDIR:

* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)

* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.

* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
 1.74 31-Oct-2001  tv Allow "-m" to be used in a .MAKEFLAGS: special target and get it to work.
(This splits out the "default system include paths" into its own Lst
variable, and uses it only if sysIncPath is empty. This allows sysIncPath
to be filled in by the Makefile itself.)
 1.73 24-Sep-2001  wiz va_{start,end} audit:
Make sure that each va_start has one and only one matching va_end,
especially in error cases.
If the va_list is used multiple times, do multiple va_starts/va_ends.
If a function gets va_list as argument, don't let it use va_end (since
it's the callers responsibility).

Improved by comments from enami and christos -- thanks!

Heimdal/krb4/KAME changes already fed back, rest to follow.

Inspired by, but not not based on, OpenBSD.
 1.72 20-Aug-2001  wiz precede, not preceed.
 1.71 03-Jul-2001  christos add .USEBEFORE Attribute
 1.70 12-Jun-2001  sjg Add 4th arg (flags) to Var_Set so that VarLoopExpand can tell it not
to export interator variables when using context VAR_CMD.

Reviewed: christos
 1.69 10-Jun-2001  sjg Simplify the exporting of VAR_CMD's via MAKEFLAGS.
We now just list the names of such variables in .MAKEOVERRIDES.
When we come to export MAKEFLAGS we quote the value of each exported variable
using :Q, using: ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}
The :O:u suppresses duplicate names.
Also modifed Parse_DoVar to re-export MAKEFLAGS whenever .MAKEOVERRIDES
is assigned to so .MAKEOVERRIDES+= PATH will export PATH=${PATH:Q}
to the environment, while .MAKEOVERRIDES= will disable export of VAR_CMD's.
 1.68 09-Jun-2001  sjg Modify handling of command line variable assignments and their exporting
via MAKEFLAGS. Instead of appending them directly to .MAKEFLAGS, put
them in .MAKEOVERRIDES (and ensure they are quoted). This is now done
in Var_Set when it exports VAR_CMD's.
Use ExportMAKEFLAGS() to export MAKEFLAGS, using the combined content
of .MAKEFLAGS and .MAKEOVERRIDES (with duplicate supression).
If .MAKEFLAGS is assigned to in a Makefile, ExportMAKEFLAGS is called again.
This allows a line like:
.MAKEOVERRIDES=
to effectively stop the exporting of the command line vars in MAKEFLAGS.
 1.67 02-Jun-2001  sommerfeld Avoid being overly specific since the unresolved merge conflict tags
we detect could have come from something other than cvs.
 1.66 02-Jun-2001  christos mention `cvs' in the the previous hack so that the clueless get a clue.
 1.65 02-Jun-2001  sommerfeld Gratuitous make(1) hack of the morning: if operator-less lines start
with merge delimeters (<<<<<<, ======, >>>>>>), report "Makefile
contains unresolved merge conflict" rather than "Need an operator".
 1.64 01-Jun-2001  sjg A number of semi-related changes.
1. make -dx turns on DEBUG_SHELL which causes sh -x to be used where
possible.
2. PrintOnError() is now called when make is stopping due to an error.
This routine reports the curdir and the value of any variables listed
in MAKE_PRINT_VAR_ON_ERROR.
3. Variables set via command line, are propagated to child-makes via
MAKEFLAGS. This behaviour appears to be necessary for POSIX (according
to the GNU folk anyway).
4. Do not reset MAKEFILE when reading ".depend" as this rather eliminates the
usefulness of ${MAKEFILE}.
5. Added ${.newline} as a simple means of being able to include \n in the
result of a :@ loop expansion.
6. Set ${MAKE_VERSION} if defined. Need to come up with a useful value.

Reviewed: christos
 1.63 23-Feb-2001  christos PR/12251: Thomas Klausner: Make core dumps on unclosed conditional.
Well, it should say 'make core-dumps on any error on the primary makefile'.
This was a result of the new changes to print the path to the parsed
Makefile... Made the code a lot more conservative, plus prepended <progname>:
to each message.
 1.62 14-Jan-2001  mycroft Once again, do the warning in a format that doesn't completely blow, and that
corresponds with text in the man page. Also split it into 2 pieces that can
both be used with, e.g., C-x` in Emacs.
 1.61 14-Jan-2001  christos convert error messages into english
 1.60 14-Jan-2001  christos We cannot override commands yet, ignore the additional sets for now.
This will be reverted when the tree is fixed.
 1.59 14-Jan-2001  christos - make the second list of commands override the first like gmake does
- remember where the first command definition occured so that we can debug
things.
 1.58 13-Jan-2001  cgd back out the change in rev 1.57. it was misguided; see discussion
on current-users (subject "build problem - multibyte.c").
 1.57 12-Jan-2001  jdolecek only print the 'duplicate script for target' warning if
parseWarnFatal is on
 1.56 10-Jan-2001  christos PR/11800: Chris Demetriou: Add -W flag to exit on parse warnings.
While I am here, s/make:.*"/%s:\1", progname/
 1.55 07-Jan-2001  sjg Always try an give the absolute pathname of the Makefile that we got an error in.
Use .PARSEDIR if set and not '.', otherwise .CURDIR to qualify the Makefile's path.
 1.54 05-Dec-2000  sommerfeld Boolean consistancy (use TRUE, not 1)
 1.53 11-Oct-2000  is More format string cleanup by sommerfeld.
 1.52 11-Jun-2000  mycroft branches: 1.52.2;
Readd optimization last night. Problems earlier were partially due to the
arguments names on one function being swapped (by a previous author).

Do not do any duplicate suppression when a source list is created. Instead:
* OP_MADE protects against trying to make the source multiple times.
* A new OP_MARK flag is introduced to suppress duplicates while expanding
the .ALLSRC variable and .USE targets.
This turns the O(n^2) insertion into O(n) in most cases.

This is tested with a `make build' and some special test cases.
 1.51 10-Jun-2000  mycroft Back out last night's optimization for now.
 1.50 10-Jun-2000  mycroft Introduce an OP_MARK bit, and use it to suppress duplicates during .ALLSRC
and .USE expansion. Also, remove some more Lst_Member() checks that are now
redundant.
 1.49 10-Jun-2000  mycroft Nuke an `optimization' that made source list creation O(n^2). This may cause
more memory to be used with stupid Makefiles, but it saves a fair amount of
time (~13% just for libc) with sane ones.
 1.48 11-May-2000  sjg branches: 1.48.2;
allow .POSIX to define %POSIX as in FreeBSD
 1.47 16-Sep-1999  mycroft Some minor cleanup of :: tests.
 1.46 15-Sep-1999  mycroft Rework how :: dependencies are handled.
Build a list of `cohorts' as before, but do *not* link each one into all the
parent nodes; instead, copy the `cohort' lists into the stream of targets to
be built inside Make_ExpandUse(). Also do the attribute propagation as a
separate pass after parsing.
This eliminates several O(n^2) algorithms.
 1.45 15-Sep-1999  mycroft Don't bother iterating through all the data structures to free(3) everything
right before exiting.
(The code is still present, `#ifdef CLEANUP', in case someone needs it...)
 1.44 09-Aug-1999  aidan Added .PARSEDIR and .PARSEFILE variables to make(1).
 1.43 04-Aug-1999  ross Trivial speed hack.
 1.42 02-Jun-1999  christos Fix awful bug where:

V := $V foo
V := $V bar

would report that variable V is recursive...
 1.41 17-Nov-1998  ross branches: 1.41.2;
Fix a bug that apparently prevented, since day 1, the .-include / .sinclude
feature from ever working. Also, fix the man page that incorrectly described
the syntax of the feature that didn't work.
 1.40 06-Nov-1998  christos - full prototypes
- more conservative printf
- char -> unsigned char
 1.39 18-Sep-1998  christos PR/6174: ITOH Yasufumi: Purify bug and a compile error in utility code.
 1.38 06-Aug-1998  christos - Add {.,}[s-]include for silent include file failures
- Make traditional include statement include more than one file if present
on the line.

Keeping up with the other's :-)
 1.37 23-Mar-1998  fair patch from PR#3573 to rename a variable "main" to "mainList"
 1.36 28-Sep-1997  lukem branches: 1.36.2;
wrap #include <sys/cdefs.h>, __RCSID(...) stuff in #ifndef MAKE_BOOTSTRAP
 1.35 11-Jul-1997  christos #if __STDC__ -> #ifdef __STDC__
 1.34 01-Jul-1997  christos Add WARNS=1
RCSID police
 1.33 09-May-1997  mycroft Make sure to propagate OP_PHONY to all cohorts that already existed.
 1.32 08-May-1997  gwr Add the new .NOPATH feature which can be used to disable .PATH search
for particular targets, i.e. .depend, objects, etc. (from Christos).
 1.31 07-May-1997  mycroft Copy the .PHONY attribute to the cohorts of a double dependency.
 1.30 02-May-1997  christos - Target searching addition:
Make used to only use the search path for nodes that were pure
sources (not targets of other sources). This has been corrected
and now gnu-autoconf generated Makefiles work in directories other
than the source one.

- Suffix transformation rescanning:
Suffix transformations (.c.o:; cc ...) were only recognized in
the past when both suffixes were members of the suffix list.
Thus a sequence like:
.z.b:
echo ${.TARGET}
.SUFFIXES: .z
would cause .z.b: to be inserted as a regular target (and the main
target in this case). Other make programs always add rules that
start with a period in the transformation list and never consider
them as targets. We cannot do that (consider .depend files) so we
resort to scanning the list of the current targets every time a
suffix gets added, and we mutate existing targets that are now
valid transformation rules into transformation rules. If the
transformed target was also the main target, we set the main target
to be the next target in the targets list.
 1.29 10-Mar-1997  christos Add a .MADE directive to indicated that the children of a target are
up-to-date, even when they are not. This is to simulate our current
make install behavior with proper dependencies.
 1.28 31-Dec-1996  christos add a missing 'static' decl.
 1.27 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.26 27-Sep-1996  thorpej Fix extra "make:" and newline in error message.
From enami tsugutomo <enami@ba2.so-net.or.jp>, PR #2651.
 1.25 13-Sep-1996  christos - Fix bug where the first line after a conditionally skipped was not ready
in its entirety if it contained a continuation.
- Print the whole error line, not just the first 20 characters of it.
 1.24 13-Aug-1996  christos Add estrdup(), a checked version of strdup and use it.
 1.23 28-May-1996  christos - Move -D flags from Makefile to config.h and explain what they do. Add
-Wall -Wno-unused to CFLAGS. Add new define SYSVVARSUB to enable SysV
style variable substitutions and enable them.
- Add SunOS style command substitutions via SUNSHCMD
- Fix core dump with '{variable = value'
 1.22 15-Mar-1996  christos branches: 1.22.4;
Add PHONY attribute and target. This is the first step to cleanup the
xinstall and xlint crud.
 1.21 06-Mar-1996  christos Fix PR/2118; apply sysincludes patch.
 1.20 17-Feb-1996  christos if PR/2090, sysvinclude too optimistic, did not check for space after the
include keyword
 1.19 07-Feb-1996  thorpej In ParseDoInclude(), make a temporary copy of the current file name
while searching for ""-type include files, since the current file name
might not be a writeable string.
 1.18 16-Dec-1995  christos - Added .WAIT to synchronize between sources like other pmake variants.
- Updated documentation to include .ORDER .PARALLEL .NO_PARALLEL .NONPARALLEL
 1.17 02-Nov-1995  christos Minor:
- ${.PREFIX} should never contain a full pathname
- Fixed gcc -Wall warnings
Major:
- compatMake is now FALSE. This means that we are now running in
full pmake mode:
* rules on dependency lines can be executed in parallel and or
out of sequence:

foo: bar baz

can fire the rule for baz before the rule for bar is fired.
To enforce bar to be fired before baz, another rule needs to be
added. [bar: baz]
* adjacent shell commands in a target are now executed by a single
invocation of the shell, not one invocation of the shell per line
(compatMake can be turned off using the -B flag)
- The -j flag now works... I.e. make -j 4 will fork up to four jobs in
parallel when it can. The target name is printed before each burst
of output caused by the target execution as '--- target ---', when j > 1
- I have changed all the Makefiles so that they work with make -j N, and
I have tested the whole netbsd by:
'make -j 4 cleandir; make -j 4 depend; make -j 4; make -j 4 install'
- I have not compiled or tested this version of make with -DREMOTE.
 1.16 10-Sep-1995  christos Fix PR/1443:
Dependency rules with `=' in the lhs are parsed as variable assignments.
E.g., the following Makefile fails:

A=a b c d
all: $(A:%=%b)
$(A:%=%b):
@echo $@
 1.15 14-Jun-1995  christos - $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.14 15-May-1995  ws Sort keyword table correctly, so binary search really works
 1.13 08-Feb-1995  christos Fixed so that orphan tabs are ignored. Should close PR760.
 1.12 06-Jan-1995  christos Fixes from Paul Borman (prb@bsdi.com)
1. Honor environment variable $MACHINE if set over uname.machine
2. archives with :: are always out of date, even when they have no children.
3. VAR= a b c # comment, gets the trailing blanks trimmed, unless
escaped by \. I'll have to read the posix manul to make sure that it
is ok to handle escapes here.
 1.11 18-Oct-1994  mycroft Deal with lines that contain only spaces, per PR 515, but implemented
differently.
 1.10 18-Oct-1994  mycroft Remove an outdated comment that is very confusing.
 1.9 06-Jun-1994  jtc Fixes from Christos Zoulas, who used purify, objectcenter and testcenter
to find memory leaks and illegal memory accesses.
 1.8 21-May-1994  jtc Fix from Thorsten Lockert: don't ignore \ before # characters
in strings (Fixes bug 255).
 1.7 07-Mar-1994  cgd kill some warnings, from Christos.
 1.6 05-Mar-1994  jtc Apply fix that was lost when Christos Zoulas' changes were integrated:
Shell commands start with tabs, not whitespace. Pmake's
POSIX behavior must have been derrived from an early draft.
 1.5 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.4 13-Jan-1994  jtc Include appropriate header files to bring prototypes into scope.
 1.3 17-Dec-1993  jtc Fix bug #47. Shell commands start with tabs, not whitespace. Pmake's
POSIX behavior must have been derrived from an early draft.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.22.4.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.36.2.1 08-May-1998  mycroft Sync with trunk, per request of christos.
 1.41.2.2 19-Oct-2000  he Pull up revision 1.53 (requested by he):
Format string cleanup.
 1.41.2.1 21-Jun-1999  perry pullup 1.41->1.42 (christos)
 1.48.2.1 23-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.52.2.1 18-Oct-2000  tv Pullup usr.bin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.95.2.1 10-May-2004  tron Pull up revision 1.96 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.97.2.3 02-Jul-2005  tron Pull up revision 1.102 (requested by rpaulo in ticket #491):
PR standards/17732: make doesn't honour escaped comment lines. Now with
a real fix.
Ok'ed by sjg and hubertf.
 1.97.2.2 16-Jun-2005  tron Backout ticket 458, it causes PR toolchain/30536.
 1.97.2.1 16-Jun-2005  tron Pull up revision 1.100 (requested by rpaulo in ticket #458):
PR bin/17732: Allow make to understand escaped comments.
Approved by sjg, christos and hubertf.
 1.120.2.5 23-Nov-2008  bouyer Pull up following revision(s) (requested by dsl in ticket #1240):
usr.bin/make/parse.c: revision 1.146
PR/38840: Pierre Pronchery: make crashes while parsing long lines in Makefiles
 1.120.2.4 23-Nov-2008  bouyer Pull up following revision(s) (requested by dsl in ticket #1239):
usr.bin/make/parse.c: revision 1.143
When we extend the buffer used to read makefiles (in order to read lines
longer than 32k) remember the new length so we DTRT for lines longer than 64k.
Should fix PR/37684
 1.120.2.3 05-Jun-2007  bouyer Apply patch (requested by tron in ticket #696):
usr.bin/make/compat.c patch
usr.bin/make/cond.c patch
usr.bin/make/dir.c patch
usr.bin/make/for.c patch
usr.bin/make/main.c patch
usr.bin/make/make.1 patch
usr.bin/make/make.c patch
usr.bin/make/make.h patch
usr.bin/make/nonints.h patch
usr.bin/make/parse.c patch
usr.bin/make/str.c patch
usr.bin/make/targ.c patch
usr.bin/make/util.c patch
usr.bin/make/var.c patch

Synchronize make(1) with HEAD branch to increase perfomance and
improve stability.
 1.120.2.2 06-May-2007  snj branches: 1.120.2.2.2;
Pull up following revision(s) (requested by dsl in ticket #479):
usr.bin/make/parse.c: revision 1.129 via patch
Avoid coredumping. Found by accidentally running make instead of gmake
in java's control/make directory.
 1.120.2.1 20-Dec-2006  bouyer Pull up following revision(s) (requested by dsl in ticket #285):
usr.bin/make/cond.c: revision 1.36
usr.bin/make/parse.c: revision 1.121-1.124
usr.bin/make/make.h: revision 1.65
usr.bin/make/targ.c: revision 1.46
usr.bin/make/main.c: revision 1.138-1.139
Simplify the code that processes .if lines.
It doesn't need a two-dimensional array to remember the states of .if lines.
It would be even simpler if we didn't try to detect .else and .elif lines
that follow .else lines.
Unfortunately this isn't the code that is stupendously slow...
Unknot this code slightly by avoiding 'break/return; else' and by putting
the short parts of some conditionals first.
First step towards speeding up the parsing of makefiles (esp. the unwanted
parts of .if clauses).
There should be no changes to the logic.
There really is no point calling estrdup() to get a copy of the makefile name
into every 'gnode' (aka target), instead just copy a pointer to the string
and avoid freeing the original name when we close the file.
I can't imagine any makefile set where this gives a larger footprint!
Add anewline to the end of the error message output when the debug log
file cannot be opened.
Put the big block of code that was common to ParseDoInclude() and
ParseTraditionalInclude() into a separate routine.
Fix the 'use after free' and 'free on item not malloced' that got added
to ParseTraditionalInclude() in Feb 2006 (rev 1.111).
Kill the 'PTR' struct and put both its members into IFile.
Remove the parameter from ParseEOF(), 1 of the 3 calls passed the wrong value!
Fortunately another test stopped anything nasty happening, we'll use that
test instead.
Revert part of a recent commit.
ParseEOF() shouldn't close the original file.
Some minor changes:
- Only test 'printVars' once.
Has side effect of not trying to find the 'main' target for '-V varname'.
- Only reap the single child process in Cmd_Exec(),
I think this is for 'xx != cmd' so probobably no other children should exist.
- Don't read and parse .depend if '-r' and '-V varname' are set.
I suspect that .depend shouldn't affect the output of any -V command...
 1.120.2.2.2.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.134.4.2 09-Jan-2008  matt sync with HEAD
 1.134.4.1 06-Nov-2007  matt sync with HEAD
 1.145.6.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.145.4.1 04-Jun-2008  yamt sync with head
 1.148.2.2 23-Nov-2008  bouyer Pull up following revision(s) (requested by dsl in ticket #117):
usr.bin/make/parse.c: revision 1.150
intFile.fd should be initialised to -1, not 0.
 1.148.2.1 23-Nov-2008  bouyer Pull up following revision(s) (requested by dsl in ticket #116):
usr.bin/make/parse.c: revision 1.149
avoid using c99 struct named initializers because this is a host tool and
needs to be compiled by a host compiler which might not be c99 compliant.
 1.173.2.1 05-Mar-2011  bouyer Sync with HEAD
 1.179.2.5 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.179.2.4 30-Oct-2012  yamt sync with head
 1.179.2.3 23-May-2012  yamt sync with head.
 1.179.2.2 17-Apr-2012  yamt sync with head
 1.179.2.1 10-Nov-2011  yamt sync with head
 1.185.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.185.2.1 23-Jun-2013  tls resync from head
 1.194.2.1 10-Aug-2014  tls Rebase.
 1.214.2.3 26-Apr-2017  pgoyette Sync with HEAD
 1.214.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.214.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.217.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.227.2.2 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.227.2.1 07-Apr-2018  pgoyette Sync with HEAD. 77 conflicts resolved - all of them $NetBSD$
 1.229.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.229.2.1 10-Jun-2019  christos Sync with HEAD
 1.731.2.1 02-Aug-2025  perseant Sync with HEAD
 1.18 29-Nov-2020  rillig make(1): use space instead of tab for preprocessor directives
 1.17 11-Apr-2009  apb Honour the TMPDIR environment variable instead of always using /tmp
as a place to store temporary files.
 1.16 24-Jun-2005  lukem branches: 1.16.30;
revert previous for now
 1.15 23-Jun-2005  lukem Deprecate support for automagically setting the .OBJDIR to
./obj.${MACHINE}
./obj
/usr/obj/${PWD}

The rules for the default .OBJDIR setting are now simplified to
(and documented as) trying the chdir to the following
(if the appropriate variable is defined):
${MAKEOBJDIRPREFIX}${.CURDIR}
${MAKEOBJDIR}
${.CURDIR}

.OBJDIR can be overridden in the makefile.
<bsd.obj.mk> uses this to provide the "culled" .OBJDIR semantics
for NetBSD's /usr/src builds.

MAKEOBJDIRPREFIX & MAKEOBJDIR still can only be provided
in the environment or on make(1)'s command line.

Per discussion on tech-toolchain.
This should reduce a lot of lossage people have experienced over
the years with various .OBJDIR setups.
 1.14 07-May-2004  ross Simplify build, no functional changes.

Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().

It's now possible to build make on some hosts with: cc *.c */*.c
 1.13 27-Oct-2003  lukem branches: 1.13.2;
Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.12 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.11 01-Aug-2003  sjg Allow .SHELL: to control the shell used by compat mode too.
Add a shell spec for ksh - a nice portable posix shell.
Document .SHELL:
 1.10 14-Sep-2002  thorpej If MAKE_BOOTSTRAP and HAVE_CONFIG_H, pull in "config.h" so that
we get the correct _PATH_BSHELL definition.
 1.9 27-Apr-2002  bjh21 branches: 1.9.2;
Rather than hardcoding "/bin/sh", use _PATH_BSHELL. To allow bootstrapping,
provide a default for this in pathnames.h, and only include <paths.h> ifndef
MAKE_BOOTSTRAP.
 1.8 24-Apr-2002  bjh21 Allow the makefile to override _PATH_DEFSHELLDIR as well.
 1.7 19-Dec-1998  christos Allow system path to be overriden in the Makefile
 1.6 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.5 30-Aug-1996  thorpej Tidy up some RCS ids a bit.
 1.4 06-Mar-1996  christos branches: 1.4.4;
Fix PR/2118; apply sysincludes patch.
 1.3 14-Jun-1995  christos - $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.4.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.9.2.1 30-Nov-2002  he Pull up revision 1.10 (requested by thorpej in ticket #812):
If MAKE_BOOTSTRAP and HAVE_CONFIG_H, pull in "config.h" so
that we get the correct _PATH_BSHELL.
 1.13.2.1 10-May-2004  tron Pull up revision 1.14 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.16.30.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.15 26-Aug-2020  rillig make(1): remove header sprite.h

Make is independent of the Sprite operating system.
 1.14 31-May-2017  maya Don't prefix include guards by _, suggested by riastradh
 1.13 31-May-2017  maya The previous change might actually be less generic.
prepend by _MAKE, to be sure.
 1.12 31-May-2017  maya Use less generic include guards
 1.11 23-Jan-2009  dsl Change 'ClientData' to 'void *' so that relevant parameters can
be made 'const void *'.
 1.10 20-Dec-2008  dsl Remove the definitions of NIL (now unused) and NULL (defined elsewhere).
 1.9 05-Aug-2005  christos More KNF cleanups from Max Okumoto
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.7 04-May-2000  drochner make cleaner C for more picky compilers
 1.6 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.5 14-Jun-1995  christos branches: 1.5.6;
- $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.4 06-Jun-1994  jtc Fixes from Christos Zoulas, who used purify, objectcenter and testcenter
to find memory leaks and illegal memory accesses.
 1.3 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.6.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.106 28-Jun-2025  rillig make: error out on an ":M" modifier whose pattern ends with backslash

This edge case is not expected to occur intentionally in practice.
 1.105 07-Jul-2024  rillig make: only generate code for cleanup functions in CLEANUP mode
 1.104 06-Jul-2024  rillig make: error out on a matching malformed matching pattern '[['
 1.103 14-Apr-2024  rillig branches: 1.103.2;
make: make string matching platform-independent

Previously, whether the character range '[a-ä]' matched, depended on the
signedness of the plain 'char' type. Since make operates on byte
strings and does not support UTF-8 or other multi-byte character
encodings, this edge case is not expected to occur in practice.

No change in the unit tests as this edge case is not covered by tests.
 1.102 05-Jan-2024  rillig make: miscellaneous cleanups
 1.101 17-Dec-2023  rillig make: speed up pattern matching in the ':M' modifier

In the common patterns where '*' is followed by a regular character,
such as in the patterns '*.c' or '*.mk', search the next possible
matching position in a small loop, instead of repeatedly comparing the
first remaining pattern character to all special characters.
 1.100 16-Dec-2023  rillig make: eliminate a local variable in Str_Match

No functional change.
 1.99 23-Jun-2023  rillig make: reduce indentation in pattern matching code

No functional change.
 1.98 23-Jun-2023  rillig make: warn about malformed patterns in ':M', ':N' and '.if make(...)'

These patterns shouldn't occur in practice, as their results are tricky
to predict. Generate a warning for now, and maybe an error later.

Reviewed by sjg@.
 1.97 22-Jun-2023  rillig make: unclutter string matching code
 1.96 22-Jun-2023  rillig make: rename variables in string matching, remove redundant code

No functional change.
 1.95 22-Jun-2023  rillig make: speed up pattern matching in the ':M' and ':N' modifiers

In the code coverage report, the highest count for Str_Match goes from
5,298,924 down to 79,646.
 1.94 07-Dec-2022  rillig make: clean up comments
 1.93 11-Jun-2022  rillig make: clean up comments for string splitting and string matching

No binary change.
 1.92 11-Jun-2022  rillig make: condense Str_Match

The test for '\\' followed by '\0' was redundant since at that point,
*str is guaranteed to be not '\0', which takes the next 'return false'.

No functional change.
 1.91 13-May-2022  rillig make: document platform dependency in string pattern matching

No unit test for this edge case since all other unit tests are platform-
independent.

To reproduce:
$ make clean
$ make -s PROG=s-make NOMAN=yes USER_CFLAGS=-fsigned-char
$ make clean
$ make -s PROG=u-make NOMAN=yes USER_CFLAGS=-funsigned-char
$ make clean
$ range=$(lua -e 'print(("[%c-%c]"):format(0xe4, 0x61))')
$ ./s-make -V "\${:UM:M$range}\${:UN:N$range}"
M
$ ./u-make -V "\${:UM:M$range}\${:UN:N$range}"
N
 1.90 13-May-2022  rillig make: clean up low-level comments, eliminate common subexpression

No functional change.
 1.89 03-Mar-2022  rillig make: make code for string matching syntactically more consistent

No functional change.
 1.88 15-Dec-2021  rillig make: in CLEANUP mode, free interned strings at the very end

Noticed by sjg.
 1.87 13-Dec-2021  rillig make: fix memory leak for filenames in .for loops (since 2013-06-18)

Previously, each time a .for directive pushed its buffer on the input
file stack, the current filename was duplicated. This was a waste of
memory.

The name of a file is typically only used while it is read in. There is
one situation when the filename is needed for longer, which is when a
target is defined.

Since .for loops are implemented as a special form of included files,
each .for loop duplicated the current filename as well.

$ cat << EOF > for.mk
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.endfor
.endfor
.endfor
.endfor
.endfor
.endfor
.endfor

all:
@ps -o rsz -p ${.MAKE.PID}
EOF

$ make-2021.12.13.03.55.16 -r -f for.mk
RSZ
10720

$ ./make -r -f for.mk
RSZ
1716

The difference is 8 MB, which amounts to 1 million .for loops.
 1.86 21-Jun-2021  rillig make: eliminate local variable in Substring_Words

No functional change.
 1.85 30-May-2021  rillig make: inline str_concat4

This function is only ever used for forming strings of the form
"archive(member)".

No functional change.
 1.84 11-Apr-2021  rillig branches: 1.84.2;
make: avoid unnecessary calls to strlen when evaluating modifiers

No functional change.
 1.83 03-Apr-2021  rillig make: backport to C90

In the past few months I had accidentally used C99 features in the make
code. According to tools/README, tools that are used in the build
system should restrict themselves to C90.

This allows make to build with GCC's options "-pedantic
-Wno-system-headers -Dinline= -Wno-error=cast-qual".

I didn't notice anyone actively complaining though, I just wanted to see
how much work this backporting would be. The identifier __func__ is
still used, as in other tools.

No functional change.
 1.82 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.81 01-Feb-2021  rillig make: document necessary tests for Str_Match
 1.80 01-Feb-2021  rillig make: replace pre-increment with post-increment or simple addition

The rest of the code already prefers post-increment if there is no
actual difference.
 1.79 19-Jan-2021  rillig make(1): remove do-not-format markers from comments

These markers had been used inconsistently. Furthermore the source code
had not been formatted automatically before 2020 at all, otherwise there
wouldn't have been any trailing whitespace left.
 1.78 10-Jan-2021  rillig make(1): make a few more bool expressions more precise

The previous version of lint(1) from a few hours ago didn't catch all
occurrences. And even the current one doesn't catch everything.
Function arguments and return types still need some work. The "return
quietly" from shouldDieQuietly still implicitly converts from int to
_Bool.

No functional change.
 1.77 10-Jan-2021  rillig make(1): consistently use boolean expressions in conditions

Most of the make code already followed the style of explicitly writing
(ptr != NULL) instead of the shorter (ptr) in conditions.

The remaining 50 instances have been found by an experimental,
unpublished check in lint(1) that treats bool expressions as
incompatible to any other scalar type, just as in Java, C#, Pascal and
several other languages.

The only unsafe operation on Boolean that is left over is (flags &
FLAG), for an enum implementing a bit set. If Boolean is an ordinary
integer type (the default), some high bits may get lost. But if Boolean
is the same as _Bool (by compiling with -DUSE_C99_BOOLEAN), C99 6.3.1.2
defines that a conversion from any scalar to the type _Bool acts as a
comparison to 0, which cannot lose any bits.
 1.76 30-Dec-2020  rillig make(1): format multi-line comments
 1.75 12-Dec-2020  rillig make(1): remove redundant call to strlen in Str_Words
 1.74 16-Nov-2020  rillig make(1): use postfix increment where possible
 1.73 15-Nov-2020  rillig make(1): clean up make.h, meta.c, parse.c, str.c

The main changes are in the comments, which have been shortened and
corrected.

Some local variables changed their names.

In ParseErrorInternal, the scope of va_start is now narrower.

In ParseDoDependency, the type of tOp has been fixed.

ParseGetLine doesn't take flags anymore but instead a parsing mode.
Previously, the flags had not been combined anyway.

At the beginning of Parse_File, fatals is already guaranteed to be 0, and
even if not, it would be wrong to just discard the fatal errors.
 1.72 07-Nov-2020  rillig make(1): add pp_skip_hspace to skip horizontal whitespace during parsing
 1.71 07-Nov-2020  rillig make(1): clean up code stylistically

* Replace character literal 0 with '\0'.
* Replace pointer literal 0 with NULL.
* Remove redundant parentheses.
* Parentheses in multi-line conditions are not redundant at the
beginning of a line.
* Replace a few !ptr with ptr == NULL.
* Replace a few ptr with ptr != NULL.
* Replace (expr & mask) == 0 with !(expr & mask).
* Remove redundant braces for blocks in cases where the generated code
stays the same. (Assertions further down in the code would get
different line numbers.)
* Rename parameters in CondParser_String to reflect the data flow.
* Replace #ifdef notdef with #if 0.

The generated code stays exactly the same, at least with GCC 5.5.0 on
NetBSD 8.0 amd64 using the default configuration.
 1.70 24-Oct-2020  rillig make(1): remove macros MIN and MAX

These macros typically evaluate one of their arguments twice. Until
2020-08-31, they had not parenthesized their arguments properly. They
are only used in a few places, therefore it doesn't hurt much to have
them expanded.
 1.69 22-Oct-2020  rillig make(1): remove redundant type casts

This mainly affects the void pointers in callback functions for lists.
These had been necessary once when the parameter type was still
ClientData instead of void pointer.
 1.68 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.67 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.66 03-Oct-2020  rillig make(1): inline Str_FindSubstring in JobOutput
 1.65 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.64 30-Aug-2020  rillig make(1): replace brk_string with Str_Words

The API is much simpler, and there is less detail that is exposed by
default and fewer punctuation to type on the caller's side. To see that
there is some memory to be freed, one would have to look into the
struct. Having part of the return value as the actual return value and
the rest in output parameters was unnecessarily asymmetrical.
 1.63 29-Aug-2020  rillig make(1): allow for strict type checking for Boolean

Having Boolean aliased to int creates ambiguities since int is widely
used. Allow to occasionally compile make with -DUSE_DOUBLE_BOOLEAN to
check that the type definitions still agree.
 1.62 23-Aug-2020  rillig make(1): make brk_string return size_t for the number of words
 1.61 23-Aug-2020  rillig make(1): prepare str.c for WARNS=6

The next step is to make brk_string return size_t instead of int.
 1.60 11-Aug-2020  rillig make(1): add str_concat4 to make the other code simpler

There's no need for arch.c to call strlen when there is a high-level API
for the same purpose.
 1.59 10-Aug-2020  rillig make(1): replace str_concat with str_concat2 and str_concat3

The new functions have a simpler interface, and str_concat3 is even more
general-purpose, since the middle string is no longer required to be
exactly of length 1.
 1.58 10-Aug-2020  rillig make(1): fix parameter name of str_concat

The previous documentation mentioned Str_Concat, but str_concat has been
written in lowercase for years. The "flags" are not flags since they
cannot be combined, not even when they are written in hex.
 1.57 10-Aug-2020  rillig make(1): fix integer type in str_concat
 1.56 09-Aug-2020  rillig make(1): format code in str.c consistently
 1.55 03-Aug-2020  rillig make(1): no declaration-after-statement anymore

NetBSD make is intended to be maximally portable, therefore it uses only
C89. This was not declared in the Makefile before.

There are still a few places in parse.c and metachar.c that use
end-of-line comments. These will be fixed in a follow-up commit.
 1.54 01-Aug-2020  rillig make(1): reduce scope of local variables in brk_string

This also removes the unused assignment to words_cap.
 1.53 26-Jul-2020  rillig make(1): document the circumstances in which brk_string returns NULL
 1.52 19-Jul-2020  rillig make(1): move SysV string matching to var.c

This kind of string matching is only used in variable modifiers, and only
if this feature is enabled by SYSVVARSUB.
 1.51 03-Jul-2020  rillig make(1): refactor Str_Match

- use shorter variable names to avoid line breaks
- eliminate c2 variable
- change return type to Boolean
 1.50 03-Jul-2020  rillig make(1): clean up Str_Match

- removed unnecessary parentheses
- uniform test for end of string
 1.49 03-Jul-2020  rillig make(1): clean up documentation of Str_Match
 1.48 15-Jun-2020  rillig make(1): fix performance problem in specially crafted :M modifier

This fix was previously suspected to make the vax build fail. The next
build succeeded though, and it started 2 hours before this fix was
reverted.
 1.47 14-Jun-2020  rillig usr.bin/make: revert performance improvement

That change might be the cause of a build failure for vax.
http://releng.netbsd.org/builds/HEAD/202006131940Z/ builds fine.
http://releng.netbsd.org/builds/HEAD/202006141020Z/ doesn't.

The build fails with:
/home/source/ab/HEAD/src/external/gpl3/gcc/dist/gcc/machmode.h:524:28:
error: 'mode_size_inline' was not declared in this scope
 1.46 13-Jun-2020  rillig usr.bin/make: make Str_Match faster for repeated asterisks

Conceptually related to https://en.wikipedia.org/wiki/ReDoS.
 1.45 13-Jun-2020  rillig usr.bin/make: remove redundant parentheses around return
 1.44 13-Jun-2020  rillig usr.bin/make: consistently use ++ for incrementing pointers
 1.43 13-Jun-2020  rillig usr.bin/make: fix typo in comment
 1.42 06-May-2020  christos Behave like gmake: empty string does not match % pattern
 1.41 03-May-2020  rillig usr.bin/make: refactor brk_string

The variables are renamed to reflect to which memory region each pointer
belongs.

The variable "curlen" was always zero.

The type of "ch" has changed to char, and its scope is now limited to
its actual use.

Comparisons of pointers are now consistently written as p != NULL
instead of !p, like character comparisons are written as ch != '\0'.

The "store_words_buf" is updated when the function returns, not before.
 1.40 25-Apr-2020  christos - Percent on the rhs is special only if the lhs has one too.
- If the rhs does not have percent, but the lhs has, the result is the rhs
This behavior matches gmake
 1.39 01-Dec-2019  rillig Fix out-of-bounds read in Str_Match.
 1.38 21-Apr-2017  sjg branches: 1.38.12;
Str_Match: fix closure tests for [^] and add unit-test.
 1.37 11-Apr-2017  sjg Str_Match: allow [^a-z] to behave as expected.
 1.36 06-Apr-2016  gson branches: 1.36.2; 1.36.4;
Fully avoid the nonstandard types u_char, u_int, and u_long, which
were only used inconsistently in a few places anyway.
 1.35 12-Feb-2014  sjg Reduce the calls to realloc from brk_string by basing initial argmax guess
on length of input.

Reviewed by: christos
 1.34 03-Mar-2012  dholland branches: 1.34.2;
Note in comment that Str_Match() does not detect or report invalid
patterns. This is not critical, since for the moment both possible
cases (unclosed [], and \ at the end of the string) are handled more
or less sanely.
 1.33 25-Feb-2009  sno branches: 1.33.6;
replace c++ style comment by a c-style one
 1.32 17-Jan-2009  dsl branches: 1.32.2;
Change 'Buffer' so that it is the actual struct, not a pointer to it.
Saves having to malloc/free a fixed size structure.
Buf_Init() now takes ptr to Buffer to initialiase.
Change Buf_Destroy() to return ptr to string when not freed.
Remove large number of casts to (Byte) and (Byte *) - 'Byte' is 'char' here.
Buf_AddByte[s] guarantees that the data is 0 termininated, so never add '\0'.
Keep 'count' not 'left' and 'inPtr', code is simplier with only one update.
Fix fallou, no functional change.
 1.31 19-Dec-2008  christos PR/32154: Roland Illig: brk_string fails to report errors in unquoted strings.
 1.30 19-Dec-2008  christos PR/34138: Roland Illig: In the non-expand case, fix brk_string not to eat
quotes.
 1.29 06-Oct-2008  joerg Don't use emalloc and friends directly, but call them consistently
bmake_malloc and friends. Implement them via macros for the native case
and provide fallback implementations otherwise. Avoid polluting the
namespace by not defining enomem globally. Don't bother to provide
strdup and strndup, they were only used for the estrdup and estrndup
comapt code.

This addresses the presence of emalloc in system libraries on A/UX and
resulted strange issues as reported by Timothy E. Larson.
 1.28 15-Feb-2008  christos back all changes out until I fix it properly.
 1.27 14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.26 22-Dec-2006  erh Correctly handle '\' at the end of a variable in the non-expanding case.
 1.25 11-Aug-2006  christos branches: 1.25.2; 1.25.4;
If a word is "" eat the last quote since we ate the first.
 1.24 08-Aug-2005  christos From Max Okumoto:
- Remove casts to NULL.
- Remove space between cast and object.
 1.23 16-Feb-2005  christos PR/29203, PR/29204: Max Okumoto: KNF changes to make [no functional changes]
 1.22 07-May-2004  ross Simplify build, no functional changes.

Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().

It's now possible to build make on some hosts with: cc *.c */*.c
 1.21 27-Sep-2003  sjg branches: 1.21.2;
Implement :[] modifier to allow picking a range of words out of a variable.
Also :tW and a W flag to :C and :S to allow treating value as a single word.
Add unit tests for the above, and fix some corner cases.
Based on patches supplied by Alan Barrett <apb@cequrux.com>
 1.20 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.19 14-Jul-2003  christos Pass WARNS=3
 1.18 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.17 06-Nov-1998  christos - full prototypes
- more conservative printf
- char -> unsigned char
 1.16 26-Mar-1998  christos PR/5210: Hauke Fath: make core dumps with .SHELL
Unfortunately this revealed a deeper problem with the brk_string code.
To fix it:
- remove sharing of the buffer between brk_string invocations
- change the semantics of brk_string so that the argument array
starts with 0, and return the buffer where the strings are
stored
 1.15 28-Sep-1997  lukem branches: 1.15.2;
wrap #include <sys/cdefs.h>, __RCSID(...) stuff in #ifndef MAKE_BOOTSTRAP
 1.14 01-Jul-1997  christos Add WARNS=1
RCSID police
 1.13 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.12 29-Mar-1996  jtc branches: 1.12.4;
Added erealloc() function that calls enomem() if the allocation fails
(this is like the existing emalloc() function). Changed all realloc()
calls to erealloc().
 1.11 30-Oct-1995  ws Always ensure space for trailing NULL in argv
 1.10 14-Jun-1995  christos branches: 1.10.2;
- $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.9 04-Feb-1995  christos str.c: Don't free NULL; does not work with non posix frees.
var.c: Minor memory leak plugged.
suff.c: Don't add extra sources on the null suffix if it has dependency
lines or commands attached to it [POSIX says so]
 1.8 16-Jun-1994  jtc Christos' fix for quoting variable extraction properly.
 1.7 06-Jun-1994  jtc Fixes from Christos Zoulas, who used purify, objectcenter and testcenter
to find memory leaks and illegal memory accesses.
 1.6 17-May-1994  jtc Properly parse null command line arguments in makefile rules.
Fix from Christos Zoulas.
 1.5 23-Mar-1994  jtc Fixes from Christos Zoulas:
The following two patches fix a couple of problems with make(1)

1. Null Suffixes were not being copied, but they were being free'd
This caused rules of the form:

.c:
${CC} ...

to access invalid memory and potentially core dump..
[That was always broken; I did not break that one :-)]

2. My recent fixes to parse ${VAR:%.foo=%.bar} handled the null string
case incorrectly (${VAR:=.c} was broken).
 1.4 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.3 13-Jan-1994  jtc Include appropriate header files to bring prototypes into scope.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.10.2.1 30-Oct-1995  jtc Update from trunk: Always ensure space for trailing NULL in argv
 1.12.4.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.15.2.1 08-May-1998  mycroft Sync with trunk, per request of christos.
 1.21.2.1 10-May-2004  tron Pull up revision 1.22 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.25.4.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.25.2.1 05-Jun-2007  bouyer Apply patch (requested by tron in ticket #696):
usr.bin/make/compat.c patch
usr.bin/make/cond.c patch
usr.bin/make/dir.c patch
usr.bin/make/for.c patch
usr.bin/make/main.c patch
usr.bin/make/make.1 patch
usr.bin/make/make.c patch
usr.bin/make/make.h patch
usr.bin/make/nonints.h patch
usr.bin/make/parse.c patch
usr.bin/make/str.c patch
usr.bin/make/targ.c patch
usr.bin/make/util.c patch
usr.bin/make/var.c patch

Synchronize make(1) with HEAD branch to increase perfomance and
improve stability.
 1.32.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.33.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.33.6.1 17-Apr-2012  yamt sync with head
 1.34.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.36.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.36.2.1 26-Apr-2017  pgoyette Sync with HEAD
 1.38.12.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.84.2.1 31-May-2021  cjep sync with head
 1.103.2.1 02-Aug-2025  perseant Sync with HEAD
 1.20 07-Jul-2024  rillig make: only generate code for cleanup functions in CLEANUP mode
 1.19 05-Jan-2024  rillig branches: 1.19.2;
make: clean up string functions

No binary change.
 1.18 05-Jan-2024  rillig make: inline Substring_Sub

Remove redundant assertions.
 1.17 23-Jun-2023  rillig make: warn about malformed patterns in ':M', ':N' and '.if make(...)'

These patterns shouldn't occur in practice, as their results are tricky
to predict. Generate a warning for now, and maybe an error later.

Reviewed by sjg@.
 1.16 05-Dec-2022  rillig make: inline LazyBuf_AddBytesBetween

No binary change.
 1.15 15-Dec-2021  rillig make: in CLEANUP mode, free interned strings at the very end

Noticed by sjg.
 1.14 13-Dec-2021  rillig make: fix memory leak for filenames in .for loops (since 2013-06-18)

Previously, each time a .for directive pushed its buffer on the input
file stack, the current filename was duplicated. This was a waste of
memory.

The name of a file is typically only used while it is read in. There is
one situation when the filename is needed for longer, which is when a
target is defined.

Since .for loops are implemented as a special form of included files,
each .for loop duplicated the current filename as well.

$ cat << EOF > for.mk
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.endfor
.endfor
.endfor
.endfor
.endfor
.endfor
.endfor

all:
@ps -o rsz -p ${.MAKE.PID}
EOF

$ make-2021.12.13.03.55.16 -r -f for.mk
RSZ
10720

$ ./make -r -f for.mk
RSZ
1716

The difference is 8 MB, which amounts to 1 million .for loops.
 1.13 12-Dec-2021  rillig make: remove unused type MFStr

The only binary change is the line number of the assertion in
Substring_Sub.
 1.12 12-Dec-2021  rillig make: fix memory leak in LazyBuf

This affects many operations on variable expressions. Those using
LazyBuf_Done are affected, those using LazyBuf_DoneGet aren't.

$ cat <<'EOF' > lazybuf-memleak.mk
.for i in ${:U:range=5}
. for j in ${:U:range=1000}
. for k in ${:U:range=1000}
. if 0 && ${VAR:Dpattern\: that needs unescaping}
. endif
. endfor
. endfor
.endfor

all:
@ps -o vsz -p ${.MAKE.PID} | sed 1d
EOF

Before using LazyBuf for the modifier ':D':

$ make-2021.04.14.16.12.26 -r -f lazybuf-memleak.mk
VSZ RSZ
1357136 1336432

Using LazyBuf for the modifier ':D':

$ make-2021.04.14.16.59.34 -r -f lazybuf-memleak.mk
VSZ RSZ
1590864 1574164

This commit alone allocates around 150 MB more data, which matches
5_000_000 strings * 30 bytes/string.

It looks very wrong that the above simple makefile uses 1.3 GB of RAM at
all, and it had already done this in 2017, long before LazyBuf was
introduced. Before 2017.01.30.02.46.20, the above test makefile reports
way smaller numbers, but that's because the modifier ':range' did not
exist back then.
 1.11 05-Dec-2021  rillig make: save a memory allocation in each modifier ':O' and ':u'

No functional change.
 1.10 05-Dec-2021  rillig make: inline Str_Words into .for loop handling

This saves one memory allocation and a bit of copying, per .for loop.

No functional change.
 1.9 30-May-2021  rillig make: inline str_concat4

This function is only ever used for forming strings of the form
"archive(member)".

No functional change.
 1.8 14-Apr-2021  rillig branches: 1.8.2;
make: let the compiler decide whether to inline string functions

On x86_64, this reduces the binary size by 2 kB.
 1.7 14-Apr-2021  rillig make: reduce memory allocations in the modifiers ':D' and ':U'
 1.6 12-Apr-2021  rillig make: reduce memory allocation and strlen calls in modifier ':from=to'

Previously, SysVMatch was quite verbose and felt like hand-optimized
assembler code, which made it difficult to discover the underlying idea
of the code.

All this code was replaced with two simple calls to Substring_HasPrefix
and Substring_HasSuffix. Now that the operands of that modifier are no
longer passed as C strings, there is no need to collect all information
in a single scan through the word and the pattern.

It was not necessary to call Var_Subst unconditionally. Calling it only
when the string contains a '$' saves another memory allocation and two
string copies (because of the Buf_DoneDataCompact).

No functional change.
 1.5 11-Apr-2021  rillig make: improve performance for LazyBuf

The previous O(n^2) time complexity for parsing a long string with many
variable expressions was not meant to last for long. I had hoped to fix
it within a few minutes, but that will take more time.

For now, make LazyBuf simpler by using a traditional C string for the
expected part instead of a Substring. This avoids a strlen call per
Var_Parse.

No functional change, only performance.
 1.4 11-Apr-2021  rillig make: migrate ParseModifierPart to use Substring

This will reduce memory allocation for modifier parts without the escape
characters '$' or '\'.

No functional change.
 1.3 11-Apr-2021  rillig make: avoid unnecessary calls to strlen when evaluating modifiers

No functional change.
 1.2 11-Apr-2021  rillig make: migrate ModifyWord functions to use Substring

This benefits the modifiers ':T' and ':H' since these scan the word from
the end. The SysV modifier '.c=.o' does not benefit yet, this will be
done in a follow-up commit.

Currently ModifyWords calls strlen for each single word, which degrades
performance. This will be cleaned up in a follow-up commit as well.

No functional change.
 1.1 11-Apr-2021  rillig make: add types Substring and LazyBuf

These will be used for making the string handling more efficient,
avoiding allocations, especially when evaluating variable expressions.

Since the string handling has grown quite a bit in the last months,
extract it into its own header file.

No functional change.
 1.8.2.1 31-May-2021  cjep sync with head
 1.19.2.1 02-Aug-2025  perseant Sync with HEAD
 1.9 25-Oct-2020  rillig make(1): remove unused strlist_t
 1.8 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.7 11-Sep-2020  rillig make(1): replace *a->b with a->b[0]

This allows the code to be read strictly from left to right. In most
places this style was already used.
 1.6 25-Aug-2020  rillig make(1): allow make to be compiled in C90 mode

Since the inline functions are the only C99 feature used by now, setting
USER_CFLAGS='-std=c90 -ansi -Dinline=' is enough for compiling make with
a C90 compiler.
 1.5 09-Aug-2020  rillig make(1): format the source code consistently, at least per file

Some files use 4 spaces per indentation level, others use 8. At least
for the few files from this commit, they use a consistent style
throughout each file now.

In Cond_Eval, the #define has changed into an enum since the identifiers
need not be visible to the C preprocessor.
 1.4 24-Jan-2009  dsl Move the bmake_malloc() functions into their own .c and .h files.
Include instead of make.h in a few places.
 1.3 16-Jan-2009  dsl Allocate string vector in chunks, instead of calling realloc()
every time something is added.
 1.2 10-Jan-2009  dsl Allow the user to save an unsigned int (eg the length or flags) with
each string.
 1.1 20-Dec-2008  dsl Add functions for processing extendable arrays of pointers to strings.
Use for the .for variables and substution items - changing the latter from
make's all conquering lst.lib functions.
Being able to index everything makes the code simpler.
No functional changes intended.
 1.5 25-Oct-2020  rillig make(1): remove unused strlist_t
 1.4 13-Aug-2020  rillig make(1): follow naming conventions for multiple-inclusion guards

This avoids undefined behavior.
 1.3 16-Jan-2009  dsl Allocate string vector in chunks, instead of calling realloc()
every time something is added.
 1.2 10-Jan-2009  dsl Allow the user to save an unsigned int (eg the length or flags) with
each string.
 1.1 20-Dec-2008  dsl Add functions for processing extendable arrays of pointers to strings.
Use for the .for variables and substution items - changing the latter from
make's all conquering lst.lib functions.
Being able to index everything makes the code simpler.
No functional changes intended.
 1.384 18-May-2025  rillig make: rename variables, remove now-redundant comments
 1.383 14-Jan-2025  rillig make: clarify that undefined expressions are allowed in dependencies
 1.382 07-Jul-2024  rillig make: only generate code for cleanup functions in CLEANUP mode
 1.381 05-Jul-2024  rillig make: reduce lint-specific comments about ARGSUSED
 1.380 02-Jun-2024  rillig branches: 1.380.2;
make: sync VarEvalMode constant names with their debug log names
 1.379 25-May-2024  rillig make: fix some more memory leaks
 1.378 07-Feb-2024  rillig make: remove unneeded conditional-compilation toggles

The toggles INCLUDES, LIBRARIES, POSIX, SYSVINCLUDE, SYSVVARSUB,
GMAKEEXPORT and SUNSHCMD are no longer needed, they were unconditionally
set.

The toggle NO_REGEX was configurable from the command line, but
disabling it would result in various error messages about the unknown
':C' modifier.

OK sjg@.
 1.377 05-Jan-2024  rillig make: miscellaneous cleanups
 1.376 30-Dec-2023  rillig make: clean up freeing of suffixes

No functional change.
 1.375 30-Dec-2023  rillig make: remove unused field from suffix

No functional change.
 1.374 29-Dec-2023  rillig make: fix declared types of list nodes

No functional change.
 1.373 29-Dec-2023  rillig make: simplify memory allocation for string buffers

In edge cases and short-lived buffers, the initial buffer size is
irrelevant, so use the default.

No functional change.
 1.372 19-Dec-2023  rillig make: clean up comments

No binary change, except for line numbers in assertions.
 1.371 17-Dec-2023  rillig make: clean up names of local variables

No binary change.
 1.370 19-Nov-2023  rillig make: replace 'variable expression' with 'expression' in comments

No binary change.
 1.369 19-Nov-2023  rillig make: replace 'variable expression' with 'expression' in diagnostics
 1.368 14-Feb-2023  rillig make: clean up calls to Var_Subst

None of the calls to Var_Subst used the return value, and the return
value was always VPR_OK.

No functional change.
 1.367 14-Feb-2023  rillig make: reduce complexity of evaluating expressions

No functional change.
 1.366 04-Mar-2022  sjg Fix some unused warnings
 1.365 03-Mar-2022  rillig make: improve comments and a parameter name

No binary change.
 1.364 07-Jan-2022  rillig make: remove redundant function parameter in suffix handling

Now that mainNode is globally visible, there is no need to pass it
through function parameters.

No functional change.
 1.363 07-Jan-2022  rillig make: merge duplicate variables for the main target

No functional change.
 1.362 01-Jan-2022  rillig make: remove redundant comments from ParseDependencySourceSpecial
 1.361 28-Dec-2021  rillig make: extract OP_NOTARGET into separate function

No binary change, except for line numbers in assertions.
 1.360 15-Dec-2021  rillig make: format comments according to /usr/share/misc/style

Assisted by indent(1), with manual corrections due to its many remaining
bugs.

No functional change.
 1.359 15-Dec-2021  rillig make: use consistent indentation for statements and continuations

No binary change, except for line numbers in assertions in suff.c.
 1.358 13-Dec-2021  rillig make: fix memory leak when evaluating ${.SUFFIX} (since yesterday)
 1.357 12-Dec-2021  sjg Add .SUFFIXES as read-only variable.

References to ${.SUFFIXES} are handled dynamically in
ParseVarnameLong by calling Suff_NamesStr.

The variable cannot be set normally.

Reviewed by: rillig
 1.356 09-Dec-2021  rillig make: remove period from end of error messages and warnings

The majority of the existing error messages and warnings does not
include a period at the end. Follow this style consistently.
 1.355 28-Nov-2021  rillig make: move duplicate function Buf_AddFlag to buf.c

It is used only for debug output, therefore performance doesn't matter.

No functional change.
 1.354 28-Nov-2021  rillig make: inline SuffixFlags_ToString into Suffix_Print

This gets rid of the string literal "none" and the complicated memory
handling.

No functional change.
 1.353 28-Nov-2021  rillig make: inline SuffixFlags into the Suffix itself

No functional change.
 1.352 28-Nov-2021  rillig make: replace bloated bit-set-to-string code with simple code

It was a nice idea to implement a bit-set using an enum type and have a
generic ToString function for them. In the end, the implementation
involved really heavy preprocessor magic and was probably difficult to
understand. Replace all the code with a few bits of straight-forward
preprocessor magic that can be readily understood by just looking 5
lines around, instead of digging through 130 lines of lengthy macro
definitions.

Curiously, this reduces the binary size even though the 3 ToString
functions now have a few lines of duplicate code and there are more
explicit function calls.

The ToString functions are only seldom used, so the additional memory
allocation is acceptable.

No functional change.
 1.351 31-Jul-2021  rillig make: fix lint warnings

The string functions from str.h are declared as 'static __unused' when
compiled with GCC, but lint explicitly undefines __GCC__ during
preprocessing. Therefore, make those functions inline, to prevent
warnings that they are unused.

The macro UNCONST is used in a few places, and (again) since lint
undefines __GCC__, that macro expanded to a simple type cast, which lint
warned about. To prevent this warning, implement UNCONST as a function
that works everywhere and hides the type cast.

In filemon_open, the code for closing F->in was obviously unreachable.

No functional change.
 1.350 04-Apr-2021  rillig make: rename a few functions to be more descriptive

No functional change.
 1.349 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.348 15-Mar-2021  rillig make: replace enum bit-field with struct bit-field for VarEvalFlags

This makes the code easier to read, especially in var.c. It also makes
debugging sessions easier since some debuggers don't show enum
bit-fields symbolically as soon as more than one bit is set.

The code outside var.c is basically unchanged, except that instead of
passing the individual flags, there are 4 predefined evaluation modes.
These suffice for all practical use cases. Only in the implementation
deep inside var.c, the value of the flags keepDollar and keepUndef
differs.

There is no way of passing the struct to EnumFlags_ToString, which means
the ToString function has to be spelled out explicitly. This allows for
fine-tuning the representation in the debug log, to reduce the amount of
uppercae letters.

No functional change.
 1.347 15-Mar-2021  rillig make: rename VARE_NONE to VARE_PARSE_ONLY

The name 'NONE' described the bit pattern, which was not useful to
understand its meaning. Omitting VARE_WANTRES only parses the
expression, without evaluating any part of it.

No functional change, not even in debug mode since Enum_FlagsToString
always returns "none" for all-bits-unset.
 1.346 23-Feb-2021  rillig make: improve error message for unclosed modifier

Replace "variable specification" with the more modern "variable
expression", reduce the number of parentheses, output more than a single
character for modifiers, make it obvious that in expressions such as
${:Serror}, the "" means a variable name.
 1.345 05-Feb-2021  rillig make: in the Var_ functions, move the scope to the front

This change provides for a more natural reading order in the code.
Placing the scope first makes it immediately clear in which context the
remaining parameters are interpreted.

No functional change.
 1.344 04-Feb-2021  rillig make: rename context and ctxt to scope

This continues the previous commit, in which VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE were renamed.

Renaming the variable 'ctxt' was trivial since that word is used nowhere
else. In the comments though, each occurrence of the word 'context' had
to be checked individually since the word 'context' was not only used
for referring to a variable scope. It is also used to distinguish
different situations where characters are escaped in a certain way
('parsing context') and in a few other expressions.
 1.343 03-Feb-2021  rillig make: replace Global_SetExpand with Global_Set for constant names
 1.342 03-Feb-2021  rillig make: use shortcut functions Global_SetExpand and Global_AppendExpand

There are many places where global variables are set or appended to. To
reduce clutter and code size, encode the VAR_GLOBAL in the function
name.

The word Expand in the function names says that the variable name is
expanded. In most of the cases, this is not necessary, but there are no
corresponding functions Global_Set or Global_Append yet.

Encoding the information whether the name is expanded or not in the
function name will make inconsistencies obvious in future manual code
reviews. Letting the compiler check this by using different types for
unexpanded and expanded variable names is probably not worth the effort.
There are still a few bugs to be fixed, such as in SetVar, which expands
the variable name twice in a row.
 1.341 30-Jan-2021  rillig make(1): reduce boilerplate for printing bit sets in debug mode

No functional change.
 1.340 24-Jan-2021  rillig make(1): convert SearchPath to struct

This prepares for making dotLast a simple struct member instead of a
fake CachedDir, which is easier to understand.
 1.339 23-Jan-2021  rillig make(1): rename local variable in FindCmds
 1.338 23-Jan-2021  rillig make(1): remove the remaining beasts from the comments
 1.337 23-Jan-2021  rillig make(1): rename Dir_AddDir, reorder parameters of SearchPath_ToFlags
 1.336 23-Jan-2021  rillig make(1): rename Dir_Expand to SearchPath_Expand

The main subject of this function is the search path. In this search
path the pattern is expanded.
 1.335 10-Jan-2021  rillig make(1): consistently use boolean expressions in conditions

Most of the make code already followed the style of explicitly writing
(ptr != NULL) instead of the shorter (ptr) in conditions.

The remaining 50 instances have been found by an experimental,
unpublished check in lint(1) that treats bool expressions as
incompatible to any other scalar type, just as in Java, C#, Pascal and
several other languages.

The only unsafe operation on Boolean that is left over is (flags &
FLAG), for an enum implementing a bit set. If Boolean is an ordinary
integer type (the default), some high bits may get lost. But if Boolean
is the same as _Bool (by compiling with -DUSE_C99_BOOLEAN), C99 6.3.1.2
defines that a conversion from any scalar to the type _Bool acts as a
comparison to 0, which cannot lose any bits.
 1.334 09-Jan-2021  rillig make(1): fix lint warnings
 1.333 30-Dec-2020  rillig make(1): format multi-line comments
 1.332 20-Dec-2020  rillig make(1): return FStr from Var_Parse

This reduces the number of variable declarations at the call sites.
 1.331 18-Dec-2020  rillig make(1): spell nonexistent consistently
 1.330 13-Dec-2020  rillig make(1): add str_basename to reduce duplicate code

The function basename from POSIX has a few unfortunate properties, it is
allowed to return a pointer to static memory. This is too unreliable,
therefore this trivial own implementation.
 1.329 07-Dec-2020  rillig make(1): actually fix the use-after-free bug and the double-free

The use-after-free bug had been there since 2020-11-22, the double-free
bug since a few minutes.
 1.328 07-Dec-2020  rillig make(1): fix use-after-free in -DDEBUG_SRC mode (since 2020-11-22)
 1.327 06-Dec-2020  rillig make(1): inline macros for debug logging

No changes to the resulting binary, except for the line numbers in
assertions.
 1.326 05-Dec-2020  rillig make(1): define constants for enum zero-values
 1.325 05-Dec-2020  rillig make(1): extract ExpandChildrenRegular from ExpandChildren
 1.324 05-Dec-2020  rillig make(1): indent suff.c with tabs instead of spaces

ExpandChildren is way too deeply nested.
 1.323 29-Nov-2020  rillig make(1): reduce memory allocation for dirSearchPath
 1.322 29-Nov-2020  rillig make(1): reduce memory allocations in suffix storage
 1.321 29-Nov-2020  rillig make(1): reduce memory allocations in suffix handling
 1.320 29-Nov-2020  rillig make(1): reduce memory allocation in ExpandWildcards for suffixes
 1.319 29-Nov-2020  rillig make(1): reduce memory allocation in ExpandChildren for suffixes
 1.318 29-Nov-2020  rillig make(1): reduce memory allocation in suffix candidate search
 1.317 29-Nov-2020  rillig make(1): reduce memory allocation in suffix rule handling
 1.316 29-Nov-2020  rillig make(1): reduce memory allocation in suffix handling

The function Lst_MoveAll previously freed the source list. This
function was only used in a few places, and none of them really needed
the allocation.
 1.315 28-Nov-2020  rillig make(1): replace Dir_Destroy with SearchPath_Free

The function Dir_Destroy is an implementation detail of the cached
directories, and it should not be exported to the other modules. The
search paths, on the other hand, are the high-level API that may be used
by the other modules, as the concept of search paths is documented in
the manual page.
 1.314 28-Nov-2020  rillig make(1): rename some Dir functions to SearchPath

These functions have the search path as their main subject.
 1.313 28-Nov-2020  rillig make(1): reduce pointer indirection for GNode.implicitParents
 1.312 28-Nov-2020  rillig make(1): reduce pointer indirection for GNode.cohorts
 1.311 28-Nov-2020  rillig make(1): reduce pointer indirection for GNode.order_pred and order_succ
 1.310 28-Nov-2020  rillig make(1): reduce memory allocation for GNode.parents and GNode.children
 1.309 28-Nov-2020  rillig make(1): remove pointer indirection from GNode.commands

Just to save a few memory allocations. No noticeable effect on the
performance though.
 1.308 23-Nov-2020  rillig make(1): align end-of-line comments with tabs
 1.307 23-Nov-2020  rillig make(1): add HashSet type

This makes the code for handling suffixes simpler since it doesn't need
the clumsy API of HashTable_CreateEntry anymore.
 1.306 23-Nov-2020  rillig make(1): fix endless loop when resolving circular suffix rules
 1.305 23-Nov-2020  rillig make(1): make control flow simpler in FindThem
 1.304 23-Nov-2020  rillig make(1): fix DEBUG_SRC logging in FindThem

The node is also removed from the list if it is neither found in the
nodes nor in the file system. The logging did not reflect this.
 1.303 22-Nov-2020  rillig make(1): add high-level API for CandidateSearcher

This avoids passing invisible void pointers around in Lst_Append. It
also provides a convenient place to document what it means to "add a
candidate to the searcher".
 1.302 22-Nov-2020  rillig make(1): add CandidateSearcher to resolve transformation rules

Having a simple list of candidates is not enough. It is currently
possible to construct endless loops with huge memory usage, as
demonstrated in suff-transform-endless.mk.

To fix this, a straight-forward idea is to remember which candidates
have already been searched and to not search them again.

This also fixes a small inconsistency in the code. Most parameters had
been named slst (the s came from a time when Candidate was named Src),
except for Suff_FindDeps, where the variable was named srcs. The
confusing thing about this was that the name srcs is used throughout the
file for a different purpose. Only in FindThem there were two
parameters of the same type, which made this even more confusing.
 1.301 22-Nov-2020  rillig make(1): add more debugging for searching transformation rules
 1.300 22-Nov-2020  rillig make(1): add debug logging for setting and resetting the main target

The suffix code still doesn't behave as expected. Make sure that at
least setting the main target works as expected. It does, and the added
debug logging provides further hints for debugging the suffix handling
code.
 1.299 22-Nov-2020  rillig make(1): rename local variable in UpdateTargets
 1.298 22-Nov-2020  rillig make(1): extract FindDepsLib from FindDepsRegularKnown
 1.297 22-Nov-2020  rillig make(1): rename Candidate.pref to prefix

The new name nicely matches the .PREFIX variable.
 1.296 22-Nov-2020  rillig make(1): improve documentation of Candidate fields
 1.295 22-Nov-2020  rillig make(1): extract ExpandMember from FindDepsArchive
 1.294 22-Nov-2020  rillig make(1): extract ExpandAllChildren from FindDepsArchive
 1.293 22-Nov-2020  rillig make(1): extract string handling from Suffix_GetSuffix

Finding a suffix of a string is not the job of the Suffix type.
 1.292 22-Nov-2020  rillig make(1): rename StrIsPrefix to StrTrimPrefix

Only functions returning Boolean should have the word Is in their name.
 1.291 22-Nov-2020  rillig make(1): fix C99-ism in Suffix_GetSuffix
 1.290 22-Nov-2020  rillig make(1): fix type of local variable in FindDepsRegular

The compiler cannot check these since all lists and list nodes are
aliases to each other.

Maybe it's time to add type-generic lists to the code, to delegate these
checks to the compiler.
 1.289 22-Nov-2020  rillig make(1): add comment about missing unit test for .MAIN in suffixes
 1.288 22-Nov-2020  rillig make(1): remove last occurrences of Src
 1.287 22-Nov-2020  rillig make(1): clean up comment about single-suffix inference rules
 1.286 22-Nov-2020  rillig make(1): merge functions for suffix handling

The names of the functions AddSources and AddLevel were not as precise
and guiding as possible. Merging them into a single function makes the
code indented a little more, but on the other hand provides a function
with an easy to grasp purpose.
 1.285 22-Nov-2020  rillig make(1): clean up comments for Suff_AddInclude and Suff_AddLib
 1.284 22-Nov-2020  rillig make(1): document possible bug in UpdateTarget in suffix handling
 1.283 22-Nov-2020  rillig make(1): rename type SrcList to CandidateList

The variable names will be renamed in a follow-up commit, as necessary.
 1.282 22-Nov-2020  rillig make(1): rename type Src to Candidate

In all this code about sources, targets, parents and children, it's been
way too difficult to decide whether each word 'src' meant a source as
opposed to target, or just a possible source on its own.
 1.281 21-Nov-2020  rillig make(1): remove module name from local functions in Suff module

The module name doesn't provide any useful information. More often than
not, it creates a wrong impression of a very specific function name; the
function name has to be expressive enough even without the module name.
The word Suff may have even be misleading since not all of the functions
in this module affect suffixes, some also simply work on strings.

Module boundaries are marked by function names of the form Module_Func.
Therefore, local function names don't need to start with the module
name.

Rename the FindDeps functions to list their hierarchical position in the
function name, from broad to narrow.
 1.280 21-Nov-2020  rillig make(1): remove redundant null check in SuffFindCmds

Src.suff is never null. It is initialized in the constructor and then
never modified again. It cannot be marked as const though because memory
allocation and initialization are separated in SrcNew.
 1.279 21-Nov-2020  rillig make(1): clean up Suffix_GetSuffix

This eliminates the unspecific variable names p1 and p2 and furthermore
ensures that there is never a pointer that points out of bounds.

The code could have used memcmp or strncmp as well, but since the
suffixes are usuall very short, there is no benefit over a direct loop
comparing individual characters.
 1.278 21-Nov-2020  rillig make(1): fix indentation in SuffixList_Insert
 1.277 21-Nov-2020  rillig make(1): make srclist a local variable

In all current unit tests, the variable srclist was empty both when
entering Suff_FindDeps and when leaving it. Since that's the only
function that used this variable, it has been converted to a local
variable instead, to limit its scope.

To protect against accidental implementation mistakes, an assertion has
been added to ensure that at the end, everything could be cleaned up
properly. This assertion was missing before, and if there had really
been a case where the list were non-empty, make would have resolved
completely wrong candidates for the implied sources.
 1.276 21-Nov-2020  rillig make(1): improve local variable name in SuffRemoveSrc
 1.275 21-Nov-2020  rillig make(1): move prototype of SuffFindDeps further down

Just to limit its scope.
 1.274 21-Nov-2020  rillig make(1): move SuffExpandWildcards further up

This avoids an unnecessary forward declaration.
 1.273 21-Nov-2020  rillig make(1): document Suffix and Src
 1.272 21-Nov-2020  rillig make(1): improve comment for Suffix_GetSuffix
 1.271 21-Nov-2020  rillig make(1): rename Suff functions whose subject is a single suffix

The naming scheme Suffix_Func makes these functions easily
distinguishable from those that merely happen to be in the Suff module
but have nothing to do with suffixes, such as SuffStrIsPrefix.
 1.270 21-Nov-2020  rillig make(1): rename type SuffFlags to SuffixFlags
 1.269 21-Nov-2020  rillig make(1): rename SuffList to SuffixList
 1.268 21-Nov-2020  rillig make(1): rename type Suff to Suffix

This avoids confusion with the module suff.c of the same name.

The existing naming convention is that the module's public functions are
named Suff_Func and its private functions are named SuffFunc. This
collides with the naming convention that a the functions of the type Suff
are called Suff_Func as well.

To resolve this collision, rename Suff to Suffix. The related types like
SuffList and the affected functions like SuffRef will be renamed in a
follow-up commit.
 1.267 21-Nov-2020  rillig make(1): rename suffNull to nullSuff

This variable is internal to the suff.c module, therefore there is no
need to prefix it with the module name. The new name follows the naming
convention established by emptySuff.
 1.266 21-Nov-2020  rillig make(1): improve name of local variable in SrcList_Add

Now that nothing in suff.c is named 's' anymore, there is no need for
's2' either.
 1.265 21-Nov-2020  rillig make(1): rename SuffAddSrc to SrcList_Add

The main character in this function is the list of sources, therefore
make it the subject.
 1.264 21-Nov-2020  rillig make(1): improve parameter name in SuffUpdateTarget
 1.263 21-Nov-2020  rillig make(1): document necessary condition in SuffUpdateTarget
 1.262 21-Nov-2020  rillig make(1): in SuffExpandChildren, only expand ${VAr} if needed
 1.261 21-Nov-2020  rillig make(1): clean up reference counting in SuffList_Insert
 1.260 21-Nov-2020  rillig make(1): move reference counting for suffixes to SrcNew
 1.259 21-Nov-2020  rillig make(1): clean up reference counting for suffixes
 1.258 21-Nov-2020  rillig make(1): add explanation for test suff-rebuild
 1.257 21-Nov-2020  rillig make(1): add more debug logging for suffixes

The "Removing suffix" is not covered by the current tests. It would be
best if that code were unreachable at all, since a reference count of -1
doesn't make sense.
 1.256 21-Nov-2020  rillig make(1): add debug logging when adding a suffix to the global list
 1.255 21-Nov-2020  rillig make(1): rename local variable s to suff

The name s was ambiguous. It could have meant suffix, src, str, and
probably more.
 1.254 21-Nov-2020  rillig make(1): make debug logging more precise in Suff_EndTransform
 1.253 21-Nov-2020  rillig make(1): flatten Suff_EndTransform

This avoids the duplicate code for testing OP_TRANSFORM.
 1.252 21-Nov-2020  rillig make(1): rename SuffScanTargets to SuffUpdateTarget

The word "scan" no longer applies to this function since that is done by
SuffUpdateTargets instead.
 1.251 21-Nov-2020  rillig make(1): clean up parameter names for SuffScanTargets

The prefix "gs" came from a time when SuffScanTargets was called via
Lst_ForEach, passing it a struct GNodeSuff. The "gs" had just been the
abbreviation for "GNode + Suff", which was already non-expressive. On
top of that, the struct had a third field "r", also with an unclear name,
which was not even mentioned in the name of the struct.

For now, just remove the needless prefix since it has absolutely no
meaning anymore. Maybe it will become clear what the "r" was supposed to
mean, it could be some kind of "result".
 1.250 19-Nov-2020  rillig make(1): mark srclist as a bad global variable

The previous comment "List of sources" didn't tell anything about the
purpose of the variable, it was only useful before July 2020, when its
data type was still Lst, without any type information.

Having a global variable here seems pointless, but all the code about
suffix transformations is so tricky and not well covered by tests that I
don't dare to convert the global variable to a local variable in
Suff_FindDeps. The change itself would be trivial, but the hidden and
undocumented intentions of the original author probably aren't.
 1.249 19-Nov-2020  rillig make(1): compare pointers against NULL instead of implicit conversion
 1.248 19-Nov-2020  rillig make(1): fix compilation error in -DDEBUG_SRC mode
 1.247 16-Nov-2020  rillig make(1): rename local functions in suffix handling

Name these functions after their main object, which is the suffix list.
 1.246 16-Nov-2020  rillig make(1): merge duplicate calls to SuffInsert
 1.245 16-Nov-2020  rillig make(1): clean up code style in make.c and suff.c
 1.244 16-Nov-2020  rillig make(1): rename Targ_NewGN to GNode_New

This function is a classical constructor function, and if it weren't for
CLEANUP mode, it would have no dependencies on anything else besides the
memory allocator. Therefore it doesn't really matter which module
defines this function, and there is no need for the "Targ" to be part of
the function name.
 1.243 16-Nov-2020  rillig make(1): inline SUFF_DEBUG3 and SUFF_DEBUG4

Each of them was only used a single time, which was not worth an
additional macro.
 1.242 16-Nov-2020  rillig make(1): clean up coding style in suff.c
 1.241 16-Nov-2020  rillig make(1): improve local variable names in suff.c

The name 's' was used for both 'suff' and 'src', which was unnecessarily
confusing.
 1.240 16-Nov-2020  rillig make(1): remove redundant braces and parentheses from suff.c
 1.239 16-Nov-2020  rillig make(1): use boolean expressions in conditions
 1.238 16-Nov-2020  rillig make(1): clean up comments in suff.c
 1.237 16-Nov-2020  rillig make(1): mark Suff.ref as probably unused
 1.236 15-Nov-2020  rillig make(1): clean up coding style in compat, parse, suff
 1.235 08-Nov-2020  rillig make(1): clean up code related to VarEvalFlags

Mention VARE_WANTRES before VARE_UNDEFERR since the latter depends on
the former.

In ApplyModifier_Assign, VARE_KEEP_DOLLAR doesn't have to be removed
from eflags since ParseModifierPart does this already.

In EvalUndefined, testing for VARE_WANTRES is redundant if VARE_UNDEFERR
is already set.
 1.234 08-Nov-2020  rillig make(1): rename Src.children to numChildren

There are several other types that have a field named 'children' that is
a list. To avoid confusion, rename this one to differentiate them.
 1.233 08-Nov-2020  rillig make(1): clean up local variable names in suffix handling

The file suff.c defines both Src and Suff, which makes the variable name
s ambiguous.

The word 'target' is ambiguous as well since it could mean a GNode or the
target suffix of a transformation. Therefore, make the variable names
longer but more precise.

The comment about the nil return and the beanhead had been outdated
already in 1993. There is no nil return anywhere nearby. The longer
variable names make the rest of the comment redundant.
 1.232 07-Nov-2020  rillig make(1): add pp_skip_hspace to skip horizontal whitespace during parsing
 1.231 05-Nov-2020  rillig make(1): remove redundant parentheses from sizeof operator

The parentheses are only needed if the argument is a type, not an
expression.
 1.230 31-Oct-2020  rillig make(1): do not look up local variables like .TARGET anywhere else

Nobody defines a global variable named .TARGET since that would have
many unpredictable effects, applying to all targets at once.

Nobody defines an environment variable named .TARGET since that's
against the naming conventions for environment variables and would have
the same effect.

Because of this, there is no point looking up the variables that are
local to a GNode anywhere else. This means they cannot come from the
environment and thus their value doesn't need to be freed after use,
which makes the code simpler.

The newly added accessor functions in make.h refer to external
functions, but since that header is not used anywhere outside of
usr.bin/make, it doesn't matter. Between 2020-08-25 and 2020-10-30,
that header had been referenced by usr.bin/xinstall.
 1.229 30-Oct-2020  rillig make(1): change char * to void * in Var_Value

The only purpose of the parameter freeIt is to free the memory
associated with the return value. To do this, no pointer arithmetic is
needed. Therefore, change to a void pointer, to catch accidental use of
that pointer.
 1.228 30-Oct-2020  rillig make(1): fix indentation in source code
 1.227 26-Oct-2020  rillig make(1): convert a few strings to const strings in suff.c
 1.226 25-Oct-2020  rillig make(1): properly terminate debug output with newline

Without this, NetBSD's sed adds the missing newline at the end of the
file, while other sed implementations don't do that.
 1.225 25-Oct-2020  rillig make(1): add GNode_Path to access the path of a GNode
 1.224 25-Oct-2020  rillig make(1): add more details to DEBUG_SRC log
 1.223 25-Oct-2020  rillig make(1): replace Dir_CopyDir with Dir_CopyDirSearchPath

Callback functions for the Lst functions do not belong in the public API
of a module.
 1.222 24-Oct-2020  rillig make(1): remove unused Lst_Find and Lst_FindFrom
 1.221 24-Oct-2020  rillig make(1): don't modify GNode name while rebuilding the suffix graph
 1.220 24-Oct-2020  rillig make(1): improve local variable names in SuffFindThem
 1.219 23-Oct-2020  rillig make(1): improve variable names in SuffRebuildGraph
 1.218 23-Oct-2020  rillig make(1): negate OP_NOP and rename it to GNode_IsTarget
 1.217 22-Oct-2020  rillig make(1): add Lst_ForEachUntilConcurrent

Previously, Lst_ForEachUntil allowed the list to be modified while
iterating. Almost none of the code needs this, and it's also confusing
for human readers.

None of the current unit tests makes use of this concurrent modification
right now, but that's not evidence enough. Only 72% of the code are
covered by unit tests right now, and there are lots of edge cases
(whether intended or not) that are not covered by unit tests.

Therefore, all calls to Lst_ForEachUntil were changed to
Lst_ForEachUntilConcurrent and those that were obvious were changed
back. The remaining calls probably don't need the concurrent
modification code, but that's not obvious from looking at the code.
 1.216 22-Oct-2020  rillig make(1): replace Lst_Open with simple iteration in SuffFindCmds

Again, no concurrent modification nearby.
 1.215 22-Oct-2020  rillig make(1): rename local variables in SuffFindCmds

Several types have fields named "parents" and "children", which makes an
expression like s->children ambiguous.
 1.214 22-Oct-2020  rillig make(1): migrate Lst_Open to simple iteration in SuffRemoveSrc

During the iteration, the list is modified. But after the modification,
the iteration stops by returning, therefore the additional complexity of
Lst_Open is not needed in this case.
 1.213 22-Oct-2020  rillig make(1): remove redundant type casts

This mainly affects the void pointers in callback functions for lists.
These had been necessary once when the parameter type was still
ClientData instead of void pointer.
 1.212 21-Oct-2020  rillig make(1): add suffix number to the debug log

Previously, I had taken that lonely number in the debug log for the
sNum, but it was the reference count.
 1.211 21-Oct-2020  rillig make(1): rename Src.cp to childrenList
 1.210 21-Oct-2020  rillig make(1): replace SuffGNHasName with FindTransformByName
 1.209 21-Oct-2020  rillig make(1): extract code to allocate a Src

Separating this code from the rest of the initialization makes it
obvious that there are inconsistencies in memory handling (owned vs.
shared pointers, reference counts). It also forces a consistent order
of specifying the fields of a Src.
 1.208 21-Oct-2020  rillig make(1): clean up suffix handling code

Using (name, nameLen) is easier to understand than the unusual (nameLen,
nameEnd).
 1.207 21-Oct-2020  rillig make(1): inline struct SuffSuffGetSuffixArgs in suffix search
 1.206 21-Oct-2020  rillig make(1): reduce indentation in SuffFindNormalDepsPath
 1.205 21-Oct-2020  rillig make(1): extract path search from SuffFindNormalDeps
 1.204 21-Oct-2020  rillig make(1): unindent SuffFindNormalDepsUnknown
 1.203 21-Oct-2020  rillig make(1): clean up SuffFindNormalDepsKnown
 1.202 21-Oct-2020  rillig make(1): extract handling of unknown suffix from SuffFindNormalDeps
 1.201 21-Oct-2020  rillig make(1): extract handling of known suffix from SuffFindNormalDeps
 1.200 21-Oct-2020  rillig make(1): merge duplicate code for -DDEBUG_SRC
 1.199 20-Oct-2020  rillig make(1): remove strange off-by-one feature in SuffSuffGetSuffix

The code worked as intended, yet it was strange to modify cp[1] to
temporarily shorten a string. Using cp[0] for this purpose is common
style.
 1.198 20-Oct-2020  rillig make(1): improve debug messages for suff.c

Especially for the null suffix, the previous message was hard to read.
Who would guess that in "inserting (0)", there is an empty string before
the parenthesis? The new format uses quotes to make the suffixes
clearly visible.

While here, improve some local variable names. In a file that defines
both Suff and Src, using s for a variable is just too ambiguous. The
variable name l can easily be confused with a 1, so name it list
instead.
 1.197 20-Oct-2020  rillig make(1): inline SuffSuffIsPrefix into SuffParseTransform
 1.196 20-Oct-2020  rillig make(1): untangle SuffParseTransform

That function was probably not meant to be a brain-twister, but the
convoluted loop combined with Lst_Find/Lst_FindFrom and the deeply
indented second pass for the single suffix made the code harder to
understand than necessary.

No functional change intended, that's why I had to split and enable the
test suffixes.mk first.
 1.195 19-Oct-2020  rillig make(1): inline simple Lst getters

The function call variant takes more screen space than the direct field
access. Having an abstract API is usually a good idea, in this case of
simple read-only member access it makes the code more difficult to read.

LstNode_Set has been kept as a function since it is not a read-only
accessor function.
 1.194 19-Oct-2020  rillig make(1): use consistent formatting for DEBUG_SRC

No trailing whitespace anymore, %p instead of %lx.
 1.193 19-Oct-2020  rillig make(1): remove void pointers from DEBUG_SRC debugging code

This debugging code is completely broken. Part of the output goes to
debug_file, the other part goes to stdout. The spacing in the output is
inconsistent. The printf directives vary between %p and %lx.

All these inconsistencies have already been there in June 2020, before
the big refactoring started.
 1.192 19-Oct-2020  rillig make(1): remove void pointers from SuffRebuildGraph
 1.191 19-Oct-2020  rillig make(1): remove void pointers from suffix debug printing
 1.190 18-Oct-2020  rillig make(1): extract duplicate code from SuffAddSrc into separate function
 1.189 18-Oct-2020  rillig make(1): add tags to enum types

This allows IDEs to offer better type information than "anonymous enum".
 1.188 18-Oct-2020  rillig make(1): improve parameter names for suffix functions

Both gs_gnp and gnp were terrible variable names that didn't give the
slightest clue about the variable's purpose.
 1.187 18-Oct-2020  rillig make(1): extract UpdateTargets from Suff_AddSuffix
 1.186 18-Oct-2020  rillig make(1): inline struct SuffScanTargetsArgs into SuffScanTargets
 1.185 18-Oct-2020  rillig make(1): rename struct GNodeSuff to SuffScanTargetsArgs
 1.184 18-Oct-2020  rillig make(1): inline struct LstSrc into SuffAddSrc

The variable names are still confusing. There was no useful
documentation on the struct, and the code in SuffAddSrc is highly
redundant. Maybe the next few refactorings will shed light on this part
of the code.
 1.183 18-Oct-2020  rillig make(1): remove void pointers from SuffAddSrc
 1.182 18-Oct-2020  rillig make(1): replace Lst_Open with simple iteration in SuffInsert
 1.181 18-Oct-2020  rillig make(1): replace Lst_Open in Suff_DoPaths with simple iteration

Since sufflist is not modified during iteration, there is no need for
the extra complexity of Lst_Open.
 1.180 18-Oct-2020  rillig make(1): rename Lst_Init to Lst_New

For the other types such as HashTable and Buffer, the Init function does
not allocate the memory for the structure itself, it only fills it.
 1.179 17-Oct-2020  rillig make(1): normalize initialization and cleanup of the modules
 1.178 17-Oct-2020  rillig make(1): fix indentation
 1.177 05-Oct-2020  rillig make(1): prepare job.c, main.c, parse.c, suff.c for WARNS=6

In job.c, GCC 5 complains about the macro FILENO that it has type
unsigned int, which is then passed as the argument of dup2, which
expects a simple int. Maybe this workaround from 1995 is not necessary
anymore, or maybe it is but can be restricted to the few affected
platforms.

This leaves meta.c and the filemon files to be converted. I didn't do
them since they are not well covered by the unit tests.
 1.176 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.175 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.174 03-Oct-2020  rillig make(1): clean up #include sections
 1.173 28-Sep-2020  rillig make(1): replace += 1 with ++ and -= 1 with --

Just for visual consistency. The generated code stays exactly the same.
 1.172 28-Sep-2020  rillig make(1): make debug logging simpler

This avoids referring to the debug_file variable in many places where
this implementation detail is not necessary.
 1.171 28-Sep-2020  rillig make(1): make debugging code shorter
 1.170 27-Sep-2020  rillig make(1): normalize whitespace in source code

There is no more space tab. Either only tabs or only spaces or tabs
followed by spaces, but not spaces followed by tabs.
 1.169 26-Sep-2020  rillig make(1): inline and remove LstNode_Prev and LstNode_Next

These functions made the code larger than necessary. The prev and next
fields are published intentionally since navigating in a doubly-linked
list is simple to do and there is no need to wrap this in a layer of
function calls, not even syntactically. (On the execution level, the
function calls had been inlined anyway.)
 1.168 26-Sep-2020  rillig make(1): clean up API for finding and creating GNodes

The previous API had complicated rules for the cases in which the single
function returned NULL or what it did. The flags for that function were
confusing since passing TARG_NOHASH would create a new node even though
TARG_CREATE was not included in that bit mask.

Splitting the function into 3 separate functions avoids this confusion.
It also reveals several places where the complicated API led to
unreachable code. Such code has been removed.
 1.167 25-Sep-2020  rillig make(1): declare strings for suff.c constant
 1.166 25-Sep-2020  rillig make(1): in FindSuffByName, return the suffix instead of a list node

None of the callers was interested in the list node.
 1.165 25-Sep-2020  rillig make(1): migrate suff.c from Lst_ForEachUntil to Lst_ForEach
 1.164 25-Sep-2020  rillig make(1): convert int to size_t for string lengths

Just for formal reasons. There is no practical scenario in which any
filename suffix would grow larger than a few kilocharacters.
 1.163 25-Sep-2020  rillig make(1): don't use reserved names in type names
 1.162 25-Sep-2020  rillig make(1): replace Lst_Find with FindSuffByName
 1.161 25-Sep-2020  rillig make(1): add tags to some of the unnamed structs

The tags prevent the structs from accidentally becoming compatible
types.

While here, remove a few typedefs for structs that are single-purpose,
since there is no point in abstracting from the actual representation of
these types.
 1.160 24-Sep-2020  rillig make(1): remove redundant function prototypes in suff.c
 1.159 24-Sep-2020  rillig make(1): rename Lst_ForEach to Lst_ForEachUntil

Since the callback function returns a terminating condition, this is not
really a foreach loop.

Many of the calls to Lst_ForEachUntil don't make use of the terminating
condition, and several don't modify the list structurally, which means
they don't need this complicated implementation.

In a follow-up commit, Lst_ForEach will be added back with a much
simpler implementation that iterates over the list naively, without a
terminating condition and without taking the iteration state from
Lst_Open/Lst_Next/Lst_Close into account. The migration to this simpler
implementation will be done step by step since each callback function
needs to be examined closely.
 1.158 22-Sep-2020  rillig make(1): prepare Var_Subst for proper error handling

Returning a VarParseResult instead of a string makes it possible to let
the error bubble up, until it reaches the main expression.
 1.157 22-Sep-2020  rillig make(1): use fine-grained type names for lists and their nodes

This is only intended to help the human reader. There is no additional
type safety yet.
 1.156 13-Sep-2020  rillig make(1): prepare Var_Parse for proper error handling and reporting

Right now, Var_Parse swallows many errors during parsing and evaluation.
Ideally, these errors should propagate from the deeply nested
expressions where they occur up to the top-level expressions. When such
an error occurs, the depending expressions should not be evaluated any
further. They may still be parsed, but side effects should be
minimized.

The goal is to prevent incomplete expressions like the "xy}" in
moderrs.exp:106 from being evaluated and eventually passed to the shell
for execution. This expression is a left-over from a parse error in the
mod-t-parse target in moderrs.mk:154.

This commit is a first step in analyzing and verifying the current state
of affairs. The modelling in VarParseErrors already looks complicated
but is expected to closely match reality.
 1.155 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.154 13-Sep-2020  rillig make(1): remove #endif comments for very short blocks
 1.153 12-Sep-2020  rillig make(1): reword variable invocation to variable expression

Variables are a passive thing. They cannot be invoked, they can only be
evaluated.
 1.152 12-Sep-2020  rillig make(1): rename Var_ParsePP back to Var_Parse

The migration to the "parsing position" pointer has been done.
 1.151 12-Sep-2020  rillig make(1): fix API for Targ_PrintCmd

The previous API was too low-level and not strictly typed.
 1.150 12-Sep-2020  rillig make(1): fix prototype of Suff_EndTransform
 1.149 12-Sep-2020  rillig make(1): move PrintAddr to where it belongs
 1.148 12-Sep-2020  rillig make(1): fix inconsistent code indentation
 1.147 11-Sep-2020  rillig make(1): rename GNodeSuff.gn to gnp

It was confusing to have a field called "gn" that was not a pointer to a
GNode, but a double-pointer to GNode instead.
 1.146 11-Sep-2020  rillig make(1): replace *a->b with a->b[0]

This allows the code to be read strictly from left to right. In most
places this style was already used.
 1.145 08-Sep-2020  rillig make(1): fix off-by-one error in SuffExpandChildren

In suff.c r1.144 from yesterday, in the line "cp += nested_p - cp", I
accidentally removed the "- 1". Since these "- 1" lines lead to slow
execution, each branch now increments the pointer separately by the
actually needed amount.

Fixing this bug posed way more new questions than it answered, and it
revealed an inconsistency in the parser about how characters are to be
escaped, and missing details in the documentation of Var_Parse, as well
as a parse error that unexpectedly doesn't stop make from continuing.
 1.144 07-Sep-2020  rillig make(1): migrate SuffExpandChildren to Var_ParsePP
 1.143 05-Sep-2020  rillig make(1): remove trailing whitespace in -dg1 debug output
 1.142 31-Aug-2020  rillig make(1): fix compilation for -DNDEBUG and -O3

The -O3 option of GCC 5.5 is unsure about whether s and t are always
defined, since SuffParseTransform only defines them if it returns TRUE.

Therefore assert that it does. When compiled with -NDEBUG, this would
result in an unused variable, therefore use it using the well-known
cast-to-void pattern.
 1.141 31-Aug-2020  rillig make(1): fix unbalanced Lst_Open/Lst_Close in SuffFindCmds

This bug had been there since the initial import of make, on 1993-03-21.
It just never broke the build because of the missing assertion.

https://mail-index.netbsd.org/tech-toolchain/2020/08/30/msg003847.html

The error message "cd: can't cd to include" that I got when I first
applied the fix was unrelated. It was caused by an extra directory
"include" in src/tools/compat that didn't belong there. With that
directory removed, running "./build.sh -j8 tools" succeeds as expected.
 1.140 30-Aug-2020  rillig make(1): add debug macros to suff.c

This reduces the visual space that the debugging statements need.
 1.139 30-Aug-2020  rillig make(1): rename GNode.iParents to implicitParents

The i alone was too ambiguous. It could have meant ignore, implicit,
interactive, and probably many more.
 1.138 30-Aug-2020  rillig make(1): rename Lst_Datum to LstNode_Datum
 1.137 30-Aug-2020  rillig make(1): rename Lst_Memeber to Lst_FindDatum

The new name nicely aligns with Lst_Find and Lst_FindFrom.
 1.136 29-Aug-2020  rillig make(1): trust that Var_Parse never returns NULL

That function is quite long, but all its return paths lead either to the
expanded variable expression, or to var_Error or varNoError.
 1.135 29-Aug-2020  rillig make(1): trust that Var_Subst never returns NULL

It really never does, and it doesn't even report errors. It just
returns the content of the buffer, up to the first parse error.
 1.134 29-Aug-2020  rillig make(1): clean up comments in suff.c, small refactorings

In SuffParseTransform, the parameter names have been renamed to make the
"side effects" comment redundant.

In Suff_AddSuffix and Suff_AddLib, the parameter has been made const.

In SuffRemoveSrc, the unused variable has been removed, and the return
type has been fixed.
 1.133 29-Aug-2020  rillig make(1): add bmake_strsedup for duplicating a substring
 1.132 29-Aug-2020  rillig make(1): merge duplicate code for bmake_strldup
 1.131 29-Aug-2020  rillig make(1): rename LstNode functions to match their type
 1.130 29-Aug-2020  rillig make(1): rename Lst_FindB back to Lst_Find

The migration from "comparison function" to "match function" is done,
the "B" in the names is no longer needed.
 1.129 29-Aug-2020  rillig make(1): migrate remaining Lst_Find to Lst_FindB

While here, rename SuffSuffIsSuffix to SuffSuffGetSuffix since a
function named "is" should return a boolean, not a string pointer.
 1.128 28-Aug-2020  rillig make(1): rename SuffixCmpData to SuffSuffIsSuffixArgs

The new name makes the comment above that struct redundant.
 1.127 28-Aug-2020  rillig make(1): clean up suffix handling
 1.126 28-Aug-2020  rillig make(1): fix assertion failure in suffix handling

Found by running ./build.sh, in the very early stage.
Fixed by restoring the previous behavior of returning NULL for invalid
arguments.
 1.125 28-Aug-2020  rillig make(1): remove trailing 'S' from names of Lst functions

The migration from null-passing Lst functions to argument-checking Lst
functions is completed.

There were 2 surprises: The targets list may be NULL, and in Dir_AddDir,
the path may be NULL. The latter case is especially surprising since
that function turns into an almost-nop in that case. This is another
case where probably 2 independent functions have been squeezed into a
single function. This may be improved in a follow-up commit.

All other lists were fine. They were always defined and thus didn't
need much work.
 1.124 28-Aug-2020  rillig make(1): migrate Lst_Find to Lst_FindS
 1.123 28-Aug-2020  rillig make(1): migrate Lst_First to Lst_FirstS
 1.122 28-Aug-2020  rillig make(1): print suffix flags in the standard way

This changes the output (it is now SUFF_NULL instead of just NULL), and
the order of the flags in the output is reversed.
 1.121 27-Aug-2020  rillig make(1): migrate Lst_IsEmpty to Lst_IsEmptyS
 1.120 27-Aug-2020  rillig make(1): migrate Lst_Last to Lst_LastS
 1.119 27-Aug-2020  rillig make(1): migrate Lst_Succ to Lst_SuccS
 1.118 27-Aug-2020  rillig make(1): migrate Lst_ForEach to Lst_ForEachS

Most lists are always valid. Only the "targets" variable may be null in
some cases, probably.
 1.117 26-Aug-2020  rillig make(1): merge duplicate code for creating a new suffix
 1.116 26-Aug-2020  rillig make(1): add stricter variants for remaining Lst functions

In most cases the Lst functions are only called when the arguments are
indeed valid. It's not guaranteed though, therefore each function call
needs to be analyzed and converted individually.

While here, remove a few statements that were only useful when the Lst
functions handled circular lists.
 1.115 25-Aug-2020  rillig make(1): fix obvious bugs in -DCLEANUP mode

The outdated type name FreeProc had been renamed to LstFreeProc.
Casting the function free to it is not necessary since the type of this
function is already exactly the correct type. Anything else would be
undefined behavior anyway.

The uninitialized sufflist in Suff_ClearSuffixes was ok until now
because the Lst functions had silently skipped any calls with invalid
arguments. This silent skipping is a good argument to have strict
argument validation since it detects these unintended control flows.
 1.114 23-Aug-2020  rillig make(1): reverse order of the Lst_Find parameters

The other callbacks all have (function, param), only the Lst_Find had
(param, function), which was inconsistent.
 1.113 23-Aug-2020  rillig make(1): unroll loop in SuffFindArchiveDeps

The compiler had unrolled this loop anyway, and for humans it is more
readable as well.

The comments "must be first" and "must be second" came from a time when
the variables were stored in a linked list instead of a hash table.
Maybe this "must" was about performance back then. Anyway, the tests
run fine with either order, and there is absolutely no evidence that the
order of these variables could have any effect.
 1.112 22-Aug-2020  rillig make(1): replace Lst_Duplicate with Lst_CopyS

Lst_Duplicate would have passed through any null pointer, which was not
needed for make. It was the last function that used Lst_AtEnd, which in
turn was the last function that used LstInsertAfter. As a result, these
two functions have been removed.
 1.111 22-Aug-2020  rillig make(1): make moving and copying lists simpler

Instead of the two-in-one Lst_Concat, having two separate functions is
easier to understand. There is no need for a long API comment anymore
since the new functions have a single purpose that is accurately
described by their name.

The long comment inside Lst_Concat has been removed since it only
repeated the exact code, only in more words.

The comments in make.c about appending the cohorts had been wrong. They
were not appended but prepended. Once more, the function name expresses
everything that the comment said, making the comment redundant. There
is no need to test whether the cohorts list is empty, doing nothing is
implied by the word All in Lst_PrependAllS.
 1.110 22-Aug-2020  rillig make(1): make Lst_Prev stricter regarding null pointers
 1.109 22-Aug-2020  rillig make(1): clean up headers

Remove redundant headers that are already included by "make.h".
Make <assert.h> available to all compilation units that use "make.h".
 1.108 22-Aug-2020  rillig make(1): convert GNode type constants to enum

This allows debuggers to print symbolic names for the type flags.

The names of these constants need to be revised. These flags probably
started as the 3 dependency operators (:, !, ::), and at that time, the
prefix OP_ made sense. The other flags are not related to the type of
the dependency operator and could have been placed in GNode.flags as
well.
 1.107 22-Aug-2020  rillig make(1): require argument of Lst_Member to be non-null

Since the lists don't contain null pointers, it doesn't make sense to
search for a null pointer. All calls but one already had obviously
non-null arguments. The one remaining call using targ->suff has been
guarded for now.

The code for Lst_Member became much simpler than before. Partly because
the old code had an extra condition for circular lists, which are not
used by make.
 1.106 22-Aug-2020  rillig make(1): replace Lst_Datum with non-null guaranteeing Lst_DatumS
 1.105 22-Aug-2020  rillig make(1): add strict argument checks for Lst_InsertBefore

As with the other modifying operations on lists, the callers already
made sure that the arguments are valid.
 1.104 22-Aug-2020  rillig make(1): convert Lst_Enqueue and Lst_Dequeue to nonnull variants

Except for once instance in parse.c, the usage pattern for Lst_Dequeue
was to first test whether the list is empty. This pattern allowed the
implementation of Lst_Dequeue to become simpler since the null check is
not needed anymore.

The calls to Lst_Enqueue never pass an invalid list or a null pointer,
therefore making them strict was trivial.
 1.103 22-Aug-2020  rillig make(1): convert remaining Lst_AtEnd to the stricter Lst_Append

The general-purpose list library that is included in make allows to call
Lst_AtEnd for invalid lists, silently ignoring this programming error.
This is a flexibility that make doesn't need.

Another unneeded "feature" is that list items can theoretically be null
pointers. This doesn't make sense as well and is therefore not needed
by make.

These programming errors are now caught early by assertions.
 1.102 22-Aug-2020  rillig make(1): replace "(void)Lst_AtEnd" with stricter "Lst_AppendS"

This change ensures that there is actually something added to the list.
Lst_AtEnd had silently skipped the addition if the list was invalid
(null pointer), which was not intended in these cases. The "(void)" is
assumed to mean "I know that this cannot fail", while it could also mean
"I don't care whether something actually happened".

Running "./build.sh -j6 tools" still succeeds after this change,
therefore chances are very low that this change breaks anything. If
there is any change, it's an obvious assertion failure. There is no
silent change in behavior though.
 1.101 22-Aug-2020  rillig make(1): remove form feeds in the code
 1.100 21-Aug-2020  rillig make(1): use stricter list API for sequential access

In several places, it just doesn't make sense to have a null pointer
when a list is expected.

In the existing unit tests, the list passed to Lst_Open is always valid,
but that's not a guarantee for real-world usage. Therefore, Lst_Open
has been left for now, and Lst_OpenS is only the preferred alternative
to it.
 1.99 21-Aug-2020  rillig make(1): assert correct usage of the Lst_Open API

All calls to Lst_Next are properly protected by Lst_Open, so there is no
possible assertion failure here.
 1.98 21-Aug-2020  rillig make(1): make list library code stricter

Up to now, the list library didn't distinguish between programming
mistakes (violations of invariants, illegal parameter values) and
actually interesting situations like "element not found in list".

The current code contains many branches for conditions that are neither
exercised by the unit tests nor by real-world usage. There is no point
in keeping this unnecessary code.

The list functions will be migrated from their lenient variants to the
stricter variants in small parts, each function getting the S suffix
when it is made strict, to avoid any confusion about how strict a
particular function is. When all functions have been migrated, they
will be renamed back to their original names.

While here, the comments of the functions are cleaned up since they
mention irrelevant implementation details in the API comments, as well
as "side effects" that are really main effects.
 1.97 21-Aug-2020  rillig make(1): remove unused code for circular lists

The list library had probably been imported from a general-purpose
library that also supported circular lists. These are not used by make
though.

After replacing Lst_Init(FALSE) with Lst_Init(), only a single call to
Lst_Init remained with a non-constant argument, and that was in
Lst_Concat, which was to be expected.
 1.96 11-Aug-2020  rillig make(1): convert Suff.flags from #define to enum

This increases debugging support since the debugger can now display
symbolic names instead of an integer bit mask.
 1.95 10-Aug-2020  rillig make(1): replace str_concat with str_concat2 and str_concat3

The new functions have a simpler interface, and str_concat3 is even more
general-purpose, since the middle string is no longer required to be
exactly of length 1.
 1.94 10-Aug-2020  rillig make(1): fix parameter name of str_concat

The previous documentation mentioned Str_Concat, but str_concat has been
written in lowercase for years. The "flags" are not flags since they
cannot be combined, not even when they are written in hex.
 1.93 01-Aug-2020  rillig make(1): use consistent indentation in source code

Tabs for multiples of 8, then spaces.

The usage string has been kept as-is since the spaces there are
indentional and do influence the output.
 1.92 01-Aug-2020  rillig make(1): avoid calls to free(3) in the common case of a NULL pointer
 1.91 28-Jul-2020  rillig make(1): remove dead code from Var_Subst

The first parameter from Var_Subst had been a literal NULL in all cases.
These have been fixed using this command:

sed -i 's|Var_Subst(NULL, |Var_Subst(|' *.c

The one remaining case was not found because the "NULL," was followed by
a line break instead of a space.

The removed code probably wouldn't have worked as expected anyway.
Expanding a single variable to a literal string would have led to
unexpected behavior for cases like ${VAR:M${pattern}}, in case pattern
would contain an unescaped ':' itself.
 1.90 26-Jul-2020  rillig make(1): make return value of Var_Parse constant

This return value is not supposed to be modified since it can be a string
literal. The modifiable part is returned via freePtr, but only for
freeing, not for actually modifying anything.
 1.89 19-Jul-2020  rillig make(1): rename Varf_Flags to VarEvalFlags

In var.c there are lots of different flag types. To make any accidental
mixture obvious, each flag group gets its own prefix.

The only flag group that is visible outside of var.c is concerned with
evaluating variables, therefore the "e", which replaces the former "f"
that probably just meant "flag".
 1.88 03-Jul-2020  rillig make(1): remove redundant parentheses around return values
 1.87 02-Jul-2020  rillig make(1): remove useless parameter from Var_Set

The enum corresponding to this int parameter is only defined in var.c,
which makes it impractical for the outside to set this parameter to
anything but 0.

On x86_64, this reduces the size of the resulting executable by 5 kB.
 1.86 16-Apr-2017  riastradh Assert archive member syntax. Cite who guarantees it.
 1.85 16-Apr-2017  riastradh Use, don't kludge, MAKE_ATTR_UNUSED.

CID 1300234
CID 1300237
CID 1300238
CID 1300245
CID 1300255
CID 1300267
CID 1300284
 1.84 30-Jun-2016  dholland branches: 1.84.2; 1.84.4;
Fix DEBUG_SRC build. Partly from PR 51191.
 1.83 30-Jun-2016  dholland Cleanse an old mangy way of avoiding an unused variable warning.
PR 51191 from David Binderman.
 1.82 30-Jun-2016  dholland Fix botched logic; PR 51191 from David Binderman.
 1.81 15-Mar-2016  matthias Another small change to make archive member rules work. With this change
archive member rules seem to work as expected again.
 1.80 15-Mar-2016  matthias dynamic dependencies for library member targets are working again.
 1.79 14-Mar-2016  matthias make $@ an alias for $! in archive member rules (compatibility with
other makes).
 1.78 18-Feb-2016  christos Collapse the 3 boolean parameter to 1 flags parameter. No functional change.
 1.77 17-Jan-2016  christos remove free NULL checks (Tilman Sauerbeck)
 1.76 09-Jan-2016  christos Preserve $$ in := assignments..

FOO=\$$CRAP
BAR:=${FOO}

all:
echo ${FOO}
echo ${BAR}
 1.75 20-Dec-2015  sjg Suff_ClearSuffixes() needs to re-initialize suffNull,
otherwise its children retain old suffixes.
Have Suff_Init() call Suff_ClearSuffixes() for consistency.
 1.74 11-Oct-2015  sjg Add Boolean wantit to Var_Parse and Var_Subst

wantit will be FALSE when we are just consuming to discard
in which case we skip "expensive" things like Cmd_Exec.

Reviewed by: christos
 1.73 07-Sep-2014  joerg Revert all make changes except the unit tests to the state of three
weeks ago. Individual changes can be reapplied after review.
 1.72 27-Aug-2014  christos Make .INVISIBLE nodes be ignored by suffix transformations.
 1.71 23-Aug-2014  christos PR/46096: Jarmo Jaakkola: fix many problems with dependencies (PR 49086)

Quite extensive rewrite of the Suff module. Some ripple effects into
Parse and Targ modules too.

Dependency searches in general were made to honor explicit rules so
implicit and explicit sources are no longer applied on targets that
do not invoke a transformation rule.

Archive member dependency search was rewritten. Explicit rules now
work properly and $(.TARGET) is set correctly. POSIX semantics for
lib(member.o) and .s1.a rules are supported.

.SUFFIXES list maintenance was rewritten so that scanning of existing
rules works when suffixes are added and that clearing the suffix list
removes single suffix rules too. Transformation rule nodes are now
mixed with regular nodes so they are available as regular targets too
if needed (especially after the known suffixes are cleared).

The .NULL target was documented in the manual page, especially to
warn against using it when a single suffix rule would work.
A deprecation warning was also added to the manual and make also
warns the user if it encounters .NULL.

Search for suffix rules no longer allows the explicit dependencies
to override the selected transformation rule. A check is made in
the search that the transformation that would be tried does not
already exist in the chain. This prevents getting stuck in an infinite
loop under specific circumstances. Local variables are now set
before node's children are expanded so dynamic sources work in
multi-stage transformations. Make_HandleUse() no longer expands
the added children for transformation nodes, preventing triple
expansion and allowing the Suff module to properly postpone their
expansion until proper values are set for the local variables.

Directory prefix is no longer removed from $(.PREFIX) if the target
is found via directory search.

The last rule defined is now used instead of the first one (POSIX
requirement) in case a rule is defined multiple times. Everything
defined in the first instance is undone, but things added "globally"
are honored. To implement this, each node tracks attribute bits
which have been set by special targets (global) instead of special
sources (local). They also track dependencies that were added by
a rule with commands (local) instead of rule with no commands (global).

New attribute, OP_FROM_SYS_MK is introduced. It is set on all targets
found in system makefiles so that they are not eligible to become
the main target. We cannot just set OP_NOTMAIN because it is one of
the attributes inherited from transformation and .USE rules and would
make any eligible target that uses a built-in inference rule ineligible.

The $(.IMPSRC) local variable now works like in gmake: it is set to
the first prerequisite for explicit rules. For implicit rules it
is still the implied source.

The manual page is improved regarding the fixed features. Test cases
for the fixed problems are added.

Other improvements in the Suff module include:
- better debug messages for transformation rule search (length of
the chain is now visualized by indentation)
- Suff structures are created, destroyed and moved around by a set
of maintenance functions so their reference counts are easier
to track (this also gets rid of a lot of code duplication)
- some unreasonably long functions were split into smaller ones
- many local variables had their names changed to describe their
purpose instead of their type
 1.70 18-May-2013  sjg We cannot skip all Suff processing for .PHONY targets,
else, srcs which are wildcards do not get expanded as needed.
 1.69 29-Sep-2011  sjg branches: 1.69.2; 1.69.8;
Make sure .PHONY targets get .TARGET set.
This wasn't happening when a dependency of .END.
Set .PREFIX too and add a unit-test.

PR: 43534
 1.68 30-Jun-2011  wiz dependant -> dependent
 1.67 23-Jan-2009  dsl Sprinkle some const.
In particular for Lst_Find() and Lst_FindFrom().
Remove some unneeded casts and some now-undeeded UNCONST().
 1.66 23-Jan-2009  dsl Change 'ClientData' to 'void *' so that relevant parameters can
be made 'const void *'.
 1.65 13-Dec-2008  dsl Use NULL instead of -1 cast to the relavant type (usually via NIL).
This was a suggestion from christos - so blame him if there is a deep
reason for using -1 :-)
 1.64 06-Oct-2008  joerg Don't use emalloc and friends directly, but call them consistently
bmake_malloc and friends. Implement them via macros for the native case
and provide fallback implementations otherwise. Avoid polluting the
namespace by not defining enomem globally. Don't bother to provide
strdup and strndup, they were only used for the estrdup and estrndup
comapt code.

This addresses the presence of emalloc in system libraries on A/UX and
resulted strange issues as reported by Timothy E. Larson.
 1.63 15-Feb-2008  christos back all changes out until I fix it properly.
 1.62 14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.61 17-Nov-2006  dsl A rather large rototil in the way the parallel make code schedules jobs.
This gives a considerable speedup in the processing of .WAIT and .ORDER.
Both .WAIT and .ORDER stop both the commands of the node, and its dependant
nodes being built until the LH nodes are complete.
.WAIT only applies to the dependency line on which it appears, whereas
.ORDER applies globally between the two nodes.
In both cases dependant nodes can be built because other targets need them.
make now processes the target list left to right, scheduling child nodes
as they are needed to make other nodes (instead of attempting to generate
a bottom-up dependency graph at the start). This means that 'make -j1'
will tend to build in the same order as a non-parallel make.
Note that:
all: x y
x: a .WAIT b
y: b .WAIT a
does not generate a dependency loop.
But
x: y
.ORDER y x
does (unless something elswhere causes 'y' to be built).
 1.60 11-Nov-2006  dsl Point a few diagnostic printfs (the ones that got away) to debug_file
instead of stdout.
 1.59 27-Oct-2006  dsl Since 'ClientData' is 'void *', nuke almost all the (ClientData) casts.
 1.58 25-Oct-2006  dsl Rename Lst_Append() to Lst_InsertAfter() and Lst_Insert() to Lst_InsertBefore()
to better explain their actions.
 1.57 25-Oct-2006  dsl Fix previous - need to add a lstPrev()
 1.56 25-Oct-2006  dsl Only do dynamic dependecy expansion once, and follow by a single filename
globbing.
The old behaviour was the perform variable expansion and globbing on the
output of both the variable expansion and globbing. Which allows some very
strange behaviour if, for example, globbed filenames contain $ symbols.
Unconditionally add new nodes from these expansions even if the names are
already children. The .WAIT code needs the order of children preserved.
 1.55 15-Oct-2006  dsl Output all debug trace output through 'debug_file' defaulting to 'stdout'.
(Almost all the debug output went there, but some went to stderr.)
Split the parsing of -d (debug flags) out into its own routine.
Allow the output filename to be changed by specifying -dF<file> to create
a log file, or -dF+<file> to append to it. <file> may be stdout or stderr.
Also change so that -d-<flags> acts on <flags> locally but doesn't copy
them to MAKEFLAGS so they aren't inherited by child makes.
I'm not 100% happy with the command line syntax for the above, so they are
currently undocumented.
 1.54 29-Jun-2006  rillig Fixed gcc warnings about signed vs. unsigned in comparisons.
 1.53 31-Mar-2006  christos Add some coverity allocation comments, and change the way the allocator
functions work. When they allocate storage that needs to be freed, instead
of setting a boolean, set the pointer to be freed. Plug some more memory
leaks found by inspection.
 1.52 08-Jan-2006  dsl Don't (try to) use files marked .OPTIONAL as implicit sources.
There existance hasn't been verified at the point the implicit rules are
checked.
 1.51 08-Aug-2005  christos From Max Okumoto:
- Remove casts to NULL.
- Remove space between cast and object.
 1.50 05-Aug-2005  christos More KNF cleanups from Max Okumoto
 1.49 25-Jul-2005  christos Whitespace KNF cleanup from Max Okumoto
 1.48 16-Feb-2005  christos PR/29203, PR/29204: Max Okumoto: KNF changes to make [no functional changes]
 1.47 29-Dec-2004  christos Add comments in the pmake style, and factor out a local variable.
No functional change.
 1.46 29-Dec-2004  christos Dir_MTime did not search for a file using the correct parh; i.e. it was
ignoring suffix-specific path search. So if a node was marked .MADE,
then suffix rules would not be applied to it, and we would look for
the file only in the default path, not the suffix-specific path.

XXX: Now that we looked for the suffix, we can save it in the GNode,
but we don't do this yet.
 1.45 07-May-2004  ross Simplify build, no functional changes.

Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().

It's now possible to build make on some hosts with: cc *.c */*.c
 1.44 13-Feb-2004  wiz branches: 1.44.2;
Spell the plural of suffix "suffixes", not "suffices".
Inspired by PR 24400 by Todd Vierling.
 1.43 11-Jan-2004  dsl Reindent search loop in SuffFindCmds using 'continue' and 'break' instead
of netsted ifs. No logic change.
 1.42 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.41 14-Jul-2003  christos Pass WARNS=3
 1.40 05-Dec-2002  scw Lst exp -> Lst explist, to avoid warnings about gcc-current's
builtin exp() function.
 1.39 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.38 04-Feb-2002  christos branches: 1.38.2;
Remove OP_NOSUFF, fix OP_MADE in compat mode [from pk], and make the OP_MADE
comment reflect reality.
 1.37 03-Feb-2002  christos Bring down the number of stat(2) system calls from 682 to 294. This change
adds a .NOSUFF directive that has been applied to targets that have been
already made, and are not supposed to have suffix rules applied to them.
 1.36 27-Jan-2002  reinoud Fix major bug in make(1) ... due to shadowing of the dotLast path used for
the .DOTLAST primitive by a boolean variable with the same name, this whole
mechanism was broken ... it doesn't save much stat calls but it was wrong.

Thanks to Jason Thorpe for the other shadow-variable fixing patches he
made.
 1.35 14-Nov-2001  tv Fix a very old and annoying bug: Adding suffixes to sufflist wasn't setting
a refCount of 1 to indicate its presence on sufflist. Hence suffixes were
being removed by Suff_EndTransform() and being freed before all the
referential links were removed. This resulted in a malloc warning on 1.5.x:
make in free(): warning: chunk is already free.

This could be reproduced with the following simple Makefile passed to
"make -r":
=====
.SUFFIXES: .l .c
.l.c:
foo:
 1.34 20-Aug-2001  wiz precede, not preceed.
 1.33 12-Jun-2001  sjg Add 4th arg (flags) to Var_Set so that VarLoopExpand can tell it not
to export interator variables when using context VAR_CMD.

Reviewed: christos
 1.32 08-May-2001  aymeric Fix core dump triggered by a .DEFAULT target with no commands.
Bug reported privately by Nicolas Ollinger <nollinge@ens-lyon.fr>.

You can trigger this bug prior to updating your sources with for example:
% cat > Makefile <<EOF
.DEFAULT:
a
EOF
% make
 1.31 11-Jun-2000  mycroft Readd optimization last night. Problems earlier were partially due to the
arguments names on one function being swapped (by a previous author).

Do not do any duplicate suppression when a source list is created. Instead:
* OP_MADE protects against trying to make the source multiple times.
* A new OP_MARK flag is introduced to suppress duplicates while expanding
the .ALLSRC variable and .USE targets.
This turns the O(n^2) insertion into O(n) in most cases.

This is tested with a `make build' and some special test cases.
 1.30 10-Jun-2000  mycroft Back out last night's optimization for now.
 1.29 10-Jun-2000  mycroft Introduce an OP_MARK bit, and use it to suppress duplicates during .ALLSRC
and .USE expansion. Also, remove some more Lst_Member() checks that are now
redundant.
 1.28 22-Jan-2000  mycroft branches: 1.28.2;
Don't apply suffix rules for .PHONY targets. (gmake doesn't do this either.)
 1.27 16-Sep-1999  mycroft Some minor cleanup of :: tests.
 1.26 15-Sep-1999  mycroft Rework how :: dependencies are handled.
Build a list of `cohorts' as before, but do *not* link each one into all the
parent nodes; instead, copy the `cohort' lists into the stream of targets to
be built inside Make_ExpandUse(). Also do the attribute propagation as a
separate pass after parsing.
This eliminates several O(n^2) algorithms.
 1.25 15-Sep-1999  mycroft Don't bother iterating through all the data structures to free(3) everything
right before exiting.
(The code is still present, `#ifdef CLEANUP', in case someone needs it...)
 1.24 15-Sep-1999  mycroft Avoid using Lst_Member() in SuffExpandChildren(), by avoiding Lst_ForEach() and
passing in the LstNode of the child being inspected. Shaves off another few %,
particularly when there are long child lists containing $ expansions (e.g. in
libc).
 1.23 01-Nov-1998  itohy Reduced memory leaks.
I found some more leaks, but are not in inside of iterations.
 1.22 01-Nov-1998  itohy If the target name is shorter than the suffix,
the previous garbage bytes may be read.
Example: "make n" --- target = n, suffix = .ln

Changing interface of SuffSuffIsSuffix() is required to fix this bug.
 1.21 18-Sep-1998  christos PR/6162: Greg A. Woods: pmake does not add suffix rules if gnodes have children.
This is traditional make behavior (Solaris make does the same), but
GNU does not. Lets see what breaks.
 1.20 04-Jul-1998  christos Fix access to freed memory; pointed out by Todd Miller.
 1.19 02-Jul-1998  christos PR/5690: Wolfgang Rupprecht: deleting a suffix that has 0 source references
causes core-dump. Fix: when an unused suffix gets removed, delete
it from the suffix list.
 1.18 28-Sep-1997  lukem wrap #include <sys/cdefs.h>, __RCSID(...) stuff in #ifndef MAKE_BOOTSTRAP
 1.17 01-Jul-1997  christos Add WARNS=1
RCSID police
 1.16 08-May-1997  gwr Add the new .NOPATH feature which can be used to disable .PATH search
for particular targets, i.e. .depend, objects, etc. (from Christos).
 1.15 06-May-1997  mycroft Don't do a suffix search for a .PHONY target.
 1.14 02-May-1997  christos - Target searching addition:
Make used to only use the search path for nodes that were pure
sources (not targets of other sources). This has been corrected
and now gnu-autoconf generated Makefiles work in directories other
than the source one.

- Suffix transformation rescanning:
Suffix transformations (.c.o:; cc ...) were only recognized in
the past when both suffixes were members of the suffix list.
Thus a sequence like:
.z.b:
echo ${.TARGET}
.SUFFIXES: .z
would cause .z.b: to be inserted as a regular target (and the main
target in this case). Other make programs always add rules that
start with a period in the transformation list and never consider
them as targets. We cannot do that (consider .depend files) so we
resort to scanning the list of the current targets every time a
suffix gets added, and we mutate existing targets that are now
valid transformation rules into transformation rules. If the
transformed target was also the main target, we set the main target
to be the next target in the targets list.
 1.13 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.12 13-Aug-1996  christos Add estrdup(), a checked version of strdup and use it.
 1.11 02-Nov-1995  christos branches: 1.11.4;
Minor:
- ${.PREFIX} should never contain a full pathname
- Fixed gcc -Wall warnings
Major:
- compatMake is now FALSE. This means that we are now running in
full pmake mode:
* rules on dependency lines can be executed in parallel and or
out of sequence:

foo: bar baz

can fire the rule for baz before the rule for bar is fired.
To enforce bar to be fired before baz, another rule needs to be
added. [bar: baz]
* adjacent shell commands in a target are now executed by a single
invocation of the shell, not one invocation of the shell per line
(compatMake can be turned off using the -B flag)
- The -j flag now works... I.e. make -j 4 will fork up to four jobs in
parallel when it can. The target name is printed before each burst
of output caused by the target execution as '--- target ---', when j > 1
- I have changed all the Makefiles so that they work with make -j N, and
I have tested the whole netbsd by:
'make -j 4 cleandir; make -j 4 depend; make -j 4; make -j 4 install'
- I have not compiled or tested this version of make with -DREMOTE.
 1.10 25-Sep-1995  christos Revert previous suffix fix. If the .a suffix is present and a .c.a rule is
there, then the rule should be applied. This is the correct behavior.
 1.9 22-Sep-1995  christos Don't apply the default suffix rules for nodes that are not in our
current directory because we could be building things outside our
directory that were not meant to be build... Fixes PR/1488
 1.8 14-Jun-1995  christos - $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.7 04-Feb-1995  christos str.c: Don't free NULL; does not work with non posix frees.
var.c: Minor memory leak plugged.
suff.c: Don't add extra sources on the null suffix if it has dependency
lines or commands attached to it [POSIX says so]
 1.6 06-Jun-1994  jtc Fixes from Christos Zoulas, who used purify, objectcenter and testcenter
to find memory leaks and illegal memory accesses.
 1.5 23-Mar-1994  jtc Fixes from Christos Zoulas:
The following two patches fix a couple of problems with make(1)

1. Null Suffixes were not being copied, but they were being free'd
This caused rules of the form:

.c:
${CC} ...

to access invalid memory and potentially core dump..
[That was always broken; I did not break that one :-)]

2. My recent fixes to parse ${VAR:%.foo=%.bar} handled the null string
case incorrectly (${VAR:=.c} was broken).
 1.4 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.3 13-Jan-1994  jtc Include appropriate header files to bring prototypes into scope.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.11.4.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.28.2.1 23-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.38.2.1 23-Jul-2004  tron Apply patch (requested by dbj in ticket 1724):
Fix problems when building the netbsd-1-6 branch with GCC 3.3.3.
 1.44.2.1 10-May-2004  tron Pull up revision 1.45 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.69.8.1 23-Jun-2013  tls resync from head
 1.69.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.84.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.84.2.1 26-Apr-2017  pgoyette Sync with HEAD
 1.380.2.1 02-Aug-2025  perseant Sync with HEAD
 1.185 07-May-2025  rillig make: add end marker for -dg1, -dg2 and -dg3 debug log

The marker helps distinguish the output from sub-makes from the output
of the primary make.
 1.184 07-Jul-2024  rillig make: move initialization of variable scopes to targ.c

The variable scopes are freed by Targ_End, so initialize them there as
well. Separate printing statistics and freeing memory, which makes
Var_End unnecessary.
 1.183 25-May-2024  rillig branches: 1.183.2;
make: fix memory leak for command strings
 1.182 25-May-2024  rillig make: fix a few more memory leaks
 1.181 27-Apr-2024  rillig make: simplify freeing of lists
 1.180 10-Mar-2024  sjg make: record exit status in GNode

SetErrorVars can now set .ERROR_EXIT which allows
a .ERROR target to ignore the case of .ERROR_EXIT == 6
which means failure happened elsewhere.

Reviewed by:
 1.179 06-Dec-2022  rillig make: clean up comments

No binary change.
 1.178 27-Sep-2022  rillig make: set WARNS to 6, from the default 5

No binary change on x86_64.
 1.177 15-Apr-2022  rillig make: add .USEBEFORE to Targ_PrintType

When .USEBEFORE was added in targ.c 1.22 from 2001-07-03, it was not
added to Targ_PrintType, probably because the PRINTBIT macro hid the
identifier OP_USE and only used USE.
 1.176 07-Jan-2022  rillig make: merge duplicate variables for the main target

No functional change.
 1.175 07-Jan-2022  rillig make: clean up comments, variable names, function names

The comment in ApplyDependencySourceOther repeated the code, its second
half didn't match any current code.

The comment above ParseDependencySourcesEmpty repeated the code.

No binary change, except for assertion line numbers.
 1.174 07-Jan-2022  rillig make: rename and inline Targ_Precious

No functional change.
 1.173 28-Nov-2021  rillig make: convert GNodeFlags from enum into bit-fields

Now that Enum_ToString is implemented for each type separately, it's
easy to convert them to bit-fields. This gets rid of the magic numbers
12 for CYCLE and 13 for DONECYCLE that left a suspicious gap in the
numbers. This gap was not needed since the code didn't make use of the
relative ordering of the enum constants.

The effects of this conversion are fewer capital letters in the code,
smaller scope for the GNode flags, and clearer code especially when
setting a flag back to false.

One strange thing is that GCC 10.3.0 doesn't optimize GNodeFlags_IsNone
to an single bitmasking instruction, at least on x86_64. Instead it
generates a testb instruction for each of the flags, even loading bit 8
separately from the others. Clang 12.0.1 knows this optimization
though and generates the obvious sequence of movzwl, testl, jz.

No functional change.
 1.172 12-Sep-2021  rillig make: reduce number of relocations in Targ_PrintType

On x86_64, this saves 120 bytes of .text.

No functional change.
 1.171 12-Sep-2021  rillig make: fix lint warnings for strict bool mode

In strict bool mode, lint does not consider 'x & y' as having type bool,
if x and y have integer type, it only allows this for enums.

No functional change.
 1.170 12-Sep-2021  rillig make: fix Targ_PrintType for pre-C99 compilers
 1.169 12-Sep-2021  rillig make: make Targ_PrintType simpler

No functional change.
 1.168 03-Apr-2021  rillig make: use standard %H in strftime instead of %k

The conversion specifier %k is neither in C99 nor in C90.

These timestamps are only used in the debug output.
 1.167 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.166 22-Feb-2021  rillig make: update constant names in comments

No functional change.
 1.165 04-Feb-2021  rillig make: rename context and ctxt to scope

This continues the previous commit, in which VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE were renamed.

Renaming the variable 'ctxt' was trivial since that word is used nowhere
else. In the comments though, each occurrence of the word 'context' had
to be checked individually since the word 'context' was not only used
for referring to a variable scope. It is also used to distinguish
different situations where characters are escaped in a certain way
('parsing context') and in a few other expressions.
 1.164 04-Feb-2021  rillig make: rename some VAR constants to SCOPE

The word "context" does not fit perfectly to the variables that are
associate with a GNode, as the context is usually something from the
outside and the variables are more like properties inherent to the
GNode.

The term "global context" fits even less. Since the thing where
variables are looked up is commonly named a scope, use that term
instead.

This commit only renames the global variables VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE, plus a few very closely related comments. These are:

GNode.vars (because of line breaks)
GNode_Free (dito)
varname-make_print_var_on_error.mk
varname-make_print_var_on_error-jobs.mk

The debug message in Var_Stats is left as-is since there is no unit test
for it yet.

The other renamings (variable names "context", "ctxt", as well as
further comments) will be done in a follow-up commit.
 1.163 03-Feb-2021  rillig make: replace Global_AppendExpand with Global_Append

All callers with a variable name that is guaranteed to not contain a
dollar sign have been converted to call Global_Append instead of the
previous Global_AppendExpand. After that, Global_AppendExpand was
unused, therefore it was effectively just renamed.
 1.162 03-Feb-2021  rillig make: use shortcut functions Global_SetExpand and Global_AppendExpand

There are many places where global variables are set or appended to. To
reduce clutter and code size, encode the VAR_GLOBAL in the function
name.

The word Expand in the function names says that the variable name is
expanded. In most of the cases, this is not necessary, but there are no
corresponding functions Global_Set or Global_Append yet.

Encoding the information whether the name is expanded or not in the
function name will make inconsistencies obvious in future manual code
reviews. Letting the compiler check this by using different types for
unexpanded and expanded variable names is probably not worth the effort.
There are still a few bugs to be fixed, such as in SetVar, which expands
the variable name twice in a row.
 1.161 02-Feb-2021  rillig make: remove overengineered Enum_ValueToString

For printing the status of a GNode, there was already made_name (now
renamed to GNodeMade_Name), which prints user-friendly text instead of
the bare enum constant names.

To do this change confidently, I first had to demonstrate that the
output really affects something other than just the word "UNMADE". There
had not been a test for that case before, and the test immediately
discovered a bug in the -dg2 and -dg3 options. This bug is one of the
oldest in make, dating back to at least 1993.
 1.160 10-Jan-2021  rillig make(1): make a few more bool expressions more precise

The previous version of lint(1) from a few hours ago didn't catch all
occurrences. And even the current one doesn't catch everything.
Function arguments and return types still need some work. The "return
quietly" from shouldDieQuietly still implicitly converts from int to
_Bool.

No functional change.
 1.159 18-Dec-2020  rillig make(1): spell nonexistent consistently
 1.158 18-Dec-2020  rillig make(1): use symbolic time for 0 in Make_Recheck

This makes the test depsrc-optional independent from the current time
zone.
 1.157 18-Dec-2020  rillig make(1): constify Targ_FmtTime
 1.156 15-Dec-2020  rillig make(1): format function definitions consistently
 1.155 12-Dec-2020  rillig make(1): inline Targ_Ignore and Targ_Silent

Each of these functions was only used 2 times, and each of these calls
used a different part of the whole expression.
 1.154 07-Dec-2020  rillig make(1): clean up debug logging
 1.153 06-Dec-2020  rillig make(1): inline macros for debug logging

No changes to the resulting binary, except for the line numbers in
assertions.
 1.152 05-Dec-2020  rillig make(1): define constants for enum zero-values
 1.151 05-Dec-2020  rillig make(1): don't concatenate identifiers in Targ_PrintType

Concatenating identifiers makes it difficult to spot them when searching
the code. This gets rid of the special case for OP_MEMBER and MEMBER.

The same pattern is applied in the DEBUG macro, by the way.
 1.150 05-Dec-2020  rillig make(1): indent targ.c with tabs instead of spaces

Explain the tricky details of GNode_Free.

Invert a condition in Targ_PrintNode to reduce the overall indentation.
 1.149 04-Dec-2020  rillig make(1): use consistent variable names for list nodes
 1.148 29-Nov-2020  rillig make(1): reduce memory allocation for target handling
 1.147 29-Nov-2020  rillig make(1): reduce memory allocation for targets

This change moves the initialization and finalization of the list of
targets to the same function. They had been split before.
 1.146 28-Nov-2020  rillig make(1): reduce pointer indirection for GNode.implicitParents
 1.145 28-Nov-2020  rillig make(1): reduce pointer indirection for GNode.cohorts
 1.144 28-Nov-2020  rillig make(1): reduce pointer indirection for GNode.order_pred and order_succ
 1.143 28-Nov-2020  rillig make(1): reduce memory allocation for GNode.parents and GNode.children
 1.142 28-Nov-2020  rillig make(1): remove pointer indirection from GNode.commands

Just to save a few memory allocations. No noticeable effect on the
performance though.
 1.141 23-Nov-2020  rillig make(1): use comparisons in boolean expressions

The generated code stays exactly the same.
 1.140 22-Nov-2020  rillig make(1): add remark to add a "reasonable way" to format time_t 0
 1.139 21-Nov-2020  rillig make(1): rename GNode.context to vars

Especially in the variables module, the expression 'ctxt->context' looked
redundant. Having a GNode as a context sounds ok, but a context of a
context just doesn't make sense.
 1.138 21-Nov-2020  rillig make(1): add more debug logging for suffix handling

One notable thing is that there is no debug output when adding a
transformation rule like ".c.o", which means that these rules don't end
up in the global allTargets variable.

This may or may not be intentional. It seems not intentional since this
is one of the causes for the suff-rebuild test to behave unexpectedly.
 1.137 21-Nov-2020  rillig make(1): improve comment style in GNode_Free

It was unclear what the ellipsis referred to. It was meant to refer to
the function call Lst_Free, but that was not necessarily obvious to a
casual reader.
 1.136 21-Nov-2020  rillig make(1): fix comment for allTargets

Source nodes are also included in this list. What's not includes is
nodes that are _only_ source nodes.
 1.135 16-Nov-2020  rillig make(1): clean up code style in targ.c
 1.134 16-Nov-2020  rillig make(1): initialize and free GNode fields in declaration order

Initialization and destruction of the fields is independent from the
other fields. Therefore use declaration order, which allows to quickly
see whether a field was forgotten.

While here, add comments that in cleanup mode, not all memory is freed.
The variables of a node and the suffix survive right now.
 1.133 16-Nov-2020  rillig make(1): rename variables in targ.c

The previous names didn't make it obvious that 'allTargets' and 'targets'
belong together. Naming both 'allTargets' provides a stronger hint.
 1.132 16-Nov-2020  rillig make(1): clean up and extend comments in targ.c
 1.131 16-Nov-2020  rillig make(1): make some GNode functions const
 1.130 16-Nov-2020  rillig make(1): in CLEANUP mode, preallocate list of all GNodes

This makes the code simpler and more uniform.
 1.129 16-Nov-2020  rillig make(1): rename TargFreeGN to GNode_Free

This is the usual counterpart to a New function, like for Lst, HashTable,
Buffer.
 1.128 16-Nov-2020  rillig make(1): rename Targ_NewGN to GNode_New

This function is a classical constructor function, and if it weren't for
CLEANUP mode, it would have no dependencies on anything else besides the
memory allocator. Therefore it doesn't really matter which module
defines this function, and there is no need for the "Targ" to be part of
the function name.
 1.127 05-Nov-2020  rillig make(1): remove redundant parentheses from sizeof operator

The parentheses are only needed if the argument is a type, not an
expression.
 1.126 30-Oct-2020  rillig make(1): rename VAR_CMD to VAR_CMDLINE

Since make has to do with both the command line and child commands, the
former name was confusing.
 1.125 26-Oct-2020  rillig make(1): group the command line options and arguments

By having a single struct that holds all command line options and
arguments, it is easy to see in the code when such a command line
argument is modified. It also cleans up the namespace since the command
line options don't follow a common naming style. Having them in a
struct also means that there is a single place for putting the
documentation, not two as before.

The struct also suggests to extract the initialization code out of main,
which is still too large, having more than 400 lines of code and
covering far too many topics.
 1.124 25-Oct-2020  rillig make(1): add GNode_Path to access the path of a GNode
 1.123 25-Oct-2020  rillig make(1): rename hash functions to identify the type name

This makes it easier to spot mismatches between the function name and
its first parameter, although the compiler should already catch most of
them. Except for void pointers.
 1.122 23-Oct-2020  rillig make(1): rename GNode.cmgn to youngestChild

The name is longer than before but also clearer.
 1.121 23-Oct-2020  rillig make(1): negate OP_NOP and rename it to GNode_IsTarget
 1.120 22-Oct-2020  rillig make(1): remove redundant type casts

This mainly affects the void pointers in callback functions for lists.
These had been necessary once when the parameter type was still
ClientData instead of void pointer.
 1.119 19-Oct-2020  rillig make(1): clean up headers, no functional change
 1.118 19-Oct-2020  rillig make(1): remove void pointers from suffix debug printing
 1.117 19-Oct-2020  rillig make(1): fix variable names in Targ_Propagate

List nodes are called ln, not pn or cn.

While here, extract a common subexpression to save a few instructions.
The compiler cannot know that gn->type will not change during the whole
loop. For this, it would have to know that a GNode cannot have itself
as a cohort, and this is not expressed anywhere in the code.
 1.116 18-Oct-2020  rillig make(1): rename Lst_Init to Lst_New

For the other types such as HashTable and Buffer, the Init function does
not allocate the memory for the structure itself, it only fills it.
 1.115 18-Oct-2020  rillig make(1): remove underscore from Hash_Table and Hash_Entry

For consistency with the other type names, such as GNodeListNode.
 1.114 18-Oct-2020  rillig make(1): extract GNode_OpName from Targ_PrintNode
 1.113 17-Oct-2020  rillig make(1): normalize initialization and cleanup of the modules
 1.112 05-Oct-2020  rillig make(1): enable format string truncation warnings for parse.c

No node is ever going to have a million or more cohorts. And even if
there were, this name is only used for printing informational messages.
 1.111 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.110 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.109 03-Oct-2020  rillig make(1): clean up #include sections
 1.108 28-Sep-2020  rillig make(1): replace Lst_Open with direct iteration
 1.107 28-Sep-2020  rillig make(1): make debug logging simpler

This avoids referring to the debug_file variable in many places where
this implementation detail is not necessary.
 1.106 27-Sep-2020  rillig make(1): normalize whitespace in source code

There is no more space tab. Either only tabs or only spaces or tabs
followed by spaces, but not spaces followed by tabs.
 1.105 27-Sep-2020  rillig make(1): inline PrintNode

Having a separate function had only been necessary for Lst_ForEachUntil.
 1.104 27-Sep-2020  rillig make(1): inline Lst_ForEachUntil in Targ_PrintNodes

Printing a node does not modify the structure of the node, therefore the
additional housekeeping of Lst_ForEachUntil is not needed here.

Inlining the callback function also removes a lot of pointer stuff that
is more difficult to read than necessary.
 1.103 27-Sep-2020  mrg fix usr.bin/make build (which uses more warnings):

remove static only prototype TargPrintOnlySrc().
PrintOnlySources() does not return a value, make it void.
 1.102 26-Sep-2020  rillig make(1): revert migration from Lst_ForEachUntil to Lst_ForEach

There is a crucial difference between these functions, in that
Lst_ForEachUntil can cope with a few concurrent modifications while
iterating over the list. This is something that Lst_ForEach doesn't do.

This difference led to a crash very early in NetBSD's build.sh.
 1.101 26-Sep-2020  rillig make(1): inline and remove LstNode_Prev and LstNode_Next

These functions made the code larger than necessary. The prev and next
fields are published intentionally since navigating in a doubly-linked
list is simple to do and there is no need to wrap this in a layer of
function calls, not even syntactically. (On the execution level, the
function calls had been inlined anyway.)
 1.100 26-Sep-2020  rillig make(1): inline Lst_ForEach in Targ_PrintGraph
 1.99 26-Sep-2020  rillig make(1): replace a few Lst_ForEachUntil with simpler Lst_ForEach
 1.98 26-Sep-2020  rillig make(1): clean up obsolete comments about TARG constants
 1.97 26-Sep-2020  rillig make(1): remove useless comment from TargFreeGN

GNode.fname is a const char *, therefore it cannot be freed anyway.
 1.96 26-Sep-2020  rillig make(1): inline Targ_FindNodeImpl

The 3 callers of this function passed different flags, and these flags
led to code paths that almost did not overlap.

It's a bit strange that GCC 5 didn't get that, and even marking the
function as inline did not produce much smaller code, even though the
conditions inside that function were obviously constant. Clang 9 did a
better job here.

But even for human readers, inlining the function and then throwing away
the dead code leads to much easier code.

This pattern of squeezing completely different code into a single
function has already occurred in a different part of make, though I
don't remember where exactly.
 1.95 26-Sep-2020  rillig make(1): clean up API for finding and creating GNodes

The previous API had complicated rules for the cases in which the single
function returned NULL or what it did. The flags for that function were
confusing since passing TARG_NOHASH would create a new node even though
TARG_CREATE was not included in that bit mask.

Splitting the function into 3 separate functions avoids this confusion.
It also reveals several places where the complicated API led to
unreachable code. Such code has been removed.
 1.94 26-Sep-2020  rillig make(1): replace Hash_FindEntry with Hash_FindValue in Targ_FindNode
 1.93 24-Sep-2020  rillig make(1): inline Lst_ForEach in Targ_PrintCmds
 1.92 24-Sep-2020  rillig make(1): rename Lst_ForEach to Lst_ForEachUntil

Since the callback function returns a terminating condition, this is not
really a foreach loop.

Many of the calls to Lst_ForEachUntil don't make use of the terminating
condition, and several don't modify the list structurally, which means
they don't need this complicated implementation.

In a follow-up commit, Lst_ForEach will be added back with a much
simpler implementation that iterates over the list naively, without a
terminating condition and without taking the iteration state from
Lst_Open/Lst_Next/Lst_Close into account. The migration to this simpler
implementation will be done step by step since each callback function
needs to be examined closely.
 1.91 24-Sep-2020  rillig make(1): refactor add_wait_dep to not use Lst_ForEachFrom anymore

It was the last remaining use of that function outside of lst.c.

While here, clean up the code of add_wait_dep by removing unreachable
code (the GNode lists never contain NULL, only the GNode.commands lists
do that).
 1.90 23-Sep-2020  rillig make(1): fix assertion failure in -j mode with .END node

There had been two separate global variables for the .END node, and in
parallel mode, only the one in jobs.c was initialized.

The code in JobRun heads over to Compat_Make without calling Compat_Run
first, which left the variable ENDNode uninitialized.
 1.89 22-Sep-2020  rillig make(1): use fine-grained type names for lists and their nodes

This is only intended to help the human reader. There is no additional
type safety yet.
 1.88 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.87 12-Sep-2020  rillig make(1): fix API of Targ_PrintNode

There was no need to export Targ_PrintNode at all. All the callers need
is a high-level API for printing a single node or a list of nodes. The
implementation detail that Targ_PrintNode was used as a callback to
Lst_ForEach should have never leaked into the API.
 1.86 12-Sep-2020  rillig make(1): remove unintended noinline from previous commit
 1.85 12-Sep-2020  rillig make(1): fix trailing space in output of related node names (-dg2)
 1.84 12-Sep-2020  rillig make(1): fix API for Targ_PrintCmd

The previous API was too low-level and not strictly typed.
 1.83 05-Sep-2020  rillig make(1): remove initial size argument from Hash_InitTable

In all but one case this argument was set to auto-detect anyway. The
one case where it was set was not worth keeping this complicated API.
 1.82 05-Sep-2020  rillig make(1): remove trailing whitespace in -dg1 debug output
 1.81 01-Sep-2020  rillig make(1): inline constant for hash table size

The name HTSIZE didn't provide any explanation for the value 191, and it
is obvious that this is a hash table size. Therefore giving the
constant a name didn't explain anything or make it less magic.
 1.80 30-Aug-2020  rillig make(1): rename GNode.iParents to implicitParents

The i alone was too ambiguous. It could have meant ignore, implicit,
interactive, and probably many more.
 1.79 30-Aug-2020  rillig make(1): rename Lst_Datum to LstNode_Datum
 1.78 29-Aug-2020  rillig make(1): use loops instead of Lst_ForEach for propagating to cohorts

For one-liners, Lst_ForEach creates a lot of overhead, both at runtime
and for reading and understanding the code.

In this simple case where the structure of the traversed nodes is not
modified, a simple loop is enough. This avoids a lot of conversions to
void * and thus prevents type mistakes.
 1.77 28-Aug-2020  rillig make(1): clean up targ.c

The main part is removing redundant or outdated information from
comments. In a few places, the expression cond ? TRUE : FALSE has been
simplified.
 1.76 28-Aug-2020  rillig make(1): remove trailing 'S' from names of Lst functions

The migration from null-passing Lst functions to argument-checking Lst
functions is completed.

There were 2 surprises: The targets list may be NULL, and in Dir_AddDir,
the path may be NULL. The latter case is especially surprising since
that function turns into an almost-nop in that case. This is another
case where probably 2 independent functions have been squeezed into a
single function. This may be improved in a follow-up commit.

All other lists were fine. They were always defined and thus didn't
need much work.
 1.75 27-Aug-2020  rillig make(1): migrate Lst_IsEmpty to Lst_IsEmptyS
 1.74 27-Aug-2020  rillig make(1): migrate Lst_ForEach to Lst_ForEachS

Most lists are always valid. Only the "targets" variable may be null in
some cases, probably.
 1.73 26-Aug-2020  rillig make(1): add stricter variants for remaining Lst functions

In most cases the Lst functions are only called when the arguments are
indeed valid. It's not guaranteed though, therefore each function call
needs to be analyzed and converted individually.

While here, remove a few statements that were only useful when the Lst
functions handled circular lists.
 1.72 24-Aug-2020  rillig make(1): in debug mode, print GNode details in symbols

A string like OP_DEPENDS|OP_OPTIONAL|OP_PRECIOUS is much easier to read
and understand than the bit pattern 00000089.

The implementation in enum.h looks really bloated and ugly, but using
this API is as simple and natural as possible. That's the trade-off.

In enum.h, I thought about choosing the numbers in the macros such that
it is always possible to combine two of them in order to reach an
arbitrary number, because of the "part1, part2" in the ENUM__SPEC macro.
The powers of 2 are not these numbers, as 7 cannot be expressed as the
sum of two of them. Neither are the fibonacci numbers since 12 cannot
be expressed as the sum of 2 fibonacci numbers. I tried to find a
general pattern to generate these minimal 2-sum numbers, but failed.
 1.71 22-Aug-2020  rillig make(1): restructure GNode types and documentation

Having a numbered list above the type was not helpful since the numbers
didn't serve any purpose, they just consumed screen space.

Several of these list items didn't have an obvious relationship to the
struct fields. It's better to have just a rough introduction as the
type level documentation, leaving the details to the individual fields.

Converting the types and flags and other constants into separate types
and defining them outside the struct leaves more space to see the
relationship of the struct fields.

Limiting the documentation of each field to a single line, as suggested
by the end-of-line comments, reduces clarity since several of the fields
need way more documentation to be properly understood.
 1.70 22-Aug-2020  rillig make(1): replace Lst_Datum with non-null guaranteeing Lst_DatumS
 1.69 22-Aug-2020  rillig make(1): convert remaining Lst_AtEnd to the stricter Lst_Append

The general-purpose list library that is included in make allows to call
Lst_AtEnd for invalid lists, silently ignoring this programming error.
This is a flexibility that make doesn't need.

Another unneeded "feature" is that list items can theoretically be null
pointers. This doesn't make sense as well and is therefore not needed
by make.

These programming errors are now caught early by assertions.
 1.68 22-Aug-2020  rillig make(1): replace "(void)Lst_AtEnd" with stricter "Lst_AppendS"

This change ensures that there is actually something added to the list.
Lst_AtEnd had silently skipped the addition if the list was invalid
(null pointer), which was not intended in these cases. The "(void)" is
assumed to mean "I know that this cannot fail", while it could also mean
"I don't care whether something actually happened".

Running "./build.sh -j6 tools" still succeeds after this change,
therefore chances are very low that this change breaks anything. If
there is any change, it's an obvious assertion failure. There is no
silent change in behavior though.
 1.67 21-Aug-2020  rillig make(1): use stricter list API for sequential access

In several places, it just doesn't make sense to have a null pointer
when a list is expected.

In the existing unit tests, the list passed to Lst_Open is always valid,
but that's not a guarantee for real-world usage. Therefore, Lst_Open
has been left for now, and Lst_OpenS is only the preferred alternative
to it.
 1.66 21-Aug-2020  rillig make(1): assert correct usage of the Lst_Open API

All calls to Lst_Next are properly protected by Lst_Open, so there is no
possible assertion failure here.
 1.65 21-Aug-2020  rillig make(1): remove unused code for circular lists

The list library had probably been imported from a general-purpose
library that also supported circular lists. These are not used by make
though.

After replacing Lst_Init(FALSE) with Lst_Init(), only a single call to
Lst_Init remained with a non-constant argument, and that was in
Lst_Concat, which was to be expected.
 1.64 20-Jul-2020  sjg Make DEBUG_HASH less of a fire-hose.

Reporting keys on every lookup is overkill unless
playing with a new HASH, so wrap in #ifdef DEBUG_HASH_LOOKUP
Also add some stats at the end so we can see
final size and max chain length - maxchain is a better
variable name than maxlen.
 1.63 03-Jul-2020  rillig make(1): remove redundant parentheses around return values
 1.62 16-Apr-2017  riastradh Use, don't kludge, MAKE_ATTR_UNUSED.

CID 1300234
CID 1300237
CID 1300238
CID 1300245
CID 1300255
CID 1300267
CID 1300284
 1.61 17-Jan-2016  christos branches: 1.61.2; 1.61.4;
remove free NULL checks (Tilman Sauerbeck)
 1.60 25-May-2015  manu Fix warning about uninitialized variable

This warning gets fatal when including make(1) as a crunchgen(1) binary.
 1.59 07-Sep-2014  joerg Revert all make changes except the unit tests to the state of three
weeks ago. Individual changes can be reapplied after review.
 1.58 23-Aug-2014  christos PR/46096: Jarmo Jaakkola: fix many problems with dependencies (PR 49086)

Quite extensive rewrite of the Suff module. Some ripple effects into
Parse and Targ modules too.

Dependency searches in general were made to honor explicit rules so
implicit and explicit sources are no longer applied on targets that
do not invoke a transformation rule.

Archive member dependency search was rewritten. Explicit rules now
work properly and $(.TARGET) is set correctly. POSIX semantics for
lib(member.o) and .s1.a rules are supported.

.SUFFIXES list maintenance was rewritten so that scanning of existing
rules works when suffixes are added and that clearing the suffix list
removes single suffix rules too. Transformation rule nodes are now
mixed with regular nodes so they are available as regular targets too
if needed (especially after the known suffixes are cleared).

The .NULL target was documented in the manual page, especially to
warn against using it when a single suffix rule would work.
A deprecation warning was also added to the manual and make also
warns the user if it encounters .NULL.

Search for suffix rules no longer allows the explicit dependencies
to override the selected transformation rule. A check is made in
the search that the transformation that would be tried does not
already exist in the chain. This prevents getting stuck in an infinite
loop under specific circumstances. Local variables are now set
before node's children are expanded so dynamic sources work in
multi-stage transformations. Make_HandleUse() no longer expands
the added children for transformation nodes, preventing triple
expansion and allowing the Suff module to properly postpone their
expansion until proper values are set for the local variables.

Directory prefix is no longer removed from $(.PREFIX) if the target
is found via directory search.

The last rule defined is now used instead of the first one (POSIX
requirement) in case a rule is defined multiple times. Everything
defined in the first instance is undone, but things added "globally"
are honored. To implement this, each node tracks attribute bits
which have been set by special targets (global) instead of special
sources (local). They also track dependencies that were added by
a rule with commands (local) instead of rule with no commands (global).

New attribute, OP_FROM_SYS_MK is introduced. It is set on all targets
found in system makefiles so that they are not eligible to become
the main target. We cannot just set OP_NOTMAIN because it is one of
the attributes inherited from transformation and .USE rules and would
make any eligible target that uses a built-in inference rule ineligible.

The $(.IMPSRC) local variable now works like in gmake: it is set to
the first prerequisite for explicit rules. For implicit rules it
is still the implied source.

The manual page is improved regarding the fixed features. Test cases
for the fixed problems are added.

Other improvements in the Suff module include:
- better debug messages for transformation rule search (length of
the chain is now visualized by indentation)
- Suff structures are created, destroyed and moved around by a set
of maintenance functions so their reference counts are easier
to track (this also gets rid of a lot of code duplication)
- some unreasonably long functions were split into smaller ones
- many local variables had their names changed to describe their
purpose instead of their type
 1.57 12-Jun-2012  joerg branches: 1.57.10;
Replace __dead, __unused and the various printf format attributes
with versions prefixed by MAKE_ATTR_* to avoid modifying the
implementation namespace. Make sure they are available in all places
using nonints.h to fix bootstrap on Linux.
 1.56 25-Nov-2010  christos branches: 1.56.6;
Instead of keeping around the mtime of the youngest child, keep a pointer
to it, so that we can print it when we do the out of date determination.
 1.55 23-Jan-2009  dsl Change 'ClientData' to 'void *' so that relevant parameters can
be made 'const void *'.
 1.54 13-Dec-2008  dsl Use NULL instead of -1 cast to the relavant type (usually via NIL).
This was a suggestion from christos - so blame him if there is a deep
reason for using -1 :-)
 1.53 06-Oct-2008  joerg Don't use emalloc and friends directly, but call them consistently
bmake_malloc and friends. Implement them via macros for the native case
and provide fallback implementations otherwise. Avoid polluting the
namespace by not defining enomem globally. Don't bother to provide
strdup and strndup, they were only used for the estrdup and estrndup
comapt code.

This addresses the presence of emalloc in system libraries on A/UX and
resulted strange issues as reported by Timothy E. Larson.
 1.52 15-Feb-2008  christos back all changes out until I fix it properly.
 1.51 14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.50 21-Dec-2007  dsl If make can't find a rule to create a file it needs to satisfy a rule
that came from .depend then just output a message and contine.
 1.49 21-Dec-2006  dsl branches: 1.49.4;
Fix breakage of previous commit.
 1.48 20-Dec-2006  dsl Fix detection and reporting of dependency loops in parallel makes.
make's unit_tests should now run again.
 1.47 18-Dec-2006  christos From Anon Ymous:
Removed two "(void)&" constructs as there is no setjmp() or vfork() insight.
Flagged a few parameters __unused so this will compile with -Wextra now.
 1.46 04-Dec-2006  dsl There really is no point calling estrdup() to get a copy of the makefile name
into every 'gnode' (aka target), instead just copy a pointer to the string
and avoid freeing the original name when we close the file.
I can't imagine any makefile set where this gives a larger footprint!
 1.45 17-Nov-2006  dsl branches: 1.45.2;
A rather large rototil in the way the parallel make code schedules jobs.
This gives a considerable speedup in the processing of .WAIT and .ORDER.
Both .WAIT and .ORDER stop both the commands of the node, and its dependant
nodes being built until the LH nodes are complete.
.WAIT only applies to the dependency line on which it appears, whereas
.ORDER applies globally between the two nodes.
In both cases dependant nodes can be built because other targets need them.
make now processes the target list left to right, scheduling child nodes
as they are needed to make other nodes (instead of attempting to generate
a bottom-up dependency graph at the start). This means that 'make -j1'
will tend to build in the same order as a non-parallel make.
Note that:
all: x y
x: a .WAIT b
y: b .WAIT a
does not generate a dependency loop.
But
x: y
.ORDER y x
does (unless something elswhere causes 'y' to be built).
 1.44 27-Oct-2006  dsl Since 'ClientData' is 'void *', nuke almost all the (ClientData) casts.
 1.43 15-Oct-2006  dsl Output all debug trace output through 'debug_file' defaulting to 'stdout'.
(Almost all the debug output went there, but some went to stderr.)
Split the parsing of -d (debug flags) out into its own routine.
Allow the output filename to be changed by specifying -dF<file> to create
a log file, or -dF+<file> to append to it. <file> may be stdout or stderr.
Also change so that -d-<flags> acts on <flags> locally but doesn't copy
them to MAKEFLAGS so they aren't inherited by child makes.
I'm not 100% happy with the command line syntax for the above, so they are
currently undocumented.
 1.42 26-Feb-2006  apb Make ".WAIT" apply recursively to all children of nodes on the right
hand side of the .WAIT, except when the recursive interpretation would
cause a cycle in the dependency graph.

Discussed in tech-toolchain. Reviewed by christos, sjg.
 1.41 11-Feb-2006  dsl Delete obsolete static defn.
Trace number of unmade children on pass 1
 1.40 11-Feb-2006  dsl Debug trace all the targets we are actually intending making.
De-optimise the getting of a job token so we don't re-order the job
list when there are no tokens.
This might have helped etc/Makefile, but isn't enough.
 1.39 08-Jan-2006  dsl Include the 'preds' and 'successors' in the diag output.
These are the values that are actually used to control what is built.
(I suspect .WAIT info added in the previous delta isn't always useful.)
 1.38 08-Jan-2006  dsl Include .WAIT in the debug output for dependency lists.
 1.37 08-Aug-2005  christos From Max Okumoto:
- Remove casts to NULL.
- Remove space between cast and object.
 1.36 05-Aug-2005  christos More KNF cleanups from Max Okumoto
 1.35 25-Jul-2005  christos Whitespace KNF cleanup from Max Okumoto
 1.34 16-Feb-2005  christos PR/29203, PR/29204: Max Okumoto: KNF changes to make [no functional changes]
 1.33 01-Jul-2004  jmc Change to use __unused instead and provide a compat definition in make.h if
not already defined from cdefs.h
 1.32 01-Jul-2004  jmc Add some checks for gcc around a few function declarations and note the
unused variables. Also fix a few other warnings that PR#22118 shows when
trying to compile bmake on non-NetBSD hosts
 1.31 07-May-2004  ross Simplify build, no functional changes.

Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().

It's now possible to build make on some hosts with: cc *.c */*.c
 1.30 07-Aug-2003  agc branches: 1.30.2;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.29 14-Jul-2003  christos Pass WARNS=3
 1.28 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.27 20-Mar-2002  pk Xref: parse.c, rev 1.46; make.c, rev 1.23

In these revisions `::' dependency handling was simplified by not linking
the cohort nodes into the dependency graph. This broke dependency checking
on all but the first instance of a `::' target since all of the cohort nodes
now just form a collection of disconnected dependency graphs.

Fix this by keeping a back-reference in each cohort to its leader (the
first instance of a :: node with the same name) and a count of the number
of cohorts that need to be made before dependent nodes are scheduled.

Classically, we'd need six centurions for cohort, but in this case one
suffices...
 1.26 10-Feb-2002  pk Targ_PrintType(): include .PHONY and .MADE attributes.
 1.25 27-Jan-2002  reinoud Fix major bug in make(1) ... due to shadowing of the dotLast path used for
the .DOTLAST primitive by a boolean variable with the same name, this whole
mechanism was broken ... it doesn't save much stat calls but it was wrong.

Thanks to Jason Thorpe for the other shadow-variable fixing patches he
made.
 1.24 12-Nov-2001  tv Add new make variable .ALLTARGETS, which lists all targets in the Makefile.
(Makes it possible to search the target list for particular things and
apply attributes to all the relevant targets.)
 1.23 20-Aug-2001  wiz precede, not preceed.
 1.22 03-Jul-2001  christos add .USEBEFORE Attribute
 1.21 14-Jan-2001  christos - make the second list of commands override the first like gmake does
- remember where the first command definition occured so that we can debug
things.
 1.20 16-Sep-1999  mycroft Some minor cleanup of :: tests.
 1.19 15-Sep-1999  mycroft Rework how :: dependencies are handled.
Build a list of `cohorts' as before, but do *not* link each one into all the
parent nodes; instead, copy the `cohort' lists into the stream of targets to
be built inside Make_ExpandUse(). Also do the attribute propagation as a
separate pass after parsing.
This eliminates several O(n^2) algorithms.
 1.18 15-Sep-1999  mycroft Don't bother iterating through all the data structures to free(3) everything
right before exiting.
(The code is still present, `#ifdef CLEANUP', in case someone needs it...)
 1.17 15-Sep-1999  mycroft Replace the linear variable list in the GNode with a hash table. Gives a
small (~10% on my machine) speedup building libc.
Changes by: perry (+ bug fix and minor change by me)
Reviewed by: mycroft sommerfeld
 1.16 11-Nov-1998  christos This patch fixes the problem introduced in the previous commit where
parents would be get remade, even if children were not really updated
by the commands executed for them. It also makes all the children have
the real modification time set if possible, so it should fix some other
timing weirdnesses...

- collapse childMade and make fields into flags and convert them to bits
CHILDMADE and REMAKE
- introduce FORCE flag that gets set in all the parents of a child that
has no sources and does not exist.
- set oodate if the FORCE flag is set, and not if CHILDMADE
- centralize the RECHECK into Make_Recheck() and use this in make.c and compat.c
- use Make_TimeStamp for all child -> parent timestamp propagations
 1.15 04-Feb-1998  christos Y2K fixes: use strftime(), and add a fake strftime() for systems that do
not have it.
 1.14 28-Sep-1997  lukem branches: 1.14.2;
wrap #include <sys/cdefs.h>, __RCSID(...) stuff in #ifndef MAKE_BOOTSTRAP
 1.13 01-Jul-1997  christos Add WARNS=1
RCSID police
 1.12 02-May-1997  christos - Target searching addition:
Make used to only use the search path for nodes that were pure
sources (not targets of other sources). This has been corrected
and now gnu-autoconf generated Makefiles work in directories other
than the source one.

- Suffix transformation rescanning:
Suffix transformations (.c.o:; cc ...) were only recognized in
the past when both suffixes were members of the suffix list.
Thus a sequence like:
.z.b:
echo ${.TARGET}
.SUFFIXES: .z
would cause .z.b: to be inserted as a regular target (and the main
target in this case). Other make programs always add rules that
start with a period in the transformation list and never consider
them as targets. We cannot do that (consider .depend files) so we
resort to scanning the list of the current targets every time a
suffix gets added, and we mutate existing targets that are now
valid transformation rules into transformation rules. If the
transformed target was also the main target, we set the main target
to be the next target in the targets list.
 1.11 20-Feb-1997  christos Reported by cgd: fix .USE directive problems:
1. ${.*} variables did not get expanded in dependencies.
2. expanded ${.*} variables in .USE dependencies can cause tree
restructuring; handle it.
3. in compat mode, expand .USE before evaluating the list of targets,
instead of doing .USE expansions on demand, because they can cause
tree restructuring.
 1.10 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.9 30-Aug-1996  thorpej Tidy up some RCS ids a bit.
 1.8 13-Aug-1996  christos Add estrdup(), a checked version of strdup and use it.
 1.7 08-Apr-1996  jtc branches: 1.7.4;
Changed to use 1900 + tm_year instead of hardcoding "19" as the century.
From PR #2308 by Stephen J. Roznowski <sjr@zombie.ncsc.mil>.
 1.6 16-Dec-1995  christos - Added .WAIT to synchronize between sources like other pmake variants.
- Updated documentation to include .ORDER .PARALLEL .NO_PARALLEL .NONPARALLEL
 1.5 14-Jun-1995  christos - $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.4 06-Jun-1994  jtc Fixes from Christos Zoulas, who used purify, objectcenter and testcenter
to find memory leaks and illegal memory accesses.
 1.3 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7.4.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.14.2.1 08-May-1998  mycroft Sync with trunk, per request of christos.
 1.30.2.1 10-May-2004  tron Pull up revision 1.31 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.45.2.2 05-Jun-2007  bouyer Apply patch (requested by tron in ticket #696):
usr.bin/make/compat.c patch
usr.bin/make/cond.c patch
usr.bin/make/dir.c patch
usr.bin/make/for.c patch
usr.bin/make/main.c patch
usr.bin/make/make.1 patch
usr.bin/make/make.c patch
usr.bin/make/make.h patch
usr.bin/make/nonints.h patch
usr.bin/make/parse.c patch
usr.bin/make/str.c patch
usr.bin/make/targ.c patch
usr.bin/make/util.c patch
usr.bin/make/var.c patch

Synchronize make(1) with HEAD branch to increase perfomance and
improve stability.
 1.45.2.1 20-Dec-2006  bouyer branches: 1.45.2.1.2;
Pull up following revision(s) (requested by dsl in ticket #285):
usr.bin/make/cond.c: revision 1.36
usr.bin/make/parse.c: revision 1.121-1.124
usr.bin/make/make.h: revision 1.65
usr.bin/make/targ.c: revision 1.46
usr.bin/make/main.c: revision 1.138-1.139
Simplify the code that processes .if lines.
It doesn't need a two-dimensional array to remember the states of .if lines.
It would be even simpler if we didn't try to detect .else and .elif lines
that follow .else lines.
Unfortunately this isn't the code that is stupendously slow...
Unknot this code slightly by avoiding 'break/return; else' and by putting
the short parts of some conditionals first.
First step towards speeding up the parsing of makefiles (esp. the unwanted
parts of .if clauses).
There should be no changes to the logic.
There really is no point calling estrdup() to get a copy of the makefile name
into every 'gnode' (aka target), instead just copy a pointer to the string
and avoid freeing the original name when we close the file.
I can't imagine any makefile set where this gives a larger footprint!
Add anewline to the end of the error message output when the debug log
file cannot be opened.
Put the big block of code that was common to ParseDoInclude() and
ParseTraditionalInclude() into a separate routine.
Fix the 'use after free' and 'free on item not malloced' that got added
to ParseTraditionalInclude() in Feb 2006 (rev 1.111).
Kill the 'PTR' struct and put both its members into IFile.
Remove the parameter from ParseEOF(), 1 of the 3 calls passed the wrong value!
Fortunately another test stopped anything nasty happening, we'll use that
test instead.
Revert part of a recent commit.
ParseEOF() shouldn't close the original file.
Some minor changes:
- Only test 'printVars' once.
Has side effect of not trying to find the 'main' target for '-V varname'.
- Only reap the single child process in Cmd_Exec(),
I think this is for 'xx != cmd' so probobably no other children should exist.
- Don't read and parse .depend if '-r' and '-V varname' are set.
I suspect that .depend shouldn't affect the output of any -V command...
 1.45.2.1.2.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.49.4.1 09-Jan-2008  matt sync with HEAD
 1.56.6.1 30-Oct-2012  yamt sync with head
 1.57.10.1 01-Jun-2015  snj Pull up following revision(s) (requested by manu in ticket #810):
usr.bin/make/targ.c: revision 1.60
Fix warning about uninitialized variable
This warning gets fatal when including make(1) as a crunchgen(1) binary.
 1.61.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.61.2.1 26-Apr-2017  pgoyette Sync with HEAD
 1.183.2.1 02-Aug-2025  perseant Sync with HEAD
 1.9 25-Jun-2024  rillig make: fix invalid-free for custom shell definitions

Don't try to free a pointer that is taken from the middle of a string,
in this case a shell specification.
 1.8 25-May-2024  rillig make: fix a few more memory leaks
 1.7 24-May-2024  rillig make: in -DCLEANUP mode, free variables and their values

The variables in the 3 scopes must be freed before the scopes themselves
are freed by Targ_End.

The test opt-m-include-dir creates a directory of the form '*.tmp', thus
it must be removed before attempting to only remove regular files of
this name.

POSIX requires setenv to copy the passed name and value, so there is no
need to keep that memory allocated any longer.
 1.6 01-Mar-2024  rillig make: remove test variant for NO_REGEX

The compile-time toggle was removed in var.c 1.1099 from 2024-02-07.
 1.5 19-Jan-2023  rillig tests/make: add tests for whitespace in leading '@+-'
 1.4 08-May-2022  rillig make: remove test variant without GMAKEEXPORT

Undefining GMAKEEXPORT on the command line had no effect, since that
macro is defined unconditionally in config.h.
 1.3 03-May-2022  rillig make: remove test scenarios for old GCC versions

These had been useful for NetBSD 8, which used GCC 5.
 1.2 03-Mar-2022  rillig tests/make: test variant without filemon
 1.1 05-Feb-2022  rillig tests/make: migrate test-variants.sh from shell to make

Using a makefile for defining the test variants allows running several
test variants individually, instead of using a single filter expression.

The test variants can be configured more fine-grained. It is possible
to exclude a few test cases per variant, which is useful for no-regex, a
compile-time switch for excluding the variable modifier ':C'.

Fix the definitions for the C90 tests. Previously they didn't override
the compiler option '-Wsystem-headers', thereby complaining about usage
of 'long long'.
 1.16 05-Feb-2022  rillig tests/make: migrate test-variants.sh from shell to make

Using a makefile for defining the test variants allows running several
test variants individually, instead of using a single filter expression.

The test variants can be configured more fine-grained. It is possible
to exclude a few test cases per variant, which is useful for no-regex, a
compile-time switch for excluding the variable modifier ':C'.

Fix the definitions for the C90 tests. Previously they didn't override
the compiler option '-Wsystem-headers', thereby complaining about usage
of 'long long'.
 1.15 29-Jan-2022  rillig tests/make: clean up variants that are tested

Since main.c 1.373 from 2020-10-18, make does not use iovec anymore, so
remove that test variant.

Document the details of why generating the test coverage took so long on
NetBSD < 10.

Add another test variant with optimization for binary size (-Os), since
with that option, GCC 10 does not perform the same data flow analysis as
with -O2, in particular it gets confused about whether local variables
are correctly initialized across function calls.
 1.14 09-Dec-2021  rillig make: add back support for jemalloc 100

The ports sun2 and vax default to jemalloc 100, as opposed to the rest
of the ports, which use jemalloc 510. Some developers choose to use
jemalloc 100, so let them run the tests with memory debugging as well.

Suggested by mrg on source-changes-d.
 1.13 05-Dec-2021  rillig tests/make: migrate to jemalloc > 100

When I started working on usr.bin/make in 2020, I used NetBSD 8, which
used jemalloc 100.

After updating to NetBSD 8 to 9.99.x, the debugging options for jemalloc
stopped working since MALLOC_OPTIONS had been replaced with MALLOC_CONF
in 2019.

Enable malloc debugging again, to reliably reproduce the use-after-free
for the variable modifier ':@'.
 1.12 12-Sep-2021  rillig tests/make: allow to only test selected variants

Testing all variants takes several minutes, so make it possible to test
a single or a few test variants separately.
 1.11 12-Sep-2021  rillig make: error out if a pre-C99 platform defines bool in some cases

On NetBSD/amd64 9.99.88, when compiling make in C90 mode, make.h defined
its own boolean type as an alias for unsigned int. Not plain int since
that would make the value of bit-fields -1 instead of 1.

This worked fine for all files except main.c, which includes
<sys/sysctl.h>, which in turn includes <stdbool.h> unconditionally, even
in C90 mode. This meant that in main.c, sizeof(bool) was 1, while in
all other files it was 4.

This in turn led to a segmentation fault when ParseDependencySourceMain
tried to access opts.create. Since parse.c assumed sizeof(bool) == 4,
it computed an offset outside of struct CmdOpts, which was defined in
main.c with sizeof(bool) == 1.

Rather than risking these segmentation faults, prevent building make on
platforms like these and suggest a proper workaround.
 1.10 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.9 15-Feb-2021  rillig make: fix typo in comment
 1.8 07-Dec-2020  rillig make(1): normalize output of test sh-dots for non-native mode
 1.7 29-Nov-2020  rillig make(1): add test variant for reference counting logging
 1.6 20-Nov-2020  rillig make(1): run tests with different shells as well, reduce output
 1.5 23-Oct-2020  rillig make(1): allow compilation with Boolean implemented as char
 1.4 21-Sep-2020  rillig make(1): run tests with absolute filenames as well

The tests varname-dot-parsedir and varname-dot-parsefile had been broken
before if they were run with the "-f $PWD/$test.mk" option. This way of
running the tests is used by FreeBSD.
 1.3 31-Aug-2020  rillig make(1): extend the documentation for the test variants
 1.2 31-Aug-2020  rillig make(1): document the purpose of the test variants
 1.1 31-Aug-2020  rillig make(1): add test driver for different build options

This program's purpose is to reduce the build failures of the whole
build.sh just because one of the many possible configurations fails.
 1.35 09-May-2025  rillig make: replace bitset in trace output with descriptive node attributes
 1.34 22-Apr-2025  rillig make: move struct Job from job.h to job.c

The content of this struct is an implementation detail, and other parts
of make only need to access very few parts of it.
 1.33 28-Mar-2023  rillig branches: 1.33.2;
make: declare all common symbols in headers, unexport others

No functional change.
 1.32 26-Mar-2022  rillig make: prefer 'long long' over 'long' on 32-bit C99 platforms

When sorting the words of an expression numerically using the modifier
':On' (added on 2021-07-30), use 64-bit numbers even on 32-bit
platforms. A typical use case is comparing file sizes.

When tracing the execution of jobs, fix an integer overflow after 2038.
32-bit platforms that use a pre-C99 compiler still have this problem.

No change to the test suite since most tests simply skip any potential
differences between 32-bit platforms and 64-bit platforms (see
varmod-order-numeric.mk) or already account for both variants (see
varmod-localtime.mk).
 1.31 05-Feb-2022  rillig make: improve C90 support

Do not use inline functions, remove trailing comma in enum declaration,
do not use 'long long' for printing a timestamp. This re-introduces the
Year 2038 Problem for pre-C99 compilers when printing the trace log, but
that is a seldom used feature.
 1.30 15-Dec-2021  rillig make: format comments according to /usr/share/misc/style

Assisted by indent(1), with manual corrections due to its many remaining
bugs.

No functional change.
 1.29 21-Sep-2021  rillig make: reduce relocations, thereby reducing .text size

No functional change.
 1.28 05-Feb-2021  rillig make: in the Var_ functions, move the scope to the front

This change provides for a more natural reading order in the code.
Placing the scope first makes it immediately clear in which context the
remaining parameters are interpreted.

No functional change.
 1.27 04-Feb-2021  rillig make: rename some VAR constants to SCOPE

The word "context" does not fit perfectly to the variables that are
associate with a GNode, as the context is usually something from the
outside and the variables are more like properties inherent to the
GNode.

The term "global context" fits even less. Since the thing where
variables are looked up is commonly named a scope, use that term
instead.

This commit only renames the global variables VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE, plus a few very closely related comments. These are:

GNode.vars (because of line breaks)
GNode_Free (dito)
varname-make_print_var_on_error.mk
varname-make_print_var_on_error-jobs.mk

The debug message in Var_Stats is left as-is since there is no unit test
for it yet.

The other renamings (variable names "context", "ctxt", as well as
further comments) will be done in a follow-up commit.
 1.26 19-Jan-2021  rillig make(1): remove do-not-format markers from comments

These markers had been used inconsistently. Furthermore the source code
had not been formatted automatically before 2020 at all, otherwise there
wouldn't have been any trailing whitespace left.
 1.25 20-Dec-2020  rillig make(1): change return type of Var_Value to FStr
 1.24 12-Dec-2020  rillig make(1): move Job.xtraced to ShellWriter

This flag was placed wrong in the Job since it is only necessary as long
as the shell commands are written to the shell file.

Resetting it in JobStart and JobExec was completely misguided since that
is far away from writing the shell commands; this should have been done
in JobPrintCommands instead.

The status of this flag doesn't need to be printed in debugging mode
since it is controlled by a single command line option (-dx) and does
not interact with all the other switches.
 1.23 10-Dec-2020  rillig make(1): unpack struct JobFlags

The job flags are only used individually.
 1.22 10-Dec-2020  rillig make(1): split JobFlags into separate fields

Having all these flags in a single bitmask makes it harder to see where
exactly they can possibly be used since their state could also be
modified using the unsuspicious job->flags = 0. Using individual names
just leaves the single memset, and that is only used during
initialization.
 1.21 31-Oct-2020  rillig make(1): document possible undefined behavior in trace.c with .CURDIR
 1.20 30-Oct-2020  rillig make(1): change char * to void * in Var_Value

The only purpose of the parameter freeIt is to free the memory
associated with the return value. To do this, no pointer arithmetic is
needed. Therefore, change to a void pointer, to catch accidental use of
that pointer.
 1.19 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.18 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.17 03-Oct-2020  rillig make(1): clean up #include sections
 1.16 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.15 03-Aug-2020  rillig make(1): no declaration-after-statement anymore

NetBSD make is intended to be maximally portable, therefore it uses only
C89. This was not declared in the Makefile before.

There are still a few places in parse.c and metachar.c that use
end-of-line comments. These will be fixed in a follow-up commit.
 1.14 01-Aug-2020  rillig make(1): avoid calls to free(3) in the common case of a NULL pointer
 1.13 01-Aug-2020  rillig make(1): let Var_Value return a const char *

The return value must not be modified anyway, so let the compiler check
this for free.
 1.12 03-Jul-2020  rillig make(1): remove trailing whitespace
 1.11 28-Dec-2008  christos prepare for time_t 64
 1.10 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.9 15-Feb-2008  christos branches: 1.9.4;
back all changes out until I fix it properly.
 1.8 14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.7 04-Jan-2006  dsl Expunge last references to jobTokensFree
 1.6 07-May-2004  ross Simplify build, no functional changes.

Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().

It's now possible to build make on some hosts with: cc *.c */*.c
 1.5 15-Jun-2002  wiz branches: 1.5.2;
Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.4 27-Jan-2002  reinoud Fix major bug in make(1) ... due to shadowing of the dotLast path used for
the .DOTLAST primitive by a boolean variable with the same name, this whole
mechanism was broken ... it doesn't save much stat calls but it was wrong.

Thanks to Jason Thorpe for the other shadow-variable fixing patches he
made.
 1.3 23-Jan-2001  cgd <sys/time.h>, rather than <time.h>. The former is actually the documented
way to get gettimeofday(), etc. On some systems on which you might want
to host make (e.g. solaris), <time.h> won't get you a struct timeval
definition.
 1.2 30-Dec-2000  sommerfeld Include token counts in trace output.
Don't let tokensFree go negative.
 1.1 29-Dec-2000  sommerfeld Quick and dirty trace mechanism to make it easier to look at how different
parallel make job distribution algorithms work in practice.
 1.5.2.1 10-May-2004  tron Pull up revision 1.6 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.9.4.1 18-May-2008  yamt sync with head.
 1.33.2.1 02-Aug-2025  perseant Sync with HEAD
 1.6 19-Jan-2021  rillig make(1): remove do-not-format markers from comments

These markers had been used inconsistently. Furthermore the source code
had not been formatted automatically before 2020 at all, otherwise there
wouldn't have been any trailing whitespace left.
 1.5 28-Nov-2020  rillig make(1): add multiple-inclusion guard for trace.h

Needed for all-in-one mode since this header is included 3 times.
 1.4 18-Oct-2020  rillig make(1): add tags to enum types

This allows IDEs to offer better type information than "anonymous enum".
 1.3 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.2 18-Feb-2006  sjg branches: 1.2.20;
Fix enum for better portability
 1.1 29-Dec-2000  sommerfeld Quick and dirty trace mechanism to make it easier to look at how different
parallel make job distribution algorithms work in practice.
 1.2.20.1 18-May-2008  yamt sync with head.
 1.2 28-Jun-1994  mycroft Clean up deleted files.
 1.1 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.78 15-Dec-2021  rillig make: format comments according to /usr/share/misc/style

Assisted by indent(1), with manual corrections due to its many remaining
bugs.

No functional change.
 1.77 15-Dec-2021  rillig make: use consistent indentation for statements and continuations

No binary change, except for line numbers in assertions in suff.c.
 1.76 03-Feb-2021  rillig make: use shortcut functions Global_SetExpand and Global_AppendExpand

There are many places where global variables are set or appended to. To
reduce clutter and code size, encode the VAR_GLOBAL in the function
name.

The word Expand in the function names says that the variable name is
expanded. In most of the cases, this is not necessary, but there are no
corresponding functions Global_Set or Global_Append yet.

Encoding the information whether the name is expanded or not in the
function name will make inconsistencies obvious in future manual code
reviews. Letting the compiler check this by using different types for
unexpanded and expanded variable names is probably not worth the effort.
There are still a few bugs to be fixed, such as in SetVar, which expands
the variable name twice in a row.
 1.75 03-Feb-2021  rillig make: fix compiler warning about signedness in comparison
 1.74 01-Feb-2021  rillig make: replace pre-increment with post-increment or simple addition

The rest of the code already prefers post-increment if there is no
actual difference.
 1.73 30-Dec-2020  rillig make(1): format multi-line comments
 1.72 15-Dec-2020  rillig make(1): indent nonints.h and util.c with tabs instead of spaces
 1.71 05-Dec-2020  rillig make(1): refuse to use vsnprintf that is prone to buffer overflows

Several parts of make intentionally depend on the guarantee that
snprintf and vsnprintf do not overflow their buffer. If an
implementation cannot provide this guarantee, refuse to use it.
 1.70 23-Nov-2020  rillig make(1): use comparisons in boolean expressions

The generated code stays exactly the same.
 1.69 23-Nov-2020  rillig make(1): align end-of-line comments with tabs
 1.68 16-Nov-2020  rillig make(1): use postfix increment where possible
 1.67 08-Nov-2020  rillig make(1): use common indentation style for else
 1.66 07-Nov-2020  rillig make(1): clean up spacing in fallback implementation of vsnprintf
 1.65 05-Nov-2020  rillig make(1): remove redundant parentheses from sizeof operator

The parentheses are only needed if the argument is a type, not an
expression.
 1.64 06-Oct-2020  rillig make(1): remove incomplete fallback implementation of strftime

The function strftime is available since C89. Any environments older
than that are not supported anymore.
 1.63 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.62 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.61 03-Oct-2020  rillig make(1): clean up #include sections
 1.60 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.59 12-Sep-2020  rillig make(1): add typedef for signal handler

Without this typedef, both the declaration and the definition of
bmake_signal were as unreadable as the declaration in the signal(3)
manual page.
 1.58 01-Aug-2020  rillig make(1): use consistent indentation in source code

Tabs for multiples of 8, then spaces.

The usage string has been kept as-is since the spaces there are
indentional and do influence the output.
 1.57 03-Jul-2020  rillig make(1): remove trailing whitespace
 1.56 03-Jul-2020  rillig make(1): remove redundant parentheses around return values
 1.55 07-Jan-2020  rillig usr.bin/make: remove dead code

The preprocessor conditions contradicted each other: __hpux__ or __hpux
would need to be defined, and at the same time none of them would need to
be defined.
 1.54 26-Nov-2013  joerg branches: 1.54.26;
Include signal.h early for MiNT and Linux. From pkgsrc.
 1.53 04-Jun-2012  sjg branches: 1.53.2;
Fix findenv() to fully match name
 1.52 04-Jun-2012  sjg Var_UnExport() and setenv() can both realloc environ.
Use a common variable (savedEnv) to track that to avoid wasting memory.
Also, if providing setenv and unsetenv, do getenv too to ensure a consistent
set.
 1.51 02-Apr-2011  mbalmer branches: 1.51.4;
Declare variable only once. Fixes PR 44795.
 1.50 03-Jun-2010  sjg We have required sigaction() for quite a while.
Use bmake_signal() - a wrapper around sigaction()
rather than signal() to ensure that signals are handled
consistently.
 1.49 05-May-2010  sjg gcc defines __svr4__
SunPro compiler defines __SVR4
We need to check both to ensure that on SunOS signal is hooked into
sigaction - otherwise we do not pass the unit-tests due to missing
a SIGCHLD
 1.48 29-Jan-2009  dholland Fix flagrantly wrong printf formats in compat strftime.
 1.47 13-Dec-2008  dsl Use NULL instead of -1 cast to the relavant type (usually via NIL).
This was a suggestion from christos - so blame him if there is a deep
reason for using -1 :-)
 1.46 31-Oct-2008  christos Don't use putenv() because it is not portable.
 1.45 06-Oct-2008  joerg branches: 1.45.2;
Don't use emalloc and friends directly, but call them consistently
bmake_malloc and friends. Implement them via macros for the native case
and provide fallback implementations otherwise. Avoid polluting the
namespace by not defining enomem globally. Don't bother to provide
strdup and strndup, they were only used for the estrdup and estrndup
comapt code.

This addresses the presence of emalloc in system libraries on A/UX and
resulted strange issues as reported by Timothy E. Larson.
 1.44 15-Feb-2008  christos back all changes out until I fix it properly.
 1.43 14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.42 15-Oct-2007  sjg If we don't have emalloc, we won't have strndup either.
Allows building current make on 2.0.
 1.41 13-Oct-2007  apb * Convert all uses of strdup() to estrdup();
* Use estrndup() in a few cases where it simplifies the code;
* Provide compatibility definitions of strndup and estrndup;
 1.40 17-Jan-2007  hubertf branches: 1.40.4;
Remove duplicate #includes
From Slava Semushin <slava.semushin@gmail.com>, via private mail
 1.39 08-Aug-2005  christos branches: 1.39.6; 1.39.8;
From Max Okumoto:
- Remove casts to NULL.
- Remove space between cast and object.
 1.38 05-Aug-2005  christos More KNF cleanups from Max Okumoto
 1.37 25-Jul-2005  christos Whitespace KNF cleanup from Max Okumoto
 1.36 16-Feb-2005  christos PR/29203, PR/29204: Max Okumoto: KNF changes to make [no functional changes]
 1.35 07-May-2004  ross Simplify build, no functional changes.

Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().

It's now possible to build make on some hosts with: cc *.c */*.c
 1.34 16-Jul-2003  itojun branches: 1.34.2;
we can't use snprintf here, as sizeof(pathname) is unknown
 1.33 22-Sep-2002  lukem HP/UX fixes from Giles Lean:
- consistently support __hpux (which the HP compilers define) as well
as __hpux__ (not sure which compilers set this, but retained anyway)
- fix a typo in the definition of signal(). arguably the codebase should
just be converted to sigaction()...
 1.32 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.31 12-Mar-2002  christos PR/15888: Jarkko Teppo: Problems building on HP/UX
1. Compensate for h-pox assert brain damage where it gets confused by the
string in: assert(!memcmp(foo, "in", 2)); I miss the h-pox broken compiler,
I had not had to work around it for years.
2. Oh, finally h-pox has random() and utimes(). We don't need our own anymore.
 1.30 02-Mar-2002  tv Add <errno.h> to list of includes, from <imago@13thmonkey.org>,
in PR toolchain/15386.
 1.29 27-Jan-2002  reinoud Fix major bug in make(1) ... due to shadowing of the dotLast path used for
the .DOTLAST primitive by a boolean variable with the same name, this whole
mechanism was broken ... it doesn't save much stat calls but it was wrong.

Thanks to Jason Thorpe for the other shadow-variable fixing patches he
made.
 1.28 25-Jan-2002  tv Make util.c replacement functions use autoconf conditionals to probe
what is Really available in the host OS.
 1.27 11-Dec-2001  tv Add __CYGWIN__ to list of exceptions from homegrown strftime().

(XXX - This should be an inclusive, not exclusive, list. Later, this
should be autoconfiscated, but keep the internal implementation, since
src/tools/compat isn't necessarily available for use at make's build time.)
 1.26 03-Aug-2000  christos PR/10714: SUNAGAWA Keiki: Add newer hpux support, but without removing the
old hpux support.
 1.25 04-May-2000  drochner support OSF/1
 1.24 06-Jan-2000  wrstuden Add a few little changes needed to get this to compile on IRIX 6.4.
 1.23 04-Sep-1999  christos PR/8259: Chris Demetriou: Fix stack overflow bugs exposed by the glibc-2.1.1
Makefile. Use snprintf everywhere.
 1.22 27-Aug-1999  simonb Don't need strftime() on Ultrix either.
 1.21 29-Jun-1999  christos apply solaris fixes
 1.20 19-Mar-1999  christos use emalloc() instead of malloc()
 1.19 06-Nov-1998  christos - full prototypes
- more conservative printf
- char -> unsigned char
 1.18 18-Oct-1998  christos strftime is not needed for svr4 machines; also fix the prototype footprint.
 1.17 18-Sep-1998  christos PR/6174: ITOH Yasufumi: Purify bug and a compile error in utility code.
 1.16 04-Feb-1998  christos Y2K fixes: use strftime(), and add a fake strftime() for systems that do
not have it.
 1.15 28-Sep-1997  lukem branches: 1.15.2;
wrap #include <sys/cdefs.h>, __RCSID(...) stuff in #ifndef MAKE_BOOTSTRAP
 1.14 11-Jul-1997  christos #if __STDC__ -> #ifdef __STDC__
 1.13 11-Jul-1997  christos sprintf -> vsprintf
 1.12 01-Jul-1997  christos Add WARNS=1
RCSID police
 1.11 07-Jun-1997  christos Apparently, using _doprnt(_IOREAD) to emulate vsnprintf() on SVR4 *sometimes*
core-dumps; use sprintf()+strlen() for now.
 1.10 31-Dec-1996  christos implement snprintf() and vsnprintf() for non BSD4_4 systems.
 1.9 11-Nov-1996  christos Fir PR/2930: declare missing variable.
 1.8 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.7 30-Aug-1996  thorpej Tidy up some RCS ids a bit.
 1.6 13-Aug-1996  christos Add strdup() since ultrix is missing it.
From Larry Schwimmer <rosebud@cyclone.Stanford.EDU>
 1.5 22-Nov-1995  christos branches: 1.5.4;
Updates for POSIX/SVR4 compiling:

arch.c: Don't require ranlib stuff. Not everybody has it.
dir.c: SunOS-4 != Solaris; change #ifdef sun to #if sun && !__svr4__
job.c, compat.c: Don't use 'union wait', use int and the W*() macros.
main.c: Check for uname() == -1; some unames return > 0...
util.c, job.c: Add signal() with BSD semantics for svr4, don't use bsd
sigmask and friends.
 1.4 14-Jun-1995  christos - $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.3 23-Sep-1994  mycroft Use getcwd(3), not getwd(3), and remove some old, unused compatibility code.
 1.2 09-May-1994  glass bootstrap improvements
 1.1 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.5.4.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.15.2.1 08-May-1998  mycroft Sync with trunk, per request of christos.
 1.34.2.1 10-May-2004  tron Pull up revision 1.35 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.39.8.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.39.6.1 05-Jun-2007  bouyer Apply patch (requested by tron in ticket #696):
usr.bin/make/compat.c patch
usr.bin/make/cond.c patch
usr.bin/make/dir.c patch
usr.bin/make/for.c patch
usr.bin/make/main.c patch
usr.bin/make/make.1 patch
usr.bin/make/make.c patch
usr.bin/make/make.h patch
usr.bin/make/nonints.h patch
usr.bin/make/parse.c patch
usr.bin/make/str.c patch
usr.bin/make/targ.c patch
usr.bin/make/util.c patch
usr.bin/make/var.c patch

Synchronize make(1) with HEAD branch to increase perfomance and
improve stability.
 1.40.4.1 06-Nov-2007  matt sync with HEAD
 1.45.2.1 09-Nov-2008  snj Pull up following revision(s) (requested by cube in ticket #38):
usr.bin/make/util.c: revision 1.46
Don't use putenv() because it is not portable.
 1.51.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.51.4.1 30-Oct-2012  yamt sync with head
 1.53.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.54.26.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.1172 16-Sep-2025  sjg Allow compiler to set size of hexdigits
 1.1171 29-Jun-2025  rillig make: fix parsing of modifier parts for :gmtime and :localtime

There's no practical use for escaping the ":" or "}" in these two
modifiers, but the same scheme may prove useful for the :M and :N
modifiers, which are currently parsed in a completely different manner,
thus adding needless complexity.

Parsing of the :M and :N modifiers is discussed in PR bin/46139.
 1.1170 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.1169 28-Jun-2025  rillig make: add POSIX $^ support

POSIX 2024 [1] introduced the $^ internal macro. Implement it as an
alias for $> (.ALLSRC), following the suggestion from defect 1520 [2].

[1]: https://pubs.opengroup.org/onlinepubs/9799919799/utilities/make.html
[2]: https://www.austingroupbugs.net/view.php?id=1520

Patch provided by Diogo Santos in PR bin/59018.
 1.1168 13-Jun-2025  rillig make: skip inter-process stack trace when MAKE_STACK_TRACE=no

Previously, setting MAKE_STACK_TRACE to any other value than "yes"
accidentally generated almost-complete inter-process stack traces.
 1.1167 13-Jun-2025  rillig make: add on-demand inter-process stack traces

When debugging a build that heavily uses nested calls to sub-makes, the
chain of calls is useful to quickly assess the situation. If explicitly
requested, include the actions from any parent processes in the stack
traces.

Reviewed by: sjg
 1.1166 12-Jun-2025  rillig make: use a common style for unexpected error messages

In enomem, report the actual error instead of a fixed ENOMEM.
 1.1165 11-Jun-2025  sjg make: check variable names for invalid characters

Variable names should not contain white-space.
As is; make quietly ignores gmake syntax like
$(addprefix -I, $(INCLUDE_DIR_LIST))
which means we are not doing what the makefile wants, and the
user has no clue.

CheckVarname is called only if there are no modifiers to be applied
as :L and others legitimately can handle white-space,
it will issue a warning if illegal characters are found.
Currently only white-space is checked.

The NetBSD build produces a few warnings - in one case a makefile
intended for gmake, and the other some dubious constructs by bsd.prog.mk
in support of ATF tests such as OBJS.${PROG} when PROG is actually a list.

Reviewed by: rillig
 1.1164 26-May-2025  rillig make: prepare for inter-process stack traces

To understand how chains of sub-makes interact and how they are called,
it's useful to have stack traces that span multiple processes. To
implement this, a stack trace needs not only be printed but also stored
as a string.
 1.1163 26-May-2025  rillig make: show contents of MAKEFLAGS in the stack trace

When the internal -J option refers to a closed file descriptor, it's
helpful to know what the MAKEFLAGS environment variable contains, in
addition to the executed command line. Same for parse errors in
variable assignments from the command line.
 1.1162 03-May-2025  rillig make: miscellaneous cleanups
 1.1161 30-Apr-2025  rillig make: fix order of error messages in the ":?" modifier

While here: In Var_Parse, EvalStack_Pop needs to be called before
freeing the short-lived variable, as its name is part of the evaluation
stack.
 1.1160 22-Apr-2025  rillig make: clean up

Replace 'unsigned int' with simply 'unsigned'.

In compat.c, skipping whitespace is not needed, as the loop above
already skips it.

In job.c, remove the unused header <sys/file.h>.

Inline the TMPPAT macro, as it is only needed in a single place.
 1.1159 04-Apr-2025  rillig make: fix error message for undefined variable in conditional

Previously, only ${UNDEF} had the proper error message, while
${UNDEF:M*} still produced the wrong "Malformed conditional".
 1.1158 30-Mar-2025  sjg make: POSIX mode, check for sysV style modifiers first

A POSIX compatible makefile should not be using any
of our native modifiers, so give preference to the sysV style modifier
and only check the others as a fallback.

Reviewed by: rillig
 1.1157 30-Mar-2025  rillig make: fix error message for invalid ":[...]" modifier

The unparsed value of the modifier argument can already be seen in the
stack trace, but the modifier argument may contain expressions and the
expanded value of these expressions was hidden up to now. See the EMPTY
test at the bottom of varmod-select-words.mk for details.
 1.1156 30-Mar-2025  rillig make: add details to error message for the "::=" modifier

The previous error message about a bad modifier ":" was not helpful, as
the strcspn call stopped immediately due to the modifier starting with
the separater character ":". The previous error message also didn't
reveal that the "parse error" was due to the expression name being
empty.
 1.1155 30-Mar-2025  rillig make: simplify error handling for unknown modifiers
 1.1154 30-Mar-2025  rillig make: let the ":t" modifiers fall back to the ":from=to" modifier

Suggested by https://bugs.freebsd.org/285726.

This means that the ":t" modifiers cannot have future extensions that
include a "=", as that may break existing code.
 1.1153 29-Mar-2025  rillig make: let unknown ":O" modifiers fall back to the ":from=to" modifier

Inspired by https://bugs.freebsd.org/285726, which concerns the ":t"
modifier instead.

This means that future extensions to the ":O" modifier must not contain
a "=" anywhere, otherwise they may break existing code.
 1.1152 29-Mar-2025  rillig make: in a stack trace with details and includes, list the current file
 1.1151 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.1150 29-Mar-2025  rillig make: stop parsing after seeing an unknown modifier in an expression

Previously, after an expression such as ${VAR:Z::::}, make detected the
unknown modifier ":Z" and then continued parsing, which produced
unnecessary follow-up error messages. It was also necessary to
distinguish the error cases when logging the result of an applied
modifier in -dv mode.

Unify the error handling cases of a syntax error, an evaluation error
and an unknown modifier, to avoid the unnecessary follow-up error
messages.

The test in varmod-edge.mk now produces ":}" from the erroneous
expression, which may be misleading and thus will be looked at in a
follow-up commit.

The general idea of this patch was reviewed by sjg, I made a few
nonsubstantial changes after the review.
 1.1149 29-Mar-2025  rillig make: fix error message for unclosed expression

Even in an unclosed expression such as "${VAR:from=to", the modifier
":from=to" needs to be recognized as such, instead of giving an error
message about an "Unknown modifier ":from=to"".
 1.1148 29-Mar-2025  rillig make: add more details to error message about unfinished modifier

These details allow to quickly see the place where the syntax error is,
based on the surrounding lines from the stack trace.
 1.1147 29-Mar-2025  rillig make: add details about indirect modifiers to the stack traces

Previously, the error message "Unfinished modifier (',' missing)" from
moderrs.mk didn't provide enough context to understand where and why the
comma was missing.
 1.1146 29-Mar-2025  rillig make: in stack traces from target commands, add the command level

A target can contain several commands, and these commands are likely to
contain the same expressions. To distinguish them, add one more line to
the stack trace, to narrow down the source of the error.
 1.1145 22-Mar-2025  rillig make: ignore attempts to override a read-only global with the same value

Up to NetBSD 9, make passed around the internal variable .MAKE.LEVEL.ENV
via MAKEFLAGS. Allow these old versions of make to coexist with newer
versions of make. See unit-tests/varname-dot-make-level.mk for details.

Fixes PR pkg/59184.
 1.1144 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.1143 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.1142 31-Dec-2024  rillig make: reduce pointer indirections when unexporting a variable
 1.1141 23-Nov-2024  rillig make: fix confusing error message when overriding a read-only variable
 1.1140 31-Aug-2024  rillig make: simplify printing of an evaluation stack element
 1.1139 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.1138 27-Aug-2024  rillig make: treat recursive variables non-fatally

A recursive variable is no worse than an unknown modifier, so treat them
in the same way by continuing parsing until the end of the makefile.
 1.1137 25-Aug-2024  rillig make: add more context to error message about recursive variables
 1.1136 20-Jul-2024  rillig make: remove wrong error message about an undefined variable
 1.1135 09-Jul-2024  rillig make: error out on syntax errors in ':M' and ':N' modifiers

More than a year ago, the warning has been added. Now it has been
promoted to an error.
 1.1134 07-Jul-2024  rillig make: move initialization of variable scopes to targ.c

The variable scopes are freed by Targ_End, so initialize them there as
well. Separate printing statistics and freeing memory, which makes
Var_End unnecessary.
 1.1133 05-Jul-2024  rillig make: in error messages, distinguish parsing from evaluating
 1.1132 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.1131 05-Jul-2024  rillig make: error out on unclosed expressions during parse time

In exchange, this adds location information.

For unnamed expressions, the value is no longer printed. This will be
added back in a follow-up commit.
 1.1130 05-Jul-2024  rillig make: reduce lint-specific comments about ARGSUSED
 1.1129 04-Jul-2024  rillig make: error out on the "Bad modifier" error message

Previously, the "Bad modifier" error message did not affect make's exit
status. As a side effect, this kind of error now gets more context
information.
 1.1128 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.1127 02-Jul-2024  rillig make: trim trailing whitespace
 1.1126 01-Jul-2024  sjg make: add :tc to capitalize first letter of each word

This is very hard to do without :tc

Reviewed by: rillig
 1.1125 30-Jun-2024  rillig make: error out on some more syntax errors

Previously, these errors only produced a message on stderr. They only
affected make's exit status when they were evaluated at parse time, but
not when evaluating the commands for a specific target right before
executing them.

The affected syntax errors are:
* invalid regular expressions in the ':C' modifier
* out-of-range references to regex groups in the ':C' modifier
* unfinished modifiers
 1.1124 30-Jun-2024  rillig make: error out on syntax error in conditions in ':?then:else' modifier

The 'Error' function only reports errors but does not affect the exit
status, the 'Parse_Error' function does, while providing more details to
find the cause of the syntax error.
 1.1123 30-Jun-2024  rillig make: sync error handling between '!=' assignment and '::!=' modifier
 1.1122 30-Jun-2024  rillig make: add more context to "returned non-zero status" message

Previously, this message was an "error" but had no influence on the exit
status, so make it a warning instead. In the seldom used -W mode that
treats warnings as errors, this change influences the exit status.
 1.1121 15-Jun-2024  rillig branches: 1.1121.2;
make: error out if an internal read-only variable is overwritten

The affected variables are:
* .newline
* .MAKE.OS
* .MAKE.JOBS.C
* .MAKE.LEVEL.ENV
* .MAKE.PID
* .MAKE.PPID
* .MAKE.UID
* .MAKE.GID

This change does not affect the .SHELL and .SUFFIXES variables, as well
as variables that are manually turned read-only by the special .READONLY
target.
 1.1120 15-Jun-2024  rillig make: clean up collection of context information for error messages
 1.1119 02-Jun-2024  rillig make: sync VarEvalMode constant names with their debug log names
 1.1118 02-Jun-2024  rillig make: fix out-of-bounds read when parsing indirect modifiers
 1.1117 01-Jun-2024  sjg make: add .export-all

An explicit syntax for exporting all global variables is much safer
than allowing .export with no argument to do the same.

Add .export-all and have .export with no argument throw a warning saying
to use .export-all

Reviewed by: rillig
 1.1116 01-Jun-2024  rillig make: remove unused VARE_EVAL_KEEP_DOLLAR
 1.1115 31-May-2024  rillig make: merge functions that parse modifier parts

This commit subtly changes the behavior for the :gmtime and :localtime
modifiers, but only in irrelevant cases since the time value must be an
integer, and neither '\' nor ':' nor '$' may occur in these values.
 1.1114 31-May-2024  rillig make: clean up API for iterating over hash tables
 1.1113 30-May-2024  rillig make: don't log anything when freeing memory
 1.1112 25-May-2024  rillig make: fix some more memory leaks
 1.1111 25-May-2024  rillig make: fix a few more memory leaks
 1.1110 24-May-2024  rillig make: in -DCLEANUP mode, free variables and their values

The variables in the 3 scopes must be freed before the scopes themselves
are freed by Targ_End.

The test opt-m-include-dir creates a directory of the form '*.tmp', thus
it must be removed before attempting to only remove regular files of
this name.

POSIX requires setenv to copy the passed name and value, so there is no
need to keep that memory allocated any longer.
 1.1109 07-May-2024  sjg make: all command line overrides go in .MAKEOVERRIDES

Not all variables that start with '.' are internals,
and unless they are explicitly flagged as internal should go
into .MAKEOVERRIDES

Update varname-dot-makeoverrides to check this.

Also avoid using SCOPE_CMDLINE when ReadOnly will do.
 1.1108 28-Apr-2024  rillig make: don't reallocate memory after evaluating an expression

When an expression is evaluated, the resulting text is short-lived in
almost all cases. In particular, the compaction neither affects the
target names nor the global variable values, which are the prime
candidates for permanent memory usage.
 1.1107 27-Apr-2024  rillig make: fix comment about forcing a use-after-free

The previous expression didn't cause any bug, as the modifier
':@VAR@loop@' changed the value of the expression, thus making the
expression independent from the variable value.

Instead, the variable needs to be deleted from within an indirect
modifier, and that modifier needs to evaluate to an empty string, thus
doing nothing and preserving the original expression value.
 1.1106 27-Apr-2024  rillig make: clean up, test .NOPATH

Trim down the comments in the archive module, as they mainly repeated
the code. Trim down the binary code size in the archive module, as it
is rarely used.

In Var_Parse, delay two variable assignments until they are actually
needed.
 1.1105 23-Apr-2024  rillig make: clean up comments, code and tests
 1.1104 21-Apr-2024  rillig make: trim down code for parsing the :gmtime and :localtime modifiers

The :gmtime and :localtime modifiers are not used often and thus are not
time-critical. Exchange the custom code that parses an integer from a
substring for an additional memory allocation.

Thanks sjg@ for suggesting to avoid the custom parsing code.
 1.1103 21-Apr-2024  rillig make: fix out-of-bounds read when evaluating :gmtime and :localtime

The function TryParseTime takes a pointer to a string, but the LazyBuf
returns a Substring, which is not guaranteed to be null-terminated or
delimited. In TryParseTime, calling strtoul on the Substring read past
the end of the substring.

Noticed in the NetBSD build in libntp, where the :gmtime modifier is
used in two places with the same timestamp value, of which the first was
evaluated correctly and the second wasn't.

The bug was introduced in var.c 1.1050 from 2023-05-09, when the
argument of the :gmtime and :localtime modifiers was allowed to be an
expression instead of an integer constant.
 1.1102 20-Apr-2024  rillig make: provide more context information for parse/evaluate errors
 1.1101 01-Mar-2024  rillig make: fix type mismatch in lint's strict bool mode (since today)
 1.1100 01-Mar-2024  sjg make: export target scope values

Pass target scope to Var_ReexportVars so that a target process
will see the correct values in its env.
We must then mark any Global scope variable as unexported
so targets without local value get the Global one.
 1.1099 07-Feb-2024  rillig make: remove unneeded conditional-compilation toggles

The toggles INCLUDES, LIBRARIES, POSIX, SYSVINCLUDE, SYSVVARSUB,
GMAKEEXPORT and SUNSHCMD are no longer needed, they were unconditionally
set.

The toggle NO_REGEX was configurable from the command line, but
disabling it would result in various error messages about the unknown
':C' modifier.

OK sjg@.
 1.1098 04-Feb-2024  rillig make: do not evaluate indirect modifiers in parse-only mode

Discovered by sjg.
 1.1097 04-Feb-2024  rillig make: in parse-only mode, don't evaluate modifiers

Previously, the ':S', ':ts', ':tA' and ':from=to' modifiers were
evaluated in parse-only mode, unnecessarily. This is only noticeable
when an indirect modifier is evaluated in parse-only mode, which is
another bug that will be fixed in a follow-up commit.
 1.1096 03-Feb-2024  sjg make: state of save_dollars affects what is a parse error

When save_dollars is false it is not a parse error to
encounter $$ rather than \$.
 1.1095 21-Jan-2024  rillig make: clean up redundant 'const' from automatic variables

No binary change.
 1.1094 07-Jan-2024  rillig make: clean up comments, constify shell name
 1.1093 05-Jan-2024  rillig make: miscellaneous cleanups
 1.1092 05-Jan-2024  rillig make: clean up string functions

No binary change.
 1.1091 05-Jan-2024  rillig make: inline Substring_Sub

Remove redundant assertions.
 1.1090 29-Dec-2023  rillig make: simplify debug message for the ':@var@...@' modifier

The previous variant was hard to understand.
 1.1089 29-Dec-2023  rillig make: clean up variable handling

All variables from the command line scope have the fromCmd flag set, so
there is no need to check for it.

Inline redundant local variables.

Variables from a scope cannot be short-lived, so there is no need to
call VarFreeShortLived.

No functional change.
 1.1088 29-Dec-2023  rillig make: clean up comments

No binary change, except for line numbers in assertions.
 1.1087 29-Dec-2023  rillig make: simplify memory allocation for string buffers

In edge cases and short-lived buffers, the initial buffer size is
irrelevant, so use the default.

No functional change.
 1.1086 20-Dec-2023  rillig make: use consistent debug messages style when ignoring variables

When a variable is not modified or not deleted, clearly say so and state
the reason. Use the same style of debug messages everywhere, putting
the word 'ignoring' at the front. Previously, that word sticked out to
the right, but only in some cases.
 1.1085 20-Dec-2023  rillig make: fix confusing debug logging when deleting a variable

Be clear when deleting a variable is ignored and state the reason,
instead of only providing a keyword as a hint for insiders.
 1.1084 19-Dec-2023  rillig make: clean up comments

No binary change, except for line numbers in assertions.
 1.1083 17-Dec-2023  rillig make: clean up names of local variables

No binary change.
 1.1082 10-Dec-2023  rillig make: explain in the debug log why a variable assignment is ignored
 1.1081 10-Dec-2023  rillig make: remove redundant text from diagnostic about bad '?:' modifier
 1.1080 10-Dec-2023  rillig make: clean up the check for command line variables

It looked suspicious that to check whether a variable was set via the
command line, the variable value would be needed. Moving the debug
diagnostic to the calling function resolved this smell.

A variable from the command line scope is never short-lived, so there's
no need to clean up after accessing the variable.

No functional change.
 1.1079 10-Dec-2023  rillig make: clean up comments and local identifiers

No binary change, except for line numbers in assertions.
 1.1078 10-Dec-2023  rillig make: document how to trigger a use-after-free bug

Since 2017-02-01.
 1.1077 10-Dec-2023  rillig make: fix crash in ':C' modifier on an empty expression

Since var.c 1.982 from 2021-12-13.
 1.1076 09-Dec-2023  sjg make: Var_SetWithFlags set fromCmd for SCOPE_CMDLINE

Set fromCmd true for SCOPE_CMDLINE
regardless of the variable name.

Reviewed by: rillig
 1.1075 19-Nov-2023  rillig make: replace 'variable expression' with 'expression' in comments

No binary change.
 1.1074 19-Nov-2023  rillig make: replace 'variable expression' with 'expression' in diagnostics
 1.1073 19-Nov-2023  rillig tests/make: cover all code paths for the ':mtime' modifier
 1.1072 19-Nov-2023  rillig make: produce more accurate error message for invalid ':mtime' argument
 1.1071 19-Nov-2023  rillig make: extract detection of ':from=to' to a separate function

No functional change.
 1.1070 19-Nov-2023  rillig tests/make: test and explain exporting of variables
 1.1069 18-Nov-2023  rillig make: clean up the modifier ':[...]'

No functional change.
 1.1068 02-Nov-2023  rillig make: when comparing substrings, don't read beyond the substring's end

Right now, Substring_Words terminates each word with a '\0', but that's
an implementation detail that is not required by the interface, so don't
rely on it.
 1.1067 02-Nov-2023  rillig make: miscellaneous cleanups

No functional change.
 1.1066 02-Nov-2023  rillig make: clean up comments

No functional change.
 1.1065 02-Nov-2023  rillig make: sync comments with the extracted ParseModifier_Match

No functional change.
 1.1064 19-Aug-2023  rillig make: only work around wrong strftime if actually necessary

The workaround is only needed if the time format contains '%s', in all
other cases there is no need to preserve, set and restore the TZ
environment variable. Suggested by sjg@.

Only check for 's' in the format string, not for '%s', to allow for
optional modifiers of the conversion specifier.
 1.1063 19-Aug-2023  rillig make: clean up comments regarding gmtime/strftime

These two functions are not supposed to be used together, thus it is not
a bug if combining them produces unexpected results.
 1.1062 19-Aug-2023  rillig make: work around bugs in gmtime on several platforms
 1.1061 17-Aug-2023  rillig make: be strict when parsing the argument of the ':mtime' modifier
 1.1060 17-Aug-2023  rillig make: clean up variable names and indentation for the ':mtime' modifier

No functional change.
 1.1059 23-Jun-2023  rillig make: clean up variable and function names

No functional change.
 1.1058 23-Jun-2023  rillig make: warn about malformed patterns in ':M', ':N' and '.if make(...)'

These patterns shouldn't occur in practice, as their results are tricky
to predict. Generate a warning for now, and maybe an error later.

Reviewed by sjg@.
 1.1057 22-Jun-2023  rillig make: merge common code for handling the ':M' and ':N' modifiers

No functional change.
 1.1056 16-Jun-2023  sjg make: do not allow delete of readOnly variable.

Sometimes we mark a variable readOnly to guard against .undef
 1.1055 01-Jun-2023  rillig make: shorten function names, clean up comments

No functional change.
 1.1054 10-May-2023  sjg Make :mtime operate on each word in variable value.

Reviewed by: rillig
 1.1053 09-May-2023  rillig make: improve error message for failed stat in ':mtime'
 1.1052 09-May-2023  sjg make: :mtime=error throw error on stat(2) failure

Sometimes we want fatal error if stat fails on the
presumed pathname.
 1.1051 09-May-2023  sjg make: add :mtime to provide mtime of file

The value of the variable is passed to stat(2)
and st_mtime is new value.
An optional arg can be used if stat(2) fails, otherwise
the current time is used.

See varmod-mtime.mk for usage examples.
 1.1050 09-May-2023  rillig make: allow ':gmtime' and ':localtime' with dynamic argument

This allows ${%Y:L:gmtime=${mtime}} instead of the indirect
${%Y:L:${:Ugmtime=${mtime}}}.

The direct form also prevents any ':' from the nested expression to be
interpreted as a separator, which doesn't matter for the ':gmtime' and
':localtime' modifiers but will prove useful for other modifiers that
follow the same pattern.
 1.1049 28-Mar-2023  rillig make: declare all common symbols in headers, unexport others

No functional change.
 1.1048 09-Mar-2023  rillig make: fix memory leak when parsing ':from=to' modifiers

Since var.c 1.925 from 2021-04-12.
 1.1047 18-Feb-2023  rillig make: fix parsing of unevaluated subexpressions with unbalanced '{}'

Since var.c 1.323 from 2020-07-26, modifiers containing unbalanced
braces or parentheses were parsed differently, depending on whether they
were relevant or not.

For example, the expression '${VAR:...}' is enclosed with braces. When
this expression has a modifier ':S,},}},g' that would double each '}' in
that expression, the parser got confused:

If the expression was relevant, the modifier was parsed as usual, taking
into account that the 3 '}' in the modifier are ordinary characters.

If the expression was irrelevant, the parser only counted the '{' and
the '}', without taking into account that a '}' might be escaped by a
'\' or be an ordinary character. Parsing therefore stopped at the first
'}', assuming it would finish the expression '${VAR:S,}'.

This parsing mode of only counting balanced '{' and '}' makes sense for
the modifier ':@var@...@', which expands each word of the expression
using the template from the '...'. These templates tend to be simple
enough that counting the '{' and '}' suffices.
 1.1046 15-Feb-2023  rillig make: inline macros for variable names

The variable name '.MAKEOVERRIDES' was already used in the non-macro
form.

No binary change.
 1.1045 15-Feb-2023  rillig make: inline macro for variable name ".MAKE.EXPORTED"

The variable name is distinctive enough to be searched directly in the
code instead of having a named constant for it.

No binary change.
 1.1044 14-Feb-2023  rillig make: remove redundant type VarParseResult

No functional change.
 1.1043 14-Feb-2023  rillig make: clean up calls to Var_Subst

None of the calls to Var_Subst used the return value, and the return
value was always VPR_OK.

No functional change.
 1.1042 14-Feb-2023  rillig make: reduce complexity of evaluating expressions

No functional change.
 1.1041 13-Feb-2023  rillig make: extract the decision of using a specific log format

No functional change.
 1.1040 09-Feb-2023  sjg make: ApplyModifier_Remember always use SCOPE_GLOBAL

Conditionals evaluate vars with SCOPE_CMDLINE, if :_
is used within a conditional expression and is thus
set in SCOPE_CMDLINE, it breaks any use of :_ in SCOPE_GLOBAL.

The simplest solution is for :_ to always use SCOPE_GLOBAL

Reviewed by: rillig
 1.1039 26-Jan-2023  sjg make: some variables should be read-only

Make variables like .newline and .MAKE.{GID,PID,PPID,UID} read-only.

Reviewed by: rillig
 1.1038 24-Jan-2023  sjg make: log adjustments of var.readOnly
 1.1037 23-Jan-2023  sjg make: .[NO]READONLY for control of read-only variables

Reviewed by: rillig
 1.1036 05-Dec-2022  rillig make: inline LazyBuf_AddBytesBetween

No binary change.
 1.1035 01-Oct-2022  rillig make: constify, fix comment indentation

No functional change.
 1.1034 01-Oct-2022  rillig make: merge duplicate code

No functional change.
 1.1033 27-Sep-2022  rillig make: set WARNS to 6, from the default 5

No binary change on x86_64.
 1.1032 24-Aug-2022  rillig make: prevent future out-of-bounds errors when parsing expressions

A modifier in an expression ends not only at the next ':' or at the
closing '}' or ')', but also at the end of the string.

Previously, testing for the end of the string had been done separately,
which was error-prone since 2006-05-11, when indirect modifiers were
introduced. Since then, it was possible that the string terminator '\0'
was accidentally skipped in cases where the loop condition only tested
for the ending character. When parsing indirect modifiers, the ending
character is indeed '\0', but when parsing direct modifiers, it is '}'
or ')'.

A welcome side effect is that in the case of unclosed expressions such
as '${VAR:Modifier', the amount of error messages is reduced from 2 or 3
to only 1. The removed error messages were wrong and thus confusing
anyway.
 1.1031 24-Aug-2022  rillig make: fix out-of-bounds read when parsing the ':M' modifier

Since at least 2009-01-17, probably already since 2006-02-18, when
modifiers were allowed to be nested expressions.
 1.1030 24-Aug-2022  rillig make: fix out-of-bounds read when parsing the ':D' modifier

Since 2000-04-29, when the ':D' and ':U' modifiers were added.
 1.1029 23-Aug-2022  rillig make: revert parsing of modifier parts (since 2022-08-08)

The modifier ':@var@body@' parses the body in parse-only mode and later
uses Var_Subst on it, in which each literal '$' must be written as '$$'.

Trying to parse the loop body using Var_Parse treated the text
'$${var:-0}' as a single '$' followed by the expression '${var:-0}',
wrongly complaining about the 'Unknown modifier "-0"'.

Found by sjg.
 1.1028 08-Aug-2022  rillig make: fix parsing of modifiers containing unbalanced subexpressions
 1.1027 05-Aug-2022  rillig make: when parsing ':D' or ':U', only copy text if necessary

When parsing the expression ${:D any ${uninterpreted} text}, parsing of
the ':D' modifier only needs to skip to the next delimiter, there is no
need to keep record of the text that has been skipped. In this
particular example, there had been an unnecessary memory allocation
since the nested expression was not copied to the result buffer. Due to
that, the resulting buffer contained " any text", which was not a
substring of the text passed to the parser, thereby forcing the memory
allocation.

No functional change.
 1.1026 05-Aug-2022  rillig make: extract parsing of ':D' and ':U' modifiers into separate function

No functional change.
 1.1025 14-Jun-2022  rillig make: document parsing of short variable names, such as $i

No binary change.
 1.1024 14-Jun-2022  rillig make: reduce indentation in ParseVarnameShort

No functional change.
 1.1023 14-Jun-2022  rillig make: simplify return type of IsShortVarnameValid

No functional change.
 1.1022 12-Jun-2022  rillig make: reorganize Parse_Error

Determining the location where the error occurred is now done by
ParseVErrorInternal. This frees the remaining code from keeping the
filename and the line number together. It also makes Parse_Error short
enough that it might be worth providing a separate function for each of
the 3 log levels.

No functional change.
 1.1021 14-May-2022  rillig make: clean up comments in Var_Parse
 1.1020 09-May-2022  rillig make: remove obsolete comment

All instances of VarFind that could be replaced with VarFindSubstring
have been replaced.
 1.1019 27-Mar-2022  rillig make: fix spacing, and a typo in a test
 1.1018 26-Mar-2022  rillig make: avoid trailing whitespace in debug log for variables

Since trailing whitespace is invisible, describe the variable value in
words to make it visible.
 1.1017 26-Mar-2022  rillig make: add space after colon in debug logging for variables

These log messages are intended for human interpretation, so don't make
them unnecessarily hard to read.
 1.1016 26-Mar-2022  rillig make: prefer 'long long' over 'long' on 32-bit C99 platforms

When sorting the words of an expression numerically using the modifier
':On' (added on 2021-07-30), use 64-bit numbers even on 32-bit
platforms. A typical use case is comparing file sizes.

When tracing the execution of jobs, fix an integer overflow after 2038.
32-bit platforms that use a pre-C99 compiler still have this problem.

No change to the test suite since most tests simply skip any potential
differences between 32-bit platforms and 64-bit platforms (see
varmod-order-numeric.mk) or already account for both variants (see
varmod-localtime.mk).
 1.1015 26-Mar-2022  rillig make: clean up comments
 1.1014 26-Mar-2022  rillig make: fix crash on .undef of an environment variable (since 2020-10-06)
 1.1013 03-Mar-2022  rillig make: simplify ParseModifier_Match

No functional change.
 1.1012 11-Feb-2022  rillig make: remove comment about environment variable with empty name

At least on NetBSD, make cannot be fooled with an environment variable
having an empty name. When running '/usr/bin/env =undefined make', the
argument is parsed as a variable assignment, but putenv(3) refuses to
process an empty variable name. Calling execve(2) directly got a step
further, the kernel didn't filter '=undefined' from the environment
variables. But getenv(3) always returns NULL when querying the
environment variable with the empty name.

On other operating systems, things may be different. Trying to set an
environment variable with an empty name may cause errors in env(1),
putenv(3), execve(2), getenv(3) or other places, so don't add an
automatic test for now.
 1.1011 09-Feb-2022  rillig make: simplify control flow in ModifyWord_SysVSubst

No functional change.
 1.1010 09-Feb-2022  rillig make: clean up variable names

No binary change.
 1.1009 04-Feb-2022  rillig make: use fixed type for comparing numbers using the modifier ':On'

When the modifier ':On' was added on 2021-07-30, there were concerns
that pre-C99 environments would not have the type 'long long', therefore
the type was made configurable, but parsing such numbers was hard-coded
to using strtoll.

To improve compatibility with C90 environments, use 'long' and 'strtol'
in these environments. In C99 environments, use 'long long' and
'strtoll', to account for larger file sizes.

If the flexibility of choosing yet another type for these numbers should
ever arise, it can still be implemented. Until then, reduce the number
of possible build configurations.
 1.1008 29-Jan-2022  rillig make: for recursive variables in commands, print location

Print the approximate location based on the last command that has been
defined for the target. It would be possible to get more detailed
location information by counting the number of commands of the target,
but that would get messy due to .USEBEFORE, .USE and .DEFAULT, and
still, this is an edge case, so don't waste too much code for it now.
Having this hint about the location is more helpful than just a plain
"Variable X is recursive" without any further details.
 1.1007 29-Jan-2022  rillig make: inline functions that have a single call site

No functional change.
 1.1006 27-Jan-2022  sjg Allow local variable assignments in dependency lines

The variable is set in the context of the target.
This syntax has been supported by gmake for ~ever.
If necessary a makefile can set .MAKE.TARGET_LOCAL_VARIABLES=false
to disable this.

Expose GetBooleanExpr so parse.c can use it.
 1.1005 24-Jan-2022  rillig tests/make: demonstrate that the 'static' in Var_Parse has an effect
 1.1004 24-Jan-2022  rillig make: remove unsatisfiable condition in VarSubstExpr

At that point, emode can have only 2 values, none of which is
VARE_UNDEFERR.

No binary change since GCC had figured this out all the time, it just
didn't reveal this little secret.
 1.1003 24-Jan-2022  rillig make: when expanding nested variables, check simple things first

No functional change, just a little performance improvement for
expressions that are not evaluated anyway but only parsed.
 1.1002 15-Jan-2022  rillig make: remove unnecessary functions for expanding variable names

In meta mode, the affected variable patterns do not contain a '$'.

Outside of meta mode, Global_SetExpand was only called a single time, so
inline that call.

No functional change.
 1.1001 15-Jan-2022  rillig make: merge duplicate code for expanding variable expressions

No functional change.
 1.1000 09-Jan-2022  rillig make: in Cmd_Exec, return error message instead of format string

This change leaves only literal format strings in parse.c. It allows
for more detailed error messages than the current "non-zero status" or
"exited on a signal".

No functional change.
 1.999 09-Jan-2022  rillig make: shorten ApplyModifier_Assign

No functional change.
 1.998 08-Jan-2022  rillig make: inline Buf_Clear

No functional change.
 1.997 08-Jan-2022  rillig make: rename is_shell_metachar, fix character conversion warning

No binary change.
 1.996 07-Jan-2022  rillig make: clean up comments, variable names, function names

The comment in ApplyDependencySourceOther repeated the code, its second
half didn't match any current code.

The comment above ParseDependencySourcesEmpty repeated the code.

No binary change, except for assertion line numbers.
 1.995 07-Jan-2022  rillig make: merge calls to ApplyModifier_Time

This enables GCC 11 to inline ApplyModifier_Time, like all the other
modifiers. Similar pattern as for ':M' and ':N', as well as for ':D'
and ':U'.

No functional change.
 1.994 07-Jan-2022  rillig make: merge duplicate code for modifiers 'gmtime' and 'localtime'

No functional change.
 1.993 07-Jan-2022  rillig make: clean up variable modifiers 'gmtime' and 'localtime'

Use consistent wording (zulu -> gmt), make VarStrftime parameter order
consistent with strftime, rename confusing 'time_t utc' to 't',
eliminate common subexpression in error message.

No functional change.
 1.992 30-Dec-2021  rillig make: condense code in ApplyModifier_Assign

List the assignment operators in the same order as in the manual page.

No functional change.
 1.991 29-Dec-2021  rillig make: merge duplicate types CondEvalResult and CondResult

No binary change.
 1.990 29-Dec-2021  rillig make: remove redundant parameter for evaluating conditions

No functional change.
 1.989 15-Dec-2021  rillig make: amend leftover cleanups from the previous commits

No functional change.
 1.988 15-Dec-2021  rillig make: format comments according to /usr/share/misc/style

Assisted by indent(1), with manual corrections due to its many remaining
bugs.

No functional change.
 1.987 15-Dec-2021  rillig make: remove space after ':' in bit-field declarations

As seen in /usr/share/misc/style.
 1.986 13-Dec-2021  rillig make: fix memory leak when parsing a variable name

To trigger the memory leak, the expanded variable name must not be a
prefix of the textual variable name.

textual name expanded name
ok: UNDEF.${undef} UNDEF.
leak: UNDEF.${undef}. UNDEF..
 1.985 13-Dec-2021  rillig make: reduce memory allocation in modifier ':?'

The memory allocation was in LazyBuf_DoneGet. The substring for the
untaken branch had been allocated even though it was not necessary.

No functional change.
 1.984 13-Dec-2021  rillig make: reduce memory allocations in modifier ':C'

The memory allocation was in the call to LazyBuf_DoneGet.

No functional change.
 1.983 13-Dec-2021  rillig make: condense RegexReplace for the modifier ':C'

No functional change.
 1.982 13-Dec-2021  rillig make: in the modifier ':C', don't call strlen unnecessarily

No functional change.
 1.981 13-Dec-2021  rillig make: extract RegexReplaceBackref from RegexReplace

No functional change.
 1.980 13-Dec-2021  rillig make: merge duplicate code for memory handling in Var_Parse

No functional change.
 1.979 13-Dec-2021  rillig make: fix remaining memory leak for .SUFFIXES (since yesterday)
 1.978 13-Dec-2021  rillig make: distinguish between short-lived and environment variables

No functional change.
 1.977 13-Dec-2021  rillig make: rename VarFreeEnv to VarFreeShortLived

The newly added "variable" .SUFFIXES is short-lived as well, which makes
it necessary to distinguish between environment variables and
short-lived variables.

No binary change.
 1.976 13-Dec-2021  rillig make: clean up code for freeing short-lived variables

Since yesterday's addition of the short-lived "variable" named
.SUFFIXES, not only environment variables are short-lived. Clean up the
code to prepare for fixing the remaining memory leaks.

No functional change.
 1.975 13-Dec-2021  rillig make: fix memory leak when evaluating ${.SUFFIXES} (since yesterday)

perl -e '
printf(".SUFFIXES: %s\n", "x" x 224);
printf("_:=\${.SUFFIXES}\n" x 100_000);
printf("all:\n");
' \
| MALLOC_CONF=stats_print:true \
./make -r -f - 2>&1 \
| awk '/bins:/,/^ *256/ { print $1 "\t" $4}'

Roughly 100000 less allocations for bin size 16, for the variable name.
 1.974 13-Dec-2021  rillig make: fix memory leak when evaluating ${.SUFFIX} (since yesterday)
 1.973 12-Dec-2021  sjg Add .SUFFIXES as read-only variable.

References to ${.SUFFIXES} are handled dynamically in
ParseVarnameLong by calling Suff_NamesStr.

The variable cannot be set normally.

Reviewed by: rillig
 1.972 12-Dec-2021  sjg ParseVarnameLong: minimize calls to LazyBuf_Get

Reviewed by: rillig
 1.971 11-Dec-2021  rillig make: inline ParseEmptyArg into CondParser_FuncCallEmpty

No functional change.
 1.970 09-Dec-2021  rillig make: in parse errors, mark whitespace more clearly

This prevents any trailing whitespace from going unnoticed. It also
marks leading whitespace more clearly, as in the examples with the time
value " 1".
 1.969 09-Dec-2021  rillig make: remove period from end of error messages and warnings

The majority of the existing error messages and warnings does not
include a period at the end. Follow this style consistently.
 1.968 07-Dec-2021  rillig make: merge branches for modifiers ':D' and ':U'

These branches have the exact same code, without involving any macros,
nevertheless GCC 10 doesn't merge them. Further, GCC thinks that the
function ApplyModifier_Defined were called from two different places,
thus creating an actual function definition. Merging the case labels
inlines the function, saving a few instructions and a few hundred bytes
in the binary.

No functional change.
 1.967 07-Dec-2021  rillig make: extract common code into Expr_Words

No functional change.
 1.966 06-Dec-2021  rillig make: move low-level implementation details out of Var_Parse

No functional change.
 1.965 06-Dec-2021  rillig make: extract common code into Expr_Str

This change turns Expr into a more abstract data type.

No functional change.
 1.964 05-Dec-2021  rillig make: fix types for modifier ':O' (since today)

In var.c 1.962 from 2021-12-05, the type of the array to be sorted
changed from 'const char *' to 'Substring'. The code still worked since
the first member of Substring is 'const char *start', but that was pure
luck.

Fix the type assumptions in the comparison functions.

Add an assertion that the words must be null-terminated since the
comparison functions currently assume this.

This kind of inconsistency may be possible to detect using static
analysis, but NetBSD's lint is currently too limited for that. To
detect this, it would have to analyze each possible comparison function
and remember the assumed type. This type could then be compared to the
argument type of a function call to qsort or bsearch.

No functional change.
 1.963 05-Dec-2021  rillig make: fix use-after-free in modifier ':@'

Without memory allocator debugging, the newly added test doesn't show
any obvious failure.

With memory allocator debugging enabled, all make versions since
2016.02.27.16.20.06 crash with a segmentation fault.
 1.962 05-Dec-2021  rillig make: save a memory allocation in each modifier ':O' and ':u'

No functional change.
 1.961 05-Dec-2021  rillig make: save a memory allocation in the modifier ':[...]'

No functional change.
 1.960 05-Dec-2021  rillig make: save a memory allocation in the modifier ':[...]'

No functional change.
 1.959 05-Dec-2021  rillig make: in UnexportVars, replace Str_Words with Substring_Words

This skips an allocation and a bit of memory copying.

No functional change.
 1.958 03-Dec-2021  rillig make: condense ParseModifierPartSubst

No functional change.
 1.957 03-Dec-2021  rillig make: extract ParseModifierPartExpr from ParseModifierPartSubst

No functional change.
 1.956 03-Dec-2021  rillig make: extract ParseModifierPartDollar from ParseModifierPartSubst

No functional change.
 1.955 28-Nov-2021  rillig make: fix type of variable in ApplyModifier_IfElse

No functional change.
 1.954 20-Nov-2021  rillig make: use correct plural form in debug message
 1.953 17-Oct-2021  rillig make: fix order of parameters in function comments

No functional change.
 1.952 23-Sep-2021  rillig make: fix memory leak in error case of the ':?' modifier
 1.951 21-Sep-2021  rillig make: reduce relocations, thereby reducing .text size

No functional change.
 1.950 11-Sep-2021  rillig make: eliminate a few common subexpressions

This commit contains only changes that don't increase the code size on
x86_64. Replacing the remaining instance of ModChain_ShouldEval would
either increase the code size or make the code harder to understand.

No functional change.
 1.949 06-Sep-2021  rillig make: fix typos in comments
 1.948 25-Aug-2021  rillig make: fix lint warnings on ilp32 platforms

The warnings in arch.c were about conversions from int to long.

The warnings in var.c were about conversions from long long to
ptrdiff_t.

No functional change.
 1.947 14-Aug-2021  rillig make: remove workaround for initialization bug in lint

The bug has been fixed in init.c 1.208 from 2021-08-14.
 1.946 08-Aug-2021  rillig make: remove redundant initialization in ApplyModifier_Order

No functional change.
 1.945 31-Jul-2021  rillig make: fix lint warnings

The string functions from str.h are declared as 'static __unused' when
compiled with GCC, but lint explicitly undefines __GCC__ during
preprocessing. Therefore, make those functions inline, to prevent
warnings that they are unused.

The macro UNCONST is used in a few places, and (again) since lint
undefines __GCC__, that macro expanded to a simple type cast, which lint
warned about. To prevent this warning, implement UNCONST as a function
that works everywhere and hides the type cast.

In filemon_open, the code for closing F->in was obviously unreachable.

No functional change.
 1.944 31-Jul-2021  rillig make: clean up ApplyModifier_Order

No functional change.
 1.943 30-Jul-2021  rillig make: reword comment for ApplyModifier_Order
 1.942 30-Jul-2021  rillig make: handle parse errors in ':O' uniformly

Previously, the error handling for the variable modifier ':O' differed
depending on the exact variant and in some cases led to misleading
or missing diagnostics.
 1.941 30-Jul-2021  rillig make: merge duplicate code for sorting strings and numbers

No functional change.
 1.940 30-Jul-2021  rillig make: fix typo in manual page, add more tests for the new ':On'
 1.939 30-Jul-2021  sjg Add :On for numeric sort

Reviewed by: christos rillig
 1.938 21-Jun-2021  rillig make: use more practical data type in RegexReplace

While size_t is most appropriate for array indexes, make needs to be
compatible with C90, which does not support the %zu printf conversion.
To avoid type casts, use a simple unsigned int here, which is more than
enough for storing a single decimal digit.

No functional change.
 1.937 21-Jun-2021  rillig make: extract RegexReplace from ModifyWord_SubstRegex

No functional change.
 1.936 21-Jun-2021  rillig make: move all labels in ModifyWord_SubstRegex to the same level

No functional change.
 1.935 21-Jun-2021  rillig make: reduce indentation in ModifyWord_SubstRegex for ':C'

No functional change.
 1.934 21-Jun-2021  rillig make: fix documentation for ParseModifierPart
 1.933 21-Jun-2021  sjg Do not report unmatched regex subexpressions

It is not always an error for a subexpression to have not matched,
since the regex library can/does not convey how many matches are
expected, only report an error if opts.strict (-dL)

Reviewed by: christos
 1.932 30-May-2021  rillig make: uncompress code in ApplyModifier_Unique

The algorithm is easier to understand when each line of code only
focuses on a single topic.

No change to the resulting binary, except for line numbers in assertion
messages.
 1.931 30-May-2021  rillig make: inline VarUniq into ApplyModifier_Unique

No functional change.
 1.930 19-Apr-2021  rillig branches: 1.930.2;
make: use straight quotes for error 'Bad conditional expression'

This diagnostic was supposed to be an error, see ApplyModifier_IfElse.

When such an error occurs while the makefiles are read, make stops with
an error, as can be expected. But when such an error occurs later,
after all makefiles have been read, the message is printed but make does
not stop.

In lint mode (-dL), make stops in such a case. I didn't dare to make
this the default behavior, out of fear of breaking existing build
infrastructure, not only in NetBSD or pkgsrc, but also FreeBSD and other
operating systems that use the bmake distribution, generated from the
same source code.
 1.929 14-Apr-2021  rillig make: reduce memory allocations in the modifiers ':D' and ':U'
 1.928 14-Apr-2021  rillig make: rename members of ModifyWord_LoopArgs

No functional change.
 1.927 14-Apr-2021  rillig make: clean up pattern flags for the modifiers ':S' and ':C'

No special handling is necessary for C90 since none of the struct
members is a const_member.

The prefix 'Var' is not necessary since this type does not apply to a
variable but only to a modifier.

No functional change.
 1.926 12-Apr-2021  rillig make: spell SysV in mixed case

No functional change.
 1.925 12-Apr-2021  rillig make: reduce memory allocation and strlen calls in modifier ':from=to'

Previously, SysVMatch was quite verbose and felt like hand-optimized
assembler code, which made it difficult to discover the underlying idea
of the code.

All this code was replaced with two simple calls to Substring_HasPrefix
and Substring_HasSuffix. Now that the operands of that modifier are no
longer passed as C strings, there is no need to collect all information
in a single scan through the word and the pattern.

It was not necessary to call Var_Subst unconditionally. Calling it only
when the string contains a '$' saves another memory allocation and two
string copies (because of the Buf_DoneDataCompact).

No functional change.
 1.924 12-Apr-2021  rillig make: in the ':Q' modifier, only allocate memory if necessary
 1.923 11-Apr-2021  rillig make: improve performance for LazyBuf

The previous O(n^2) time complexity for parsing a long string with many
variable expressions was not meant to last for long. I had hoped to fix
it within a few minutes, but that will take more time.

For now, make LazyBuf simpler by using a traditional C string for the
expected part instead of a Substring. This avoids a strlen call per
Var_Parse.

No functional change, only performance.
 1.922 11-Apr-2021  rillig make: remove redundant parameter from ParseVarnameLong

No functional change.
 1.921 11-Apr-2021  rillig make: migrate ParseModifierPart to use Substring

This will reduce memory allocation for modifier parts without the escape
characters '$' or '\'.

No functional change.
 1.920 11-Apr-2021  rillig make: avoid unnecessary calls to strlen when evaluating modifiers

No functional change.
 1.919 11-Apr-2021  rillig make: migrate ModifyWord functions to use Substring

This benefits the modifiers ':T' and ':H' since these scan the word from
the end. The SysV modifier '.c=.o' does not benefit yet, this will be
done in a follow-up commit.

Currently ModifyWords calls strlen for each single word, which degrades
performance. This will be cleaned up in a follow-up commit as well.

No functional change.
 1.918 11-Apr-2021  rillig make: migrate handling of the modifier ':S,from,to,' to Substring

Right now this does not gain any performance, it only makes the code in
ModifyWord_Subst a little simpler since it only uses
Buf_AddBytesBetween, not a mixture with Buf_AddBytes.

When the word passed to the ModifyWord functions is converted to
Substring as well, the call to strlen will become redundant.

No functional change.
 1.917 11-Apr-2021  rillig make: clean up remaining references to VarEvalFlags

VarEvalFlags has been replaced with VarEvalMode. There were some
comments and tests that still referred to the old names.

No functional change.
 1.916 11-Apr-2021  rillig make: avoid allocating memory for simple variable names

The main change is in ParseVarname, where a Buffer is replaced with the
newly introduced LazyBuf. LazyBuf is inspired by
https://golang.org/src/path/path.go.

In CanonicalVarname, the pre-comparison of the first letter of the
variable name is no longer necessary. GCC 9 optimizes a fixed-length
memcmp so well that the code can finally be written to target human
readers, leaving the optimization to the compiler.
 1.915 10-Apr-2021  rillig make: fix out-of-bounds read in Var_Parse_FastLane (since 30 minutes)

This bug made the test varmod-edge.mk fail sometimes with varying error
messages, as can be expected for an out-of-bounds read.
 1.914 10-Apr-2021  rillig make: reword debug log message for empty variable name

The function names did not match anymore, after one of the many
refactorings in the last few months.
 1.913 10-Apr-2021  rillig make: reduce debug logging and memory allocation for ${:U...}

Expressions of the form ${:U...} are often generated by .for loops.
Since these expressions are not generated knowingly by the make user, do
not fill the debug log with them since that would interrupt the normal
reading flow of the -dv log for nested expressions.
 1.912 06-Apr-2021  rillig make: reduce verbosity of the -dv debug logging for standard cases

The verbosity was already removed from LogBeforeApply, now it is
consistent between LogBeforeApply and LogAfterApply.
 1.911 05-Apr-2021  rillig make: in debug log, add space between scope and variable name

Without this space, the debug log looked more like line noise, even
though the only punctuation was a single innocent ':'. From a make
user's perspective, the variable name is a word of its own and should
not be visually glued to its namespace.
 1.910 05-Apr-2021  rillig make: omit unnecessary details from -dv debug log

When an expression is based on a defined variable, it does not matter
whether the evaluation mode is "eval" or "eval-defined", therefore omit
these details to reduce confusion.
 1.909 05-Apr-2021  rillig make: be more verbose in -dv debug logging

The previous log output was too brief to be understandable. Give more
hints by describing each part of the expression when evaluating a
modifier. Distinguish between parse-only mode and eval mode since in
parse-only mode most of the details are irrelevant.
 1.908 05-Apr-2021  rillig make: clean up debug logging for ':M' and ':N'

Using square brackets as quotes was confusing since patterns can contain
square brackets themselves.

The debug logging for VarMatch was a bit too detailed. Having the
"before" and "after" states is enough for all practically relevant
cases.
 1.907 04-Apr-2021  rillig make: disallow '$' in the variable name of the modifier ':@'

If this restriction should break any existing makefile, the author of
that makefile was probably heading for the IOMCC.
 1.906 04-Apr-2021  rillig make: convert VarEvalFlags back into an enum, but not a bit-set

As was apparent in VarEvalFlags_ToString, a bit-set was not the best
data type since most of the flags were not freely combinable. The two
flags that could be combined were keepDollar and keepUndef, but even
these have distinguished names in the debug log.

The downside of struct bit-fields is that they need extra helper
functions in C90 (see nonints.h). Exchange these for a few helper
functions in var.c, to keep the code outside var.c simple.

No functional change.
 1.905 04-Apr-2021  rillig make: extract decision for evaluating an expression

No functional change.
 1.904 03-Apr-2021  rillig make: move VarEvalFlags_ToString down to the other functions

No functional change.
 1.903 03-Apr-2021  rillig make: condense definition of VarPatternFlags

No functional change.
 1.902 03-Apr-2021  rillig make: inline VarFlags into Var

No functional change.
 1.901 03-Apr-2021  rillig make: replace enum bit-set with struct bit-fields

This makes the code easier to read, especially when setting one of the
flags to false.

No functional change.
 1.900 03-Apr-2021  rillig make: remove unused Expr.varFlags

No functional change.
 1.899 03-Apr-2021  rillig make: remove VarFlags from debug logging

Before the introduction of ExprDefined, VarFlags contained whether the
expression was defined or not, which was useful to know since the final
value of the expression depends on this information. The other VarFlags
do not influence the evaluation, so there is no point logging them.
 1.898 03-Apr-2021  rillig make: simplify access to the name of an expression during evaluation

During the evaluation, the flags of the variable don't change, except
for VFL_IN_USE, but in such a case make exits immediately anyway.

Logging the variable flags does not provide any useful information, so
it will be removed soon. Logging the variable flags made sense when the
definedness of the expression was still encoded in the variable flags,
instead of in the separate ExprDefined.

No functional change.
 1.897 03-Apr-2021  rillig make: backport to C90

In the past few months I had accidentally used C99 features in the make
code. According to tools/README, tools that are used in the build
system should restrict themselves to C90.

This allows make to build with GCC's options "-pedantic
-Wno-system-headers -Dinline= -Wno-error=cast-qual".

I didn't notice anyone actively complaining though, I just wanted to see
how much work this backporting would be. The identifier __func__ is
still used, as in other tools.

No functional change.
 1.896 03-Apr-2021  rillig make: rename function parameters to match boolean constants

No functional change.
 1.895 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.894 30-Mar-2021  rillig make: remove workaround for bug in lint

The bug has been fixed in lint.

No functional change.
 1.893 21-Mar-2021  rillig make: fix typos in documentation of ModChain
 1.892 16-Mar-2021  rillig make: fix documentation for ModChain

The outer ModChain can be interrupted by an inner ModChain, but it
continues to exist.

No functional change.
 1.891 15-Mar-2021  rillig make: rename ApplyModifiersState to ModChain

The new name accurately describes the structural element that holds such
properties as the separator character and whether the expression value
is considered a single word. The old name ApplyModifiersState was too
long and was meant as a placeholder anyway, when I introduced it in
var.c 1.236 from 2020-07-03.
 1.890 15-Mar-2021  rillig make: improve documentation of ApplyModifiersState

No functional change.
 1.889 15-Mar-2021  rillig make: document an example for a 'chain of modifiers'

No functional change.
 1.888 15-Mar-2021  rillig make: fix double varname expansion in the variable modifier '::='

This is an edge case that doesn't occur in practice since pretty much
nobody dares to use variable names that contain an actual '$' in their
name. This is not about the fairly common VAR.${param} (as written in
the makefile), but instead about the variable whose name is literally
'VAR.${param}'.

The test demonstrates that after the fix, the variable name is taken
exactly as-is for the simple assignment modifier '::='. There are no
such tests for the modifiers '::+=', '::!=' and '::?=', but that's ok.
The code in ApplyModifier_Assign would look assymetrical and suspicious
enough if one of these modifiers would expand its variable name and the
others wouldn't.
 1.887 15-Mar-2021  rillig make: clean up documentation of ApplyModifiersState

No functional change.
 1.886 15-Mar-2021  rillig make: change debug log for variable evaluation flags to lowercase

This makes them easier distinguishable from variable names since the
latter are usually uppercase.

No functional change outside debug mode.
 1.885 15-Mar-2021  rillig make: replace enum bit-field with struct bit-field for VarEvalFlags

This makes the code easier to read, especially in var.c. It also makes
debugging sessions easier since some debuggers don't show enum
bit-fields symbolically as soon as more than one bit is set.

The code outside var.c is basically unchanged, except that instead of
passing the individual flags, there are 4 predefined evaluation modes.
These suffice for all practical use cases. Only in the implementation
deep inside var.c, the value of the flags keepDollar and keepUndef
differs.

There is no way of passing the struct to EnumFlags_ToString, which means
the ToString function has to be spelled out explicitly. This allows for
fine-tuning the representation in the debug log, to reduce the amount of
uppercae letters.

No functional change.
 1.884 15-Mar-2021  rillig make: rename VARE_NONE to VARE_PARSE_ONLY

The name 'NONE' described the bit pattern, which was not useful to
understand its meaning. Omitting VARE_WANTRES only parses the
expression, without evaluating any part of it.

No functional change, not even in debug mode since Enum_FlagsToString
always returns "none" for all-bits-unset.
 1.883 14-Mar-2021  rillig make: fix documentation of VarFreeEnv

No functional change.
 1.882 14-Mar-2021  rillig make: skip variable lookup for '::=' modifiers in parse-only mode

This is just to keep the code consistent among the various variable
modifiers. The performance gain is negligible.

The actual assignment to the variable had already been skipped
previously.

No functional change.
 1.881 14-Mar-2021  rillig make: separate parsing and evaluating for modifier '::='

No functional change.
 1.880 14-Mar-2021  rillig make: in parse-only mode, do not update the expression value in ':sh'

No functional change outside debug mode. The other variable modifiers
behave in the same way.
 1.879 14-Mar-2021  rillig make: do not evaluate the ':O' modifiers in parse-only mode

No functional change in practical usage. Theoretically this change can
be observed by looking at the generated random numbers for the ':Ox'
modifier, but the quality or exact sequence of these random numbers is
not guaranteed anyway.
 1.878 14-Mar-2021  rillig make: separate parsing and evaluating in the ':O' modifiers

No functional change.
 1.877 14-Mar-2021  rillig make: do not evaluate modifier ':[...]' in parse-only mode

In parse-only mode, variable expressions in the argument to that
modifier are not resolved. This led to the error message about the 'Bad
modifier' in var-eval-short.mk.
 1.876 14-Mar-2021  rillig make: do not evaluate modifiers ':M' and ':N' in parse-only mode

No functional change outside debug mode (-dv for ModifyWord_Match).
 1.875 14-Mar-2021  rillig make: do not return unevaluated 'else' part from the ':?' modifier

No functional change outside debug mode.
 1.874 14-Mar-2021  rillig make: do not evaluate ':gmtime' and ':localtime' in parse-only mode

No functional change.
 1.873 14-Mar-2021  rillig make: don't evaluate several simple modifiers in parse-only mode

This affects the modifiers ':E', ':H', ':P', ':Q', ':R', ':T', ':hash',
':q', ':range', ':tl', ':ts', ':tu', and ':u'. All these modifiers are
side-effect free.

Skipping the evaluation for these modifiers is purely for code
consistency and performance.

No functional change.
 1.872 14-Mar-2021  rillig make: skip strdup when parsing an irrelevant ':L' modifier

No functional change.
 1.871 14-Mar-2021  rillig make: skip memcpy when parsing but not evaluating ':D' and ':U'

No functional change, just a tiny bit of performance improvement,
probably not even measurable. Having the code nevertheless serves as a
copy-and-paste template for implementing other modifiers that might
perform more costly tasks.
 1.870 14-Mar-2021  rillig make: only evaluate the ':@' modifier if the result is actually used

The test 'var-eval-short' had produced the output 'unexpected' before,
on stderr. It had been generated by '${:Uword:@${FAIL}@expr@}' by
combining the following obscure "features" of make:

1. the ':@' modifier loops over the words of the variable. This
modifier is not really obscure, it still takes some time to get used
to it.

2. the ':@' modifier allows a '$' sign in the variable name, which is
useless in practice.

3. the ':@' modifier creates a temporary loop variable in the global
namespace. Luckily there are only few collisions with other
variable names since their naming conventions differ.

4. after looping over the words of the expression, the temporary global
loop variable is deleted, and at that point the '$' is expanded,
being interpreted as the start of a variable expression.

5. The ':@' modifier deleted the global variable even when it was
called in parse-only mode (without VARE_WANTRES).

When the modifier ':@' was initially added to make in var.c 1.40 from
2000-04-29, Var_Delete didn't expand the variable name. That feature
was added in var.c 1.174 from 2013-05-18, probably without thinking of
this very edge-casey combination of features.

This commit fixes item 5 from the above list. The other obscurities
remain for now.
 1.869 14-Mar-2021  rillig make: eliminate common subexpression in ApplyModifier_Remember

No functional change.
 1.868 14-Mar-2021  rillig make: merge duplicate code in ApplyModifier_Remember

This way, parsing and evaluating the modifier is only written once in
the code. The downside is that the variable name is allocated even if
VARE_WANTRES is not set, but since this modifier is so obscure and
seldom used this doesn't matter in practice.
 1.867 14-Mar-2021  rillig make: do not expand the variable name in the ':_' modifier

This edge case had been so obscure that even discovering this takes
quite some time and requires reading the source code of make.

The manual page doesn't document whether the variable name is expanded
or not, it doesn't even give an example. When this obscure modifier was
initially added in var.c 1.210 from 2017-01-30, Var_Set always expanded
the variable name once, and there was no way around it. Therefore this
expansion has probably been unintentional.
 1.866 14-Mar-2021  rillig make: only evaluate the ':_' modifier if the expression is needed

See var-eval-short.mk:46 for the test demonstrating this change.
Previously, the expression ${:Uword:_=VAR} was evaluated including all
its side effects even though it was in an irrelevant branch of the
condition.
 1.865 14-Mar-2021  rillig make: return failure in TryParseIntBase0 for empty string

No functional change since the only caller of TryParseIntBase0 already
handles all possible parse errors. Without this check, the code just
looked wrong though.
 1.864 14-Mar-2021  rillig make: separate parsing from evaluating for several modifiers

This aligns the implementation of these modifiers with the requirements
in the long comment starting with 'The ApplyModifier functions'.

No functional change.
 1.863 14-Mar-2021  rillig make: reduce indentation in ApplyModifier_SunShell

No functional change.
 1.862 14-Mar-2021  rillig make: separate parsing and evaluating for modifier ':u'

No functional change.
 1.861 14-Mar-2021  rillig make: separate parsing and evaluating for modifiers ':Q' and ':q'

No functional change.
 1.860 14-Mar-2021  rillig make: extract duplicate code for parsing ':S' and ':C'

No functional change.
 1.859 14-Mar-2021  rillig make: extract duplicate code for detecting a modifier's end

No functional change.
 1.858 14-Mar-2021  rillig make: document how error handling should be done correctly

Right now, when a variable expression cannot be parsed, the result of
calling Var_Subst is a string containing garbage, and no error is
reported. In addition, there are some silent errors that are not
reported at all. This combination makes it difficult to change the
error handling without introducing subtle breakage in some edge cases.

An example for garbage output is in varmod-subst-regex.mk, in target
mod-regex-compile-error.

No functional change.
 1.857 14-Mar-2021  rillig make: sort modifiers in ApplyModifier alphabetically

No functional change.
 1.856 14-Mar-2021  rillig make: fix wrong expression evaluation in -dL mode

The modifier ':C' now only compiles the regular expression if the result
of the expression is actually needed.

Several other modifiers have the same bug of evaluating the expression
in cases where this is not needed. It just doesn't show up because they
don't have any noticeable side effects, other than wasting CPU time.
This affects irrelevant conditions as well.
 1.855 23-Feb-2021  rillig make: reduce indentation in Var_Parse

The extra condition had been necessary before FStr made memory
management simpler.

The Coverity annotation got out-of-date when the parameter was converted
to FStr since that type is not allocated on the heap, only its inner
members are.

No functional change.
 1.854 23-Feb-2021  rillig make: restructure code in ParseVarname to target human readers

Breaking the loop once for depth == 0 and once for depth == 1 was
unnecessarily confusing, as was the nested 'if'. Start counting with 0
since there is no reason to start at 1.

Evaluating the common subexpression '*p == endc' is left as an exercise
to the compiler.

No functional change.
 1.853 23-Feb-2021  rillig make: improve error message for bad modifier in variable expression

The improvement is especially noteable for variable expressions based on
the empty variable, see moderrs.exp:103.
 1.852 23-Feb-2021  rillig make: improve error message for unclosed modifier

Replace "variable specification" with the more modern "variable
expression", reduce the number of parentheses, output more than a single
character for modifiers, make it obvious that in expressions such as
${:Serror}, the "" means a variable name.
 1.851 23-Feb-2021  rillig make: improve error message for unknown modifier

Back in 1995, the modifiers were all single-character, and it made sense
to print only the first character. Nowadays, with ':S', ':@var@...@',
'::=' and several others, a little more context is useful to see where
the exact error is. The actual modifier is still guessed, and the guess
may be wrong as soon as backslashes get involved, but it is still better
than before.
 1.850 23-Feb-2021  rillig make: remove redundant parameter of ApplySingleModifier
 1.849 23-Feb-2021  rillig make: explain non-obvious code around indirect variable modifiers

No functional change.
 1.848 23-Feb-2021  rillig make: comment on possible inconsistency in handling modifier ':sh'
 1.847 23-Feb-2021  rillig make: note inconsistent parsing behavior in modifier ':_='
 1.846 23-Feb-2021  rillig make: quote ':S' in error message about missing delimiter
 1.845 23-Feb-2021  rillig make: extract ParseModifier_Match into separate function

No functional change.
 1.844 23-Feb-2021  rillig make: add context information to error message about ':range' modifier
 1.843 23-Feb-2021  rillig make: fix local variable name for parsing arguments

The variable name 'arg' was misleading since after a successful
TryParseTime, it would no longer point to the argument of the variable
modifier, but to the _end_ of the argument. To reduce confusion, use p
instead, like everywhere else. This name is less specific, which is
still better than a wrong name.
 1.842 23-Feb-2021  rillig make: add quotes around variable name in an error message
 1.841 22-Feb-2021  rillig make: reorder code in ModifyWords

No functional change.
 1.840 22-Feb-2021  rillig make: use more common parameter order for VarSelectWords

No functional change.
 1.839 22-Feb-2021  rillig make: make ModifyWord_Subst a little easier to understand

Addition is easier than subtraction, and the expression 'word + wordLen'
obviously means 'the end of the word', which was not as easy to spot
before.

No functional change.
 1.838 22-Feb-2021  rillig make: remove freestanding freeIt variables

These variables all belong to a string variable. Connect them using
FStr, which reduces the number of variables to keep track of.

No functional change.
 1.837 22-Feb-2021  rillig make: remove boolean parameter and return type from VarFreeEnv

There was only a single case where this parameter was false. Inline
that case. That was the only case that needed the return value, so
remove that as well.
 1.836 22-Feb-2021  rillig make: add a few open questions to Var_SetWithFlags
 1.835 22-Feb-2021  rillig make: do not expand variable name from the command line twice in a row

When

1. there is a global variable containing a dollar in its expanded name
(very unlikely since there are lots of undocumented edge cases that
make variable names containing dollar signs fragile), and

2. after that (unlikely since that requires .MAKEFLAGS instead of a
normal command line)

3. there is a command line variable of the same name (again very
unlikely since that variable name would contain a dollar sign as
well in the expanded form),

the global variable would not be undefined as promised by the comments
since its name was expanded once more than intended.

Because of the two 'very unlikely' above, this edge case hopefully does
not affect any practical use cases.

Note that this is not about VAR.${param} (which has a dollar sign in its
unexpanded form), but about the case where param itself would expand to
a dollar sign, such as after param=$$.
 1.834 22-Feb-2021  rillig make: extract ExistsInCmdline from Var_SetWithFlags

No functional change.
 1.833 22-Feb-2021  rillig make: save a hash map lookup when defining a cmdline variable

This is a preparation to extract the code for exporting a cmdline
variable. That code differs in several details from the other code in
ExportVar.

No functional change.
 1.832 22-Feb-2021  rillig make: document interaction between cmdline and global variables

Make prevents global variables from being or becoming visible when a
command line variable of the same name is already defined.

There is a double safety net here. Even if the call to Var_DeleteExpand
were removed, there would be no noticeable effect, other than one less
line in the debug log.

No functional change.
 1.831 16-Feb-2021  rillig make: clean up VarAdd, Var_Delete, Var_ReexportVars

No functional change.
 1.830 16-Feb-2021  rillig make: clean up and update comments in var.c

During the refactorings of the last months, several comments have become
outdated, some are now redundant since the code is as clear as the
comment, and some code benefits from a bit of explanation.
 1.829 16-Feb-2021  rillig make: use bit-shift expressions for VarFlags constants

These are easier to read than hex constants.

There was no need to skip bits 2 and 3 (there were no constants for 0x04
and 0x08). Close this gap, to avoid confusing future readers. Keep the
relative order of the flags since that affects the debug output of -dv.

No functional change.
 1.828 16-Feb-2021  rillig make: rename constants for VarFlags

The old prefix was "VAR_" and this prefix is used for several other
constants as well, which made it ambiguous.
 1.827 16-Feb-2021  rillig make: sync comment about duplicated code with reality

There are only very few places in var.c that contain really duplicate
code anymore.

There is still lots of _almost_ duplicate, for example the code for
parsing variable modifiers. It differs subtly in behavior:

* The modifiers ':M' and ':N' use '$$' to escape a '$' sign, while
almost all other modifiers use '\$' for this purpose.

* The modifiers ':M', ':N', ':S', ':@' and several others parse
balanced parentheses and braces, allowing '(' to '}' to match.
The modifiers ':D' and ':U' only treat the end character special but
not the other 3 of '(){}'.

* When parsing the modifier ':S' but not evaluating it, the code for
nested variable expressions is parsed differently from when it is in
evaluation mode (VARE_WANTRES). This applies to an outer ':S'
modifier and an inner ':D' or ':M' modifier.

Since these inconsistencies affect the behavior in edge cases and some
users of make might depend on it, they cannot be fixed by
behavior-preserving refactorings.
 1.826 15-Feb-2021  rillig make: rename ExprDefined constants for debug logging
 1.825 15-Feb-2021  rillig make: rename ExprStatus to ExprDefined

The type describes the definedness of an expression, not a general
status, therefore the new name is more precise.

The constants are renamed as well since their prefix 'VES' does not
match the type name anymore, it was correct 3 days ago when the type was
still named VarExprStatus. The name VES_NONE was misleading since
'none' does not describe its actual effect. That name came from the
time when the status was a bit set, and 'none' simply meant 'none of the
bits are set'.

The names used in debug logging will be renamed in a follow-up commit,
to demonstrate that the changes in this commit indeed have no functional
change, especially not the change from '!=' to '==' in line 4304.

No functional change.
 1.824 15-Feb-2021  rillig make: update comments for Expr, amending the previous commit
 1.823 15-Feb-2021  rillig make: split parameters for evaluating variable expressions

The details of how variable expressions are evaluated is controlled by
several parameters: startc and endc differ for $(VAR) and ${VAR}, the
value of the expression can be interpreted as a single big word, and
when joining several words (such as with ':M' or ':S'), there may be a
custom word separator (defined with ':ts*').

The scope of half of these parameters is the whole variable expression,
the other half of the parameters are reset after each chain of indirect
modifiers. To make this distinction obvious in the code, extract Expr
from ApplyModifiersState. Previously, these details were hidden in how
parameters are passed and restored among ApplyModifiersIndirect and
ApplyModifiers.

The changes in the individual ApplyModifier functions are numerous but
straight-forward. They mostly replace 'st' with 'expr'.

The changes in ApplyModifiers and ApplyModifiersIndirect are more
subtle. The value of the expression is no longer passed around but is
stored in a fixed location, in Expr, which makes it easier to reason
about memory management.

The code in ApplyModifiers after 'cleanup' looks quite different but
preserves the existing behavior. Expr_SetValueRefer is nothing else
than the combination of FStr_Done followed by FStr_InitRefer. Storing
exprStatus back at the end was responsible for passing the definedness
of the expression after applying the indirect modifiers back to the
outer ApplyModifiersState. The same effect is now achieved by having
Expr.status with a wider scope.

No functional change.
 1.822 15-Feb-2021  rillig make: clean up code and comments around ModifyWord

In ModifyWords, there is no "passed string" anymore since that function
now directly operates on the expression value.

While here, improve the documentation of ModifyWordsCallback and rename
it to ModifyWordProc, focusing on its purpose instead of where it is
used.
 1.821 14-Feb-2021  rillig make: clean up memory management in evaluation of expressions

The condition "st->newValue.str != val" in ApplySingleModifier made the
memory management look more complicated than it really was. Freeing an
object based on another object's value is harder to understand than
necessary.

To fix this, the "current value" of the expression is now stored in
ApplyModifiersState, and it gets updated in-place by the ApplyModifier
functions. This reduces the number of parameters for the ApplyModifier
functions.

Accessing the current value of the expression is now more verbose than
before (st->value.str instead of the simple val). To compensate for
this verbosity, ApplyModifiersIndirect is now much easier to understand
since there is no extra "current value" floating around.

There is still room for improvement. In ApplyModifiers, passing an FStr
in and returning another (or possibly the same) makes it difficult to
understand memory management. Adding a separate Expr type that outlives
the ApplyModifiersState will make this easier, in a follow-up commit.
 1.820 14-Feb-2021  rillig make: reduce redundant code around ModifyWords

The result of ModifyWords had been passed to Expr_SetValueOwn in all
cases. The last argument to ModifyWords had always been st->sep.
 1.819 14-Feb-2021  rillig make: print error about failed shell command before overwriting variable

Memory management of the value of variable expressions is currently more
complicated than necessary. It is the responsibility of ApplyModifiers,
even though conceptually the value belongs to an expression, so it
should rather be in Expr. Right now, this is an alias for
ApplyModifiersState, but that will change soon.

When that is done, there will no longer be a "current value" and a "new
value", only a single "value" of an expression. At that point, before
Expr_SetValueOwn will overwrite the old value with the output of the
shell command, the error message needs to refer to the latter.
 1.818 14-Feb-2021  rillig make: clean up ValidShortVarname

The switch statement was hard to read, especially the "break" that
needed a comment since it was effectively a "continue".
 1.817 14-Feb-2021  rillig make: clean up ParseVarnameShort

Single-character short variable expressions such as $V neither have a
starting character nor an ending character. The only interesting
character forms the complete variable name.

No functional change.
 1.816 14-Feb-2021  rillig make: rename VarExprStatus to ExprStatus

It is only used in var.c so there is no need to use a prefix.
 1.815 14-Feb-2021  rillig make: revert part of previous commit

That code was not ready yet.
 1.814 14-Feb-2021  rillig make: update line numbers in expected test output

The documentation from the previous commit added a few lines.
 1.813 14-Feb-2021  rillig make: add functions for assigning the value of an expression

The plan is to have only the "current value" of the expression as a
member, not the "new value". To do this consistently and get the memory
management right, there must be a single place (or two) where the value
of the expression is updated.

No functional change.
 1.812 14-Feb-2021  rillig make: rename ApplyModifiersState_Define to Expr_Define

The type name ApplyModifiersState was only intended as a working draft,
its name is too long and its scope a little too narrow.

Applying the modifiers is the main part of evaluating a variable
expression, and the scope of that type will be extended to parsing the
name of the expression as well. This will hopefully reduce the number
of parameters, which is currently at 14.

No functional change.
 1.811 14-Feb-2021  rillig make: condense the code for parsing :S and :C modifiers

No functional change.
 1.810 14-Feb-2021  rillig make: rearrange some comments to make them easier to spot
 1.809 14-Feb-2021  rillig make: document purpose of stepping back in the parser

In ApplyModifier_Assign there was no need to compute the delimiter from
st->startc since that has already be done at that point.
 1.808 06-Feb-2021  rillig make: sync comment for ApplyModifier_Assign with reality

In compat mode, empty shell commands are handled correctly since at
least 1993.

In jobs mode, empty shell commands are handled correctly since at least
job.c 1.93 from 2005-06-16.

The only place where empty shell commands led to problems was in
Cmd_Exec, but that has nothing to do with the example from the comment.
See var-op-shell.mk for more details.
 1.807 05-Feb-2021  rillig make: improve documentation about variable scopes

In an experiment, I tried to separate the concepts of a GNode and a
variable scope. The global variables SCOPE_GLOBAL, SCOPE_INTERNAL and
SCOPE_CMDLINE are implemented as GNode even though they only need the
members 'name' and 'vars'. All their other members are unused.
Therefore it seemed natural to extract this part of the GNode into a
separate type called Scope.

The resulting code was harder to read though since it had split the
namespace of the functions into several parts that were not obviously
related: The Var_ functions, the Scope_ functions, and the short-cut
Global_ functions. Because of this, I threw away the experiment.

All that is left are a few updated comments.
 1.806 05-Feb-2021  rillig make: rename remaining ctx to scope

One less small inconsistency. Everywhere else, that variable had been
named ctxt, not ctx.
 1.805 05-Feb-2021  rillig make: in the Var_ functions, move the scope to the front

This change provides for a more natural reading order in the code.
Placing the scope first makes it immediately clear in which context the
remaining parameters are interpreted.

No functional change.
 1.804 05-Feb-2021  rillig make: add shortcut Global_Delete for deleting a global variable
 1.803 04-Feb-2021  rillig make: rename Var_ValueDirect to GNode_ValueDirect
 1.802 04-Feb-2021  rillig make: rename context and ctxt to scope

This continues the previous commit, in which VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE were renamed.

Renaming the variable 'ctxt' was trivial since that word is used nowhere
else. In the comments though, each occurrence of the word 'context' had
to be checked individually since the word 'context' was not only used
for referring to a variable scope. It is also used to distinguish
different situations where characters are escaped in a certain way
('parsing context') and in a few other expressions.
 1.801 04-Feb-2021  rillig make: rename some VAR constants to SCOPE

The word "context" does not fit perfectly to the variables that are
associate with a GNode, as the context is usually something from the
outside and the variables are more like properties inherent to the
GNode.

The term "global context" fits even less. Since the thing where
variables are looked up is commonly named a scope, use that term
instead.

This commit only renames the global variables VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE, plus a few very closely related comments. These are:

GNode.vars (because of line breaks)
GNode_Free (dito)
varname-make_print_var_on_error.mk
varname-make_print_var_on_error-jobs.mk

The debug message in Var_Stats is left as-is since there is no unit test
for it yet.

The other renamings (variable names "context", "ctxt", as well as
further comments) will be done in a follow-up commit.
 1.800 04-Feb-2021  rillig make: merge SetVar into Var_SetWithFlags

No functional change.
 1.799 04-Feb-2021  rillig make: rename Var_SetWithFlags to Var_SetExpandWithFlags

Add back Var_SetWithFlags for the one call that doesn't need to expand
the name.

Now one of the flags is encoded in the function name while the others
are encoded in VarSetFlags. This is inconsistent. Maybe there is a
better way to model the different variants of setting a variable.
 1.798 04-Feb-2021  rillig make: rename Var_Set to Var_SetExpand

After doing the textual renaming across all files, I added a new
function Var_Set that does not expand the variable name. I then undid
the renaming for all calls where the variable name cannot ever contain a
dollar sign. I omitted the word "Expand" from the textual references in
the unit tests and in the debug logging messages since the focus is
usually on the "Set" part, not on the "Expand".

No functional change.
 1.797 03-Feb-2021  rillig make: rename Var_Delete to Var_DeleteExpand, Var_DeleteVar to Var_Delete

The function names now follow the naming scheme from the other functions
that handle variables.

There are several calls that remain syntactically unchanged but that
omit the call to strchr('$') now. Since all these calls use constant
variable names, there is no functional change.
 1.796 03-Feb-2021  rillig make: split Var_Exists into plain Var_Exists and Var_ExistsExpand

Most previous calls to Var_Exists use constant variable names. Only the
two calls in parse.c need to expand the variable name.

It may be a good idea to expand the variable name once in VarAssign_Eval
instead of repeating the expansion in each of its special cases.

No functional change.
 1.795 03-Feb-2021  rillig make: replace Global_AppendExpand with Global_Append

All callers with a variable name that is guaranteed to not contain a
dollar sign have been converted to call Global_Append instead of the
previous Global_AppendExpand. After that, Global_AppendExpand was
unused, therefore it was effectively just renamed.
 1.794 03-Feb-2021  rillig make: split Var_Append into Var_Append and Var_AppendExpand

The plain Var_Append now does not expand the variable name anymore. It
is used in situations where the variable name is known to not contain a
dollar sign.

This is a preparation for adding Global_Append, corresponding to
Global_AppendExpand.
 1.793 03-Feb-2021  rillig make: fix double expansion when appending to a new variable
 1.792 03-Feb-2021  rillig make: replace Global_SetExpand with Global_Set for constant names
 1.791 03-Feb-2021  rillig make: use shortcut functions Global_SetExpand and Global_AppendExpand

There are many places where global variables are set or appended to. To
reduce clutter and code size, encode the VAR_GLOBAL in the function
name.

The word Expand in the function names says that the variable name is
expanded. In most of the cases, this is not necessary, but there are no
corresponding functions Global_Set or Global_Append yet.

Encoding the information whether the name is expanded or not in the
function name will make inconsistencies obvious in future manual code
reviews. Letting the compiler check this by using different types for
unexpanded and expanded variable names is probably not worth the effort.
There are still a few bugs to be fixed, such as in SetVar, which expands
the variable name twice in a row.
 1.790 02-Feb-2021  rillig make: remove unused INTERNAL flag

It had been used for cached_realpaths, until this variable had its type
changed from GNode to HashTable in main.c 1.469 from 2020-11-14.
 1.789 02-Feb-2021  rillig make: replace VarExprFlags with VarExprStatus

The combination of !VEF_UNDEF && VEF_DEF was not possible, which made it
rather strange to model this state as a bit set.

The only functional change is the renamed constants in the debug output.

Using ENUM_VALUE_RTTI_2 felt like overengineering since it's harder to
understand than a simple array of names.
 1.788 02-Feb-2021  rillig make: replace enum bit-set with bit-field

No functional change.

The generated code from GCC 5.5 is very similar. On x86_64, memory
access is no longer in 32-bit units but in 8-bit units since only the
first few bits are actually used. The bit patterns are the same as
before, so if there is any difference in performance, GCC should have
chosen the more efficient variant all along.

In a previous experiment, the code size increased a lot, surprisingly.
 1.787 01-Feb-2021  rillig make: replace pre-increment with post-increment or simple addition

The rest of the code already prefers post-increment if there is no
actual difference.
 1.786 30-Jan-2021  rillig make(1): inline Buf_Len
 1.785 30-Jan-2021  rillig make(1): inline Buf_GetAll
 1.784 30-Jan-2021  rillig make(1): split Buf_Destroy into Buf_Done and Buf_DoneData

In all cases except one, the boolean argument to Buf_Destroy was
constant. Removing that argument by splitting the function into two
separate functions makes the intention clearer on the call site. It
also removes the possibility for using the return value of Buf_Done,
which would have made no sense.

The function Buf_Done now pairs with Buf_Init, just as in HashTable and
Lst.

Even though Buf_Done is essentially a no-op, it is kept as a function,
both for symmetry with Buf_Init and for clearing the Buffer members
after use (this will be done only in CLEANUP mode, in a follow-up
commit).
 1.783 30-Jan-2021  rillig make(1): reduce boilerplate for printing bit sets in debug mode

No functional change.
 1.782 16-Jan-2021  rillig make(1): fix a few inconsistencies for lint's strict bool mode
 1.781 10-Jan-2021  rillig make(1): make a few more bool expressions more precise

The previous version of lint(1) from a few hours ago didn't catch all
occurrences. And even the current one doesn't catch everything.
Function arguments and return types still need some work. The "return
quietly" from shouldDieQuietly still implicitly converts from int to
_Bool.

No functional change.
 1.780 10-Jan-2021  rillig make(1): consistently use boolean expressions in conditions

Most of the make code already followed the style of explicitly writing
(ptr != NULL) instead of the shorter (ptr) in conditions.

The remaining 50 instances have been found by an experimental,
unpublished check in lint(1) that treats bool expressions as
incompatible to any other scalar type, just as in Java, C#, Pascal and
several other languages.

The only unsafe operation on Boolean that is left over is (flags &
FLAG), for an enum implementing a bit set. If Boolean is an ordinary
integer type (the default), some high bits may get lost. But if Boolean
is the same as _Bool (by compiling with -DUSE_C99_BOOLEAN), C99 6.3.1.2
defines that a conversion from any scalar to the type _Bool acts as a
comparison to 0, which cannot lose any bits.
 1.779 09-Jan-2021  rillig make(1): fix lint warnings
 1.778 30-Dec-2020  rillig make(1): format multi-line comments
 1.777 29-Dec-2020  rillig make(1): clean up code in extracted ExportVar functions
 1.776 29-Dec-2020  rillig make(1): split ExportVar into separate functions
 1.775 29-Dec-2020  rillig make(1): rename local variables in Var_ReexportVars
 1.774 28-Dec-2020  rillig make(1): replace global preserveUndefined with VARE_KEEP_UNDEF

Controlling the expansion of variable expressions using a global
variable and a VARE flag was inconsistent.

Converting the global variable into a flag had to prerequisites:

1. The unintended duplicate variable assignment had to be fixed, as
done in parse.c 1.520 from 2020-12-27. Without this fix, it would have
been necessary to add more flags to Var_Exists and Var_SetWithFlags, and
this would have become too complex.

2. There had to be a unit test demonstrating that VARE_KEEP_DOLLAR only
applies to the top-level expression and is not passed to the
subexpressions, while VARE_KEEP_UNDEF applies to all subexpressions as
well. This test is in var-op-expand.mk 1.10 from 2020-12-28, at least
for the ':@word@' modifier. In ParseModifierPartSubst, VARE_KEEP_UNDEF
is not passed down either, in the same way.
 1.773 27-Dec-2020  rillig make(1): remove dead code from ApplyModifiersIndirect

At that point, the expression can never be varUndefined. At the
beginning of ParseVarnameLong, the expression is initialized to a simple
empty string, and that string is only ever converted to varUndefined at
the very end of Var_Parse.
 1.772 27-Dec-2020  rillig make(1): remove outdated comment about string comparisons

Back in 1993, the variables in a context were stored in a linked list.
Searching such a list indeed required literally thousands of calls to
strcmp. In make.h 1.22 from 1999-09-15, the linked list was replaced
with a hash table, requiring much fewer string comparisons. Since then,
the rationale doesn't apply anymore.
 1.771 27-Dec-2020  rillig make(1): remove unnecessary VPR_ERR_SILENT
 1.770 27-Dec-2020  rillig make(1): do not inspect output variables in ParseVarnameShort
 1.769 27-Dec-2020  rillig make(1): move error handling code out of UndefinedShortVarValue
 1.768 27-Dec-2020  rillig make(1): split Var_Subst into easily understandable functions

Extracting the character-level details makes the essence of Var_Subst
visible in the code, which is to iterate over the given text, handling a
few types of tokens.
 1.767 27-Dec-2020  rillig make(1): clean up VarParseResult constants

The many constants were invented because at that time I didn't quite
understand the actual outcomes of Var_Parse that need to be
distinguished. There are only a few:

(1) Errors, whether they are parse errors, or evaluation errors or
undefined variables. The old constants VPR_PARSE_MSG and
VPR_UNDEF_MSG are merged into VPR_ERR.

(2) Undefined expressions in a situation in which they are allowed.
Previously the documentation for VPR_UNDEF_SILENT talked about
undefined expressions in situations where they were not allowed.
That case is fully covered by VPR_ERR instead.

(3) Errors that are silently ignored. These are probably bugs.

(4) Everything went fine, the expression has a defined value.
 1.766 27-Dec-2020  rillig make(1): remove unnecessary VPR_UNKNOWN for error handling

There is no sensible way for a caller of Var_Parse to deal with an error
state of "maybe successful, maybe not", therefore remove the constant
for it.
 1.765 27-Dec-2020  rillig make(1): align names of VarExportMode with the directives
 1.764 23-Dec-2020  rillig make(1): rename CmdOpts.lint to strict

When running lint(1) on the code, it defines the preprocessor macro
"lint" to 1, which generated a syntax error in the declaration "Boolean
lint", as that became "Boolean 1".
 1.763 23-Dec-2020  rillig make(1): fix memory leak in Var_Undef (since 2020-12-22)
 1.762 22-Dec-2020  rillig make(1): allow .undef to undefine multiple variables at once

Since make doesn't support variable names containing spaces, this edge
case is not enough reason to stop this feature. Having multiple
variable names as arguments nicely aligns with other directives such as
.for and .export.
 1.761 21-Dec-2020  rillig make(1): remove excess newline from parse errors (since 2020-11-01)

For the modifiers :gmtime and :localtime, the excess newline had been
added in var.c 1.631 from 2020-10-31 21:40:20.

For the modifiers :range and :ts, the excess newline had been added in
var.c 1.635 from 2020-11-01 14:36:25.
 1.760 21-Dec-2020  rillig make(1): remove redundant parameters from ParseModifierPart
 1.759 21-Dec-2020  rillig make(1): save a few memory allocations in variable expressions
 1.758 21-Dec-2020  rillig make(1): switch memory handling from MFStr to FStr

This makes all intermediate strings constant. For this simple
search-and-replace refactoring, all intermediate locations where the
"current value of the expression" was stored had to be of the type
MFStr.

Using FStr instead of MFStr allows to save a few memory allocations,
which will be done in the follow-up commits.
 1.757 21-Dec-2020  rillig make(1): clean up memory management for expanding variable expressions

Previously, memory management had been split among several variables.
The general idea was very simple though. The current value of the
expression needs to be kept in memory, and each modifier either keeps
that value or replaces it with its own newly allocated result, or
var_Error or varUndefined.

Using MFStr, it does not matter anymore that var_Error and varUndefined
are statically allocated since these are assigned using MFStr_InitRefer.

The complexity of the implementation is now closer to the actual
complexity. Most probably the code can be simplified even more.
 1.756 20-Dec-2020  rillig make(1): use FStr for ApplyModifiersState.newVal

Memory management is still complicated in this area. To clean this up,
the previous value of the expression needs to be converted to an MFStr
first, and later to an FStr.
 1.755 20-Dec-2020  rillig make(1): remove redundant assignment in ApplyModifier_SysV
 1.754 20-Dec-2020  rillig make(1): error out on unknown variable modifiers at parse time

Before, make printed an "error message" that did not include the word
error and thus was not easily identified as such. This "error message"
also did not influence the exit status in the default mode but only in
-dL mode. The error message also didn't include any line number
information and was thus rude.
 1.753 20-Dec-2020  rillig make(1): remove wrong error message for indirect modifier in lint mode
 1.752 20-Dec-2020  rillig make(1): document that indirect modifiers fall back to SysV modifiers
 1.751 20-Dec-2020  rillig make(1): remove redundant const declarations for parameters
 1.750 20-Dec-2020  rillig make(1): extract ApplySingleModifier from ApplyModifiers
 1.749 20-Dec-2020  rillig make(1): turn ApplyModifiersState.val into a local variable

This reduces the scope and makes it more obvious at which places this
variable can be changed and how the memory management is done.
 1.748 20-Dec-2020  rillig make(1): use FStr for memory management in Var_SetWithFlags
 1.747 20-Dec-2020  rillig make(1): extract SetVar from Var_SetWithFlags

SetVar contains the part that is not concerned about memory management
and expansion of the variable name.
 1.746 20-Dec-2020  rillig make(1): fix memory leak in Var_Delete (since yesterday)

The memory leak had been introduced in var.c 1.736 from 2020-12-19
20:47:24.
 1.745 20-Dec-2020  rillig make(1): change return type of Var_Value to FStr
 1.744 20-Dec-2020  rillig make(1): use FStr in VarNew
 1.743 20-Dec-2020  rillig make(1): return FStr from Var_Parse

This reduces the number of variable declarations at the call sites.
 1.742 20-Dec-2020  rillig make(1): export FStr and MFStr

These types are a replacement for the pattern "var + var_freeIt" that
enforces these two variables to be updated together.
 1.741 20-Dec-2020  rillig make(1): document memory handling in ApplyModifiers
 1.740 20-Dec-2020  rillig make(1): replace freeIt with FStr in EvalUndefined

Previously, the parameter out_freeIt was not guaranteed to be
initialized in every case, at least when looking only at EvalUndefined.
This contradicted the variable name.

Replace the two parameters with a single FStr to ensure that these
variables are always initialized together.
 1.739 20-Dec-2020  rillig make(1): replace FStr_Assign with separate initialization functions

In GetVarnamesToUnexport, there is no need to free the local FStr since
the only place where it is assigned an allocated string is at the very
end.

Having separate functions for the two main use cases of a possibly
allocated string makes the calling code simpler. This is a preparatory
commit for making the memory allocation in ApplyModifiers easier to
understand.
 1.738 20-Dec-2020  rillig make(1): extract string functions from ApplyModifier_To
 1.737 19-Dec-2020  rillig make(1): error out if .undef has not exactly 1 argument
 1.736 19-Dec-2020  rillig make(1): extract Var_DeleteVar from Var_Delete
 1.735 19-Dec-2020  rillig make(1): extract Var_Undef from ParseDirective
 1.734 13-Dec-2020  rillig make(1): replace %zu with %u in printf calls

This is needed to compile bmake with GCC 2.8.1 on SunOS 5.9.

To support ancient systems like this, the whole code of usr.bin/make is
supposed to use only ISO C90 features, except for filemon, which is not
used on these systems.
 1.733 13-Dec-2020  rillig make(1): add str_basename to reduce duplicate code

The function basename from POSIX has a few unfortunate properties, it is
allowed to return a pointer to static memory. This is too unreliable,
therefore this trivial own implementation.
 1.732 13-Dec-2020  rillig make(1): remove dead code from GetVarnamesToUnexport

Now that the parsing of the directives is unified and strict, there is
no need anymore for the dispatched functions to check for unknown
directives. These functions don't even get the information to decide
that since this decision is already done.
 1.731 13-Dec-2020  rillig make(1): clean up Var_Export
 1.730 13-Dec-2020  rillig make(1): replace bitset VarExportFlags with enum VarExportMode

The previous flags were not combined at all.
 1.729 12-Dec-2020  rillig make(1): eliminate boolean argument of Var_Export
 1.728 12-Dec-2020  rillig make(1): extract ExportVarsExpand from Var_Export
 1.727 12-Dec-2020  rillig make(1): fix undefined behavior when exporting ${:U }
 1.726 12-Dec-2020  rillig make(1): extract ExportVars from Var_Export
 1.725 12-Dec-2020  rillig make(1): rename Var_ExportVars to Var_ReexportVars
 1.724 12-Dec-2020  rillig make(1): error out on misspelled .export directives
 1.723 12-Dec-2020  rillig make(1): error out on misspelled .unexport-env
 1.722 12-Dec-2020  rillig make(1): inline local variable in ApplyModifiersIndirect
 1.721 12-Dec-2020  rillig make(1): in ApplyModifiersIndirect, rename local variable

In other places, the parsing position is abbreviated as pp as well.
 1.720 12-Dec-2020  rillig make(1): remove const from function parameters

These have been left-overs from refactoring, when these pieces were
extracted to separate functions.
 1.719 07-Dec-2020  rillig make(1): rename Var_Export1 to ExportVar

Since Var_Export1 is neither exported by the module nor does it belong
to the Var type, the previous function name was misleading. The 1 in
the function name was not as expressive as possible. The new name
aligns nicely with UnexportVar, which is a very young name as well.
 1.718 06-Dec-2020  rillig make(1): remove comment decoration
 1.717 06-Dec-2020  rillig make(1): move CleanEnv to UnexportVars

It clearly didn't belong in the GetVarnamesToUnexport part of the code.
 1.716 06-Dec-2020  rillig make(1): extract UnexportVars from Var_UnExport
 1.715 06-Dec-2020  rillig make(1): clean up GetVarnamesToUnexport
 1.714 06-Dec-2020  rillig make(1): extract GetVarnamesToUnexport from Var_UnExport
 1.713 06-Dec-2020  rillig make(1): replace pointer comparisons with enum

Keeping track of what it means if varname.str == str is not as
expressive as declaring what exactly to unexport.
 1.712 06-Dec-2020  rillig make(1): use FStr in Var_UnExport
 1.711 06-Dec-2020  rillig make(1): add FStr to var.c to make memory handling simpler

The pattern of having a variable and a corresponding freeIt variable
appears over and over again in make, so cast it into a struct.
 1.710 06-Dec-2020  rillig make(1): move type definitions in var.c to the top
 1.709 06-Dec-2020  rillig make(1): extract FreeEnvVar from Var_Parse
 1.708 06-Dec-2020  rillig make(1): inline macros for debug logging

No changes to the resulting binary, except for the line numbers in
assertions.
 1.707 05-Dec-2020  rillig make(1): define constants for enum zero-values
 1.706 05-Dec-2020  rillig make(1): remove redundant assignments
 1.705 05-Dec-2020  rillig make(1): extract ShuffleStrings from ApplyModifier_Order
 1.704 05-Dec-2020  rillig make(1): indent remaining code of var.c with tabs instead of spaces
 1.703 05-Dec-2020  rillig make(1): indent large parts of var.c with tabs instead of spaces

The few remaining functions need to be cleaned up before being indented
further, to reduce the overall indentation.
 1.702 05-Dec-2020  rillig make(1): improve explanation of tests for the SysV modifier
 1.701 04-Dec-2020  rillig make(1): extract UnexportEnv from Var_UnExport
 1.700 04-Dec-2020  rillig make(1): extract UnexportVar from Var_UnExport
 1.699 28-Nov-2020  rillig make(1): improve type of local variable in Var_Export1
 1.698 28-Nov-2020  rillig make(1): rename local variable in ModifyWord_Root

The name 'dot' conflicted with the global variable from dir.c when make
was compiled in all-in-one mode.
 1.697 28-Nov-2020  rillig make(1): rename local variable in ModifyWord_Suffix

It conflicted with 'dot' from dir.c.
 1.696 24-Nov-2020  rillig make(1): rename local variable in ApplyModifier_Assign
 1.695 23-Nov-2020  rillig make(1): use comparisons in boolean expressions

The generated code stays exactly the same.
 1.694 23-Nov-2020  rillig make(1): use properly typed comparisons in boolean contexts
 1.693 21-Nov-2020  rillig make(1): rename GNode.context to vars

Especially in the variables module, the expression 'ctxt->context' looked
redundant. Having a GNode as a context sounds ok, but a context of a
context just doesn't make sense.
 1.692 21-Nov-2020  rillig make(1): clean up freeing of environment variables in Var_Parse

The previous code with the extra boolean variable was a brain-twister
since the responsibility of freeing the memory was distributed over 3
different functions.
 1.691 21-Nov-2020  rillig make(1): clean up parameter order in EvalUndefined
 1.690 21-Nov-2020  rillig make(1): rename local variable in Var_Subst
 1.689 17-Nov-2020  rillig make(1): fix error message of failed :!cmd! modifier (since 2000-04-29)
 1.688 16-Nov-2020  rillig make(1): rename Targ_NewGN to GNode_New

This function is a classical constructor function, and if it weren't for
CLEANUP mode, it would have no dependencies on anything else besides the
memory allocator. Therefore it doesn't really matter which module
defines this function, and there is no need for the "Targ" to be part of
the function name.
 1.687 15-Nov-2020  rillig make(1): add remarks to var.c and the test varmod-match
 1.686 15-Nov-2020  rillig make(1): rename ApplyModifiersState.v to var
 1.685 14-Nov-2020  rillig make(1): replace a few HashTable_CreateEntry with HashTable_Set

Instead of HashTable_CreateEntry and HashEntry_Set, several places just
need the HashEntry for storing a value in it. This makes the calling
code simpler to understand.

These parts of the code are already hard enough to understand since they
are about memory management and aliasing. Having a too detailed API for
the HashTable only distracts from these topics.
 1.684 10-Nov-2020  rillig make(1): use consistent definition for MAKE_INLINE
 1.683 08-Nov-2020  rillig make(1): move lint option away from the debug flags

The lint option affects much more than a typical debug flag. Not only
does it produce additional diagnostics, it also changes the control flow
and fixes the traditional error handling in a few places.

No functional change.
 1.682 08-Nov-2020  rillig make(1): clean up code related to VarEvalFlags

Mention VARE_WANTRES before VARE_UNDEFERR since the latter depends on
the former.

In ApplyModifier_Assign, VARE_KEEP_DOLLAR doesn't have to be removed
from eflags since ParseModifierPart does this already.

In EvalUndefined, testing for VARE_WANTRES is redundant if VARE_UNDEFERR
is already set.
 1.681 08-Nov-2020  rillig make(1): clean up VarEvalFlags in the calls to Var_Parse and Var_Subst

There are only 3 flags, and some combinations don't even make sense.

VARE_UNDEFERR only makes sense if combined with VARE_WANTRES. If the
latter is not set, the variable expressions are only parsed, without
asking whether they are defined or not. Therefore, VARE_UNDEFERR cannot
have any effect in that case.

VARE_KEEP_DOLLAR is actively ignored by ParseModifierPart. In cases
where VARE_WANTRES is not set, this means that VARE_NONE can be passed,
which is easier to grasp than any bitset operations. This also gets rid
of a few type casts from enum to unsigned int that were necessary to
pass WARNS=6.
 1.680 08-Nov-2020  rillig make(1): rename local variable in VarSubstNested
 1.679 08-Nov-2020  rillig make(1): reorder branches in Var_Subst

This way, '$$' is handled first, followed by '$', followed by everything
else. This is easier to follow than first '$$' then not '$' and finally
'$'.
 1.678 08-Nov-2020  rillig make(1): extract VarSubstNested from Var_Subst

Each of these functions now fits on a moderately large screen.
 1.677 08-Nov-2020  rillig make(1): rename VARE_ASSIGN to VARE_KEEP_DOLLAR

The other flags in VarEvalFlags already describe their effects, not the
place where they are used. It's more important to know the effect.

Only a single unit test had to be adjusted. This probably means that
there are too few tests where the special effects of VARE_KEEP_DOLLAR
come into play. It could also mean that the effects are so simple and
obvious that they don't need any debug log, but that's not the case.
 1.676 08-Nov-2020  rillig make(1): use strict typing in conditions of the form !var
 1.675 07-Nov-2020  rillig make(1): fix type mismatch between int and VarExportFlags
 1.674 07-Nov-2020  rillig make(1): fix type mismatch between int and VarSetFlags
 1.673 07-Nov-2020  rillig make(1): make API of Buf_Init simpler

In most cases, the caller doesn't want to specify the exact number of
preallocated bytes.
 1.672 07-Nov-2020  rillig make(1): clean up code stylistically

* Replace character literal 0 with '\0'.
* Replace pointer literal 0 with NULL.
* Remove redundant parentheses.
* Parentheses in multi-line conditions are not redundant at the
beginning of a line.
* Replace a few !ptr with ptr == NULL.
* Replace a few ptr with ptr != NULL.
* Replace (expr & mask) == 0 with !(expr & mask).
* Remove redundant braces for blocks in cases where the generated code
stays the same. (Assertions further down in the code would get
different line numbers.)
* Rename parameters in CondParser_String to reflect the data flow.
* Replace #ifdef notdef with #if 0.

The generated code stays exactly the same, at least with GCC 5.5.0 on
NetBSD 8.0 amd64 using the default configuration.
 1.671 07-Nov-2020  rillig make(1): rename Var_Set_with_flags to Var_SetWithFlags

Now that the function is exported from the var module, it should stick
to the naming conventions for public functions.
 1.670 07-Nov-2020  rillig make(1): rename VarSet_Flags to VarSetFlags

Most other types don't have an underscore as well.
 1.669 06-Nov-2020  rillig make(1): rename getBoolean and s2Boolean
 1.668 06-Nov-2020  rillig make(1): rename local variable in Var_Parse
 1.667 06-Nov-2020  rillig make(1): format source code of a few functions in var.c
 1.666 05-Nov-2020  rillig make(1): update and clean up documentation of Var_Parse
 1.665 05-Nov-2020  rillig make(1): fix parameter name in ApplyModifiersIndirect and ApplyModifiers

The variable must be properly initialized before these functions are
called.
 1.664 05-Nov-2020  rillig make(1): clean up ParseVarnameLong

A parameter named pp is usually used as the parsing position, which is
updated upon successful return. Not so in ParseVarnameLong, where it
was updated in the unsuccessful branch only.

To avoid confusion, rename it to out_FALSE_pp, which is a longer name
but expresses more clearly what actually happens.
 1.663 05-Nov-2020  rillig make(1): extract EvalUndefined from ParseVarnameLong
 1.662 05-Nov-2020  rillig make(1): extract FindLocalLegacyVar from Var_Parse
 1.661 05-Nov-2020  rillig make(1): replace '(' and ')' with neutral '\0' in Var_Parse

The only possible values for extramodifiers are "H:" and "T:", therefore
parsing is independent of startc and endc. Use '\0' instead of '(' and
')' to remove any possible confusion about how '{' and '}' would be
handled.
 1.660 05-Nov-2020  rillig make(1): clean up documentation for Var_Subst
 1.659 05-Nov-2020  rillig make(1): remove redundant parentheses from sizeof operator

The parentheses are only needed if the argument is a type, not an
expression.
 1.658 05-Nov-2020  rillig make(1): remove wrong comment from Var_Subst

The error handling in variable expressions is inconsistent. Some errors
are detected, most aren't. In particular, the error message for
undefined variables is _not_ issued on undefined variables but instead
on parse errors.
 1.657 04-Nov-2020  rillig make(1): negate discardUndefined to preserveUndefined
 1.656 04-Nov-2020  rillig make(1): add test for undefined variables in command line arguments

The variable discardUndefined has an implicit negation in its name,
which makes it hard to understand. Plus, most of the time it is true.
It's better to have a flag that is false most of the time and has a
positive name.

On the first attempt of inverting that variable, I stumbled upon
MainParseArgs, which initially leaves discardUndefined == FALSE, and
after handling the dashed options, sets it to TRUE. This would make a
difference when more command line arguments would be added later via the
.MAKEFLAGS special target.

Upon further inspection, the only place where discardUndefined is used
is in VarAssign_EvalSubst in parse.c, and that place is not reachable
from any of the dashed options. Therefore, discardUndefined could
already be set at the very beginning of MainParseArgs or even when
initializing the global variable itself, without any observable
difference.

Not even the ::= variable modifier could do anything about this since it
is not reachable from the dashed command line options as well, and in
addition, it expands its right-hand side in any case, always discarding
undefined variables. Oh, these little inconsistencies everywhere.
 1.655 04-Nov-2020  rillig make(1): rename oldVars to discardUndefined

While here, moved all the documentation about this variable into a
single place.
 1.654 04-Nov-2020  rillig make(1): remove redundant condition from ApplyModifiersIndirect

Whenever varUndefined is returned from another function, that is only
done if eflags does not contain VARE_UNDEFERR. Therefore, testing for
that flag is unnecessary.
 1.653 04-Nov-2020  rillig make(1): replace emptyString with allocated empty string

Special-casing this variable only made the code more complicated.
Furthermore, it is not related to error handling in any way and
therefore distracted the reader from this topic.
 1.652 02-Nov-2020  rillig make(1): fix error handling on parse errors in variable expressions

This change doesn't change any of the unit tests since the error
handling code is not yet complete, see the many "handle errors" in the
code. Nevertheless, the "out_FALSE_res = VPR_PARSE_MSG" was wrong since
the error message was only printed in lint mode, not in default mode.
 1.651 02-Nov-2020  rillig make(1): improve local variable name in ParseVarname
 1.650 02-Nov-2020  rillig make(1): document that skipping a modifier on parse errors is risky
 1.649 02-Nov-2020  rillig make(1): error out on unclosed expressions after the colon
 1.648 02-Nov-2020  rillig make(1): remove word "Ptr" from variable names

Whether or not a variable is a pointer is obvious from the context.
Since the introduction of function prototypes in C90, this information
is checked by the compiler and no longer needs to be encoded in the
variable names.
 1.647 02-Nov-2020  rillig make(1): fix wording of a comment in var.c

The "why again" could be easily misunderstood, it was ambiguous.
 1.646 02-Nov-2020  rillig make(1): add a comment where to fix the STOP/STORE test from varmod.mk
 1.645 02-Nov-2020  rillig make(1): format code in ApplyModifiersIndirect and ApplyModifiers
 1.644 02-Nov-2020  rillig make(1): merge variables p and nested_p in ApplyModifiersIndirect

When the code was still in ApplyModifiers, the variable nested_p was
necessary to distinguish the parsing position in the nested modifier
from the parsing position of the main expression.
 1.643 02-Nov-2020  rillig make(1): rename rval to mods in ApplyModifiersIndirect
 1.642 02-Nov-2020  rillig make(1): inline and rename variables in ApplyModifiersIndirect
 1.641 01-Nov-2020  rillig make(1): extract ApplyModifiersIndirect from ApplyModifiers
 1.640 01-Nov-2020  rillig make(1): rename local variable in ApplyModifiers
 1.639 01-Nov-2020  rillig make(1): rename local variables in ApplyModifier_SysV
 1.638 01-Nov-2020  rillig make(1): reduce number of nested parentheses in ApplyModifier_Assign
 1.637 01-Nov-2020  rillig make(1): revert unintended change from previous commit
 1.636 01-Nov-2020  rillig make(1): fix indentation of source code
 1.635 01-Nov-2020  rillig make(1): treat malformed :range, :ts and :[...] as errors

Before, integer overflow in the :[1..2] modifier had not been detected,
and the actual behavior varied between ILP64 and LP64I32 machines.

Before, the :ts modifier accepted character literals like \012345 and
\x1F600, which don't fit in a single character and were thus truncated.

Before, the :range modifier issued an "Unknown modifier" error message
for :range=x, which was not quite correct. The error message in this
case is now "Invalid number".
 1.634 01-Nov-2020  rillig make(1): add tests for the variable modifiers :[words] and :range
 1.633 01-Nov-2020  rillig make(1): clean up comments in ApplyModifier_Words
 1.632 31-Oct-2020  rillig make(1): rename parameter of Var_Value
 1.631 31-Oct-2020  rillig make(1): make parsing of the :gmtime and :localtime modifiers stricter

These variable modifiers accept an optional timestamp in seconds, to
select which date to print. This feature is only used very rarely. The
NetBSD build doesn't use it at all, and the FreeBSD build mainly uses
the plain modifiers :gmtime and :localtime, but not their optional
argument :gmtime=1500000000.

Therefore, this change is not going to affect many builds. Those that
are indeed affected had been wrong all the time anyway.

At parse time, these errors stop the build, as intended. After that,
when the actual shell commands of the targets are expanded and run,
these errors don't stop anything, the build just continues as if nothing
had happened. This is a general problem with Var_Parse, see the many
"handle errors" markers in the code. Another problem is that on parse
errors, parsing continues and spits out spurious strings of the form
"mtime" and "ocaltime". This as well is a general problem with error
handling in make.

ok sjg
 1.630 31-Oct-2020  rillig make(1): format #include directives consistently
 1.629 31-Oct-2020  rillig make(1): rename ismeta to is_shell_metachar

The old name was too broad.
 1.628 31-Oct-2020  rillig make(1): remove debug logging for the :Q variable modifier

The same information is already logged in LogAfterApply.
 1.627 31-Oct-2020  rillig make(1): fix local variable names in ParseModifierPart
 1.626 31-Oct-2020  rillig make(1): rewrite VarIsDynamic to VarnameIsDynamic

The condition for the context is the same for both short and long names,
therefore move that condition to the only caller.

Clean up the comment and move its parts to the appropriate places. The
"with the dollar sign escaped" part had been wrong already in 1993, and
it didn't get better over time.
 1.625 31-Oct-2020  rillig make(1): rename local variable freePtr in Var_Parse
 1.624 31-Oct-2020  rillig make(1): use consistent parameter order in varname parsing functions
 1.623 31-Oct-2020  rillig make(1): extract ParseVarnameLong from Var_Parse
 1.622 31-Oct-2020  rillig make(1): extract ParseVarnameShort from Var_Parse

With its more than 200 lines, the latter has too much code to be read
easily.
 1.621 31-Oct-2020  rillig make(1): fix type of ParseModifierPart parameter delim
 1.620 31-Oct-2020  rillig make(1): extract IsEscapedModifierPart from ParseModifierPart
 1.619 31-Oct-2020  rillig make(1): clean up ModifyWords

Reorder the parameters to match the documentation comment, and the
remaining parameters in chronological order. Remove the unused
parameter ctxt. The callbacks that need it pass it in their
modifyWordArgs instead.
 1.618 31-Oct-2020  rillig make(1): add test for combining the :@ and :? variable modifiers
 1.617 31-Oct-2020  rillig make(1): remove redundant condition for regmatch_t.rm_eo being -1

If rm_so is -1, rm_eo is guaranteed to be -1 as well.
 1.616 31-Oct-2020  rillig make(1): do not look up local variables like .TARGET anywhere else

Nobody defines a global variable named .TARGET since that would have
many unpredictable effects, applying to all targets at once.

Nobody defines an environment variable named .TARGET since that's
against the naming conventions for environment variables and would have
the same effect.

Because of this, there is no point looking up the variables that are
local to a GNode anywhere else. This means they cannot come from the
environment and thus their value doesn't need to be freed after use,
which makes the code simpler.

The newly added accessor functions in make.h refer to external
functions, but since that header is not used anywhere outside of
usr.bin/make, it doesn't matter. Between 2020-08-25 and 2020-10-30,
that header had been referenced by usr.bin/xinstall.
 1.615 31-Oct-2020  rillig make(1): reduce the scope where recursive expressions are detected

Only the call to Var_Subst needs to be protected since the other
functions have nothing to do with expanding variables.
 1.614 31-Oct-2020  rillig make(1): fix indentation in source code
 1.613 31-Oct-2020  rillig make(1): remove redundant null check from s2Boolean
 1.612 31-Oct-2020  rillig make(1): remove redundant code branch in SysVMatch

The general code path of parsing :from=to achieves the same effect.
 1.611 31-Oct-2020  rillig make(1): merge duplicate code in ModifyWord_Subst
 1.610 30-Oct-2020  rillig make(1): rename Str_SYSVMatch and its parameters
 1.609 30-Oct-2020  rillig make(1): improve variable name in Var_Value, document callback
 1.608 30-Oct-2020  rillig make(1): remove unsatisfiable conditions in Var_Set_with_flags
 1.607 30-Oct-2020  rillig make(1): document where the variable name is expanded
 1.606 30-Oct-2020  rillig make(1): change char * to void * in Var_Value

The only purpose of the parameter freeIt is to free the memory
associated with the return value. To do this, no pointer arithmetic is
needed. Therefore, change to a void pointer, to catch accidental use of
that pointer.
 1.605 30-Oct-2020  rillig make(1): clean up comments and local variables in var.c
 1.604 30-Oct-2020  rillig make(1): fix documentation for VARP_SUB_ONE

The pattern is only replaced a single time, not everywhere in the first
matching word.
 1.603 30-Oct-2020  rillig make(1): make iterating over HashTable simpler
 1.602 30-Oct-2020  rillig make(1): rename VAR_EXPORTED_YES to VAR_EXPORTED_SOME

The "yes" sounded too much like "all".
 1.601 30-Oct-2020  rillig make(1): document VAR_READONLY, now that it is really read-only
 1.600 30-Oct-2020  rillig make(1): prevent appending to read-only variables
 1.599 30-Oct-2020  rillig make(1): fix indentation in source code
 1.598 30-Oct-2020  rillig make(1): extract MayExport from Var_Export1
 1.597 30-Oct-2020  rillig make(1): remove redundant evaluations in VarFind
 1.596 30-Oct-2020  rillig make(1): replace VarFindFlags with a simple Boolean

Either all flags had been given or none. Except in Var_Append, but
since the ctxt was VAR_GLOBAL anyway, adding FIND_GLOBAL there did not
make a difference.
 1.595 30-Oct-2020  rillig make(1): rename FIND_CMD to FIND_CMDLINE, to match VAR_CMDLINE

While here, use a consistent order for the enum constants. This is both
the declaration order and at the same time the usual lookup order,
unless the -e option is given.
 1.594 30-Oct-2020  rillig make(1): rename VAR_CMD to VAR_CMDLINE

Since make has to do with both the command line and child commands, the
former name was confusing.
 1.593 30-Oct-2020  rillig make(1): rename SAVE_DOLLARS to follow the naming conventions
 1.592 30-Oct-2020  rillig make(1): clean up and update module comment in var.c
 1.591 27-Oct-2020  rillig make(1): initialize all CmdOpts fiels
 1.590 26-Oct-2020  rillig make(1): group the command line options and arguments

By having a single struct that holds all command line options and
arguments, it is easy to see in the code when such a command line
argument is modified. It also cleans up the namespace since the command
line options don't follow a common naming style. Having them in a
struct also means that there is a single place for putting the
documentation, not two as before.

The struct also suggests to extract the initialization code out of main,
which is still too large, having more than 400 lines of code and
covering far too many topics.
 1.589 25-Oct-2020  rillig make(1): add GNode_Path to access the path of a GNode
 1.588 25-Oct-2020  rillig make(1): rename hash functions to identify the type name

This makes it easier to spot mismatches between the function name and
its first parameter, although the compiler should already catch most of
them. Except for void pointers.
 1.587 25-Oct-2020  rillig make(1): reduce duplicate code in VarFind
 1.586 25-Oct-2020  rillig make(1): reduce amount of string hashing

In pkgsrc, running "bmake show-all" in pkgtools/pkglint called the hash
function 249130 times before, and only 115502 times after.

Still, a single call to Var_Set hashes the same string 3 times.
 1.585 25-Oct-2020  rillig make(1): replace PtrVector with Vector, which can contain any type
 1.584 25-Oct-2020  rillig make(1): rename type Vector to PtrVector

This allows the name Vector to be used for a more generic vector type,
which will be added soon.
 1.583 24-Oct-2020  rillig make(1): remove macros MIN and MAX

These macros typically evaluate one of their arguments twice. Until
2020-08-31, they had not parenthesized their arguments properly. They
are only used in a few places, therefore it doesn't hurt much to have
them expanded.
 1.582 23-Oct-2020  rillig make(1): move comment in Var_Set_with_flags

Until 2000-05-11, that comment was just above a VarFind call. 20 years
later, it is back again where it belongs.
 1.581 22-Oct-2020  rillig make(1): remove redundant type casts

This mainly affects the void pointers in callback functions for lists.
These had been necessary once when the parameter type was still
ClientData instead of void pointer.
 1.580 22-Oct-2020  rillig make(1): extract CanonicalVarname from VarFind
 1.579 20-Oct-2020  rillig make(1): document parameter to Var_Parse
 1.578 18-Oct-2020  rillig make(1): add tags to enum types

This allows IDEs to offer better type information than "anonymous enum".
 1.577 18-Oct-2020  rillig make(1): rename HashEntry.name to key
 1.576 18-Oct-2020  rillig make(1): remove underscore from Hash_Table and Hash_Entry

For consistency with the other type names, such as GNodeListNode.
 1.575 18-Oct-2020  rillig make(1): make API for iterating over hash tables simpler
 1.574 18-Oct-2020  rillig make(1): rename Stack to Vector

Both Var_Dump and GetActuallyIncludingFile access more than only the top
item of the stack, therefore it is more honest to rename the data type.
 1.573 18-Oct-2020  rillig make(1): sort variables in debug output

This way it's easier to see whether an expected variable is missing, or
to compare the values of related variables, since they usually share a
common prefix. Any sorting criterion is better than the hash code.

Sorting the variables by name changed the order of the output in
varname.mk. That test didn't test anything meaningful, it was just a
playground to understand and demonstrate the current implementation of
how the variables are stored, therefore it has been removed.
 1.572 17-Oct-2020  rillig make(1): normalize initialization and cleanup of the modules
 1.571 17-Oct-2020  rillig make(1): fix indentation
 1.570 06-Oct-2020  rillig make(1): rework memory allocation for the name of variables

There's more to know about variable names than fits in a one-liner.
While here, enforce that the name is not modified by splitting it into
the established (var + var_freeIt) pattern.

Since the name is not modified and not freed in the middle of evaluating
an expression, there is no need to make a backup copy of it. That code
had been necessary more than 12 years ago, but not anymore since the
code got a lot cleaner since then.
 1.569 06-Oct-2020  rillig make(1): remove duplicate code for creating variables
 1.568 05-Oct-2020  rillig make(1): fix compilation with GCC 10 and -Wimplicit-fallthrough=4
 1.567 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.566 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.565 04-Oct-2020  rillig make(1): only use the VARE_ASSIGN flag if necessary

When checking the right-hand side of a variable assignment for syntax
errors, it does not matter whether a '$$' is expanded to '$' or kept as
'$$'.
 1.564 03-Oct-2020  rillig make(1): use consistent pattern for parsing whitespace

The pp and cpp in the function names stand for "parsing position" and
"const parsing position".
 1.563 03-Oct-2020  rillig make(1): inline Str_FindSubstring in ModifyWord_Subst
 1.562 03-Oct-2020  rillig make(1): extract ApplyModifier_Literal into separate function
 1.561 03-Oct-2020  rillig make(1): extract ApplyModifier_Unique into separate function
 1.560 03-Oct-2020  rillig make(1): in lint mode, reject modifiers without delimiter

The expression ${VAR:LPL} must now be written as ${VAR:L:P:L}. The
manual page has never documented that some modifiers don't need to be
delimited by ':' and others need to. That would have been unnecessarily
confusing anyway.
 1.559 03-Oct-2020  rillig make(1): ignore -env and -literal in assignments to .MAKE.EXPORTED

Previously, assigning the string "-env" to the variable .MAKE.EXPORTED
had the same effect as the .export-env directive. This was only due to
a sloppy implementation, not by design.

For the string "-literal" and the directive .export-literal, the
situation was even worse since the actually executed code was a wild
mixture between .export and .export-literal that in the end exported the
expanded form of the variable. Therefore there was no practical use
case of this implementation flaw.
 1.558 03-Oct-2020  rillig make(1): do not export variable names starting with '-'

By convention, names of environment variables consist of uppercase
letters and underscores. Most of them start with an uppercase letter.
In a few cases, the names also contain lowercase letters, such as in
http_proxy.

Variable names starting with a hyphen are confusing and might be
mistaken as command line options. Therefore don't export these.

This also affects a few edge cases that don't occur in practice, such as
setting .MAKE.EXPORTED=-env or .MAKE.EXPORTED=-literal. These had not
worked as expected anyway.
 1.557 03-Oct-2020  rillig make(1): clean up confusing code in Var_Export

The generated code stays exactly the same.
 1.556 02-Oct-2020  rillig make(1): in ApplyModifier_To, update pp in each branch

Before, the parsing position was updated once at the beginning, which
didn't make sense. Updating it in each branch allows to decide for its
appropriate value in each branch individually.
 1.555 30-Sep-2020  rillig make(1): extract ApplyModifier_Quote into separate function
 1.554 30-Sep-2020  rillig make(1): fix bug in evaluation of indirect variable modifiers

Since 2020-09-22, when indirect variable modifiers were applied to a
variable expression based on an undefined variable, these modifiers did
not change the state of a variable expression from undefined to defined.
The modifiers that do this are :D, :U, :L, :P. Minimal example:

${VARNAME:${:UL}}

The :L modifier from the inner expression sets the value of the outer
expression to its variable name, in this case "VARNAME". The outer
expression was not marked as being defined though, which resulted in a
"Malformed conditional" error.

In the commit from 2020-09-22, vardebug.exp had changed a lot, and I had
not inspected the change closely. The important detail was in lines 56
and 60, where VAR_JUNK|VAR_KEEP changed into VEF_UNDEF, thereby losing
the VEF_DEF bit.
 1.553 29-Sep-2020  rillig make(1): rename ShortVarValue to UndefinedShortVarValue
 1.552 29-Sep-2020  rillig make(1): remove unused assignments to local variables

These only became obvious once ApplyModifier had been extracted, which
shrank the source code of ApplyModifiers by about 100 lines.

Even GCC 5 had seen that they are redundant and had not generated any
code for them.
 1.551 29-Sep-2020  rillig make(1): extract ApplyModifier from ApplyModifiers

This allows a return, instead of a variable assignment followed by a
break, saving a few lines of source code.

The size of the resulting binary shrinks as well, even though the code
is essentially the same as before.
 1.550 28-Sep-2020  rillig make(1): make debug logging simpler

This avoids referring to the debug_file variable in many places where
this implementation detail is not necessary.
 1.549 28-Sep-2020  rillig make(1): extract logging from ApplyModifiers into separate functions

These two logging blocks are massive enough to disturb the reading flow
of the remaining code.

Even without these two blocks, ApplyModifiers is still 250 lines long,
which is quite much.
 1.548 28-Sep-2020  rillig make(1): move variable modifier :sh into separate function
 1.547 28-Sep-2020  rillig make(1): make debug logging in var.c compatible to C90

The ... ellipsis for macros is only available since C99.
 1.546 27-Sep-2020  rillig make(1): normalize whitespace in source code

There is no more space tab. Either only tabs or only spaces or tabs
followed by spaces, but not spaces followed by tabs.
 1.545 27-Sep-2020  rillig make(1): rename Buf_Size to Buf_Len

The new name better matches the field name Buffer.len as well as the
variables around the calls to this function.
 1.544 27-Sep-2020  rillig make(1): replace direct access to Buffer fields with inline function

This way, renaming the fields of the buffer is restricted to only buf.h
and buf.c.
 1.543 26-Sep-2020  rillig make(1): clean up API for finding and creating GNodes

The previous API had complicated rules for the cases in which the single
function returned NULL or what it did. The flags for that function were
confusing since passing TARG_NOHASH would create a new node even though
TARG_CREATE was not included in that bit mask.

Splitting the function into 3 separate functions avoids this confusion.
It also reveals several places where the complicated API led to
unreachable code. Such code has been removed.
 1.542 26-Sep-2020  rillig make(1): add Hash_FindValue, for direct access to hash table data
 1.541 25-Sep-2020  rillig make(1): add tags to some of the unnamed structs

The tags prevent the structs from accidentally becoming compatible
types.

While here, remove a few typedefs for structs that are single-purpose,
since there is no point in abstracting from the actual representation of
these types.
 1.540 25-Sep-2020  rillig make(1): fix type of local variable in ParseModifierPart

Thanks, Clang-Tidy.
 1.539 25-Sep-2020  rillig make(1): fix type of local variable in ApplyModifiers

Thanks, Clang-Tidy.
 1.538 25-Sep-2020  rillig make(1): document expansion of undefined variables in Var_Subst

From reading the code alone, it is not obvious what effects this
innocent-looking code has.
 1.537 25-Sep-2020  rillig make(1): rename local variables in Var_Subst

The variable name "str" did not make it clear enough that the pointer is
constantly moving, to parse the given string. The name "p" expresses
this more clearly.
 1.536 23-Sep-2020  rillig make(1): fix unexpected behavior in ::= variable modifier

Previously, the ::= modifier had returned an error value, which caused
the variable expression to be preserved. This behavior was not useful
in this case; it had only been intended to be used for undefined
variables.

To fix it, distinguish between parse errors, undefined variables and
regular empty strings.
 1.535 23-Sep-2020  rillig make(1): inline local variable delim

Now that ParseModifierPart generates the error message itself, there is
no need to keep this variable around since it is read a single time.
 1.534 22-Sep-2020  rillig make(1): condense code in Var_Subst
 1.533 22-Sep-2020  rillig make(1): prepare Var_Subst for proper error handling

Returning a VarParseResult instead of a string makes it possible to let
the error bubble up, until it reaches the main expression.
 1.532 22-Sep-2020  rillig make(1): remove obsolete fix for PR bin/29985
 1.531 22-Sep-2020  rillig make(1): prepare error handling in nested variable expressions

Having ParseModifierPart return VarParseResult allows to report the
errors from nested variable expressions.
 1.530 22-Sep-2020  rillig make(1): handle errors about missing delimiter in a single place
 1.529 22-Sep-2020  rillig make(1): move ParseModifierPart further down in the code

This way, it can access the ApplyModifierState, which will be used in a
follow-up commit to reduce the code duplication around the error
handling for missing delimiters.
 1.528 22-Sep-2020  rillig make(1): remove remaining references to VAR_JUNK and VAR_KEEP
 1.527 22-Sep-2020  rillig make(1): move VAR_JUNK and VAR_KEEP away from VarFlags

These two flags have nothing to do with a variable. They are only used
while evaluating a variable expression.

While here, rename the flags and make their documentation more precise.
 1.526 22-Sep-2020  rillig make(1): rename VarParseErrors to VarParseResult

The name VPE_OK was confusing since it was not an error at all.
 1.525 22-Sep-2020  rillig make(1): extract common code from the ApplyModifier functions
 1.524 22-Sep-2020  rillig make(1): use fine-grained type names for lists and their nodes

This is only intended to help the human reader. There is no additional
type safety yet.
 1.523 21-Sep-2020  rillig make(1): clean up VarParseErrors, for proper error handling

Having a pure bitset was wrong.

Instead, there are several alternatives (parse error, eval error, undef
error), and each of them can either have an error message printed (good)
or not (bad). In addition, there are VPE_OK for successful expression
evaluation and VPE_UNKNOWN (only used during migration to the correct
error handling scheme).
 1.522 14-Sep-2020  rillig make(1): fix wrong error for undefined variables in lint mode
 1.521 14-Sep-2020  rillig make(1): inline character constants in var.c

This removes a level of indirection, and the macro names were quite
similar in appearance as well. The macros may have been used by people
whose editors don't recognize C string and character literals when
navigating to the corresponding brace or parenthesis. These editors had
already been confused before this commit since there are also string
literals with unbalanced parentheses, and there are far fewer
compensating comments such as /*{*/ or /*)*/ in the code. In fact, the
only such comment that is left over was in for.c.

This way, there is now a single consistent way of writing these
character literals, which is without macros or comments, since that is
the simplest form.
 1.520 14-Sep-2020  rillig make(1): don't require nested variables to be defined in conditions

This code only applies to lint mode (-dL) for now. After a test phase
and a thorough check for possible side effects, it will be activated in
normal mode, too. Having this code in lint mode is required to run
src/build.sh, which relies a lot on using variables with undefined
nested variables in conditions.

In the default mode, any errors about nested undefined variables are not
printed since in Var_Subst, oldVars is true. Therefore, it is not urgent
to properly handle these nested variables correctly there.
 1.519 13-Sep-2020  rillig make(1): in Var_Parse, replace bmake_strldup with bmake_strsedup
 1.518 13-Sep-2020  rillig make(1): in lint mode, report undefined variables in conditions
 1.517 13-Sep-2020  rillig make(1): suppress wrong "Malformed conditional" for undefined variables

This only has an effect in lint mode right now.
 1.516 13-Sep-2020  rillig make(1): in lint mode, improve error handling for undefined variables

It's a first step for improving the error message that make prints.
 1.515 13-Sep-2020  rillig make(1): make documentation of VarParseErrors more precise
 1.514 13-Sep-2020  rillig make(1): prepare Var_Parse for proper error handling and reporting

Right now, Var_Parse swallows many errors during parsing and evaluation.
Ideally, these errors should propagate from the deeply nested
expressions where they occur up to the top-level expressions. When such
an error occurs, the depending expressions should not be evaluated any
further. They may still be parsed, but side effects should be
minimized.

The goal is to prevent incomplete expressions like the "xy}" in
moderrs.exp:106 from being evaluated and eventually passed to the shell
for execution. This expression is a left-over from a parse error in the
mod-t-parse target in moderrs.mk:154.

This commit is a first step in analyzing and verifying the current state
of affairs. The modelling in VarParseErrors already looks complicated
but is expected to closely match reality.
 1.513 13-Sep-2020  rillig make(1): shorten debug output of ApplyModifiers

Having the words "eflags" and "vflags" in the debug output was too
repetitive. That they are flags is made obvious by the '|' separator,
and the flags have clearly distinguishable names (VARE_* vs. VAR_*),
which lowers the chance for confusion.
 1.512 13-Sep-2020  rillig make(1): clean up RCSID blocks

These blocks mostly consisted of redundant structure, following the same
#ifndef pattern over and over, with only minimal variation.

It's easier to maintain if the common structure is only written once and
encapsulated in a macro.

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.511 13-Sep-2020  rillig make(1): clean up API for evaluating conditions

There was no need to make struct If publicly visible.

There was no need to have parameters in the public API that were passed
the same constants all the time.

The former function names had not been distinctive.
 1.510 13-Sep-2020  martin Initialize endc unconditionally, gcc complains and it is not obvious
whether this is a false positive.
 1.509 13-Sep-2020  rillig make(1): rename ApplyModifier_Exclam

The names of all other ApplyModifier functions already describe the
effect instead of the spelling.
 1.508 13-Sep-2020  rillig make(1): inline call to strchr in ValidShortVarname

It's a pity that neither GCC 5 nor GCC 10 nor Clang 9 inline this code
themselves, even though it would be easy to do.

Clang 9 at least replaces strchr with memchr, but that is still too
complicated for a simple "is this character one of these" question.

For a repeated "if (varname != ...)" instead of the switch, GCC 10
generates really boring and inefficient code, even though it is easy to
see that the order of the comparisons doesn't matter.
 1.507 13-Sep-2020  rillig make(1): in lint mode, complain about erroneous $$

Since 2008-12-21, make has silently ignored strange variable names in
constructs like '$$', '$}', '$' followed by nothing. Ignoring these
bugs in makefiles instead of reporting them is not a good idea.

To improve the situation, make complains about these errors now, but
only in lint mode (-dL). This preserves existing behavior while still
allowing to validate existing makefiles that they don't depend on this
bug.

If the test phase goes well, these error messages may be enabled
unconditionally.

https://mail-index.netbsd.org/pkgsrc-users/2020/09/12/msg032229.html
 1.506 13-Sep-2020  rillig make(1): improve implementation comment in Var_Parse
 1.505 12-Sep-2020  rillig make(1): fix return type of ApplyModifier_Localtime
 1.504 12-Sep-2020  rillig make(1): move buffer from Var_Parse to ParseVarname

There's no reason to keep the buffer in memory after the variable name
has been parsed.
 1.503 12-Sep-2020  rillig make(1): reword variable invocation to variable expression

Variables are a passive thing. They cannot be invoked, they can only be
evaluated.
 1.502 12-Sep-2020  rillig make(1): extract ShortVarValue from Var_Parse
 1.501 12-Sep-2020  rillig make(1): extract ParseVarname from Var_Parse

This was an easy part since it affects only a few variables. 250 lines
for a single function is still quite a lot, so further refactorings will
follow.
 1.500 12-Sep-2020  rillig make(1): rename local variable in Var_Subst
 1.499 12-Sep-2020  rillig make(1): remove double negation in Var_Parse
 1.498 12-Sep-2020  rillig make(1): clean up Var_Parse
 1.497 12-Sep-2020  rillig make(1): rename local variables in Var_Parse

The main property of the former "str" is not being a string but pointing
at the start of the expression to be parsed.

The main property of the former "tstr" is not being a string but being
the moving pointer, the current parsing position. No idea what the "t"
in "tstr" stood for.
 1.496 12-Sep-2020  rillig make(1): rename Var_ParsePP back to Var_Parse

The migration to the "parsing position" pointer has been done.
 1.495 12-Sep-2020  rillig make(1): migrate CondParser_String to Var_ParsePP
 1.494 12-Sep-2020  rillig make(1): fix inconsistent code indentation
 1.493 11-Sep-2020  rillig make(1): add wrappers around ctype.h functions

This avoids casting the argument to unsigned char, and to cast the
result of toupper/tolower back to char.
 1.492 11-Sep-2020  rillig make(1): replace *a->b with a->b[0]

This allows the code to be read strictly from left to right. In most
places this style was already used.
 1.491 08-Sep-2020  rillig make(1): fix off-by-one error in SuffExpandChildren

In suff.c r1.144 from yesterday, in the line "cp += nested_p - cp", I
accidentally removed the "- 1". Since these "- 1" lines lead to slow
execution, each branch now increments the pointer separately by the
actually needed amount.

Fixing this bug posed way more new questions than it answered, and it
revealed an inconsistency in the parser about how characters are to be
escaped, and missing details in the documentation of Var_Parse, as well
as a parse error that unexpectedly doesn't stop make from continuing.
 1.490 07-Sep-2020  rillig make(1): migrate to Var_ParsePP in Var_Parse and Var_Subst
 1.489 07-Sep-2020  rillig make(1): migrate ApplyModifiers to Var_ParsePP
 1.488 07-Sep-2020  rillig make(1): remove redundant includes
 1.487 04-Sep-2020  rillig make(1): add more explanation for undefined variable expressions
 1.486 03-Sep-2020  rillig make(1): migrate ApplyModifier_Defined to Var_ParsePP
 1.485 03-Sep-2020  rillig make(1): migrate Var_Parse API to parsing position

The ApplyModifier functions already use this pattern. For simplicity
and consistency Var_Parse should do the same. This saves a parameter to
be passed.

The migration takes place step by step, just like for the Lst functions
a few days ago.
 1.484 02-Sep-2020  rillig make(1): fix documentation of Var_Subst

The "var" parameter does not exist anymore.
 1.483 02-Sep-2020  rillig make(1): clean up comments in var.c, make VarQuote const-correct
 1.482 31-Aug-2020  rillig make(1): inline a local variable in VarUniq

Just to eliminate any remote possibility of aliasing and thereby
forgetting to update all involved variables.
 1.481 31-Aug-2020  rillig make(1): add more examples to the documentation of ParseModifierPart
 1.480 31-Aug-2020  rillig make(1): fix the :u modifier, which was broken for almost a day

Big thanks go to sjg, who discovered the bug and did the main work to
track it down.

In the unit tests for the :u modifier from the previous commit, I had
forgotten to actually add the :u modifier at the end. I added it now
and also added a few other tests. It's better to have a few more tests
than too few.
 1.479 30-Aug-2020  rillig make(1): replace brk_string with Str_Words

The API is much simpler, and there is less detail that is exposed by
default and fewer punctuation to type on the caller's side. To see that
there is some memory to be freed, one would have to look into the
struct. Having part of the return value as the actual return value and
the rest in output parameters was unnecessarily asymmetrical.
 1.478 29-Aug-2020  rillig make(1): trust that Var_Parse never returns NULL

That function is quite long, but all its return paths lead either to the
expanded variable expression, or to var_Error or varNoError.
 1.477 29-Aug-2020  rillig make(1): trust that Var_Subst never returns NULL

It really never does, and it doesn't even report errors. It just
returns the content of the buffer, up to the first parse error.
 1.476 29-Aug-2020  rillig make(1): add comments for ModifyWord_Subst

Without any comments, the code is unnecessarily hard to follow.
 1.475 29-Aug-2020  rillig make(1): split ApplyModifier_To into paragraphs
 1.474 29-Aug-2020  rillig make(1): add bmake_strsedup for duplicating a substring
 1.473 29-Aug-2020  rillig make(1): allow for strict type checking for Boolean

Having Boolean aliased to int creates ambiguities since int is widely
used. Allow to occasionally compile make with -DUSE_DOUBLE_BOOLEAN to
check that the type definitions still agree.
 1.472 25-Aug-2020  rillig make(1): fix error message for ::!= modifier with shell error

It's just too easy to confuse st->val and val.
 1.471 25-Aug-2020  rillig make(1): distinguish enum flags and values in debugging mode

When printing an enum value in debugging mode, distinguish between
bitsets containing flags and ordinary enums that just contain different
values.

Make the macros in enum.h more uniform. Provide a simple scheme for
defining the run-time type information of enums whose number of values
is a number with more than 2 bits set in the binary representation.
This case was not obvious before, and it was pure luck that the current
interesting enum types only had 3, 10 or 32 different values.

The type with the 32 different values actually only has 31 significant
bits since the enum constant OP_OPMASK is only used when querying the
enum, not for defining or describing the possible values. For this
reason, it was unavoidable to refactor the rtti macros, to support even
this case.
 1.470 24-Aug-2020  rillig make(1): in debug mode, print GNode details in symbols

A string like OP_DEPENDS|OP_OPTIONAL|OP_PRECIOUS is much easier to read
and understand than the bit pattern 00000089.

The implementation in enum.h looks really bloated and ugly, but using
this API is as simple and natural as possible. That's the trade-off.

In enum.h, I thought about choosing the numbers in the macros such that
it is always possible to combine two of them in order to reach an
arbitrary number, because of the "part1, part2" in the ENUM__SPEC macro.
The powers of 2 are not these numbers, as 7 cannot be expressed as the
sum of two of them. Neither are the fibonacci numbers since 12 cannot
be expressed as the sum of 2 fibonacci numbers. I tried to find a
general pattern to generate these minimal 2-sum numbers, but failed.
 1.469 23-Aug-2020  rillig make(1): remove redundant range restriction

re.re_nsub is at least 0, and (at least 0) + 1 cannot be 0.
 1.468 23-Aug-2020  rillig make(1): restructure code of the :ts modifier

Now there is one paragraph per case, as opposed to the highly condensed
code from before.

In the cases of :ts\n and :ts\t, the variables for number parsing are no
longer in the code path, which makes the code easier to understand for
humans. Not sure what the compilers made out of it.

The assignment "base = 0" has gone since it was redundant. An integer
that starts with 0 is always interpreted as octal by strtol, no matter
if the base is 8 or 0.
 1.467 23-Aug-2020  rillig make(1): extend the documentation on the ApplyModifier functions
 1.466 23-Aug-2020  rillig make(1): split code for parsing the :U modifier into digestible parts

The comment about "unescaped $'s that aren't before the delimiter" was
wrong, as the code didn't contain the "aren't before the delimiter"
part. By splitting the code into paragraphs, the larger structure
becomes easily visible. Having a few short comments in the right place
is more helpful than a big block of text.
 1.465 23-Aug-2020  rillig make(1): make brk_string return size_t for the number of words
 1.464 23-Aug-2020  rillig make(1): save a variable lookup when adding a read-only variable
 1.463 23-Aug-2020  rillig make(1): fix assertion failure in debug output for read-only variables
 1.462 23-Aug-2020  rillig make(1): improve variable name in ApplyModifiers

The bare q was too unspecific.
 1.461 23-Aug-2020  rillig make(1): use local variable in ApplyModifier_Path

Without this variable, it might seem as if st->newVal could become NULL
in some code paths.
 1.460 23-Aug-2020  rillig make(1): add assertions for non-nullness of strings

Verified by manually inspecting all call sites.
 1.459 22-Aug-2020  rillig make(1): clean up headers

Remove redundant headers that are already included by "make.h".
Make <assert.h> available to all compilation units that use "make.h".
 1.458 22-Aug-2020  rillig make(1): prevent assignment to the variable with the empty name
 1.457 22-Aug-2020  sjg Add .SHELL as read-only variable

The .SHELL variable represents the shellPath used to run
scripts.

Reviewed by: rillig, christos
 1.456 22-Aug-2020  rillig make(1): fix indentation
 1.455 22-Aug-2020  rillig make(1): fix documentation of Var_Parse
 1.454 20-Aug-2020  rillig make(1): make a few comments more precise
 1.453 20-Aug-2020  rillig make(1): use more descriptive variable name in ModifyWords
 1.452 20-Aug-2020  rillig make(1): remove VARP_SUB_MATCHED

This flag didn't really belong to the other flags. The other flags are
set during parsing and are then left as-is by ModifyWord_Subst and
ModifyWord_SubstRegex.

It's clearer to use a separate variable for storing whether there was a
match already.
 1.451 20-Aug-2020  rillig make(1): consistently access args->pflags in ModifyWord_Subst

It was confusing that some accesses were via pflags and some via
args->pflags.
 1.450 20-Aug-2020  rillig make(1): remove unreached code from bmake_strndup

The "at most" branch was never taken since all call sites in var.c only
ever need a substring, and the target buffer is not limited. Therefore
rename the function and make it simpler.

It's ok that bmake_strldup is defined as estrndup in case of USE_EMALLOC
since that function's implementation is compatible to the "copy
exactly", it just contains some extra null checks that will never match
since the variable values cannot (well, or should not) contain null
bytes. Theoretically they can, but the behavior then depends on the
exact implementation and is unreliable, therefore nobody does this.
After all, Makefiles are used for text processing, not for binary data.
 1.449 13-Aug-2020  rillig make(1): remove type alias Byte = char

This alias was only actually used in very few places, and changing it to
unsigned char or any other type would not be possible without generating
lots of compile-time errors. Therefore there was no abstraction, only
unnecessary complexity.
 1.448 12-Aug-2020  rillig make(1): prepare var.c for WARNS=6

I'm unhappy with the (unsigned) casts for the enum constants, but there
is no way around that since the base type of enums is int by definition,
and there is no way in C90 to explicitly specify the base type of an
enum type.

The (size_t) casts on the pointer differences are another pain point,
but for these as well, C90 does not have a ready-made solution. A
possible workaround would be an inline function ptr_diff that returns
size_t instead of ptrdiff_t, but that would make the code look even more
bloated than with the casts.

The remaining casts to (char), (int) and (time_t) look so suspicious
that it's easy enough to stumble upon them, as soon as someone finds the
time to fix these properly by adding a function ParseInt or
ParseSeconds.
 1.447 12-Aug-2020  rillig make(1): replace redundant NULL tests with assertions
 1.446 10-Aug-2020  rillig make(1): replace snprintf with concat3

This makes the code more predictable for long strings, since the main
action is never skipped.

The code also becomes simpler since there is no %s anymore, and the 3
arguments just appear in the same order as in the result.
 1.445 09-Aug-2020  rillig make(1): clean up code for subexpressions in the :C modifier

An ampersand in the replacement string can never produce an
out-of-bounds error or an undefined-subexpression error. This makes the
error message simpler since it only needs to cover the case of a single
digit.
 1.444 09-Aug-2020  rillig make(1): use char literals, improve documentation
 1.443 09-Aug-2020  rillig make(1): revert C99 initializer in ApplyModifiers

The code of usr.bin/make is supposed to be C90-compatible. That's why
it neither uses line-end comments nor declaration-after-statement nor a
few other features.

The fields that were copied "by name" did not get any additional
comments, only the ones with literal values did, since it's hard to see
what these mean.

This style of initializer has the additional benefit that a missing or
extraneous initializer-item would lead to a compile-time error, rather
than going undetected.
 1.442 09-Aug-2020  rillig make(1): mark inconsistent word separators for variable modifiers
 1.441 09-Aug-2020  rillig make(1): improve type signature of Var_Export
 1.440 09-Aug-2020  rillig make(1): extend the documentation for variable flags
 1.439 09-Aug-2020  rillig make(1): clean up indentation, includes, add documentation
 1.438 09-Aug-2020  rillig make(1): document a hard-to-understand pointer calculation
 1.437 09-Aug-2020  rillig make(1): restrict the type of startc and endc to char
 1.436 09-Aug-2020  rillig make(1): use fixed-size arrays for Enum_ToString

Declaring the ToStringSize as "static const size_t" made it an ordinary
integer expression. To avoid variable length arrays, the commonly
accepted way is to declare the length as an enum constant, as that is
considered an integer constant expression, which in turn makes the
declaration a fixed-size array.
 1.435 09-Aug-2020  christos Fix build; gcc does not like VLA's, so hard code the boundary
Use c99 initializers
 1.434 08-Aug-2020  rillig make(1): merge duplicate code for the :H :T :R :E modifiers

By setting modifyWord first, the rest of the code becomes exactly the
same and is merged by the compiler.
 1.433 08-Aug-2020  rillig make(1): remove trailing Z from buffer functions

This Z had been useful during the migration from int to size_t. This
migration is finished, at least for the Buffer type, so the Z is no
longer necessary.
 1.432 08-Aug-2020  rillig make(1): add debug logging for Var_Parse

This will hopefully help with tracking down why the "Undefined variable"
error message is not triggered.

There is some other non-obvious behavior nearby. In Parse_DoVar, the !=
assignment operator evaluates the variable using VARE_UNDEFERR, but
there is not even a warning for the following line:

!= echo err ${UNDEFINED} 1>&2
 1.431 08-Aug-2020  rillig make(1): extend debug logging to error values

The error marker var_Error is just an empty string. In the debug log
this empty string was not distinguishable from an otherwise empty
string.

Having this distinction helps in understanding the exact data flow.
 1.430 08-Aug-2020  rillig make(1): add more detailed debug logging for variable modifiers

Before a modifier is applied to a variable, it is not yet parsed,
therefore it is only possible to log a rough estimate of the modifier.
But after applying it, the parsing position has advanced, and the full
modifier can be logged.

In addition, to fully understand how the modifiers work, it's not enough
to just know the variable names and values, there are also some flags
that influence how the modifiers behave. The most influential is
VARE_WANTRES.

Thanks to sjg for the extensive review and valuable feedback on the
first drafts.
 1.429 08-Aug-2020  rillig make(1): improve documentation of Var_Parse and reorder conditions
 1.428 08-Aug-2020  rillig make(1): improve error message in case of unfinished modifiers

The previous error message "Unclosed substitution" was wrong for several
reasons.

It is not about "unclosed", but about "unfinished" since in the
:@var@...@ modifier the missing '@' does not really close anything.

The word "substitution" may have originated in a time where :S and
:from=to were the only modifiers, and these were indeed substitutions,
but several other modifiers aren't.

The :S and :C modifiers allow an arbitrary delimiter, therefore it is
helpful to enclose the delimiter in quotes, just in case someone chooses
')' or '{' or even ' ' as delimiter.
 1.427 08-Aug-2020  rillig make(1): align the code in Var_Append with Var_Set

The code has the same effect in both functions, therefore it should also
look the same.
 1.426 08-Aug-2020  rillig make(1): consistently use postfix-increment
 1.425 08-Aug-2020  rillig make(1): clean up VarStrftime

The parameter names were confusing and had outdated types.
 1.424 08-Aug-2020  rillig make(1): add test for unknown sub-modifier of the :S modifier
 1.423 08-Aug-2020  rillig make(1): clean up Var_UnExport

Mark the parameter as constant since it is not modified.

Remove tests for '\n' since these can never succeed.

newenv can never be NULL since neither of bmake_malloc or bmake_realloc
returns NULL.

Improve variable names: vlist was too unexpressive.

Add debug logging since unexporting variables is an uncommon operation
that directly affects the observable environment of the child processes.

Fix CRLF line endings in a few unit tests.
 1.422 08-Aug-2020  rillig make(1): clean up Var_Export

The string from the .export directive can never be NULL.

The test for local single-char variables is already done in Var_Export1.
 1.421 08-Aug-2020  rillig make(1): change return type of Var_Export1 to Boolean
 1.420 08-Aug-2020  rillig make(1): fix yoda-style comparisons in var.c
 1.419 08-Aug-2020  rillig make(1): condense comment for ApplyModifiers

This comment only repeats what is written in the manual page.
Furthermore, it didn't get updated consistently. The missing modifiers
were :_, :gmtime, :localtime, :hash, :Q, :range, :Or.
 1.418 08-Aug-2020  rillig make(1): fix debug output for indirect modifiers

The trailing part after the modifier was confusing at best. It does
make sense to log the string from p to p+rlen, but not from p+len to
p+len+len.

Consistently use double quotes for strings.
 1.417 07-Aug-2020  rillig make(1): format the code in var.c a little more consistently
 1.416 06-Aug-2020  rillig make(1): use consistent name for result of Cmd_Exec
 1.415 06-Aug-2020  rillig make(1): reduce code size in :D and :U modifier

This affects both the source code size and the binary code size, at
least on x86_64.
 1.414 06-Aug-2020  rillig make(1): clean up code for variable handling

The VarFlags type doesn't need an underscore. The underscore is
typically only used for exported functions.

Document the memory allocation details for Var.name.

Use consistent names for Hash_Entry variables. Quite possibly one of
them was a Lst_Node in ancient times, but that's not a reason to keep
this variable name forever.
 1.413 03-Aug-2020  rillig make(1): fix wrong assertion in ApplyModifiers

The assertion was supposed to validate startc and endc individually.

For unknown reasons (once again), this reduces the code size by 49 bytes
on x86_64.
 1.412 03-Aug-2020  rillig make(1): no declaration-after-statement anymore

NetBSD make is intended to be maximally portable, therefore it uses only
C89. This was not declared in the Makefile before.

There are still a few places in parse.c and metachar.c that use
end-of-line comments. These will be fixed in a follow-up commit.
 1.411 03-Aug-2020  rillig make(1): use VAR_DEBUG macro instead of if statements

This removes some clutter from the code and reduces the indentation.
 1.410 03-Aug-2020  rillig make(1): in lint mode, disallow dynamic variable names in :@ modifier

This is an extremely obscure feature that hopefully nobody ever
considered using.
 1.409 03-Aug-2020  rillig make(1): replace st->next with a simple string iterator

This is the same style that OpenBSD's make has been using for 20 years
now. Having one less field in ApplyModifiersState reduces complexity in
that place.

The individual modifiers currently don't handle parse errors
consistently. Some update pp while others leave it as-is. This
behavior may be aligned in a follow-up commit.
 1.408 03-Aug-2020  rillig make(1): don't use st->next as a local variable
 1.407 02-Aug-2020  rillig make(1): remove duplicate code in :ts modifier

The pointer xp had already been there with the correct value, and
there's no point in not using it. This reduces the code size on x86_64
by 48 bytes, which is more than I had expected.
 1.406 02-Aug-2020  rillig make(1): clean up NULL pointer comparisons, use separate variable

st->newVal is not meant to be a general-purpose storage.

Eliminate the unnecessary initialization of freeIt since Var_Parse
initializes it in every case.
 1.405 02-Aug-2020  rillig make(1): make :hash modifier more efficient

It's not necessary to allocate a 256-byte buffer just to store 9 bytes
in it, and to null-terminate it after writing every single byte to it.
 1.404 02-Aug-2020  rillig make(1): move qsort helper functions closer to ApplyModifier_Order
 1.403 02-Aug-2020  rillig make(1): merge duplicate code in the :O and :u modifiers
 1.402 02-Aug-2020  rillig make(1): inline VarOrder into ApplyModifier_Order

Removing the extra mapping layer "otype" makes the code both faster and
smaller.
 1.401 02-Aug-2020  rillig make(1): reduce scope of variables

This groups the variables by topic and only introduces them when they
are actually needed. The compiler doesn't care, but during a debugging
session this means fewer uninitialized variables.

In VarUniq, the variable i has been split into two. All others remain
exactly as before, just with a smaller scope.
 1.400 02-Aug-2020  rillig make(1): clean up comments in var.c

Some of the effects listed in "Side Effects" were really "Main Effects"
and have been moved to the main description.

VarAdd: There's no "front" in a hash table.

VarHash: A const char * is not a "String to modify".

Var_Subst: Even in r1.1 of var.c, there was no "variable structure to
store in" anywhere nearby.
 1.399 02-Aug-2020  rillig make(1): remove visual clutter from VarFind

Having fewer { else } around makes the return statements easier to find.
 1.398 02-Aug-2020  rillig make(1): remove unnecessary assignment in Var_Parse

In a variable expression without braces or parentheses, it is not
possible to have modifiers. Therefore the assigned endc could not have
been used anywhere.
 1.397 02-Aug-2020  rillig make(1): eliminate another unnecessary UNCONST in Var_Delete
 1.396 02-Aug-2020  rillig make(1): document almost duplicate code

ParseModifierPart and Var_Parse are very similar, but there might be
subtle differences. Until these differences are documented in the form
of unit tests, merging these code pieces is too dangerous.
 1.395 02-Aug-2020  rillig make(1): eliminate local variable in ParseModifierPart

The evaluation flags passed to the nested variables consist of 3 flags.
Therefore, (eflags & VARE_UNDEFERR) | (eflags & VARE_WANTRES) is
equivalent to (eflags & ~VARE_ASSIGN).

The variable name errnum was misleading anyway, just like the other
errnum from a few commits ago that had been renamed to errfmt.
 1.394 02-Aug-2020  rillig make(1): don't needlessly chain p-- and p++ in ParseModifierPart

At least GCC 5 didn't optimize this, although I wouldn't have been
surprised if it did.
 1.393 02-Aug-2020  rillig make(1): reduce the number of moving variables in ParseModifierPart

Having only the p walk through the string is easier to understand than
assigning between p and cp2 (with its unexpressive name).
 1.392 02-Aug-2020  rillig make(1): use shorter local variable names

The c in cp was redundant since the context makes it obvious that this
is a character pointer. In a tight loop where lots of characters are
compared, every letter counts.
 1.391 02-Aug-2020  rillig make(1): reduce indentation in ParseModifierPart
 1.390 02-Aug-2020  rillig make(1): restructure documentation of ParseModifierPart

Before, the long documentation looked too frightening, and it was not
immediately clear which parts of it had to be read and which could be
skipped.
 1.389 02-Aug-2020  rillig make(1): update implementation documentation
 1.388 01-Aug-2020  rillig make(1): switch Buffer size from int to size_t

This change helps to make the various integer types compatible and is a
preparational step for setting WARNS=6 in the Makefile.

The documentation of buf.c has been cleaned up and condensed since it
was mostly redundant, and some statements were even slightly wrong.

All code changes are covered by the existing unit tests, except for the
few lines in for.c around for_var_len. These changes have been reviewed
thoroughly and manually, like all the others in this commit.

Those buffer functions that deal with sizes have been renamed by
appending a Z, to make sure that no function call was accidentally
forgotten. They will be renamed back in a follow-up commit.

As usual, the scope of a few affected variables has been reduced, and
some variables had to be split since they had been incorrectly merged
before.

The order of the arguments to Buf_AddBytes has changed from (mem_len,
mem) to (mem, mem_len), in order to make it consistent with the
functions from the C standard library, such as snprintf.
 1.387 01-Aug-2020  rillig make(1): start nesting level in ApplyModifier_Match at 0

There is no need to start at 1, and starting at 0 generates smaller code
on x86_64. Reordering the --nest and the following break would increase
the code size though, for unknown reasons.
 1.386 01-Aug-2020  rillig make(1): inline and untangle the code for the :range modifier

There's no need to keep the result from brk_string in memory until the
buffer has been filled with the range. The only thing necessary from
brk_string is the number of words.
 1.385 01-Aug-2020  rillig make(1): fix error message when regcomp fails

If regcomp fails, it's not the regex substitution that is erroneous, but
the regex compilation.
 1.384 01-Aug-2020  rillig make(1): use enum for return values of Cond_Eval and friends
 1.383 01-Aug-2020  rillig make(1): fix documentation, use safer fallback value

The variable res is overwritten in every case, but better be safe than
sorry. In case of programming errors it's better to issue an error
message than to continue.
 1.382 01-Aug-2020  rillig make(1): make ModifyWords simpler

There is no need to test whether an actual word has been added. The
rule is simply "add a space before every word, except for the very
first".
 1.381 01-Aug-2020  rillig make(1): inline literal dollar characters

This reduces the code size when compiling with GCC 5. Apparently GCC
wasn't sure enough that str[0] and str[1] stay the same around the call
to Buf_AddByte.
 1.380 01-Aug-2020  rillig make(1): use consistent indentation in source code

Tabs for multiples of 8, then spaces.

The usage string has been kept as-is since the spaces there are
indentional and do influence the output.
 1.379 01-Aug-2020  rillig make(1): inline function in SysV modifier processing
 1.378 01-Aug-2020  rillig make(1): reduce the number of string comparisons in ${VAR:%.c=%.o}

There is only a single position in the word where the tail ".c" can
match, since it is implicitly anchored at the end. Therefore there's no
need to do several string comparisons.
 1.377 01-Aug-2020  rillig make(1): make variable names in SysV modifier more expressive

When matching a word against a substitution having a lhs and a rhs,
including a possible wildcard, there are just too many string variables
around to know what a simple "len" means and where it belongs.
 1.376 01-Aug-2020  rillig make(1): more descriptive variable names in Str_SYSVSubst
 1.375 01-Aug-2020  rillig make(1): let Var_Value return a const char *

The return value must not be modified anyway, so let the compiler check
this for free.
 1.374 01-Aug-2020  rillig make(1): fix documentation of Var_Value
 1.373 01-Aug-2020  rillig make(1): use better variable names in Var_Exists

Calling strchr just to initialize a variable to NULL is not as
straight-forward as possible.

The unspecific variable name cp made it unnecessarily difficult to
understand its purpose.
 1.372 01-Aug-2020  rillig make(1): make condition in Var_Export1 simpler to read
 1.371 01-Aug-2020  rillig make(1): use consistent pattern for testing flags
 1.370 01-Aug-2020  rillig make(1): clearly mark a variable in Var_Set_with_flags for freeing

No functional change.
 1.369 01-Aug-2020  rillig make(1): remove unnecessary snprintf from Var_ExportVars

String literals can be concatenated at compile time.

Furthermore, MAKE_EXPORTED can now contain percent characters without
invoking undefined behavior. Not that anyone would ever want to do this.
 1.368 31-Jul-2020  rillig make(1): mark unmodified part of ApplyModifiersState as constant
 1.367 31-Jul-2020  rillig make(1): reduce number of parameters to ApplyModifiers

This saves a call to strlen and some arithmetic operations.
 1.366 31-Jul-2020  rillig make(1): clean up Var_Parse

If *freePtr is not NULL, it only makes sense to free that pointer and not
a semmingly unrelated variable.
 1.365 31-Jul-2020  rillig make(1): remove some redundant parentheses
 1.364 31-Jul-2020  rillig make(1): omit unnecessary memory writes in :tu and :tl modifiers
 1.363 31-Jul-2020  rillig make(1): fix undefined behavior when parsing incomplete :t modifier

mod[2] must only ever be accessed if mod[1] != '\0'.
 1.362 31-Jul-2020  rillig make(1): reduce scope of local variables in ApplyModifier_Subst
 1.361 31-Jul-2020  rillig make(1): reduce scope of local variables in ApplyModifier_Regex
 1.360 31-Jul-2020  rillig make(1): fix undefined behavior when parsing malformed :C modifier

Same as in the :S modifier.
 1.359 31-Jul-2020  rillig make(1): fix undefined behavior in malformed :S modifier

The unit tests failed on Ubuntu, and by looking closely at the code, it
was trivial to see the out-of-bounds memory read.

Other modifiers may have the same problem and will be inspected later.
 1.358 29-Jul-2020  rillig make(1): remove unnecessary assignments to st->next

No change in the size of the resulting binary. Apparently GCC already
knew these assignments were redundant.
 1.357 29-Jul-2020  rillig make(1): document parameters to ApplyModifiers
 1.356 29-Jul-2020  rillig make(1): use specialized return type for ApplyModifier functions

This makes it immediately obvious what happens after a modifier has been
applied, instead of having to translate single-character mnemonics or
booleans to their actual intention.

This also reduces the size of the binary since there are fewer jumps.
 1.355 29-Jul-2020  rillig make(1): fix segfault when evaluating ${::=value}

The bug had been in the handling of the SysV modifier for many years, but
it had not been triggered since the "parsing position for the next
modifier" had been initialized to a non-NULL pointer.

In var.v r1.350, this pointer had been initialized to NULL instead since
every ApplyModifier function must set it in every case where it returns
anything except "default_case".

There might have been a slight chance of tricking make to output a wrong
error message, but nothing worse.
 1.354 29-Jul-2020  rillig make(1): add enough tests to cover the ApplyModifier functions

Only a few return statements are still missing from the code coverage.

In ApplyModifier_Assign, the test for an empty variable name is skipped
for now since it segfaults.

In ApplyModifier_SysV after the second ParseModifierPart, the branch for
the missing delimiter is not reached since this case is already checked
for in the first part of the function. To trigger this branch, a
specially crafted, unrealistic string needs to be created, and that's too
complicated for the moment.
 1.353 28-Jul-2020  rillig make(1): issue a parse error on unclosed variables

These errors had not been detected before by make.
In pkgsrc, this task as been done by pkglint since 2019-04-07.
 1.352 28-Jul-2020  rillig make(1): remove dead code from Var_Subst

The first parameter from Var_Subst had been a literal NULL in all cases.
These have been fixed using this command:

sed -i 's|Var_Subst(NULL, |Var_Subst(|' *.c

The one remaining case was not found because the "NULL," was followed by
a line break instead of a space.

The removed code probably wouldn't have worked as expected anyway.
Expanding a single variable to a literal string would have led to
unexpected behavior for cases like ${VAR:M${pattern}}, in case pattern
would contain an unescaped ':' itself.
 1.351 28-Jul-2020  rillig make(1): remove redundant ApplyModifiersState.termc
 1.350 27-Jul-2020  rillig make(1): document and reorder ApplyModifiersState
 1.349 27-Jul-2020  rillig make(1): rename ApplyModifiersState.nstr and newStr

The old names were too easy to confuse. In Var_Parse, nstr is indeed
used for the "new string", but that was misleading in ApplyModifiers,
especially since there was another variable called newStr.

The new variable names focus on the purpose of the variables, not on
their data types.
 1.348 27-Jul-2020  rillig make(1): rename ApplyModifiersState.cp to next

The name "next" is more descriptive than a mere "cp". It's easy to look
up the type of the variable, but not so easy to guess the purpose of the
variable, therefore the new name concentrates on the purpose.
 1.347 27-Jul-2020  rillig make(1): in ApplyModifier_Match, use short local variable name
 1.346 27-Jul-2020  rillig make(1): in ModifyWord_Match, use different variables

Using the same registers or memory locations for different variables is
the job of the register allocator, not the programmer. For humans, that
practice is rather confusing.
 1.345 27-Jul-2020  rillig make(1): replace comment in ApplyModifier_Match with code
 1.344 27-Jul-2020  rillig make(1): remove unused lengthPtr and freePtr from ApplyModifiersState
 1.343 27-Jul-2020  rillig make(1): remove unnecessary field from ApplyModifiersState
 1.342 27-Jul-2020  rillig make(1): remove unnecessary variable assignment

It is not the job of an ApplyModifier function to directly manipulate the
final result of the ApplyModifiers function. In fact, the resulting
pointer was overwritten unconditionally, in such an obvious way that the
compiler could have detected this. GCC 5 didn't though, which reduces
the code size a bit.
 1.341 27-Jul-2020  rillig make(1): move modifier character out of ApplyModifiersState

It is only used in the outer part of the loop to apply the modifiers.
 1.340 27-Jul-2020  rillig make(1): replace macros with functions

Having the hidden parameter st->endc in the macro made it unnecessarily
difficult to understand the code.
 1.339 27-Jul-2020  rillig make(1): use shorter variable name for parsing :D and :U
 1.338 27-Jul-2020  rillig make(1): remove unnecessary argument validation
 1.337 27-Jul-2020  rillig make(1): document API of Var_Value
 1.336 26-Jul-2020  rillig make(1): make test for dynamic variable name more specific

Since all the string literals have either 7 or 8 characters, there is no
need to call strcmp for shorter or longer variable names.
 1.335 26-Jul-2020  rillig make(1): extract code for dynamic variable names out of Var_Parse
 1.334 26-Jul-2020  rillig make(1): fix off-by-one error in Var_Parse for dynamic variables
 1.333 26-Jul-2020  rillig make(1): rename VarEvalFlags variables to eflags

This way, they cannot be confused with other flags, and any mismatch of
mixing eflags with constants other than VARE_* is immediately apparent.
 1.332 26-Jul-2020  rillig make(1): rename local variable in Var_Parse
 1.331 26-Jul-2020  rillig make(1): make return value of Var_Parse constant

This return value is not supposed to be modified since it can be a string
literal. The modifiable part is returned via freePtr, but only for
freeing, not for actually modifying anything.
 1.330 26-Jul-2020  rillig make(1): revert making Var_Parse return a const string

The dependencies between the C files and nonints.h are not declared
properly, which resulted in a successful partial build, but a full "make
clean && make" failed.
 1.329 26-Jul-2020  rillig make(1): mark result of Var_Parse as const

Var_Parse can return either a string literal or an allocated string. The
former must not be modified by the caller. If the string is allocated,
it is returned in freePtr as well, but only for freeing it after use.
 1.328 26-Jul-2020  rillig make(1): reduce scope and rename local variable in Var_Parse
 1.327 26-Jul-2020  rillig make(1): eliminate another local variable in Var_Parse
 1.326 26-Jul-2020  rillig make(1): split local variable into two in Var_Parse
 1.325 26-Jul-2020  rillig make(1): split local variable into two

Reusing a const char * parameter to store a char * and later free that
string was not a good idea. It made the pretty long code of Var_Parse
more difficult to understand.
 1.324 26-Jul-2020  rillig make(1): reorder arguments of ParseModifierPart

First the input parameters, then additional data, then special arguments.
 1.323 26-Jul-2020  rillig make(1): merge VARE_NOSUBST into VARE_WANTRES

The flag VARE_NOSUBST is only a few days old. It had grown out of the
VARP_NOSUBST and VAR_NOSUBST flags, not knowing at that time that it
meant the exact opposite of VARE_WANTRES.
 1.322 26-Jul-2020  rillig make(1): remove wrong comment from VarOrder
 1.321 26-Jul-2020  rillig make(1): reorder code in ParseModifierPart to be more readable
 1.320 26-Jul-2020  rillig make(1): in ParseModifierPart, only update length on success
 1.319 26-Jul-2020  rillig make(1): remove wrong comment for VarUniq

VarUniq is not about sorting the words.
 1.318 26-Jul-2020  rillig make(1): save a few bytes and cycles by comparing against 0

The comparison against ac - 1 could have been optimized by the compilers
as well, but both GCC 5 and Clang produce smaller code for the comparison
against 0.
 1.317 26-Jul-2020  rillig make(1): remove unnecessary block scope
 1.316 26-Jul-2020  rillig make(1): avoid memory allocation for oneBigWord in modifiers
 1.315 26-Jul-2020  rillig make(1): help the compiler to find common subexpressions
 1.314 26-Jul-2020  rillig make(1): add convenience functions for adding to a SepBuf
 1.313 26-Jul-2020  rillig make(1): add Buffer functions for common tasks

Adding a string or a substring to a buffer are common tasks when handling
variables. There is no need to spell out the strlen call or the pointer
subtraction at every call site.

Subtracting pointers results in a ptrdiff_t, which would have to be
converted to an int in each case for WARNS=6. Having this conversion in a
single place keeps the code clean.
 1.312 26-Jul-2020  rillig make(1): add Buf_AddInt to make the calling code simpler
 1.311 26-Jul-2020  rillig make(1): make code in the :S modifier simpler

This code path is covered by the "sequences of letters" in modmisc.mk.
 1.310 26-Jul-2020  rillig make(1): fix bug in :S modifier from 2020-07-19
 1.309 26-Jul-2020  rillig make(1): fix missing error message about missing @ delimiter

This had been broken since 2020-07-03, during a "refactoring".
 1.308 24-Jul-2020  rillig make(1): remove redundant condition

If there are multiple words from brk_string, none of them can be empty.
And if there is oneSingleWord that is empty, it doesn't hurt to add 0
bytes.
 1.307 24-Jul-2020  rillig make(1): prefer direct jump over indirect variable assignment
 1.306 24-Jul-2020  rillig make(1): make condition in ModifyWord_SubstRegex simpler

The generated code is still the same, at least with Clang.
 1.305 24-Jul-2020  rillig make(1): reduce lifetime of regmatch_t for :C modifier
 1.304 24-Jul-2020  rillig make(1): rename local variable
 1.303 24-Jul-2020  rillig make(1): allocate capturing groups for :C modifier statically

Since there are at most 10 capturing groups, it's easier to allocate them
on the stack.

To avoid growing the code size on x86_64, the matches have been moved to
the end of the struct, to keep the other offsets small.
 1.302 24-Jul-2020  rillig make(1): clean up Var_Export
 1.301 24-Jul-2020  rillig make(1): inline Var_Parse_State into ApplyModifiersState

There was no need to have this as a separate struct. Especially none of
the modifiers used by ModifyWords modify this state, therefore it was
not necessary to pass it by reference. This makes the code easier to
understand since there's less modifiable state.
 1.300 24-Jul-2020  rillig make(1): document ApplyModifiersState.cp
 1.299 24-Jul-2020  rillig make(1): eliminate ApplyModifiersState.tstr

This field always pointed to the beginning of the current modifier.
Therefore a better name is "mod", and there is no need to store it in the
shared state.
 1.298 23-Jul-2020  rillig make(1): only set missing_delim if it is actually missing

Just to make it easier to understand the code.
 1.297 23-Jul-2020  rillig make(1): fix wrong warning about missing delimiter
 1.296 23-Jul-2020  rillig make(1): reduce code size on x86_64
 1.295 21-Jul-2020  rillig make(1): remove parameter from ModifyWordCallback

Most modifiers don't need a variable context, and those that do already
get all their parameters in a custom Args struct.
 1.294 21-Jul-2020  rillig make(1): make implementation of the :C modifier simpler
 1.293 21-Jul-2020  rillig make(1): only ask for newline if :Q actually needs it

This simple change reduces the binary size of var.o by 96 bytes (Clang,
x86_64). Given that the code is still the same, just in a different
order, this is a bit surprising.
 1.292 21-Jul-2020  rillig make(1): clean up various things in var.c
 1.291 21-Jul-2020  rillig make(1): use consistent and descriptive names for callback functions
 1.290 21-Jul-2020  rillig make(1): remove unnecessary VarSelectWords_t struct
 1.289 20-Jul-2020  rillig make(1): extract :ts<separator> modifier into separate function
 1.288 20-Jul-2020  rillig make(1): clean up implementation of :[...] and other modifiers
 1.287 20-Jul-2020  rillig make(1): fix edge cases with $ at the end of the :@ modifier

In both parts of the :@ modifier, by passing &pflags to
ParseModifierPart, a final $ was interpreted as an anchor, which only
makes sense in the :S and :C modifiers.

This edge case is neither used by src nor by pkgsrc, except for the unit
tests that have been adjusted.
 1.286 20-Jul-2020  sjg Make DEBUG_HASH less of a fire-hose.

Reporting keys on every lookup is overkill unless
playing with a new HASH, so wrap in #ifdef DEBUG_HASH_LOOKUP
Also add some stats at the end so we can see
final size and max chain length - maxchain is a better
variable name than maxlen.
 1.285 20-Jul-2020  rillig make(1): make conditions work without pattern flags

The "pattern flag" VARP_NOSUBST was used to prevent evaluating
irrelevant conditions. Omitting the evaluation flag VARE_WANTRES has the
same effect.
 1.284 20-Jul-2020  rillig make(1): fix obscure edge case for ${VAR:e$=x}

The characters "$=" do not occur in either src or pkgsrc, therefore this
case is unlikely to occur in practice.
 1.283 20-Jul-2020  rillig make(1): move documentation for assignment modifiers
 1.282 20-Jul-2020  rillig make(1): prefer memcmp over strncmp
 1.281 20-Jul-2020  rillig make(1): fix type of VarPattern.lhsLen and rhsLen

String length is measured in size_t, not int.
 1.280 20-Jul-2020  rillig make(1): fix undefined behavior in :S modifier

The expression word + wordLen - leftLen had resulted in an out-of-bounds
pointer before. Luckily the heap addresses were high enough in typical
applications to prevent a wrap-around.
 1.279 20-Jul-2020  rillig make(1): make implementation of the :S modifier simpler
 1.278 20-Jul-2020  rillig make(1): make modifier handling simpler

Implementing a modifier such as :S or :M should not be concerned with
separating the words of the resulting string. Ideally this should be
done in the same way by all modifiers.

Before, the :R (filename root) modifier added a separator even if the
resulting filename root was an empty string. The chances that this
change in behavior breaks anything are epsilon.

The :@ modifier, if it appeared after a :ts modifier, did not use the
word separator from the :ts modifier (which all other modifiers do) but
always added a space. This behavior has been preserved for now. It's an
unnecessary inconsistency though.

In contrast to Buffer, the newly added SepBuf uses size_t for memory
sizes and also uses the conventional parameter order (mem, memsize)
instead of the unusual (memsize, mem).
 1.277 19-Jul-2020  rillig make(1): remove unnecessary UNCONST
 1.276 19-Jul-2020  rillig make(1): make ampersand in ${VAR:from=to&} an ordinary character

In SysV substitutions, wildcards are expressed with % instead of &. The
& is not mentioned in the manual page, and having another wildcard for
the whole word would be such an obscure feature that not even pkgsrc uses
it. The easiest way to discover this feature had been to read the source
code of make(1) or to use a fuzzer and accidentally stumble upon this
edge case.
 1.275 19-Jul-2020  rillig make(1): don't call VarSubstitute unnecessarily
 1.274 19-Jul-2020  rillig make(1): remove wrong VarPattern from ApplyModifier_Exclam
 1.273 19-Jul-2020  rillig make(1): remove wrong VarPattern from ApplyModifier_Assign
 1.272 19-Jul-2020  rillig make(1): flatten ApplyModifier_Assign
 1.271 19-Jul-2020  rillig make(1): fix off-by-one error in :C modifier

Previously this off-by-one error had invoked undefined behavior.
Until today there was no corresponding unit test though.
 1.270 19-Jul-2020  rillig make(1): fix double free introduced this morning in r1.258
 1.269 19-Jul-2020  rillig make(1): remove redundant loop control variable
 1.268 19-Jul-2020  rillig make(1): rename ApplyModifiersState.flags to eflags

There are just too many variables called "flags" in this file, and their
constants must not accidentally overlap.
 1.267 19-Jul-2020  rillig make(1): clean up VarLoop structure
 1.266 19-Jul-2020  rillig make(1): remove unused parameter from ParseModifierPart
 1.265 19-Jul-2020  rillig make(1): rename VarGetPattern to ParseModifierPart
 1.264 19-Jul-2020  rillig make(1): eliminate unused local variables
 1.263 19-Jul-2020  rillig make(1): eliminate macro from VarGetPattern
 1.262 19-Jul-2020  rillig make(1): replace ApplyModifiersState field with local variable
 1.261 19-Jul-2020  rillig make(1): rename flags for :S and :C pattern matching

Renaming these flags makes it obvious that VarPattern is used in a few
places where it doesn't belong. These will be fixed in follow-up
commits.
 1.260 19-Jul-2020  rillig make(1): convert VarFind flags to typed enum
 1.259 19-Jul-2020  rillig make(1): rename Varf_Flags to VarEvalFlags

In var.c there are lots of different flag types. To make any accidental
mixture obvious, each flag group gets its own prefix.

The only flag group that is visible outside of var.c is concerned with
evaluating variables, therefore the "e", which replaces the former "f"
that probably just meant "flag".
 1.258 19-Jul-2020  rillig make(1): clean up handling of :? modifier

The VarPattern type had nothing to do with parsing conditions.
 1.257 19-Jul-2020  rillig make(1): clean up code in var.c

* use canonical comparison to zero in more cases
* omit unnecessary snprintf for string literal concatenation
* omit a few redundant parentheses and braces
 1.256 19-Jul-2020  rillig make(1): move SysV string matching to var.c

This kind of string matching is only used in variable modifiers, and only
if this feature is enabled by SYSVVARSUB.
 1.255 04-Jul-2020  rillig make(1): expand the test for variable expansion in the :@ modifier
 1.254 04-Jul-2020  rillig make(1): add debugging output for :@ modifier

The inner working of the :@ modifier is quite tricky. To understand what
really happens, it helps to look at each word as it is being modified.
 1.253 04-Jul-2020  rillig make(1): constify VarModify parameter

Since var.c r1.238 and r1.239, the callbacks for the :H :T :E :R modifiers
don't modify the word anymore, and the others didn't modify it at all.
 1.252 04-Jul-2020  rillig make(1): fix :hash modifier on 16-bit platforms

On platforms where int has only 16 bits the shifts would have been in
16-bit arithmetic, which would invoke undefined behavior for "ustr[3] <<
24" as well as "ustr[2] << 16" (C99, 6.5.7p3).
 1.251 04-Jul-2020  rillig make(1): remove unnecessary _t suffix from VarLoop type
 1.250 04-Jul-2020  rillig make(1): fix documentation of Var_Subst, clean up other documentation
 1.249 04-Jul-2020  rillig make(1): remove unnecessary forward declarations, fix indentation
 1.248 04-Jul-2020  rillig make(1): remove unnecessary forward declarations
 1.247 04-Jul-2020  lukem make: fix sign-compare warning

Fix -Wsign-compare warning on amd64, introduced in rev 1.239
 1.246 03-Jul-2020  rillig make(1): reduce line length in var.c
 1.245 03-Jul-2020  rillig make(1): refactor ApplyModifier_SysV to have less indentation
 1.244 03-Jul-2020  rillig make(1): clean up documentation, small refactorings for variables

- document the callback for VarModify
- clearly mark the callbacks
- shorten the documentation for some callback functions
- fix the documentation of VarSYSVMatch
- remove unnecessary null check from VarLoopExpand
- add test for applying modifiers to empty strings
 1.243 03-Jul-2020  rillig make(1): fix bug in :E modifier, introduced in r1.239 today

That case was not covered by the tests before.
 1.242 03-Jul-2020  rillig make(1): fix indentation in var.c

Fixing the indentation manually is a tedious task. indent(1) was no help
since it has several bugs and is not flexible enough for the original
make code.
 1.241 03-Jul-2020  rillig make(1): add Hash_ForEach to avoid duplicate code
 1.240 03-Jul-2020  rillig make(1): fix indentation and alignment
 1.239 03-Jul-2020  rillig make(1): make code for the :E and :R modifiers simpler
 1.238 03-Jul-2020  rillig make(1): clean up code for the :H and :T modifiers
 1.237 03-Jul-2020  rillig make(1): add missing test for the :H and :T modifiers
 1.236 03-Jul-2020  rillig make(1): refactor ApplyModifiers

Previously, ApplyModifiers was 1200 lines long and pretty complicated.
Now each of the complicated modifiers has its own function, which reduces
the indentation and makes it possible to use early returns.
 1.235 03-Jul-2020  rillig make(1): remove trailing whitespace
 1.234 03-Jul-2020  rillig make(1): remove redundant parentheses around return values
 1.233 02-Jul-2020  rillig make(1): fix unnecessary evaluation of variables in :@var@ modifier
 1.232 02-Jul-2020  rillig make(1): fix unnecessary evaluation for :S :C := modifiers
 1.231 02-Jul-2020  rillig make(1): clean up code in var.c

- remove redundant parentheses in return statements
- add missing space after comma
- remove some redundant parentheses around comparisons
- use hexadecimal numbers for bit mask constants
- remove Var_GetTail and Var_GetHead, which had been unused for 19 years
 1.230 02-Jul-2020  rillig make(1): remove useless parameter from Var_Set

The enum corresponding to this int parameter is only defined in var.c,
which makes it impractical for the outside to set this parameter to
anything but 0.

On x86_64, this reduces the size of the resulting executable by 5 kB.
 1.229 02-Jul-2020  rillig make(1): use enum instead of #define for VarPattern flags
 1.228 02-Jul-2020  rillig make(1): add more type safety for enums

There are several types of flags for variables, and these cannot be
mixed. To prevent accidental typos, these are defined in separate enum
types. Clang warns about direct assignments between distinct types, but
not about mixing distinct types in binary expressions like A | B. GCC
does not warn at all.
 1.227 02-Jul-2020  rillig make(1): fix unnecessary evaluation of :M and :N modifiers
 1.226 02-Jul-2020  rillig make(1): fix edge case for evaluating unnecessary conditions
 1.225 01-Jul-2020  sjg Fix parsing of nested variables during .for loop

Recent change to cond.c to avoid eval of unnecessary
terms had side effect on constructs like:

.for s in 1 2
.if defined(MAN$s) && !empty(MAN$s)
MAN+= ${MAN$s}
.endif
.endfor

resulting in MAN being flagged as recursive.

When Var_Parse encounters a variable within a variable name
we want to force it to be expanded.
But given the way get_mpt_arg calls Var_Parse we need to check
whether we actually started parsing a variable yet.
 1.224 05-Jun-2020  sjg make: add :Or for reverse sort

:Or is more efficient than :O:[-1..1]

Reviewed by: christos
 1.223 25-Apr-2020  christos - Percent on the rhs is special only if the lhs has one too.
- If the rhs does not have percent, but the lhs has, the result is the rhs
This behavior matches gmake
 1.222 03-Feb-2019  mrg - add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily
 1.221 21-Dec-2018  sjg unexport-env: avoid SEGFAULT if MAKELEVEL not in env
 1.220 27-May-2018  christos branches: 1.220.2;
- Introduce :q modifier for make variables and make it double escape $'s so
that passing variables to recursive makes with :q works as expected.
- Revert :Q to work as before.
- Adjust makefiles that use recursive make to use :q

Discussed on tech-toolchain@
XXX: pullup 8
 1.219 24-May-2018  christos Since ${MAKE} converts $$ -> $ during parsing we need to put it back to
preserve the original variable value with :Q.
XXX: pullup-8
 1.218 18-Feb-2018  sjg branches: 1.218.2;
Var_Set: avoid SIGSEGV if val is NULL

A NULL val is handled gracefully (by VarAdd) when
var is not previously set, so we ought not crash
the second time.

PR: 53034
 1.217 08-Dec-2017  sjg Ensure VAR+=val on command line is handled correctly

If VAR is not previously set, call Var_Set to deal with
the special case of VAR_CMD.

If VAR is previously set, and ctxt is VAR_CMD we should do the update
even if VAR_FROM_CMD is set.
 1.216 18-Nov-2017  sjg Do not append to variable set on command line

POSIX requires that variables set on the command line
be immutable.
Var_Append needs to pass FIND_CMD and skip append
if found variable has VAR_FROM_CMD flag set.
 1.215 16-Apr-2017  riastradh branches: 1.215.4;
Plug memory leak.

CID 978372
 1.214 16-Apr-2017  riastradh Use, don't kludge, MAKE_ATTR_UNUSED.

CID 1300234
CID 1300237
CID 1300238
CID 1300245
CID 1300255
CID 1300267
CID 1300284
 1.213 01-Feb-2017  sjg Since we are avoiding VAR_INTERNAL, allow the variable :_ stores to
to be specified, also allows for multiple stages of modification to
be stashed.
 1.212 01-Feb-2017  sjg Just have :_ use current ctxt, avoid need to force VAR_INTERNAL.
 1.211 31-Jan-2017  sjg Use VAR_INTERNAL when calling ApplyModifiers for VAR_{CMD,GLOBAL} only.
 1.210 30-Jan-2017  sjg Add :range and :_

:range replaces var value with an integer sequence one per word
in the current var value.

:_ stores the current var value in $_ so that it can be referred to
later in the modifier series.

Reviewed by: christos
 1.209 14-Jan-2017  sjg branches: 1.209.2;
Allow providing a utc value to :{gm,local}time

Reviewed by: christos
 1.208 03-Jun-2016  sjg branches: 1.208.2;
Add cached_realpath()

realpath(3) is expensive, and meta mode at least uses it extensively.
We use cached_realpath() to save the result of successful calls to
realpath(3) in a private variable context.

This improves the worst case performance (eg examining libc with
nothing to do) by a factor of 4.

Reviewed by: christos
 1.207 11-Mar-2016  matthias $% is $(.MEMBER) and not $(.ARCHIVE), $! is $(.ARCHIVE) and not $(.MEMBER)
 1.206 07-Mar-2016  sjg For :ts numeric escapes \x* is hex, anything else is octal.
 1.205 20-Feb-2016  sjg Add a knob .MAKE.SAVE_DOLLARS to control the behavior of $$ during :=

If TRUE '$$' are not consumed (saved).
If FALSE '$$' becomes '$' just like normal expansion rules.

default is TRUE.

Reviewed by: christos
 1.204 18-Feb-2016  sjg Delete :@ loop iterator when done with it
 1.203 18-Feb-2016  sjg Add .export-literal to avoid the need for $$ dance when trying to put
unexpanded variables into environment.

Reviewed by: christos
 1.202 18-Feb-2016  christos Collapse the 3 boolean parameter to 1 flags parameter. No functional change.
 1.201 09-Jan-2016  christos Preserve $$ in := assignments..

FOO=\$$CRAP
BAR:=${FOO}

all:
echo ${FOO}
echo ${BAR}
 1.200 01-Dec-2015  sjg Avoid calling brk_string() and hence Var_Export1() on
empty strings.
 1.199 20-Oct-2015  sjg Ensure emsg initialized
 1.198 12-Oct-2015  sjg The conditional expressions used with ':?' can be expensive
eg. exists() does stat(2).
If 'wantit' is FALSE, we are going to discard everything anyway,
so skip evaluating the conditional and expanding either lhs or rhs.
 1.197 11-Oct-2015  sjg Add Boolean wantit to Var_Parse and Var_Subst

wantit will be FALSE when we are just consuming to discard
in which case we skip "expensive" things like Cmd_Exec.

Reviewed by: christos
 1.196 06-Oct-2015  christos don't check for NULL before free() (Tilman Sauerbeck)
 1.195 19-Jun-2015  christos use isspace()
 1.194 19-Jun-2015  mlelstv Adjust metachar handling to previous behaviour:
- space and tab are no shell metachars, remove them from generic
metachar function
- add space and tab as to-be-quoted characters for :Q modifier
- add = and : as characters that require command handling by the shell
 1.193 17-Jun-2015  christos Centralize the "is a meta char" test, instead of using two different arrays.
 1.192 05-May-2015  sjg When evaluating condtionals from .if we want to require
that the lhs is a variable reference, a number or a quoted string.
This helps avoid subtle bugs caused by typos.

When conditionals are being evaluated during variable expansion
we cannot be as strict becuase lhs will already have been expanded.

We therefor pass a boolean to Cond_EvalExpression to tell it how
lhs should be treated.

Add unit-tests/cond2.mk to test the above

Reviewed by: christos, joerg
 1.191 14-Sep-2014  dholland Fix handling of the silly $(@D) $(@F) etc. vars so modifiers on them
work. This is issue #1 in PR 49085 from Jarmo Jaakkola, but I've used
a different and cleaner patch this time.
 1.190 13-Sep-2014  dholland Recognize the crazy POSIXisms $(?D) and $(?F); issue 2 in PR 49085
from Jarmo Jaakkola.
 1.189 13-Sep-2014  dholland typo in comment, from the first reverted patch
 1.188 07-Sep-2014  joerg Revert all make changes except the unit tests to the state of three
weeks ago. Individual changes can be reapplied after review.
 1.187 23-Aug-2014  christos PR/49085: Jarmo Jaakkola: fix several parsing errors

Don't exit from var.c:Var_Parse() before possible modifiers are handled
on D and F modified versions of local variables. Properly expand $(?D)
and $(?F) too.

Make line continuations in rule's commands POSIX compliant.

Fix the syntax error caused by lib(member) as the last target before
a dependency operator.

Document the line continuation change in the manual page. Also talk
more about the POSIX style local variables and their modifiers.

Add tests covering the fixed problems into d_posix.mk. The test is
a known failure at the moment because of PR 49086 and PR 49092.

[XXX: unconverted tests]
 1.186 20-Jun-2014  sjg Return varNoError rather than var_Error for ::?= etc.
 1.185 19-May-2014  sjg Var_Parse: endc only counts when at the correct nesting depth.
This ensures we correctly detect errors like:
.if empty(VAR && !empty(FOO)

Var_Subst: if Var_Parse returns var_Error it is an error.
This ensures we detect errors like:

VAR:= ${FOO.${GOO}
 1.184 04-Sep-2013  sjg branches: 1.184.2;
Add VAR_INTERNAL as a context for variables set by make itself,
which should not override those set by makefiles.
Currently MAKEFILE is the only variable affected.

Reviewed by: christos
 1.183 16-Jul-2013  sjg When a var is set in the CMD context, it prevents the same name
being set in GLOBAL context. We should also delete any such
variable in GLOBAL context, else make -V will show the wrong value.
 1.182 16-Jul-2013  christos More gmake compatibility:
1. add -w flag to print Entering and Leaving directory name the the beginning
and the end of processing.
2. export MAKELEVEL=$((MAKELEVEL + 1)) only in the child environment.
3. when printing error messages, prefix them with the program name [$MAKELEVEL]
for $MAKELEVEL > 0
4. if $MAKEFLAGS consists only of letters assume it is a set of flags (as
allowed by posix), convert them to -f -l -a -g -s, so that they get parsed
properly.
With those fixes gmake -> bmake -> gmake -> bmake etc. works as expected.
 1.181 15-Jul-2013  christos Make this work again like gmake. sjg: see the test program.
 1.180 06-Jul-2013  sjg If using gmake's MAKELEVEL; use it the same way
 1.179 18-Jun-2013  sjg Use a #define for the variable name we put in environment to pass .MAKE.LEVEL
in case we don't want to use gmake's MAKELEVEL in a different way.
 1.178 10-Jun-2013  christos put back previous change
 1.177 10-Jun-2013  joerg Revert last, it doesn't even build.
 1.176 10-Jun-2013  christos 1. Don't export .MAKE.LEVEL, because this is an illegal variable name for
some shells; export MAKELEVEL like gmake(1) does.
2. It is absurd for the environment variable to be one greater than the
make variable!?!?! To wit...
printf 'all:\n\t@echo ${.MAKE.LEVEL}; printenv .MAKE.LEVEL' | make -f -
 1.175 29-May-2013  sjg Clean up some left overs
 1.174 18-May-2013  sjg Var_Delete: expand name if needed.
 1.173 24-Feb-2013  christos While it is nice to have the same function do both the upper case and
lower case conversion, it ends up eating 4% of the total time we spend
in make calling tolower() while building libc.
 1.172 15-Nov-2012  christos include the variable name in debugging printfs.
 1.171 12-Jun-2012  joerg branches: 1.171.2;
Replace __dead, __unused and the various printf format attributes
with versions prefixed by MAKE_ATTR_* to avoid modifying the
implementation namespace. Make sure they are available in all places
using nonints.h to fix bootstrap on Linux.
 1.170 04-Jun-2012  sjg Var_UnExport() and setenv() can both realloc environ.
Use a common variable (savedEnv) to track that to avoid wasting memory.
Also, if providing setenv and unsetenv, do getenv too to ensure a consistent
set.
 1.169 18-May-2012  sjg Avoid nested extern declaration warnings
 1.168 24-Apr-2012  sjg Var* are generally very liberal with memory, with the expectation
that none of it persists for long.
This isn't always true - for example a long running .for loop.

Buf_DestroyCompact() is used by Var_Subst(), rather than Buf_Destroy().
If it looks like we can save BUF_COMPACT_LIMIT (128) or more bytes,
call realloc. This can reduce memory consumption by about 20%
Setting BUF_COMPACT_LIMIT to 0 dissables this.
 1.167 03-Jun-2011  sjg branches: 1.167.2;
ApplyModifiers: if we parse a variable in the modifier list,
do not consider it a nested modifier set, unless it is followed by
endc, a ':' or end of string.
 1.166 21-May-2011  tsutsui branches: 1.166.2;
Explicitly #include <time.h> for time(3) and strftime(3).
Fixes warnings on some non NetBSD hosts.
 1.165 11-Apr-2011  sjg If a "long" modifier name does not match, goto default case
so SysV modifier can be tried.
 1.164 11-Apr-2011  sjg Add :localtime and :gmtime which use value as format string for strftime.
 1.163 07-Apr-2011  joerg Add the :hash modifier to compute a 32bit hash of an variable.
This uses MurmurHash3 to get a reasonable collission-free hash with
small code. The result is endian neutral.
 1.162 06-Mar-2011  sjg Add unit tests to check that exists(some/dir/) works

Also fix handling of sysV substitutions when lhs and variable are empty.

Also that modifiers do not cause errors during conditional tests
when undefined variables should otherwise be ok.
Ie. .if defined(nosuch) && ${nosuch:Mx} != ""
 1.161 02-Dec-2010  christos From Aleksey Cheusov: Fix unexpected behavior with:
all: test1 test2
test1:
@echo ${foo::=foo-text}
test2:
@echo $(foo::=foo-text)
Saying:
nbmake: Unclosed substitution for foo (} missing)
for test 2
 1.160 02-Dec-2010  christos add commented out a possible addition that provides $^ like gmake, but
I am not sure if we should add it, since we already have $> for it.
 1.159 06-Jun-2010  sjg Add .export-env which tells make to export a variable to the environment
but not to track it - as is done for .export
This allows the variable to be updated without affecting what was put
into the environment.
Older versions of make will simply treat this as .export
 1.158 21-Apr-2010  sjg If we do .export (all) and have any variables that involve :sh
we will hit an error (var is recursive) while trying to evaluate that.
Fix, and add a unit test for this.
 1.157 20-Apr-2010  sjg Behavior of realpath() appears to vary.
To ensure consistent results, use stat(2) as a final check for success.
 1.156 15-Apr-2010  sjg Add :tA to attempt to resolve to absoute path using realpath().
 1.155 19-Nov-2009  sjg Add .unexport - the exact opposite of .export
and .unexport-env which unexport's all previously .export'd globals
as well as clearing environ[].
Allow's sys.mk near total controll.

Reviewed by: apb
 1.154 08-Sep-2009  sjg Reviewed by: apb

Use .MAKE.LEVEL to track recursion.
The first instance of make will have .MAKE.LEVEL 0, which
can be handy for excluding rules which should not apply
in a sub-make.
gmake and freebsd's make have a similar mechanism, but each
uses a different variable to track it. Since we cannot be
compatible with both, we allow the makefiles to cope if they want
by handling the export of .MAKE.LEVEL+1 in Var_Set().
 1.153 07-Sep-2009  sjg PR: 41998

:Ufu\:goo

should expand to fu:goo even when it appears in :M${:Ufu\:goo}
When scanning for :M do not compress \: if we know we have
to call Var_Subst.
 1.152 16-Jun-2009  sjg Child of vfork() must not alter the state of parent.
There is no need to touch the state of vars in child anyway.
Change 2nd arg to Var_Export1() to indicate if we are the parent or child,
and only set flags in the parent.
 1.151 18-Feb-2009  christos adjust patch to current.
 1.150 18-Feb-2009  christos CID 5044: Protect against NULL deref.
 1.149 28-Jan-2009  dsl branches: 1.149.2;
Allow for () in the argument to .ifdef et al.
Save/restore current values of global data across expression evaluation
to give ${foo:? ...} a change of working inside another .if.
 1.148 23-Jan-2009  dsl Change 'ClientData' to 'void *' so that relevant parameters can
be made 'const void *'.
 1.147 18-Jan-2009  lukem fix -Wsign-compare issues
 1.146 17-Jan-2009  dsl Change 'Buffer' so that it is the actual struct, not a pointer to it.
Saves having to malloc/free a fixed size structure.
Buf_Init() now takes ptr to Buffer to initialiase.
Change Buf_Destroy() to return ptr to string when not freed.
Remove large number of casts to (Byte) and (Byte *) - 'Byte' is 'char' here.
Buf_AddByte[s] guarantees that the data is 0 termininated, so never add '\0'.
Keep 'count' not 'left' and 'inPtr', code is simplier with only one update.
Fix fallou, no functional change.
 1.145 16-Jan-2009  dsl Debug print improvements.
 1.144 29-Dec-2008  dsl In the :M code, 'pattern' is always malloced memory - so unconditionally
free.
 1.143 29-Dec-2008  dsl Count both () and {} when looking for the end of a :M pattern.
In particular inside .if empty(...) it was only counting ().
In reality this needs further changes.
This may well fix recent pkgsrc breakage.
 1.142 23-Dec-2008  dsl Treat '\\' as a possible terminator for a loop control variable.
(Typically an escaped \: of a nested modifier.)
 1.141 21-Dec-2008  dsl Don't allow $) $} $: or $$ as variable expansions, they confuse other
parts of make that try to scan through variable expansions.
(given the make syntax that is all rather doomed anyway!)
Move the check for $\0 to a place where it will be detected - otherwise
the parser will run off the input buffer!
 1.140 20-Dec-2008  dsl A lot of code assumes that the pointer returned by Buf_GetAll() is malloced.
Replace Buf_Discard() with Buf_Empty() since the former might leave the
'outPtr != buffer' and the only caller wanted all the data discared.
Remove 'outPtr' now that it always equals 'buffer'.
The assumption about Buf_GetAll()is now guaranteed by design.
 1.139 20-Dec-2008  dsl Do not allow Var_Set() or Var_Append() to set the empty variable (which will
now forever remain undefined).
Rework/simplify code to avoid UNCONST().
 1.138 20-Dec-2008  dsl Change some "^I *^I" to "^I^I" and align the comment block about
variable modifiers.
 1.137 19-Dec-2008  christos add a little more debugging.
 1.136 13-Dec-2008  dsl Use NULL instead of -1 cast to the relavant type (usually via NIL).
This was a suggestion from christos - so blame him if there is a deep
reason for using -1 :-)
 1.135 13-Dec-2008  dsl Do not let the variable name "" be set from the command line (-D "")
or from ::= modifiers (${::=foo}).
 1.134 06-Oct-2008  joerg Don't use emalloc and friends directly, but call them consistently
bmake_malloc and friends. Implement them via macros for the native case
and provide fallback implementations otherwise. Avoid polluting the
namespace by not defining enomem globally. Don't bother to provide
strdup and strndup, they were only used for the estrdup and estrndup
comapt code.

This addresses the presence of emalloc in system libraries on A/UX and
resulted strange issues as reported by Timothy E. Larson.
 1.133 31-Jul-2008  joerg Micro-optimise VarQuote by exploiting that meta characters are normally
rare and skipping over normal characters with strcspn is therefore
faster. Further simplify logic by always setting newline and precompute
the size of the string.

OK christos@
 1.132 31-Jul-2008  joerg Meta characters are a constant, mark it so.
 1.131 15-May-2008  sjg VAR_CMD context is used by conditionals and other purposes, so
actually set VAR_FROM_CMD when appropriate and only skip setting in
VAR_GLOBAL when that flag is set.
 1.130 15-May-2008  sjg Disable this for now, VAR_CMD is abused for other purposes...
 1.129 14-May-2008  sjg Do not set vars in VAR_GLOBAL context, if they have been set on the
command line.
Add a suitable unit-test.
 1.128 31-Mar-2008  sjg branches: 1.128.2; 1.128.4;
If the name passed to Var_Exists contains '$' run it through Var_Subst.
 1.127 15-Feb-2008  christos back all changes out until I fix it properly.
 1.126 15-Feb-2008  christos remove error/noerror const
 1.125 15-Feb-2008  christos - symbolic names for error and no error
- more size_t
 1.124 14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.123 13-Oct-2007  apb Don't write into const strings; not even if we intend to
reinstate the original contents later.
 1.122 13-Oct-2007  apb * Convert all uses of strdup() to estrdup();
* Use estrndup() in a few cases where it simplifies the code;
* Provide compatibility definitions of strndup and estrndup;
 1.121 13-Oct-2007  apb Oops, missed a few more comments in previous.
 1.120 13-Oct-2007  apb Correct documentation for Var_Parse's freePtr arg. It's a pointer to
the thing to be freed (or NULL if nothing to free), not to a pointer to
boolean saying whether or not to free the result.
 1.119 09-Oct-2007  sjg Fix an off-by-one error in handing mal-formed modifiers.
The issue seems to have been present for some time, only showed up
when running unit-tests on SunOS.
Make sure we get an error message, but otherwise behave as before.
 1.118 05-Oct-2007  sjg Add the ability to .export variables to the environment.
 1.117 16-Jun-2007  dsl branches: 1.117.4;
Under DEBUG(VAR) report when the variable wasn't found.
Disposes of pr bin/15842
 1.116 01-Jan-2007  dsl Since the 'buf' code here is only used by make, we don't need two names
for the default buffer size of 256.
Also allow for the trailing 0 byte!
 1.115 27-Oct-2006  dsl branches: 1.115.2; 1.115.4;
Since 'ClientData' is 'void *', nuke almost all the (ClientData) casts.
 1.114 15-Oct-2006  dsl Output all debug trace output through 'debug_file' defaulting to 'stdout'.
(Almost all the debug output went there, but some went to stderr.)
Split the parsing of -d (debug flags) out into its own routine.
Allow the output filename to be changed by specifying -dF<file> to create
a log file, or -dF+<file> to append to it. <file> may be stdout or stderr.
Also change so that -d-<flags> acts on <flags> locally but doesn't copy
them to MAKEFLAGS so they aren't inherited by child makes.
I'm not 100% happy with the command line syntax for the above, so they are
currently undocumented.
 1.113 26-Aug-2006  christos More programs using efun.
 1.112 28-Jul-2006  sjg Indicate which modifier a result applies to, helps debug complex cases.
 1.111 29-Jun-2006  rillig Fixed the bug reported in PR 33866, which is that the :Q operator does not
handle newlines correctly. Ok'ed by christos.
 1.110 19-May-2006  christos branches: 1.110.2;
Coverity CI D3758: Plug memory leak.
 1.109 19-May-2006  christos Coverity CID 3757: Plug memory leak.
 1.108 11-May-2006  sjg Extract the variable modifier logic to a separate function.
This cuts Var_Parse in half! and allows the modifier logic to
be used recursively - when getting modifiers via variables.

Add new unit-test, to check that certain error cases are handled
correctly.
 1.107 22-Apr-2006  christos Coverity CID 529: Call VarFreeEnv to prevent leak.
 1.106 22-Apr-2006  christos Coverity CID 534: Free junk variables on return from Var_Parse.
 1.105 22-Apr-2006  christos Coverity CID 533: Plug memory leak.
Add a new function VarFreeEnv() to free environment variables and use it.
 1.104 31-Mar-2006  christos Add some coverity allocation comments, and change the way the allocator
functions work. When they allocate storage that needs to be freed, instead
of setting a boolean, set the pointer to be freed. Plug some more memory
leaks found by inspection.
 1.103 19-Mar-2006  sjg Fix :P modifier so it actually works as described.
I.e ${var.c:P} should expand to the absolute path of var.c found via .PATH
 1.102 26-Feb-2006  sjg Update man page and add test case for specifying modifiers via variable.
Also allow said variable to appear anywhere in the modifier list.
 1.101 18-Feb-2006  sjg Allow variable modifiers to be specified via variable.
 1.100 27-Aug-2005  christos PR/31077: Wil L: /usr/bin/make can read off of end of buffer
 1.99 08-Aug-2005  christos From Max Okumoto:
- Remove casts to NULL.
- Remove space between cast and object.
 1.98 05-Aug-2005  christos More KNF cleanups from Max Okumoto
 1.97 25-Jul-2005  christos Whitespace KNF cleanup from Max Okumoto
 1.96 01-Jul-2005  christos PR/29985: Roland Illig: make(1) interprets backslash wrongly in for
loop expansions, when the expanded variable ends in backslash and
the backslash is the last character on the line. While this fix is
ugly (detect the condition and append a space), it is the least
intrusive for now.
 1.95 03-Jun-2005  lukem * Improve error handling with unrecognized chars after :t.
* Explicitly goto default_case for unknown chars encountered after
various : modifiers, rather than multiple FALLTHRUs.
* Appease gcc -Wuninitialized for sv_name and v_ctxt.

Discussed with sjg.
 1.94 03-Jun-2005  lukem cosmetic comment tweak
 1.93 01-Jun-2005  sjg Add :Ox for random ordering, based on patch from
Mike M. Volokhov <mishka@apk.od.ua>
 1.92 16-Feb-2005  christos PR/29203, PR/29204: Max Okumoto: KNF changes to make [no functional changes]
 1.91 30-Oct-2004  dsl Add (unsigned char) cast to ctype functions
 1.90 01-Jul-2004  jmc Change to use __unused instead and provide a compat definition in make.h if
not already defined from cdefs.h
 1.89 01-Jul-2004  jmc Add some checks for gcc around a few function declarations and note the
unused variables. Also fix a few other warnings that PR#22118 shows when
trying to compile bmake on non-NetBSD hosts
 1.88 07-May-2004  ross Simplify build, no functional changes.

Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().

It's now possible to build make on some hosts with: cc *.c */*.c
 1.87 20-Feb-2004  sjg branches: 1.87.2;
Fix :M so that modifiers in nested variables don't terminate parsing
early. Add a unit-test to verify it works and keeps working.
Re-jig the unit-tests so that all are sub makefiles.
 1.86 24-Jan-2004  dsl Restore correct name string when VarGetPattern() returns.
Stops error from free() evaluating ${x::=y} when x is undefined.
(Erm why is free() allowed to write to fd 2?)
 1.85 08-Jan-2004  sjg Fix :?: modifier so that it works again.
 1.84 26-Dec-2003  jmc Support variable expansions inside of SYSV style = substitutions. Better matches
expectations (and some cases of historical behavior I've found). Also fixes
PR#3865
 1.83 26-Dec-2003  jmc Don't assume startc is always {, set delim to endc when separating the args to
the ? test.
 1.82 23-Oct-2003  jmc Fixes from PR#23210 to eliminate use of asprintf which makes cross building
on non-NetBSD hosts work again
 1.81 27-Sep-2003  sjg Implement :[] modifier to allow picking a range of words out of a variable.
Also :tW and a W flag to :C and :S to allow treating value as a single word.
Add unit tests for the above, and fix some corner cases.
Based on patches supplied by Alan Barrett <apb@cequrux.com>
 1.80 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.79 31-Jul-2003  scw Const poisoning.
 1.78 29-Jul-2003  sjg A couple of other places where delim should be set
 1.77 29-Jul-2003  sjg First bug picked up by the unit tests - delim wasn't always initialized.
Avoid putting '\' in test case script lines since shell's like that on
SunOS insist on interpreting them.
 1.76 28-Jul-2003  sjg Fix parsing bug for :ts - patch from Alan Barrett <apb@cequrux.com>
Also add simple unit-test jig (regress/usr.bin/make will use it too)
but having it local here makes inclusion in bmake simpler.
 1.75 23-Jul-2003  sjg Fix merge problem with ts modifier and const correctness.
Need to pass nstr to VarModify.
 1.74 14-Jul-2003  sjg Add a :ts[c] modifier to allow controlling the separator used between
words in a variable expansion. If 'c' is omitted no separator is used.
 1.73 14-Jul-2003  christos Pass WARNS=3
 1.72 22-May-2003  christos PR/19781: Thomas Klausner: make error message not helpful on unclosed ${var:foo
 1.71 14-Mar-2003  thorpej Add a -X option, which prevents make(1) from putting variables
set on the command line into the environment individually. This
can be useful on systems which have a tight limit on the size
of the argument space.
 1.70 15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.69 21-Mar-2002  christos don't print extra newlines on errors.
 1.68 06-Feb-2002  pk Add `tu' and `tl' variable expansion modifiers, which transform the
value to uppercase and lowercase, respectively. From Kevin Neal from FreeBSD.
 1.67 27-Jan-2002  reinoud Fix major bug in make(1) ... due to shadowing of the dotLast path used for
the .DOTLAST primitive by a boolean variable with the same name, this whole
mechanism was broken ... it doesn't save much stat calls but it was wrong.

Thanks to Jason Thorpe for the other shadow-variable fixing patches he
made.
 1.66 25-Dec-2001  lukem - partially fix ${foo:?true:false} so that at least it now parses ok and
the true result works. for some reason the false result doesn't, even
though make -dv shows it being set as the result. (blah!)
- add braces in comments to fix vi showmatch
 1.65 12-Jun-2001  sjg Add 4th arg (flags) to Var_Set so that VarLoopExpand can tell it not
to export interator variables when using context VAR_CMD.

Reviewed: christos
 1.64 10-Jun-2001  sjg Simplify the exporting of VAR_CMD's via MAKEFLAGS.
We now just list the names of such variables in .MAKEOVERRIDES.
When we come to export MAKEFLAGS we quote the value of each exported variable
using :Q, using: ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}
The :O:u suppresses duplicate names.
Also modifed Parse_DoVar to re-export MAKEFLAGS whenever .MAKEOVERRIDES
is assigned to so .MAKEOVERRIDES+= PATH will export PATH=${PATH:Q}
to the environment, while .MAKEOVERRIDES= will disable export of VAR_CMD's.
 1.63 09-Jun-2001  sjg Do a better job of duplicate suppression in .MAKEOVERRIDES.
From Var_Set: We actually want the equivalent of
.MAKEOVERRIDES:= ${.MAKEOVERRIDES:Nname=*} name='val'
clearing the previous value for name is important, since
doing simple duplicate suppression does not handle:
$ make FOO=goo
which then runs a sub-make with FOO=boo
the commands from that sub-make should see just FOO=boo.
 1.62 09-Jun-2001  sjg Modify handling of command line variable assignments and their exporting
via MAKEFLAGS. Instead of appending them directly to .MAKEFLAGS, put
them in .MAKEOVERRIDES (and ensure they are quoted). This is now done
in Var_Set when it exports VAR_CMD's.
Use ExportMAKEFLAGS() to export MAKEFLAGS, using the combined content
of .MAKEFLAGS and .MAKEOVERRIDES (with duplicate supression).
If .MAKEFLAGS is assigned to in a Makefile, ExportMAKEFLAGS is called again.
This allows a line like:
.MAKEOVERRIDES=
to effectively stop the exporting of the command line vars in MAKEFLAGS.
 1.61 05-Jun-2001  explorer Perform variable expansion on sysv rhs patterns. That is, expand ${O} in: ${SRCS:.c=.${O}}
 1.60 01-Jun-2001  sjg A number of semi-related changes.
1. make -dx turns on DEBUG_SHELL which causes sh -x to be used where
possible.
2. PrintOnError() is now called when make is stopping due to an error.
This routine reports the curdir and the value of any variables listed
in MAKE_PRINT_VAR_ON_ERROR.
3. Variables set via command line, are propagated to child-makes via
MAKEFLAGS. This behaviour appears to be necessary for POSIX (according
to the GNU folk anyway).
4. Do not reset MAKEFILE when reading ".depend" as this rather eliminates the
usefulness of ${MAKEFILE}.
5. Added ${.newline} as a simple means of being able to include \n in the
result of a :@ loop expansion.
6. Set ${MAKE_VERSION} if defined. Need to come up with a useful value.

Reviewed: christos
 1.59 12-May-2001  sjg Modifier :P avoid segfault if gn is found but path is NULL.
 1.58 10-Mar-2001  itojun redo of previous: do not destroy v->val if str points to v->val.
XXX GC of v->val
 1.57 09-Mar-2001  itojun correct case with VAR_KEEP. if clause checked VAR_KEEP backwards,
and made str a dangling pointer.
 1.56 05-Sep-2000  christos fixed comment U -> u
 1.55 05-Sep-2000  christos :u modifier a'la uniq(1) [from der Mouse]
 1.54 13-Aug-2000  christos don't attempt to free varNoError too.
 1.53 10-Jun-2000  sjg branches: 1.53.2;
no need for v->name-- on JUNK vars anymore
 1.52 10-Jun-2000  mycroft For VAR_JUNK variables, defer freeing of the name string until the bottom of
Var_Parse(), as it may be used (strdup()ed) by some modifiers.
 1.51 10-Jun-2000  sjg Don't free v until after the last use.
 1.50 06-Jun-2000  mycroft Do some evil with VAR_KEEP to make it happier. This seems... wrong.
 1.49 06-Jun-2000  mycroft Allow further patterns after a :D or :U, as in ODE make. (Copied some code
from VarGetPattern. It should become more flexible instead.)
 1.48 06-Jun-2000  mycroft Roll back my for-expansion changes. Doing this right is just too hard to be
worth it.
 1.47 01-Jun-2000  sjg Make ::= work again with the VAR_FOR context changes.
 1.46 01-Jun-2000  mycroft Create a `for' context, and substitute iteration variable from it using the
normal Var_Parse() path. This allows :R, etc. to work on iteration variables.
 1.45 01-Jun-2000  sjg Rats! ${FOO:=bar} is a common usage of the SysV = modifier.
To avoid that, we now do ::[+?!]*= but the SysV = modifier can
conflict with any new modifier. At there are currently no Makefiles
in our tree that use ${FOO::=bar}
 1.44 30-May-2000  sjg Implemented a set of assignment modifiers. These solve obscure
problems such as using modifiers on .for loop iterators derived from
local variables (eg .TARGET).
Unless the variable already exists in a global context, these assignments are
local to the current context (this is usually what is wanted).
 1.43 14-May-2000  sjg branches: 1.43.2;
Expand variables that appear in a [No]Match pattern. Allows
[ x${DONE:M${.TARGET}} != x ] || blah
 1.42 11-May-2000  sjg Expand variables in variable name passed to Var_Set and Var_Append.
This allows ${FOO}.bar=fubar etc to work.
This does not impact any Makefiles in the current tree but allows
some cool magic (which I need elsewhere).
 1.41 11-May-2000  sjg Pass ctxt along to VarLoopExpand so that local variables such as .TARGET
can be expanded.
 1.40 29-Apr-2000  sjg Added the :U :D :L :P :! and :@ modifiers as used by ODE make.
These allow some very useful magic in the makefiles.
The comment in var.c describing their behaviour is mostly lifted
from ODE make, but the implementation of the modifiers themselves
is quite different (much simpler) due to divergence of our code base.
 1.39 17-Apr-2000  christos Don't type && when you mean || (pointed out by David Holland)
 1.38 16-Apr-2000  christos PR/9898: David Holland: small glitch in var substitution for single letter
variables.
 1.37 15-Sep-1999  sommerfeld Reuse the Hash_Entry `name' field to store the variable name when we
can (i.e., everything except environment variables, which aren't
stored in hash tables).

While we're here, inline the body of VarDelete into Var_Delete since
it's the only caller and it's just simpler that way when v->name can
share storage with the hash entry and may not need to be freed
separately.

Speeds up the infamous libc build benchhmark maybe 1% on PIII, 4% on
alpha pc164

Suggested by Perry Metzger.
 1.36 15-Sep-1999  mycroft Replace the linear variable list in the GNode with a hash table. Gives a
small (~10% on my machine) speedup building libc.
Changes by: perry (+ bug fix and minor change by me)
Reviewed by: mycroft sommerfeld
 1.35 12-Sep-1999  christos Add :O var modifier, that sorts the words in a variable.
 1.34 06-Jun-1999  christos Revert previous change. I am a bonehead.
 1.33 06-Jun-1999  christos remove accidentally left debugging code
 1.32 06-Jun-1999  christos Allow junk variable to work in non dynamic contexts. Allows as to say things
like:
.if defined(COPTS) && !empty(COPTS:M*-g*)
 1.31 03-Apr-1999  gwr Make regex support conditional on NO_REGEX (was MAKE_BOOTSTRAP)
Solaris has a compatible regex, as do many others now...
 1.30 06-Nov-1998  christos - full prototypes
- more conservative printf
- char -> unsigned char
 1.29 01-Nov-1998  itohy Reduced memory leaks.
I found some more leaks, but are not in inside of iterations.
 1.28 13-Oct-1998  wsanchez Include sys/types.h
 1.27 18-Sep-1998  christos Fix conditional variable expression parsing (reported by cgd)
 1.26 03-Apr-1998  cgd in Var_Parse(), set delim in a couple of other paths into cleanup
 1.25 01-Apr-1998  christos Add conditional variable evaluation from Alistair Crooks.
 1.24 26-Mar-1998  christos PR/5210: Hauke Fath: make core dumps with .SHELL
Unfortunately this revealed a deeper problem with the brk_string code.
To fix it:
- remove sharing of the buffer between brk_string invocations
- change the semantics of brk_string so that the argument array
starts with 0, and return the buffer where the strings are
stored
 1.23 28-Sep-1997  lukem branches: 1.23.2;
wrap #include <sys/cdefs.h>, __RCSID(...) stuff in #ifndef MAKE_BOOTSTRAP
 1.22 22-Sep-1997  christos Expand variables within variables correctly; eg.
foo.123=abc
bar=123
all:
echo ${foo.${bar}}
 1.21 10-Jul-1997  christos Fix memory corruption that was caused by debugging code leftovers.
 1.20 07-Jul-1997  christos PR/3825: David A. Holland: global regexp handling gets stuck in infinite loop.
Actually there were two bugs:
- Add REG_NOTBOL after the first substitution.
- Handle the rm_so == rm_eo == 0 case, where in a substitution such
as 's/bzzzt/z*/g' the first time z* matches nothing.
 1.19 01-Jul-1997  christos Add WARNS=1
RCSID police
 1.18 18-Mar-1997  christos Fix problems in the RE substitution error handling.
 1.17 31-Dec-1996  christos Don't compile the regex code if MAKE_BOOTSTRAP (from gwr)
 1.16 24-Dec-1996  christos [initial version of the substitution/regexp changes were courtesy of Der Mouse]

- fix the variable substitution code in make [PR/2748]
1. change s/a/b/ so that it substitutes the first occurance of the
pattern on each word, not only the first word.
2. add flag '1' to the variable substitution so that the substitutions
get performed only once.

***THIS IS AN INCOMPATIBLE CHANGE!***

Unfortunately there was no way to make things consistent without
modifying the current behavior. Fortunately none of our Makefiles
depended on this.

OLD:

VAR = aa1 aa2 aa3 aa4

S/a/b/ = ba1 aa2 aa3 aa4
S/a/b/g = bb1 bb2 bb3 bb4

NEW:

VAR = aa1 aa2 aa3 aa4

S/a/b/ = ba1 ba2 ba3 ba4
S/a/b/1 = ba1 aa2 aa3 aa4
S/a/b/g = bb1 bb2 bb3 bb4
S/a/b/1g = bb1 aa2 aa3 aa4

- add regexp variable substitution via 'C/foo/bar/' [PR/2752]

- add variable quoting via the ${VAR:Q} modifier. This is useful when running
recursive invocations of make(1):

make VAR=${VAR:Q}

will always work... (This may prove useful in the kernel builds...) [PR/2981]
 1.15 06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.14 13-Aug-1996  christos Add estrdup(), a checked version of strdup and use it.
 1.13 28-May-1996  christos - Move -D flags from Makefile to config.h and explain what they do. Add
-Wall -Wno-unused to CFLAGS. Add new define SYSVVARSUB to enable SysV
style variable substitutions and enable them.
- Add SunOS style command substitutions via SUNSHCMD
- Fix core dump with '{variable = value'
 1.12 02-Nov-1995  christos branches: 1.12.4;
Minor:
- ${.PREFIX} should never contain a full pathname
- Fixed gcc -Wall warnings
Major:
- compatMake is now FALSE. This means that we are now running in
full pmake mode:
* rules on dependency lines can be executed in parallel and or
out of sequence:

foo: bar baz

can fire the rule for baz before the rule for bar is fired.
To enforce bar to be fired before baz, another rule needs to be
added. [bar: baz]
* adjacent shell commands in a target are now executed by a single
invocation of the shell, not one invocation of the shell per line
(compatMake can be turned off using the -B flag)
- The -j flag now works... I.e. make -j 4 will fork up to four jobs in
parallel when it can. The target name is printed before each burst
of output caused by the target execution as '--- target ---', when j > 1
- I have changed all the Makefiles so that they work with make -j N, and
I have tested the whole netbsd by:
'make -j 4 cleandir; make -j 4 depend; make -j 4; make -j 4 install'
- I have not compiled or tested this version of make with -DREMOTE.
 1.11 14-Jun-1995  christos - $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.10 04-Feb-1995  christos str.c: Don't free NULL; does not work with non posix frees.
var.c: Minor memory leak plugged.
suff.c: Don't add extra sources on the null suffix if it has dependency
lines or commands attached to it [POSIX says so]
 1.9 20-Jan-1995  christos Fixed to parse correctly SysV variable substitutions ${VAR:P1=P2} when
P1 or P2 contain }'s or )'s. From mikeb@snow.datametrics.com
 1.8 09-Jan-1995  christos Save the name of the environment variables. Remove the comment that
says that we don't. from Paul Borman (prb@bsdi.com)
 1.7 16-Jun-1994  jtc Christos' fix for quoting variable extraction properly.
 1.6 06-Jun-1994  jtc Fixes from Christos Zoulas, who used purify, objectcenter and testcenter
to find memory leaks and illegal memory accesses.
 1.5 05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.4 13-Jan-1994  jtc Include appropriate header files to bring prototypes into scope.
 1.3 13-Jan-1994  cgd add missing arg to setenv(). reported by downsj@csos.orst.edu
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.12.4.1 26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.23.2.1 08-May-1998  mycroft Sync with trunk, per request of christos.
 1.43.2.1 23-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.53.2.1 07-Jun-2001  he Pull up revision 1.61 (requested by explorer):
Expand variables in SysV patterns, as in ``${SRCS:.c=.${O}}''.
 1.87.2.1 10-May-2004  tron Pull up revision 1.88 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.110.2.2 19-May-2006  christos Coverity CI D3758: Plug memory leak.
 1.110.2.1 19-May-2006  christos file var.c was added on branch chap-midi on 2006-05-19 17:29:02 +0000
 1.115.4.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.115.2.1 05-Jun-2007  bouyer Apply patch (requested by tron in ticket #696):
usr.bin/make/compat.c patch
usr.bin/make/cond.c patch
usr.bin/make/dir.c patch
usr.bin/make/for.c patch
usr.bin/make/main.c patch
usr.bin/make/make.1 patch
usr.bin/make/make.c patch
usr.bin/make/make.h patch
usr.bin/make/nonints.h patch
usr.bin/make/parse.c patch
usr.bin/make/str.c patch
usr.bin/make/targ.c patch
usr.bin/make/util.c patch
usr.bin/make/var.c patch

Synchronize make(1) with HEAD branch to increase perfomance and
improve stability.
 1.117.4.1 06-Nov-2007  matt sync with HEAD
 1.128.4.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.128.4.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.128.2.1 18-May-2008  yamt sync with head.
 1.149.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.166.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.167.2.4 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.167.2.3 16-Jan-2013  yamt sync with (a bit old) head
 1.167.2.2 30-Oct-2012  yamt sync with head
 1.167.2.1 23-May-2012  yamt sync with head.
 1.171.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.171.2.2 23-Jun-2013  tls resync from head
 1.171.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.184.2.1 10-Aug-2014  tls Rebase.
 1.208.2.2 26-Apr-2017  pgoyette Sync with HEAD
 1.208.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.209.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.215.4.2 09-Jun-2018  martin Pull up following revision(s) (requested by christos in ticket #870):

sys/lib/libgnuefi/Makefile.inc: revision 1.5
external/mit/xorg/xorg-pkg-ver.mk: revision 1.9
sys/arch/i386/stand/lib/Makefile.inc: revision 1.17
sys/compat/common/Makefile.inc: revision 1.25
usr.bin/make/unit-tests/varquote.exp: revision 1.1, 1.2
sys/lib/libsa/Makefile.inc: revision 1.24
usr.bin/make/var.c: revision 1.220
sys/arch/ia64/stand/efi/libefi/Makefile.inc: revision 1.5
sys/arch/hppa/spmath/Makefile.inc: revision 1.10
usr.bin/make/unit-tests/varquote.mk: revision 1.1, 1.2
usr.bin/make/unit-tests/Makefile: revision 1.53
sys/lib/libkern/Makefile.inc: revision 1.45
sys/arch/acorn32/stand/lib/Makefile.inc: revision 1.4
sys/arch/m68k/fpsp/Makefile.inc: revision 1.21
usr.bin/make/make.1: revision 1.273
sys/lib/libz/Makefile.inc: revision 1.17

- Introduce :q modifier for make variables and make it double escape $'s so
that passing variables to recursive makes with :q works as expected.
- Adjust makefiles that use recursive make to use :q

Discussed on tech-toolchain@

XXX: pullup 8
 1.215.4.1 07-Jun-2018  martin Pull up following revision(s) (requested by christos in ticket #834):

usr.bin/make/var.c: revision 1.219
share/mk/bsd.obj.mk: revision 1.52
usr.sbin/crash/Makefile: revision 1.40
share/mk/sys.mk: revision 1.131
share/mk/bsd.sys.mk: revision 1.276
share/mk/bsd.sys.mk: revision 1.277

Prevent 'make obj' creating an objdir inside an objdir. This happens the
second time we call 'make obj' in /usr/src/rescue with MAKEOBJDIR set.
XXX: pullup-8
-
Need to delete ${DESTDIR} for lint
XXX: pullup-8
-
Fix reproducible builds
XXX: pullup-8
-
Also substitute ${X11SRCDIR} for the random seed for reproducible builds so
that the random seed is consistent.
XXX: pullup-8
-
Since ${MAKE} converts $$ -> $ during parsing we need to put it back to
preserve the original variable value with :Q.
XXX: pullup-8
-
Be more selective about remapping object directories otherwise we pick
objdump and objcopy with the regex.
XXX: pullup-8
 1.218.2.2 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.218.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.220.2.1 10-Jun-2019  christos Sync with HEAD
 1.930.2.1 31-May-2021  cjep sync with head
 1.1121.2.2 02-Aug-2025  perseant Sync with HEAD
 1.1121.2.1 01-Jul-2024  perseant Sync with HEAD.
 1.4 05-Jul-2014  dholland Reorg docs, part 1:
Move all the reference manuals to subdirs of /usr/share/doc/reference.
We have subdirs ref1-ref9, corresponding to man page sections 1-9.

Everything that's the reference manual for a program (sections 1, 6,
8), C interface (sections 2, 3), driver or file system (section 4),
format or configuration (section 5), or kernel internal interface
(section 9) belongs in here.

Section 7 is a little less clear: some things that might go in section
7 if they were a man page aren't really reference manuals. So I'm only
putting things in reference section 7 that are (to me) clearly
reference material, rather than e.g. tutorials, guides, FAQs, etc.
This obviously leaves some room for debate, especially without first
editing the docs with this distinction in mind, but if people hate
what I've done things can always be moved again.

Note also that while roff macro man pages traditionally go in section
7, I have put all the roff documentation (macros, tools, etc.) in one
place in reference/ref1/roff. This will make it easier to find and
also easier to edit it into some kind of coherent form.
 1.3 05-Jul-2014  dholland Rework /usr/share/doc.

Update the <bsd.doc.mk> infrastructure, and update the docs to match
the new infrastructure.

- Build and install text, ps, pdf, and/or html, not roff sources.

- Don't wire the chapter numbers into the build system, or use them in
the installed pathnames. This didn't matter much when the docs were a
museum, but now that we're theoretically going to start maintaining
them again, we're going to add and remove documents periodically and
having the chapter numbers baked in creates a lot of thrashing for no
purpose.

- Specify the document name explicitly, rather than implicitly in a
path. Use this name (instead of other random strings) as the name
of the installed files.

- Specify the document section, which is the subdirectory of
/usr/share/doc to install into.

- Allow multiple subdocuments. (That is, multiple documents in one
output directory.)

- Enumerate the .png files groff emits along with html so they can be
installed.

- Remove assorted hand-rolled rules for running roff and roff widgetry
and add enough variable settings to make these unnecessary. This
includes support for
- explicit use of soelim
- refer
- tbl
- pic
- eqn

- Forcibly apply at least minimal amounts of sanity to certain
autogenerated roff files.

- Don't exclude USD.doc, SMM.doc, and PSD.doc directories from the
build, as they now actually do stuff.

Note: currently we can't generate pdf. This turns out to be a
nontrivial problem with no immediate solution forthcoming. So for now,
as a workaround, install compressed .ps as the printable form.
 1.2 14-Jun-1995  christos branches: 1.2.80; 1.2.92;
- $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.1 19-Jun-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 19-Jun-1994  cgd from Lite
 1.2.92.1 10-Aug-2014  tls Rebase.
 1.2.80.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.14 18-Dec-2020  rillig make(1): spell nonexistent consistently
 1.13 01-Mar-2017  kre Improve appearance (a little) when read with nroff, rather than troff
 1.12 30-Sep-2014  christos branches: 1.12.2; 1.12.4;
Define some of the missing macros. The only error now is:

213: warning: can't find font `C'

Because the CW macro wants to use a constant width font is "ascii" mode,
and this does not exist with -Tascii. I don't think this should be fixed
here...
 1.11 18-Aug-2011  sjg Fix formatting of Notes to work with groff.
Patch from Andrew O. Shadoura.
 1.10 27-Jun-2004  uwe Fit ASCII output onto an 80-column terminal. From FreeBSD.
 1.9 27-Jun-2004  uwe Fix a few typos. From FreeBSD.
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.7 14-Jul-2003  wiz Fix two minor whitespace problems.
 1.6 16-May-2002  wiz Comment out token after #endif. (Hmmmmmmm.)
 1.5 20-Aug-2001  wiz precede, not preceed.
 1.4 19-Nov-1999  kristerw Typos (from OpenBSD)
 1.3 06-Mar-1996  christos branches: 1.3.10;
Fix PR/2118; apply sysincludes patch.
 1.2 14-Jun-1995  christos - $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.1 19-Jun-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1 19-Jun-1994  cgd from Lite
 1.3.10.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.12.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.12.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.6 15-Dec-2021  rillig make: remove redundant comments for multiple-inclusion guards
 1.5 19-Jan-2021  rillig make(1): remove do-not-format markers from comments

These markers had been used inconsistently. Furthermore the source code
had not been formatted automatically before 2020 at all, otherwise there
wouldn't have been any trailing whitespace left.
 1.4 29-Nov-2020  rillig make(1): use space instead of tab for preprocessor directives
 1.3 18-Oct-2020  rillig make(1): use consistent include guard for headers
 1.2 22-Jan-2020  sjg branches: 1.2.4;
Rename guard to avoid that already used by Linux filemon.h

Reviewed by: riastradh
 1.1 19-Jan-2020  riastradh Per sjg's suggestion, split filemon API into separate back ends.

By default we use the ktrace back end, but the /dev/filemon back end
is available as a compile-time option, by setting USE_FILEMON=dev in
make. sjg raised concerns about ktrace performance and would like to
continue using /dev/filemon on FreeBSD (which has seen more
maintenance kernel-side) without forking make.
 1.2.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2.4.1 22-Jan-2020  martin file filemon.h was added on branch phil-wifi on 2020-04-13 08:05:44 +0000
 1.9 04-Mar-2022  sjg Fix some unused warnings
 1.8 01-Feb-2021  rillig make: indent preprocessor directives consistently

As seen in share/misc/style.
 1.7 19-Jan-2021  rillig make(1): remove do-not-format markers from comments

These markers had been used inconsistently. Furthermore the source code
had not been formatted automatically before 2020 at all, otherwise there
wouldn't have been any trailing whitespace left.
 1.6 29-Nov-2020  rillig make(1): use space instead of tab for preprocessor directives
 1.5 23-Nov-2020  rillig make(1): use comparisons in boolean expressions

The generated code stays exactly the same.
 1.4 05-Nov-2020  rillig make(1): remove redundant parentheses from sizeof operator

The parentheses are only needed if the argument is a type, not an
expression.
 1.3 10-Jul-2020  sjg Use O_CLOEXEC and save a syscall.

Reviewed by: riastradh
 1.2 10-Jul-2020  sjg filemon_dev:filemon_open need FD_CLOEXEC

We need to mark the fd for filemon FD_CLOEXEC
so that when we call filemon_close() the device is
closed and unflushed data written to our temp file.
 1.1 19-Jan-2020  riastradh branches: 1.1.4;
Per sjg's suggestion, split filemon API into separate back ends.

By default we use the ktrace back end, but the /dev/filemon back end
is available as a compile-time option, by setting USE_FILEMON=dev in
make. sjg raised concerns about ktrace performance and would like to
continue using /dev/filemon on FreeBSD (which has seen more
maintenance kernel-side) without forking make.
 1.1.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1.4.1 19-Jan-2020  martin file filemon_dev.c was added on branch phil-wifi on 2020-04-13 08:05:44 +0000
 1.15 31-Jul-2021  rillig make: fix lint warnings

The string functions from str.h are declared as 'static __unused' when
compiled with GCC, but lint explicitly undefines __GCC__ during
preprocessing. Therefore, make those functions inline, to prevent
warnings that they are unused.

The macro UNCONST is used in a few places, and (again) since lint
undefines __GCC__, that macro expanded to a simple type cast, which lint
warned about. To prevent this warning, implement UNCONST as a function
that works everywhere and hides the type cast.

In filemon_open, the code for closing F->in was obviously unreachable.

No functional change.
 1.14 01-Feb-2021  rillig make: document the syscalls that are not monitored by filemon_ktrace
 1.13 19-Jan-2021  rillig make(1): remove do-not-format markers from comments

These markers had been used inconsistently. Furthermore the source code
had not been formatted automatically before 2020 at all, otherwise there
wouldn't have been any trailing whitespace left.
 1.12 10-Jan-2021  rillig make(1): make a few more bool expressions more precise

The previous version of lint(1) from a few hours ago didn't catch all
occurrences. And even the current one doesn't catch everything.
Function arguments and return types still need some work. The "return
quietly" from shouldDieQuietly still implicitly converts from int to
_Bool.

No functional change.
 1.11 10-Jan-2021  rillig make(1): consistently use boolean expressions in conditions

Most of the make code already followed the style of explicitly writing
(ptr != NULL) instead of the shorter (ptr) in conditions.

The remaining 50 instances have been found by an experimental,
unpublished check in lint(1) that treats bool expressions as
incompatible to any other scalar type, just as in Java, C#, Pascal and
several other languages.

The only unsafe operation on Boolean that is left over is (flags &
FLAG), for an enum implementing a bit set. If Boolean is an ordinary
integer type (the default), some high bits may get lost. But if Boolean
is the same as _Bool (by compiling with -DUSE_C99_BOOLEAN), C99 6.3.1.2
defines that a conversion from any scalar to the type _Bool acts as a
comparison to 0, which cannot lose any bits.
 1.10 09-Jan-2021  rillig make(1): fix lint warnings
 1.9 31-Dec-2020  rillig make(1): replace pointers in controlling conditions with booleans
 1.8 29-Nov-2020  rillig make(1): use space instead of tab for preprocessor directives
 1.7 28-Nov-2020  rillig make(1): remove unused label
 1.6 23-Nov-2020  rillig make(1): use comparisons in boolean expressions

The generated code stays exactly the same.
 1.5 23-Nov-2020  rillig make(1): align end-of-line comments with tabs
 1.4 05-Nov-2020  rillig make(1): remove redundant parentheses from sizeof operator

The parentheses are only needed if the argument is a type, not an
expression.
 1.3 18-Oct-2020  rillig make(1): prepare for WARNS=6

The FD_* macros from sys/sys/fd_set.h use signed integers on NetBSD 8
and thus produce conversion errors. On NetBSD 9, these macros are fixed
to use 1U instead of 1.
 1.2 19-Jan-2020  riastradh branches: 1.2.4;
Missed a spot -- define _KERNTYPES to get register_t.
 1.1 19-Jan-2020  riastradh Per sjg's suggestion, split filemon API into separate back ends.

By default we use the ktrace back end, but the /dev/filemon back end
is available as a compile-time option, by setting USE_FILEMON=dev in
make. sjg raised concerns about ktrace performance and would like to
continue using /dev/filemon on FreeBSD (which has seen more
maintenance kernel-side) without forking make.
 1.2.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2.4.1 19-Jan-2020  martin file filemon_ktrace.c was added on branch phil-wifi on 2020-04-13 08:05:44 +0000
 1.1 30-Nov-2019  rillig branches: 1.1.4;
Ignore temporary files from running the unit tests
 1.1.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.1.4.1 30-Nov-2019  martin file .cvsignore was added on branch phil-wifi on 2020-04-08 14:09:17 +0000
 1.372 04-Aug-2025  sjg Use printf rather than echo -n
 1.371 04-Aug-2025  sjg sync-mi should do .inc files too?
 1.370 03-Aug-2025  sjg make: ensure output captured in meta file is accurate

In CollectOutput() a newline before the end of job->outBuf
results in a short write to stdout, but meta_job_output()
was recording the entire string in the meta file, so on
next call the left overs would be duplicated in the meta file.

Pass a length to meta_job_output() if it should only report part of
the data in meta file.
 1.369 29-Jun-2025  rillig tests/make: test backslash at the end of a line and in the :M modifier

As described in PR bin/46139 by David A. Holland.
 1.368 27-Jun-2025  rillig tests/make: test missing support for $^

Test provided by Diogo Santos via PR bin/59018; extended by me for .WAIT
and implicit rules.
 1.367 13-Jun-2025  rillig tests/make: fix race condition in debug output in parallel mode

Discovered in ATF run on evbearmv7hf.
 1.366 13-Jun-2025  rillig make: add on-demand inter-process stack traces

When debugging a build that heavily uses nested calls to sub-makes, the
chain of calls is useful to quickly assess the situation. If explicitly
requested, include the actions from any parent processes in the stack
traces.

Reviewed by: sjg
 1.365 13-Jun-2025  sjg Fix replacing ${TEST_MAKE} with make
 1.364 12-Jun-2025  rillig make: use a common style for unexpected error messages

In enomem, report the actual error instead of a fixed ENOMEM.
 1.363 05-Jun-2025  rillig make: remove empty line from diagnostic, add tests for output handling

The warning for the invalid internal option "-J" does not need a
trailing newline, as that is provided by Parse_Error already.

Having this newline in the output demonstrated a previously unknown bug
in handling the output of child commands in parallel mode. There, empty
lines are randomly discarded, depending on the chunks in which the
output from the child process is copied to make's stdout. See
job-output.mk for a demonstration.

The test for the Korn shell did not run the Korn shell in error handling
mode, as the error handling mode only affects the parallel mode but the
test didn't switch to that mode.

After fixing the shell-ksh.mk test, the single '"' in the output looked
suspicious, and indeed, the shell-csh.mk test had the same problem of
filtering more characters from the output than intended.
 1.362 09-May-2025  rillig make: unify debug messages for parallel mode

Always print the process status in hex, with a leading "0x", to avoid
confusion for status 127f, which looks suspiciously decimal.

Prefix all process IDs with "pid", to be able to filter them easily.

Omit trailing whitespace when printing a command.
 1.361 07-May-2025  rillig make: add end marker for -dg1, -dg2 and -dg3 debug log

The marker helps distinguish the output from sub-makes from the output
of the primary make.
 1.360 03-May-2025  rillig make: use uniform debug log messages for the token pool
 1.359 22-Apr-2025  rillig make: group the code for handling the job token pool
 1.358 13-Apr-2025  rillig tests/make: add tests for POSIX mode
 1.357 12-Apr-2025  sjg make/unit-tests: Fix expected results for meta-ignore tests
 1.356 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.355 25-Jan-2025  sjg make/unit-tests: avoid failure on NFS

The 'rm -rf ${TMPDIR}' at the end of the 'test' target, fails
when building on NFS because the temp file used for the target script
keeps the directory from being empty.

Move it to a separate target attached to '.END'

Reviewed by: rillig
 1.354 10-Jan-2025  rillig tests/make: test expressions based on undefined variables

When an undefined variable is used in a conditional, make complains about
"Malformed conditional", which is wrong since the conditional is
well-formed but errors out during evaluation.

In order to fix this wrong error message and preserve the remaining
behavior, cover the places in which an expression is evaluated with
undefined expressions being an error (VARE_EVAL_DEFINED), but with
neither producing an error message nor handling errors. This combination
results in the same behavior as evaluating the expressions in the mode
that allows undefined variables to be used in expressions.
 1.353 22-Nov-2024  rillig tests/make: speed up running the tests

Only 4 of the 389 tests need to postprocess their output, so spare the
extra 'cat' call in the majority of cases.
 1.352 31-Oct-2024  rillig make: in the debug log, always qualify line number with filename

Previously, to find out the filename corresponding to a line number from
a 'Parsing' line, it was necessary to find the preceding
'SetFilenameVars' line, which was unnecessarily time-consuming and
distracting.

The 'filename:line' format matches the one used in PrintStackTrace, and
it differs from the one used in PrintLocation, as the former format is
more common in other tools.

Most of the affected unit tests only use the 'Parsing' lines to give
additional context to their debug log, so no structural changes there.
 1.351 18-Aug-2024  rillig tests/make: clean up private temporary directory after running tests

Fixes PR bin/58569.
 1.350 07-Jul-2024  rillig make: don't track hash table chain lengths during lookup

The chain lengths are only used for debugging purposes, so avoid the
extra cost at each lookup. Instead, calculate the maximum chain length
only when it is actually requested in -dh mode.

The reported number changes slightly: Before, it was the length of the
chain that was actually traversed to find an entry, up to that entry,
now it is the length of the largest chain in the table, no matter if it
was actually accessed or not.
 1.349 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.348 01-Jul-2024  sjg make: add :tc to capitalize first letter of each word

This is very hard to do without :tc

Reviewed by: rillig
 1.347 01-Jun-2024  sjg branches: 1.347.2;
Run check-expect.lua in .CURDIR
 1.346 01-Jun-2024  rillig tests/make: require all expected messages to be listed in the .mk files
 1.345 24-May-2024  rillig make: in -DCLEANUP mode, free variables and their values

The variables in the 3 scopes must be freed before the scopes themselves
are freed by Targ_End.

The test opt-m-include-dir creates a directory of the form '*.tmp', thus
it must be removed before attempting to only remove regular files of
this name.

POSIX requires setenv to copy the passed name and value, so there is no
need to keep that memory allocated any longer.
 1.344 30-Apr-2024  sjg Subst DEFSYSPATH in deptgt-phony
 1.343 20-Apr-2024  rillig make: provide more context information for parse/evaluate errors
 1.342 07-Jan-2024  sjg make: unit-tests handle TEST_MAKE:T != make

We need to allow for ${TEST_MAKE:T}[1-9]: etc when
TEST_MAKE is not 'make'
 1.341 09-Sep-2023  sjg Add .MAKE.JOBS.C to indicate wether -jC is supported
 1.340 17-Aug-2023  rillig tests/make: extend tests for the ':mtime' modifier
 1.339 20-Jun-2023  rillig make: allow targets to be used as multiple-inclusion guards

This style is used by FreeBSD, among others.
 1.338 16-Jun-2023  rillig tests/make: add test for multiple-inclusion guards
 1.337 16-Jun-2023  rillig tests/make: clean up tests for the ':M' and ':S' modifiers
 1.336 01-Jun-2023  rillig tests/make: clean up comments, extend a few tests
 1.335 10-May-2023  rillig tests/make: clean up tests for .for loops

Most of the tests from forloop.mk were already in directive-for.mk.
 1.334 09-May-2023  sjg make: add :mtime to provide mtime of file

The value of the variable is passed to stat(2)
and st_mtime is new value.
An optional arg can be used if stat(2) fails, otherwise
the current time is used.

See varmod-mtime.mk for usage examples.
 1.333 25-Feb-2023  sjg make: meta-ignore tests will not work if TMPDIR is /tmp

Since /tmp and /var/tmp are always part of .MAKE.META.IGNORE_PATHS
the varname-dot-make-meta-ignore_* tests will not work
if TMPDIR is either (or subdir) of those.
 1.332 23-Feb-2023  sjg Add unit-tests for .MAKE.META.IGNORE_*

These unit-tests should only be run if TEST_MAKE
has a valid .MAKE.PATH_FILEMON to indicate that filemon is
supported.

All three tests use the same meta-ignore.inc
which runs three sub-makes

one to initialize the target .meta file
two to ignore a file using .MAKE.META.IGNORE_{PATHS,PATTERNS,FILTER}
three to verify that without .MAKE.META.IGNORE_* the target is out of date.

Fix the order of _SED_CMDS to avoid errors when ${MAKE:T} appears in
.OBJDIR
 1.331 24-Jan-2023  sjg make: .SYSPATH: to add dirs to sysIncPath

.SYSPATH: with no sources will clear sysIncPath
otherwise sources are added

Reviewed by: rillig
 1.330 23-Jan-2023  sjg make: .[NO]READONLY for control of read-only variables

Reviewed by: rillig
 1.329 19-Jan-2023  rillig tests/make: rename files that are not test cases
 1.328 19-Jan-2023  rillig tests/make: add tests for whitespace in leading '@+-'
 1.327 25-Sep-2022  rillig tests/make: fix test for option '-e' (broken since 2022-01-23)
 1.326 10-Sep-2022  rillig tests/make: be more specific about the egrep compatibility
 1.325 09-Sep-2022  sjg Handle deprecation of egrep
 1.324 03-Sep-2022  sjg Only update distrib/sets/lists/tests/mi with valid files

sync-mi: use CVS/Entries to ensure we only update
distrib/sets/lists/tests/mi with files known to CVS.

Reviewed by: rillig
 1.323 02-Sep-2022  sjg Enable make/unit-tests/directive-for-break

Also ensure MAKE_VERSION is ignored.
 1.322 02-Sep-2022  sjg make: add .break to terminate .for loop early

When .break is encountered within a .for loop
it causes immediate termination.

Outside of a .for loop .break causes a parse error.

Reviewed by: christos
 1.321 25-Aug-2022  rillig tests/make: fix canonicalization for single-digit day of month
 1.320 24-Aug-2022  rillig make: prevent future out-of-bounds errors when parsing expressions

A modifier in an expression ends not only at the next ':' or at the
closing '}' or ')', but also at the end of the string.

Previously, testing for the end of the string had been done separately,
which was error-prone since 2006-05-11, when indirect modifiers were
introduced. Since then, it was possible that the string terminator '\0'
was accidentally skipped in cases where the loop condition only tested
for the ending character. When parsing indirect modifiers, the ending
character is indeed '\0', but when parsing direct modifiers, it is '}'
or ')'.

A welcome side effect is that in the case of unclosed expressions such
as '${VAR:Modifier', the amount of error messages is reduced from 2 or 3
to only 1. The removed error messages were wrong and thus confusing
anyway.
 1.319 26-Jul-2022  sjg Pass MAKEOBJDIR to opt-m-include-dir

Prevent makeing opt-m-include-dir.tmp in src tree.

Reviewed by: rillig
 1.318 10-Jun-2022  rillig tests/make: reword comment in Makefile to be more specific
 1.317 02-Jun-2022  skrll Increase the resource limit so these tests pass on hppa.

LGTM from Roland
 1.316 23-May-2022  rillig tests/make: document and demonstrate .for i containing .if empty(i)

PR bin/43821 describes the inconsistency that in a '.for i' loop, the
condition '.if ${i:M*.c}' works since 2009 while the seemingly
equivalent condition '.if !empty(i:M*.c)' does not access the variable
'i' from the .for loop but instead the global 'i'.

Resolving this situation in a backwards-compatible and non-surprising
way is hard, as make has grown several features during the last 20 years
that interact in various edge cases. For now, document the most obvious
pitfalls.
 1.315 08-May-2022  rillig tests/make: remove test varquote

The test varmod-quote-dollar covers the same topic.
 1.314 08-May-2022  rillig tests/make: migrate cond1 test to other, more specific tests

The tests in cond1 were a mixture of "everything related to conditions",
and the test cases were heavily dependent on each other, which made them
hard to understand. Move each test case to its corresponding
special-purpose test.
 1.313 07-May-2022  rillig make: allow to randomize build order of targets

In complex dependency structures, when a build fails, a probable cause
is a missing dependency declaration between some files. In compat mode,
the build order is deterministic, in jobs mode, it is somewhat
deterministic. To explore more edge cases, add the line ".MAKE.MODE +=
randomize-targets" somewhere in the makefile.

Fixes PR bin/45226 by riastradh. Reviewed by christos.
 1.312 18-Apr-2022  rillig make: only switch to POSIX mode if '.POSIX:' is the first line

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html
says that in order to make a makefile POSIX-conforming, its first
non-comment line must be the special dependency line '.POSIX:' without
any source dependencies.

Previously, make switched to POSIX mode even if such a line occurred
anywhere else, which was allowed by POSIX but was deep in the
"unspecified behavior" area. For NetBSD make, there is no big
difference since it doesn't ship any <posix.mk> file, this change mainly
affects the bmake distribution.

Previously, makefiles that contain '.POSIX:' somewhere in the middle
could fail due to <posix.mk> resetting .SUFFIXES, among other things.

Suggested by Simon J. Gerraty, who also reviewed an earlier version of
this change.
 1.311 26-Mar-2022  rillig make: fix crash on .undef of an environment variable (since 2020-10-06)
 1.310 25-Mar-2022  rillig tests/make: suppress -DCLEANUP output in test deptgt-phony
 1.309 12-Feb-2022  rillig tests/make: document the history of bugs in '-k' mode

Reported in PR#49720 in 2015, fixed independently in compat.c 1.199 from
2020-12-07.
 1.308 12-Feb-2022  rillig tests/make: demonstrate bug for .SILENT in jobs mode (since 2003)

Reported 2011 in PR#45356.
 1.307 09-Feb-2022  rillig tests/make: remove redundant 'echo' from variable assignments

Before main.c 1.231 from 2014-09-09, a variable assignment using the
operator '!=' generated a warning "Couldn't read shell's output" if the
output of the command was empty. The simplest way to suppress this
wrong warning was to add an empty 'echo' to the command. This hack is
no longer needed.
 1.306 09-Feb-2022  rillig make: fix mistakes, spelling and typos in comments and manual page

No binary change for -DNDEBUG.
 1.305 09-Feb-2022  rillig make: prefix the warning about read-only .OBJDIR with a colon

For consistency with the other warnings.
 1.304 09-Feb-2022  rillig tests/make: use more distinctive placeholder for TMPDIR
 1.303 07-Feb-2022  rillig tests/make: demonstrate combination of .USE with transformation rule

Reported in 2003 in PR toolchain/20993. Linking a transformation rule
with .USE or .USEBEFORE node makes the transformation rule fail.
 1.302 27-Jan-2022  sjg numEntries can vary
 1.301 27-Jan-2022  sjg Do not allow /usr/obj to cause failure.
 1.300 23-Jan-2022  rillig tests/make: migrate modts to varmod-to-separator and explain
 1.299 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.298 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.297 22-Jan-2022  rillig tests/make: explore edge cases involving .ifmake
 1.296 19-Jan-2022  rillig tests/make: demonstrate wrong location in diagnostic (since 2018-12-22)

When a target has multiple places where commands are defined, the
diagnostics mixed up the filename in some cases.
 1.295 11-Jan-2022  rillig tests/make: clean up after test for option '-dF'

When the file for the debug log cannot be opened, make exits
immediately. This doesn't give the test a chance to clean up the
temporary log file.

Instead of trying to treat a regular file as a directory and create a
file in it, assume that the directory /nonexistent-$uuid is actually
nonexistent. This leads to the same kind of error message, independent
of strerror(3).
 1.294 09-Jan-2022  rillig tests/make: add placeholders for .PARSEDIR and .INCLUDEDFROMDIR

When run via 'cd usr.bin/make/unit-tests && make test', the tests are in
the current directory. When run via ATF, the tests are in
/usr/tests/usr.bin/make/unit-tests, while the current directory is a
temporary directory. Allow both variants, plus others that may occur in
the bmake distribution.
 1.293 28-Dec-2021  rillig tests/make: clean up after test 'opt-debug-file'
 1.292 28-Dec-2021  rillig tests/make: document inconsistencies between '!=' and '::!='

Found while trying to make the error messages from Cmd_Exec more
detailed.
 1.291 23-Dec-2021  rillig tests/make: explain the current behavior of the option '--version'
 1.290 14-Dec-2021  rillig make: remove unreachable code for parsing the dependency operator

At the point where ParseDependencyOp is called, cp is guaranteed to
point to either ':' or '!'.

No functional change.
 1.289 13-Dec-2021  rillig tests/make: extend tests for parsing makefiles
 1.288 12-Dec-2021  rillig tests/make: test and document the newly added "variable" .SUFFIXES
 1.287 09-Dec-2021  rillig make: add back support for jemalloc 100

The ports sun2 and vax default to jemalloc 100, as opposed to the rest
of the ports, which use jemalloc 510. Some developers choose to use
jemalloc 100, so let them run the tests with memory debugging as well.

Suggested by mrg on source-changes-d.
 1.286 05-Dec-2021  rillig make: fix use-after-free in modifier ':@'

Without memory allocator debugging, the newly added test doesn't show
any obvious failure.

With memory allocator debugging enabled, all make versions since
2016.02.27.16.20.06 crash with a segmentation fault.
 1.285 05-Dec-2021  rillig tests/make: migrate to jemalloc > 100

When I started working on usr.bin/make in 2020, I used NetBSD 8, which
used jemalloc 100.

After updating to NetBSD 8 to 9.99.x, the debugging options for jemalloc
stopped working since MALLOC_OPTIONS had been replaced with MALLOC_CONF
in 2019.

Enable malloc debugging again, to reliably reproduce the use-after-free
for the variable modifier ':@'.
 1.284 19-Oct-2021  sjg Replace ${.OBJDIR} with <curdir> for consistent results.

If we replace ${.OBJDIR} with <objdir> some tests produce
different results depending on the value of .OBJDIR

For similar reasons eliminate .OBJDIR and .PATH from output of
varname-empty

Reviewed by: rillig
 1.283 30-Aug-2021  rillig tests/make: explain where "${var}" in .for loops comes from
 1.282 31-Jul-2021  rillig tests/make: split tests for the variable modifier ':O'

The tests for parse errors are now in varmod-order, which lets the other
tests focus on the desired behavior of the modifiers.
 1.281 30-Jul-2021  sjg Add :On for numeric sort

Reviewed by: christos rillig
 1.280 29-Jun-2021  sjg Allow BROKEN_TESTS to cause TESTS to be skipped.

Some tests simply do not work in some environments.
Eg. shell-ksh on macos/arm64
Allow local site to set BROKEN_TESTS to skip those they know
will not work.

Reviewed by: rillig
 1.279 16-Jun-2021  rillig tests/make: demonstrate wrong error handling in jobs mode
 1.278 18-May-2021  sjg Do not trust that /nonexistent does not exist

Use /nonexistent.${.MAKE.PID} to avoid failure when
/nonexistent actually exists.
 1.277 27-Apr-2021  rillig branches: 1.277.2;
tests/make: test the combination of -de with -j1

The test cases are the same as in opt-debug-errors.mk. The output
differs in several details though.

Even though the option '-k' is given (which is the default for any tests
that don't override it in unit-tests/Makefile), there is no message
"(continuing)" anywhere.

The failed target is printed twice. Once before the failed commands,
once after. This redundancy is not necessary and may be removed in a
follow-up commit.

The printed commands are in their unexpanded form, which may or may not
be more helpful than the expanded and space-normalized form of compat
mode. Either way, this is an unnecessary inconsistency between compat
mode and jobs mode.

In jobs mode, the message "make: stopped in $dir" is printed for each
failure, which is helpful since each of the jobs may have started in a
separate directory.
 1.276 15-Apr-2021  rillig tests/make: demonstrate handling of null bytes
 1.275 04-Apr-2021  rillig tests/make: split test for modifier ':@' into separate files

The file varmod-loop.mk has grown too large to be single-purpose, plus
it combined parse-time and run-time tests. This has the downside that
as soon as a parse-time test results in an error, the run-time tests are
not run anymore.
 1.274 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.273 14-Mar-2021  rillig tests/make: add test for short-circuit evaluation of modifiers
 1.272 14-Mar-2021  rillig make: demonstrate wrong expression evaluation in -dL mode
 1.271 14-Feb-2021  rillig make: add test for the variable modifier ':sh'
 1.270 14-Feb-2021  rillig make: fix TMPDIR in unit-tests

Combining the assignment operator ':=' with the variable modifier ':U'
on the same variable does not work as intended. At the point where the
':U' is evaluated, the variable is guaranteed to be defined because the
code in VarAssign_EvalSubst says so.
 1.269 06-Feb-2021  sjg Avoid test failures when more than one user run them.

Use a private TMPDIR
a subdir of .OBJDIR if using it
otherwise /tmp/uid${.MAKE.UID}
 1.268 04-Feb-2021  rillig make: remove .PARSEDIR from test output of varname-empty

The .PARSEDIR has nothing to do with .CURDIR. This wrong assumption
made the NetBSD test suite fail since the actual .PARSEDIR was not
replaced with "<curdir>".
 1.267 03-Feb-2021  rillig make: in the test varname-empty, keep more debug output

Filtering out the interesting lines based on the very specific pattern
"Var_Set" was surprising.
 1.266 02-Feb-2021  rillig make: demonstrate that neither -dg2 nor -dg3 produces debug output
 1.265 01-Feb-2021  rillig make: add test for reading from make's stdin

Just out of curiosity whether that really works. It does.
 1.264 30-Jan-2021  rillig make(1): add test for combining the options -j, -n, -t

This is a preparation for refactoring the complicated condition in
JobStart.
 1.263 29-Jan-2021  rillig make(1): demonstrate unnecessary creation of empty files in jobs mode
 1.262 23-Jan-2021  rillig make(1): fix unit tests for dash and bash 5.1
 1.261 19-Jan-2021  rillig make(1): normalize shell error messages in tests

Newly supported is bash, which outputs "bash: line 123".
 1.260 31-Dec-2020  rillig make(1): add test for error handling and expansion in .for loops
 1.259 30-Dec-2020  rillig make(1): add test for .endfor without corresponding .for
 1.258 29-Dec-2020  rillig make(1): add test that explains how variables are exported

Exporting the variables at the right time and with the correct values is
a subtle issue. The current implementation carefully marks variables as
ready to be exported, then exports them and at the same time tries to
export as few variables as possible, to avoid memory leaks. This test
describes and explains how all this works in detail.

This test also justifies that the call to Var_ReexportVars happens in
the make process itself, not in the child processes, no matter whether
these are created with vfork or (only theoretically) with plain fork.
This has changed in compat.c 1.217, job.c 1.390 and main.c 1.504 from
2020-12-27.
 1.257 27-Dec-2020  rillig make(1): add test for expansion errors in jobs mode

Since compat mode and jobs mode are implemented separately and vary in
lots of small details, each of them needs to be tested on its own.
 1.256 21-Dec-2020  rillig make(1): align tests for :localtime with those for :gmtime

These tests had been almost the same before, now they are as similar as
possible again.
 1.255 21-Dec-2020  rillig make(1): move tests for :gmtime to parse time

It's easier to have both the expressions and the expected values in a
single file. This also allows for flexible handling of multiple
acceptable outputs, in this case for 32-bit time_t.
 1.254 21-Dec-2020  sjg Set default for .MAKE.OS once
 1.253 20-Dec-2020  rillig make(1): include line numbers in output of test varmod-edge.mk

Suppressing the line numbers does not provide much benefit, given that
the test file doesn't change often.
 1.252 19-Dec-2020  rillig make(1): add test for null byte in .for loop body
 1.251 19-Dec-2020  rillig make(1): demonstrate wrong line numbers in .for loops, since 2007-01-01
 1.250 14-Dec-2020  rillig make(1): add test for parsing the end of a condition
 1.249 13-Dec-2020  rillig make(1): demonstrate wrong error handling in compat mode
 1.248 13-Dec-2020  sjg Prune job debug output that may appear out of order.

A race between child and parent means that we cannot
guarantee whether all child output is seen before we call
JobClosePipes, thus intervening debug output can appear
before or after the last child output.
 1.247 13-Dec-2020  sjg Ensure we have a value for .MAKE.UID
 1.246 13-Dec-2020  rillig make(1): add test for misspelled directives

This test allows the other directive-* tests to focus on the purpose of
the individual directive, allowing these tests to continue after
parsing, without errors.
 1.245 12-Dec-2020  rillig make(1): add test for a shell with error control

None of the predefined shells has error control, and the corresponding
code had not been covered by the existing unit tests.
 1.244 10-Dec-2020  rillig make(1): test all combinations of switches for running commands

The code in JobPrintSpecials is rather complicated and contains
surprising interaction between some of the switches.

To see the exact effects of the switches, record the current state and
its output, to prevent accidental breakage during the upcoming
refactorings.
 1.243 09-Dec-2020  rillig make(1): remove noise from test output of opt-jobs-no-action
 1.242 09-Dec-2020  rillig make(1): add test for the -n option combined with RunFlags
 1.241 09-Dec-2020  rillig make(1): add test for combining -j1 with -n
 1.240 07-Dec-2020  rillig make(1): normalize output of test sh-dots for non-native mode
 1.239 07-Dec-2020  rillig make(1): add tests and tutorial for the ?= assignment operator
 1.238 07-Dec-2020  rillig make(1): add test for wrong exit status 0 after failed targets with -k
 1.237 06-Dec-2020  rillig make(1): add test for .END after failed main node
 1.236 05-Dec-2020  sjg Use .MAKE.OS if we can
 1.235 04-Dec-2020  rillig make(1): use fixed format for debug output of the directory cache

The previous output format had a %-20s conversion specifier. This
produced different output depending on the length of the pathname, which
was too difficult to normalize. By moving the directory name to the
end, it is no longer necessary to fill up any space, and the numbers are
always aligned properly.

As a result, 3 of the unit tests no longer need any special
postprocessing of their output.
 1.234 01-Dec-2020  rillig make(1): add test and tutorial for indirect modifiers
 1.233 01-Dec-2020  rillig make(1): add test for the special .MAKEFLAGS variable
 1.232 01-Dec-2020  rillig make(1): add tests for suppressing "stopped in"

These tests demonstrate the unwanted behavior described in PR bin/55578
and PR bin/55832.
 1.231 30-Nov-2020  rillig make(1): fix tests for :gmtime and :localtime for 32-bit time_t

https://bugs.freebsd.org/251465
 1.230 30-Nov-2020  sjg Add some tests for meta mode
 1.229 29-Nov-2020  rillig make(1): clean up memory management for CachedDirs

Previously, the reference count for a newly created CacheDir had been
set to 1 in CacheNewDir. This was wrong because at that point, the
object had not been referenced by any nonlocal variable. The reference
count is no longer incremented at this point.

All callers of CacheNewDir either append the newly created CachedDir to
a SearchPath via Lst_Append and CachedDir_Ref, or they assign it to a
global variable via CachedDir_Assign.

Since the reference count is no longer wrongly incremented, it does not
need to be decremented more than necessary in Dir_End. To keep the code
simple and maintainable, all assignments to global variables are now
handled by CachedDir_Assign. Adding a CachedDir to a list is still done
manually via Lst_Append, and the corresponding code for decrementing is
in SearchPath_Clean and SearchPath_Free. These details may be cleaned
up in a follow-up commit.

As a result, when OpenDirs_Done is called in the unit tests, the list of
open directories is empty. It had been non-empty in a single unit test
before (dep-wildcards.mk), as a result of calling Dir_Expand.

The additional debug logging for the reference counting is not enabled
by default since it contains memory addresses, which makes the output
dependent on the memory allocator.

The function CachedDir_Destroy has been merged into CachedDir_Undef,
which had only been used in Dir_End before. The new name emphasizes
that it corresponds to CachedDir_Ref.
 1.228 29-Nov-2020  rillig make(1): add debug logging for OpenDirs_Done
 1.227 29-Nov-2020  rillig make(1): add debug logging for reference counting of CachedDir
 1.226 25-Nov-2020  sjg Add .MAKE.UID and .MAKE.GID
 1.225 25-Nov-2020  sjg access(2) does not work for root, so skip objdir-writable
 1.224 24-Nov-2020  rillig make(1): add test for bug in error handling of .BEGIN in -k mode
 1.223 24-Nov-2020  rillig make(1): add test for error in dependency of .END node in -k mode
 1.222 24-Nov-2020  rillig make(1): add test for missing "Stop" after error in .END
 1.221 23-Nov-2020  rillig make(1): make output of test opt-debug-graph1 consistent

The output from the directory cache made the regular NetBSD build fail
because the pathname to the working directory differs, thus affecting
the spacing.

This time, document why the directory cache needs to be excluded from
the output.
 1.220 23-Nov-2020  rillig make(1): test that .PHONY targets are not resolved using suffix rules
 1.219 22-Nov-2020  rillig make(1): add test for debug output from transformation rules
 1.218 22-Nov-2020  rillig make(1): add another unit test for suffix handling
 1.217 22-Nov-2020  rillig make(1): document the selection of the main target
 1.216 22-Nov-2020  rillig make(1): make configuration of export tests simpler

The configuration section of unit-tests/Makefile is already complicated
enough to read, due to the excessive use of regular expressions.
Therefore, to keep the structuring elements at a minimum, inline the
.for loop.
 1.215 22-Nov-2020  rillig make(1): add more output to test for -dg1

Previously, the variables section had been omitted. This was because
the variables had been output in hashcode order until 2020-10-18, and
because some of the variable values are specific to the test environment
or the individual run (MACHINE_ARCH, MAKE.PPID).
 1.214 21-Nov-2020  rillig make(1): capture more output from test deptgt-suffixes

This will have an effect with the next commit.
 1.213 21-Nov-2020  rillig make(1): limit memory usage in tests

There is a suspicious condition in SuffUpdateTarget code that looks wrong
on the first sight. When removing it though, make allocates huge amounts
of memory. To stop freezing the whole machine in this situation, limit
the total memory.

The limit of 200000 has been determined experimentally on NetBSD 8.0
x86_64. With a limit of 100000, make wouldn't even start. 100 MB of
memory is really a lot for such a simple program that according to top(1)
only needs 8 MB. But 200 MB is still better than 5 GB.

Since the Makefile is used on other platforms as well, via the bmake
distribution, and since every operating system has its own list of ulimit
options, make this configurable.
 1.212 21-Nov-2020  rillig make(1): add test for incomplete transformation rule
 1.211 19-Nov-2020  rillig make(1): fix test opt-debug-jobs for native shell

Even after substituting the actual shell name with <shell>, the trailing
optional -q option needs to be normalized.
 1.210 19-Nov-2020  rillig make(1): fix test opt-debug-jobs when compiled with dash as shell

make USER_CPPFLAGS=-DDEFSHELL_CUSTOM='\"/usr/pkg/bin/dash\"'
 1.209 19-Nov-2020  rillig make(1): remove redundant postprocessing for test var-op-shell

The regular expression from the previous line already matches everything
that the removed line could ever match.
 1.208 19-Nov-2020  rillig make(1): remove postprocessing for test directive-export-gmake

Since revision 1.3, directive-export-gmake.mk takes care of handling this
case. Removing the "error" lines from the output of the tests only makes
the test harder to understand and may also hide future bugs.
 1.207 18-Nov-2020  sjg Cleanup - colliding fixes for same issue
 1.206 18-Nov-2020  sjg Some tests need help with dash
 1.205 17-Nov-2020  rillig make(1): make test vardebug independent from the shell
 1.204 17-Nov-2020  rillig make(1): fix test output of var-op-shell for dash

Dash is helpful and outputs the line number in case of an error. The
other shells don't do this. Accept both variants.
 1.203 16-Nov-2020  rillig make(1): add test for self-referencing suffix rule

Just to ensure that make doesn't run into an endless loop.
 1.202 15-Nov-2020  rillig make(1): fix typo in test for variable with empty name
 1.201 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.200 14-Nov-2020  rillig make(1): use progname instead of hard-coded 'make' in warning

This only affects the warning that chdir to objdir failed. In sub-makes
the progname includes the [n], allowing to narrow down the actual cause
of the problem.
 1.199 14-Nov-2020  rillig make(1): add test for the -t option in jobs mode
 1.198 12-Nov-2020  sjg Pass a writable flag to Main_SetObjdir to control writable check

For curdir and an explicit .OBJDIR target, we allow for
the directory to be read-only.
During InitObjdir we otherwise default to requiring objdir to be
writable - this can be controlled by env variable
MAKE_OBJDIR_CHECK_WRITABLE

Add unit-tests/objdir-writable

Reviewed by: christos rillig
 1.197 10-Nov-2020  rillig make(1): add more tests for parsing .if directives

The details of parsing are quite tricky and not documented in the manual
page. Record the current behavior to be a little safer in future
refactorings.
 1.196 10-Nov-2020  rillig make(1): add test for the obsolete variable VPATH
 1.195 09-Nov-2020  rillig make(1): in tests, move command line arguments into the test proper
 1.194 09-Nov-2020  rillig make(1): move test for != assignments to var-op-shell
 1.193 09-Nov-2020  sjg Control TZ for depsrc-optional
 1.192 08-Nov-2020  rillig make(1): in lint mode, only allow '&&' and '||', not '&' and '|'

These variants of the condition operators are neither documented in the
manual page nor are they used in practice.
 1.191 08-Nov-2020  rillig make(1): add test for expanding variable expressions
 1.190 07-Nov-2020  rillig make(1): add test for OP_SUBMAKE
 1.189 07-Nov-2020  rillig make(1): add test for job command flags
 1.188 04-Nov-2020  rillig make(1): add test for undefined variables in command line arguments

The variable discardUndefined has an implicit negation in its name,
which makes it hard to understand. Plus, most of the time it is true.
It's better to have a flag that is false most of the time and has a
positive name.

On the first attempt of inverting that variable, I stumbled upon
MainParseArgs, which initially leaves discardUndefined == FALSE, and
after handling the dashed options, sets it to TRUE. This would make a
difference when more command line arguments would be added later via the
.MAKEFLAGS special target.

Upon further inspection, the only place where discardUndefined is used
is in VarAssign_EvalSubst in parse.c, and that place is not reachable
from any of the dashed options. Therefore, discardUndefined could
already be set at the very beginning of MainParseArgs or even when
initializing the global variable itself, without any observable
difference.

Not even the ::= variable modifier could do anything about this since it
is not reachable from the dashed command line options as well, and in
addition, it expands its right-hand side in any case, always discarding
undefined variables. Oh, these little inconsistencies everywhere.
 1.187 03-Nov-2020  rillig make(1): move tests from directives.mk to separate tests
 1.186 02-Nov-2020  rillig make(1): remove obsolete POSTPROC.varname from unit tests

It was not needed anymore since 2020-10-18.
 1.185 02-Nov-2020  rillig make(1): add test for parse errors in commands in lint mode (-dL)

The difference to non-lint mode is that the exit status is now 2 instead
of 0.
 1.184 02-Nov-2020  rillig make(1): remove debugging code from sync-mi
 1.183 02-Nov-2020  rillig make(1): add test for parse errors in shell commands, compat mode
 1.182 02-Nov-2020  rillig make(1): handle errors when sync-mi fails because of a syntax error
 1.181 01-Nov-2020  rillig make(1): move test flags to test varmod-match-escape.mk
 1.180 31-Oct-2020  rillig make(1): add more tests for the variable modifier :localtime
 1.179 31-Oct-2020  rillig make(1): add test for recursive variable expressions
 1.178 31-Oct-2020  rillig make(1): merge the SysV modifier tests into varmod-sysv
 1.177 30-Oct-2020  rillig make(1): move test flags for varname-dot-shell to the test itself
 1.176 29-Oct-2020  rillig make(1): move MAKEFLAGS handling in vardebug test to the test itself
 1.175 24-Oct-2020  rillig make(1): add test for looking up suffixes
 1.174 23-Oct-2020  rillig make(1): add test for dependencies of the form '%.o: %.c'
 1.173 23-Oct-2020  rillig make(1): add test case in which .BEGIN depends on .END

Just for fun.
 1.172 23-Oct-2020  rillig make(1): add test for the '::' dependency operator
 1.171 23-Oct-2020  rillig make(1): move tests from cond2.mk to varmod-ifelse.mk (fixup)
 1.170 23-Oct-2020  rillig make(1): add test for .ERROR_CMD in jobs mode
 1.169 20-Oct-2020  rillig make(1): split test suffixes.mk into simpler, isolated tests

The code in suff.c is already hard to understand, and so were the tests
in suffixes.mk since several independent topics were merged into a
single test.

Splitting this test into a separate test per issue allows to document
the expected and actual behavior in more detail. That's complicated
enough already.

PR bin/49086
 1.168 18-Oct-2020  sjg In meta mode we do not have to re-run all tests when Makefile is touched
 1.167 18-Oct-2020  rillig make(1): add test for turning a target into a transformation
 1.166 17-Oct-2020  rillig make(1): document why the ampersand is not listed in export.exp
 1.165 10-Oct-2020  sjg Limit output of export tests to POSIX compatible env vars
 1.164 08-Oct-2020  rillig make(1): remove test misc.mk from Makefile
 1.163 08-Oct-2020  rillig make(1): fix test opt-debug-jobs on non-native platforms
 1.162 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.161 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.160 04-Oct-2020  rillig make(1): add tests for parsing assignments, especially :sh

Luckily nobody uses the :sh variable assignment modifier since its
syntactical variant != is simpler.
 1.159 03-Oct-2020  rillig make(1): add test demonstrating the Towers of Hanoi puzzle

It's not the primary task of make to handle procedure calls with
parameters, combined with lexical scoping, therefore the code does not
look as straight-forward or clean as in other programming languages. It
feels more like squeezing a programming problem from the imperative
world into the world of declarative dependencies.

A more idiomatic way of implementing this puzzle should be as a
dependency graph since that's both the natural structure of the puzzle
and the primary domain of make. Something like having a main target
"hanoi-5" that depends on intermediate targets of the form
"move-1.2.3.4.5-_._._._._-_._._._._", each representing a single
configuration of the stacks. These targets could be generated
dynamically. A benefit of this implementation would be that the puzzle
could be resumed from an arbitrary configuration, just just from the
initial configuration.
 1.158 03-Oct-2020  rillig make(1): add tests for the various supported shells
 1.157 03-Oct-2020  rillig make(1): add test for the -dj debug option
 1.156 02-Oct-2020  rillig make(1): add tests for parsing and exporting variables

Once again, there are a few surprises deeply hidden inside the edge
cases.
 1.155 29-Sep-2020  rillig make(1): fix test job-output-long-lines

The test failed on Linux since the test relied on the two child
processes interleaving each other. This is not guaranteed to happen
though.
 1.154 27-Sep-2020  rillig make(1): add test for merging long lines of job output
 1.153 27-Sep-2020  rillig make(1): run tests with jemalloc debugging enabled

This protects against very simple memory allocation bugs such as
migrating Lst_ForEachUntil to Lst_ForEach without remembering that
Lst_ForEachUntil can handle the situation where the current list node is
removed from the list, but Lst_ForEach cannot. This happens in
Make_ExpandUse, for example.
 1.152 25-Sep-2020  rillig make(1): add test for harmless bug in Parse_File

When there is a dependency group at the end of a top-level makefile,
this dependency group is not finished properly. This allows to add
further commands to the targets of this dependency group, which was not
intended.
 1.151 25-Sep-2020  rillig make(1): add test for make() function in conditions
 1.150 25-Sep-2020  rillig make(1): add test for deleting the suffixes during parsing
 1.149 25-Sep-2020  rillig make(1): add test for partial expansion of undefined variables
 1.148 23-Sep-2020  rillig make(1): remove debug output from counter tests

Now that the tests work as intended, the debug information is no longer
necessary. It was only intended to track down the cause of the
unexpected behavior.
 1.147 23-Sep-2020  rillig make(1): add variant of the counter test

I had expected that using the ::+= modifier instead of the ::= modifier
would work, since the assignment modifier for COUNTER no longer contains
a reference to itself. But instead of ending up at 4, the counter even
goes up to 6.
 1.146 23-Sep-2020  rillig make(1): fix assertion failure in -j mode with .END node

There had been two separate global variables for the .END node, and in
parallel mode, only the one in jobs.c was initialized.

The code in JobRun heads over to Compat_Make without calling Compat_Run
first, which left the variable ENDNode uninitialized.
 1.145 21-Sep-2020  rillig make(1): run tests with absolute filenames as well

The tests varname-dot-parsedir and varname-dot-parsefile had been broken
before if they were run with the "-f $PWD/$test.mk" option. This way of
running the tests is used by FreeBSD.
 1.144 21-Sep-2020  rillig make(1): fix tests for .PARSEDIR/.PARSEFILE

The output of these tests previously depended upon whether the test
makefile was specified as relative or as absolute path. In NetBSD, it
is specified as relative path, in FreeBSD as absolute path.

Adjust the expected output to hide this difference; in the .rawout files
it is still visible.
 1.143 15-Sep-2020  rillig make(1): move flags for lint test into the test itself
 1.142 14-Sep-2020  rillig make(1): add test for undefined expressions in conditions in lint mode
 1.141 14-Sep-2020  rillig make(1): add tests for numbers in conditions
 1.140 13-Sep-2020  rillig make(1): add tests for the various .include directives
 1.139 13-Sep-2020  rillig make(1): fix sync-mi helper target, at least for adding tests
 1.138 07-Sep-2020  rillig make(1): explain why each test is run in a sub-make
 1.137 07-Sep-2020  rillig make(1): use consistent spelling for postprocessing
 1.136 05-Sep-2020  rillig make(1): add test for intentional hash collision for variable names

Hash collisions may slow down make in certain special situations. There
is no point though in maliciously triggering such a situation since
anyone who can inject values into makefiles can easily run shell
commands using the :!cmd! modifier or similar mechanisms. Crafting
variable names just to slow down make is thus not an attack vector.
 1.135 05-Sep-2020  rillig make(1): move test for -dg1 from opt-debug-g1 to opt-debug-graph1
 1.134 05-Sep-2020  rillig make(1): add tests for each debug option
 1.133 04-Sep-2020  rillig make(1): re-enable the archive test

The test had failed in the releng build because it assumed it were run
with .CURDIR == .PARSEDIR. This assumption is true when the tests are
run directly from usr.bin/make, but not when they are run from
tests/usr.bin/make.
 1.132 04-Sep-2020  rillig make(1): add test for the special variable MAKEFILE
 1.131 04-Sep-2020  rillig make(1): extend tests for the :hash variable modifier

The previous test vectors didn't contain any hash with a leading zero.
This could have been a simple programming mistake by using %8x instead
of the intended %08x. Using snprintf wouldn't have been possible anyway
since the hex digits are printed in little-endian order, but without
reversing the bits of each digit. Kind of unusual, but doesn't affect
the distribution of the hashes.
 1.130 02-Sep-2020  rillig make(1): add test for the .for directive

For a long time, I had assumed that the iteration variables of a .for
loop are just normal global variables. This assumption was wrong but
didn't have any consequences.

The iteration variables of a .for loop can just be accessed like global
variables, therefore it is not obvious that they are implemented in a
completely different way.

There are some edge cases in conditions used inside .for loops, in which
the iteration variables cannot be used like normal variables. An
example is brought up in https://gnats.netbsd.org/47888, which observes
that the defined() and empty() functions in conditions only work with
variables but ignore the iteration "variables", simply because these are
not variables but only expressions.
 1.129 29-Aug-2020  rillig make(1): fix sh-dots test

The exact output depends on the shell. Some shells prefix the error
message with their name, some don't.
 1.128 29-Aug-2020  rillig make(1): add test for the .ifmake directive
 1.127 29-Aug-2020  rillig make(1): add tests for .else and .for + .endif
 1.126 29-Aug-2020  rillig make(1): fix assertion failure for .SUFFIXES in archives

This occurred in the posix1.mk test, even though it is disabled in
unit-tests. But in tests/usr.bin/make it still runs. There, it should
have produced an "expected failure" but crashed instead.

The archive-suffix test is the stripped-down version of the posix1 test.
 1.125 29-Aug-2020  rillig make(1): fix test opt-debug-g1

Including the directory cache made the test output fragile.
 1.124 28-Aug-2020  rillig make(1): add test for interrupting a command
 1.123 28-Aug-2020  rillig make(1): add test for the undocumented .NULL special dependency target
 1.122 28-Aug-2020  rillig make(1): add tests for the special .INCLUDES and .LIBS variables
 1.121 28-Aug-2020  rillig make(1): disable the sync-mi convenience target
 1.120 27-Aug-2020  rillig make(1): add test for the -dg1 option
 1.119 23-Aug-2020  rillig make(1): add test for + commands with the -n command line option
 1.118 23-Aug-2020  rillig make(1): add tests for the -i -k -v -V -W options
 1.117 23-Aug-2020  rillig make(1): add tests for numeric comparisons in .if directives
 1.116 23-Aug-2020  rillig make(1): fix assertion failure in debug output for read-only variables
 1.115 23-Aug-2020  rillig make(1): add test for the newly added .SHELL variable
 1.114 22-Aug-2020  rillig make(1): add test for expanding wildcards in directories

This test covers DirExpandInt.
 1.113 22-Aug-2020  sjg bash says 'command not found'
 1.112 22-Aug-2020  rillig make(1): try to set the variable named "" using the command line

Before 2020-08-22, the command line argument '=cmline-plain' triggered
undefined behavior, just like the assignment '=assigned' in the Makefile.
 1.111 22-Aug-2020  sjg Use TEST_MAKE to run unit-tests

This lets us take advantage of new features like ${.SHELL}
 1.110 22-Aug-2020  rillig make(1): add test for assigning to the variable named ""

This has been possible at least since 2013, probably much longer.
 1.109 22-Aug-2020  rillig make(1): add test for deferred variable expansion in dependencies
 1.108 22-Aug-2020  sjg Supress /bin/sh: in error for sh-dots
 1.107 22-Aug-2020  rillig make(1): add test for "no target to make"
 1.106 22-Aug-2020  rillig make(1): add test for the special "..." in shell commands
 1.105 22-Aug-2020  rillig make(1): add test for combining :: and .USEBEFORE
 1.104 20-Aug-2020  rillig make(1): enable debug logging for archive test

This test succeeds locally on NetBSD 8.0 but not in the official test
runs on https://releng.netbsd.org/test-results.html. To see the
difference, run the test with full debug information.

This test is commented out in usr.bin/make/unit-tests/Makefile, but that
doesn't stop tests/usr.bin/make/t_make.sh from running it nevertheless,
since over there, all *.mk files are considered tests, be they commented
out or not.
 1.103 20-Aug-2020  rillig make(1): add test for parsing functions in .if conditions
 1.102 19-Aug-2020  rillig make(1): add test for the -n option
 1.101 19-Aug-2020  rillig make(1): add test for the -q option
 1.100 16-Aug-2020  rillig make(1): move tests for the :Ox modifier into separate file

The test has been extended by ensuring that the shuffled words are still
the same. Comparing two shuffled lists is probabilistic, but comparing
their sorted results is not, therefore that's completely sensible to do.

When writing this test, by coincidence I discovered how to generate the
"Undefined variable" error message. Unfortunately, the error message is
wrong since the variable NUMBERS is defined at that point. In summary,
that error message is shown when it shouldn't, and when it should it is
not shown. Still, I'm glad that I finally found it.
 1.99 16-Aug-2020  rillig make(1): move tests for the :M modifier into separate files

The test for the different escaping has been adjusted to actually show
the different parsing results in the test output. To do this, it had to
get its own file since it needs the -dv debug flag and specialized
post-processing.
 1.98 16-Aug-2020  rillig make(1): run tests in an almost empty, controlled environment

Several of the tests use simple variable names that might be influenced
by environment variables of the same name. Especially the tests for the
?= variable assignment operator need an empty environment to start with,
to produce reliable results.

The PATH must be in the base environment since several tests depend on
the usual tools like echo(1), sleep(1), grep(1). Setting the PATH to a
fixed value would have made it impossible to run the tests in a custom
environment that don't have a /bin directory. It's the user's
responsibility to provide a sane PATH.
 1.97 16-Aug-2020  rillig make(1): force all tests to be run with the -r flag

Without that flag, <sys.mk> is loaded before the tests. The tests are
not intended to either use or even test these rules and definitions,
therefore it is safe to omit this command line option.

If there should ever be tests for POSIX-conformance that need the
builtin rules and definitions, these tests can still ".include <sys.mk>"
at the beginning and be done with it, since the -m command line option
is not touched. The system-default rules and definitions are still
available, they are just not active by default.

Suggested by sjg.
 1.96 16-Aug-2020  rillig make(1): use consistent formatting for running the tests

With the many newly added tests, having two messages ("testing xzy" and
"postprocessing xyz") made the output too noisy since the words were not
aligned nicely. Use the same formatting as for MAKEVERBOSE=0, and
remove the message for postprocessing. If there should ever be problems
during postprocessing, it's trivial to run "../make TESTS=bad-test -dl"
to find out where the problem is.
 1.95 16-Aug-2020  rillig make(1): clean up cleaning of test files

The variables CLEANFILES and CLEANDIRS are not supposed to be
user-settable, thus use a simple "=" instead of "+=".

Since CLEANDIRS is always set, there is no point in making the rm
conditional.
 1.94 16-Aug-2020  rillig make(1): move tests for :S, :C, :@ from modmisc to their separate tests
 1.93 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.92 15-Aug-2020  rillig make(1): fix archive test

Even though it is commented out in this Makefile, it is still run by
atf, on purpose. This test is broken on FreeBSD, but on NetBSD it
should still be run.

Without removing the archive first, it could be left over from a
previous test failure and thus be newer than all its members, leading to
${.OODATE} being empty.
 1.91 09-Aug-2020  rillig make(1): add test for .USE combined with inference rule without commands

Discovered by christos.
 1.90 09-Aug-2020  rillig make(1): add test for non-obvious .MAKE.EXPORTED edge case
 1.89 07-Aug-2020  rillig make(1): add test for exporting variables
 1.88 07-Aug-2020  rillig make(1): document why the suffixes test must stay disabled
 1.87 07-Aug-2020  rillig make(1): enable test phony-end

This at least documents the actual behavior. Not sure what the expected
behavior is and why.
 1.86 07-Aug-2020  rillig make(1): enable test for .IMPSRC

Having this test disabled was very confusing since its content didn't
match the actual behavior, and this also differs from the GNU make
behavior.
 1.85 06-Aug-2020  sjg Use -r for recursive
 1.84 06-Aug-2020  rillig make(1): add test for unintended "recursive variable" in -dL mode
 1.83 03-Aug-2020  rillig make(1): in lint mode, disallow dynamic variable names in :@ modifier

This is an extremely obscure feature that hopefully nobody ever
considered using.
 1.82 02-Aug-2020  rillig make(1): set more predictable environment for counter test

Having an environment variable or a global variable called "C" would
change the debug output since an existing variable is not set to the
empty value first. See parse.c, keyword "!Var_Exists".
 1.81 02-Aug-2020  rillig make(1): add test for nested VAR_SUBST assignments
 1.80 01-Aug-2020  rillig make(1): fix error message when regcomp fails

If regcomp fails, it's not the regex substitution that is erroneous, but
the regex compilation.
 1.79 01-Aug-2020  rillig make(1): improve output grouping in varmod-edge test

The generated error messages are now closer to the test cases that
produce them. To keep the expected output stable, the line numbers are
omitted from the .info directives.
 1.78 31-Jul-2020  rillig make(1): automate adding or removing test files
 1.77 31-Jul-2020  rillig make(1): add test for braces in dependency lines

The comment at DirExpandCurly says something about "recursively", but the
nested braces don't work.

The manual page only mentions that "{} may be used", but it keeps quiet
about the exact meaning and also doesn't mention any nesting.
 1.76 29-Jul-2020  rillig make(1): add enough tests to cover the ApplyModifier functions

Only a few return statements are still missing from the code coverage.

In ApplyModifier_Assign, the test for an empty variable name is skipped
for now since it segfaults.

In ApplyModifier_SysV after the second ParseModifierPart, the branch for
the missing delimiter is not reached since this case is already checked
for in the first part of the function. To trigger this branch, a
specially crafted, unrealistic string needs to be created, and that's too
complicated for the moment.
 1.75 28-Jul-2020  rillig make(1): add test for setting .OBJDIR via the command line
 1.74 28-Jul-2020  sjg Use cat if no POSTPROC.${.TARGET:R}

On Linux sed with no flags throws an error.
 1.73 28-Jul-2020  sjg Ensure .CURDIR is correct for tests that run sub-makes
 1.72 28-Jul-2020  rillig make(1): disable archive test

On FreeBSD, running the archive.mk test results in "create-archive is up
to date" and similar messages. The situation is unclear, and the
archive code seems to be practically unused. Furthermore the archive
test doesn't ensure that it is run in ${.PARSEDIR}, so it needs a bit
more work.
 1.71 28-Jul-2020  sjg Use -r for export.mk to minimize interference
 1.70 27-Jul-2020  rillig make(1): add tests for parsing directives like .if and .info
 1.69 27-Jul-2020  rillig make(1): prepare test for .export to show all exported variables

Currently the unit tests don't cover exporting of local variables like
.TARGET or @. To see the effects, all exported variables must be listed
by the tests.
 1.68 27-Jul-2020  rillig make(1): sort flags for test cases alphabetically
 1.67 27-Jul-2020  rillig make(1): add very basic test for archive handling

The whole code in arch.c had been uncovered by tests before.

The code coverage shows that neither the archive name nor the member
contain any $, even though archive.mk looks like it. It could be
necessary to place the variable assignments below the dependency line,
to force late evaluation.
 1.66 26-Jul-2020  rillig make(1): add test for off-by-one error in Var_Parse
 1.65 26-Jul-2020  rillig make(1): add test for appending and exporting a variable
 1.64 25-Jul-2020  rillig make(1): add tests for previously uncovered code
 1.63 09-Jul-2020  sjg Fix typo
 1.62 04-Jul-2020  rillig make(1): ignore system-specific error message from regcomp in test

NetBSD 8 has: repetition-operator operand invalid
Ubuntu has: Invalid preceding regular expression
 1.61 04-Jul-2020  rillig make(1): add post-processing for tests

By defining SED_CMDS.${test}, a test can do additional post-processing
on its output, for example to normalize paths or error messages.

The Makefile for the tests now follows the common style to have all
relevant definitions at the top of the file, and all the implementation
details at the bottom.

By using the += instead of backslashed lists, it becomes easier to
comment out a single test, either temporarily or permanently (such as
the POSIX tests).

The :C modifier has been replaced with the simpler :S, some :S modifiers
have been replaced with simpler := modifiers.

The postprocessing commands have been extracted from the actual command.
This makes editing and commenting them easier.
 1.60 04-Jul-2020  rillig make(1): improve documentation about adding new tests
 1.59 28-Jun-2020  rillig make(1): demonstrate bug when evaluating conditions
 1.58 17-May-2020  rillig usr.bin/make: demonstrate actual behavior of .INCLUDEDFROMFILE
 1.57 10-May-2020  rillig usr.bin/make: sort test cases alphabetically
 1.56 10-May-2020  rillig usr.bin/make: add tests for surprising dollar removal
 1.55 29-Apr-2020  rillig usr.bin/make: add test case for lazy conditions
 1.54 30-Nov-2019  rillig Add unit tests for variable modifiers like :M and :N
 1.53 24-May-2018  christos branches: 1.53.2;
unit test for $ underquoting in :Q modifier
 1.52 05-May-2015  sjg branches: 1.52.8; 1.52.14;
When evaluating condtionals from .if we want to require
that the lhs is a variable reference, a number or a quoted string.
This helps avoid subtle bugs caused by typos.

When conditionals are being evaluated during variable expansion
we cannot be as strict becuase lhs will already have been expanded.

We therefor pass a boolean to Cond_EvalExpression to tell it how
lhs should be treated.

Add unit-tests/cond2.mk to test the above

Reviewed by: christos, joerg
 1.51 20-Oct-2014  sjg Extract broken tests
 1.50 29-Aug-2014  sjg *.rawout are out-of-date if ${TEST_MAKE} is newer.
 1.49 29-Aug-2014  sjg posix1.mk and suffixes.mk need to cleanup in order to achieve
repeatable results.
posix1.mk's lib.a target still looks dubious.
 1.48 24-Aug-2014  apb Let "make clean" delete the files and dirs created by some of the tests.
 1.47 24-Aug-2014  apb Add tests for backslash escaping in make(1).

Many of these tests fail, and I have populated the escape.exp file with
the results that I expect, not with the results that make(1) actually
produces.

Also update the set lists for these tests.
 1.46 23-Aug-2014  christos Instead of adding the test in 48095 I added the tests in 48096. Add the
missing test now.
 1.45 23-Aug-2014  christos Convert test in PR/49085
 1.44 21-Aug-2014  apb Add a .PATH, so you can be in any other directory and run
"make -f /path/to/this/Makefile sometest.out"
and have it create sometest.out in your current directory.
 1.43 21-Aug-2014  apb Add varmisc.mk, for miscellaneous variable tests.

For now, the only test is copied from
src/tests/usr.bin/make/d_unmatchedvarparen.mk. This was
the only test in src/tests/usr.bin/make that was not also in
src/usr.bin/make/unit-tests.

XXX: src/tests/usr.bin/mk should be changed to reach over to
src/usr.bin/make/unit-tests, instead of keeping out of date copies
of the tests.
 1.42 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.41 21-Aug-2014  apb Stricter sed expression for matching an optional PID in square brackets.
 1.40 21-Aug-2014  apb When sanitising test output, replace "${TEST_MAKE}" with "make".
This string may appear in error messages that end up in the output.
 1.39 20-Aug-2014  apb Add tests for VAR != command.
 1.38 28-Aug-2013  sjg Fix parsing of SUNSHCMD style :sh = assigments.

Submitted by: Will Andrews at freebsd.org
 1.37 16-Jul-2013  sjg Fix unit-tests to cope with recent change to progname
 1.36 22-Mar-2013  sjg Add unit-test for export-env and gmake export
 1.35 09-Nov-2012  sjg Add a unit-test for .ORDER
 1.34 19-Jun-2012  sjg branches: 1.34.2;
Add unit-tests for .for
 1.33 29-Sep-2011  sjg branches: 1.33.2;
Make sure .PHONY targets get .TARGET set.
This wasn't happening when a dependency of .END.
Set .PREFIX too and add a unit-test.

PR: 43534
 1.32 07-Apr-2011  joerg Add the :hash modifier to compute a 32bit hash of an variable.
This uses MurmurHash3 to get a reasonable collission-free hash with
small code. The result is endian neutral.
 1.31 06-Mar-2011  sjg Add unit tests to check that exists(some/dir/) works

Also fix handling of sysV substitutions when lhs and variable are empty.

Also that modifiers do not cause errors during conditional tests
when undefined variables should otherwise be ok.
Ie. .if defined(nosuch) && ${nosuch:Mx} != ""
 1.30 10-Dec-2010  sjg fix style
 1.29 10-Dec-2010  sjg Need to export LC_ALL=C too
 1.28 22-Apr-2010  sjg Force LANG=C to ensure sort(1) behaves as expected
 1.27 22-Apr-2010  sjg PR: 42850
Reviewed by:

modmisc: since we apply an exists() test to $paths, be conservative
in what we expect.

Run the unit tests with -r -m / so that we do not fail if there
is no sys.mk present.
 1.26 08-Apr-2010  sjg Process .ERROR the same as .BEGIN, .END etc
so that it cannot be the default target.
Add unit-tests for .info - .error, and .ERROR.
 1.25 19-Nov-2009  sjg Add .unexport - the exact opposite of .export
and .unexport-env which unexport's all previously .export'd globals
as well as clearing environ[].
Allow's sys.mk near total controll.

Reviewed by: apb
 1.24 07-Oct-2009  sjg The parser used to break dependency lines at ';' without regard
for substitution patterns. This (perhaps coupled with the
new handling of .for variables in ${:U<value>...) caused interesting
results for lines like:

.for file in ${LIST}
for-subst: ${file:S;^;${here}/;g}

add a unit-test to keep an eye on this.
 1.23 25-Oct-2008  apb Use ${TOOL_SED} instead if plain sed in Makefiles.
 1.22 31-Mar-2008  sjg If the name passed to Var_Exists contains '$' run it through Var_Subst.
 1.21 05-Oct-2007  sjg Add the ability to .export variables to the environment.
 1.20 11-May-2006  sjg branches: 1.20.12;
Extract the variable modifier logic to a separate function.
This cuts Var_Parse in half! and allows the modifier logic to
be used recursively - when getting modifiers via variables.

Add new unit-test, to check that certain error cases are handled
correctly.
 1.19 26-Feb-2006  apb Make ".WAIT" apply recursively to all children of nodes on the right
hand side of the .WAIT, except when the recursive interpretation would
cause a cycle in the dependency graph.

Discussed in tech-toolchain. Reviewed by christos, sjg.
 1.18 26-Feb-2006  sjg Update man page and add test case for specifying modifiers via variable.
Also allow said variable to appear anywhere in the modifier list.
 1.17 13-Feb-2006  apb Escape dots in sed regexps. Without this patch, and without
an OBJDIR, "make test" in usr.bin/make fails.
 1.16 15-Jun-2005  rpaulo Add a unit-test for comments.
Addition to PR bin/17732.
Approved by sjg and christos.
 1.15 01-Jun-2005  sjg Add :Ox for random ordering, based on patch from
Mike M. Volokhov <mishka@apk.od.ua>
 1.14 30-Jun-2004  jmc branches: 1.14.2;
Add missing NetBSD ID tags
 1.13 07-May-2004  sjg Remove use of sh -e when running in compat mode.
Its not posix compliant and serves very little purpose.
With this change compat and jobs modes are consistent wrt how
they treat each line of a script.

Add support for the '+' command line prefix as required by posix.
Lines prefixed with '+' are executed even when -n is given.
[Actually posix says they should also be done for -q and -t]

PR:
Reviewed by: jmc
 1.12 08-Apr-2004  sjg Add check for extraneous .else's - based on patch from Arne H. Juul
in PR/24420.
Add a unit-test for conditionals.
Also in the unit-test makefile strip any .CURDIR in output.

PR: 24420
 1.11 20-Feb-2004  sjg branches: 1.11.2;
Fix :M so that modifiers in nested variables don't terminate parsing
early. Add a unit-test to verify it works and keeps working.
Re-jig the unit-tests so that all are sub makefiles.
 1.10 19-Jan-2004  sjg ternary is .PHONY
 1.9 09-Jan-2004  sjg Add unit test for ternary modifier
 1.8 27-Sep-2003  sjg Implement :[] modifier to allow picking a range of words out of a variable.
Also :tW and a W flag to :C and :S to allow treating value as a single word.
Add unit tests for the above, and fix some corner cases.
Based on patches supplied by Alan Barrett <apb@cequrux.com>
 1.7 08-Aug-2003  sjg Hook make unit-tests into regress
 1.6 01-Aug-2003  sjg Avoid \a as a test of invalid separator, since if we make ksh the default
shell, we get different results. \x seems safe.
 1.5 31-Jul-2003  sjg Test behavior of commandline variable assignments.
 1.4 29-Jul-2003  sjg First bug picked up by the unit tests - delim wasn't always initialized.
Avoid putting '\' in test case script lines since shell's like that on
SunOS insist on interpreting them.
 1.3 29-Jul-2003  sjg Use single quotes to protect everything from shell's that might
alter the results.
 1.2 29-Jul-2003  sjg Regardless of the name of TEST_MAKE, force it to make in test.exp
to avoid needless failures.
 1.1 28-Jul-2003  sjg Fix parsing bug for :ts - patch from Alan Barrett <apb@cequrux.com>
Also add simple unit-test jig (regress/usr.bin/make will use it too)
but having it local here makes inclusion in bmake simpler.
 1.11.2.2 10-May-2004  tron Pull up revision 1.13 (requested by sjg in ticket #282):
Remove use of sh -e when running in compat mode.
Its not posix compliant and serves very little purpose.
With this change compat and jobs modes are consistent wrt how
they treat each line of a script.
Add support for the '+' command line prefix as required by posix.
Lines prefixed with '+' are executed even when -n is given.
[Actually posix says they should also be done for -q and -t]
PR:
Reviewed by: jmc
 1.11.2.1 10-May-2004  tron Pull up revision 1.12 (requested by sjg in ticket #282):
Add check for extraneous .else's - based on patch from Arne H. Juul
in PR/24420.
Add a unit-test for conditionals.
Also in the unit-test makefile strip any .CURDIR in output.
PR: 24420
 1.14.2.3 02-Jul-2005  tron Pull up revision 1.16 (requested by rpaulo in ticket #491):
Add a unit-test for comments.
Addition to PR bin/17732.
Approved by sjg and christos.
 1.14.2.2 16-Jun-2005  tron Backout ticket 458, it causes PR toolchain/30536.
 1.14.2.1 16-Jun-2005  tron Pull up revision 1.16 (requested by rpaulo in ticket #458):
Add a unit-test for comments.
Addition to PR bin/17732.
Approved by sjg and christos.
 1.20.12.1 06-Nov-2007  matt sync with HEAD
 1.33.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.33.2.2 16-Jan-2013  yamt sync with (a bit old) head
 1.33.2.1 30-Oct-2012  yamt sync with head
 1.34.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.34.2.2 23-Jun-2013  tls resync from head
 1.34.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.52.14.1 25-Jun-2018  pgoyette Sync with HEAD
 1.52.8.1 09-Jun-2018  martin Pull up following revision(s) (requested by christos in ticket #870):

sys/lib/libgnuefi/Makefile.inc: revision 1.5
external/mit/xorg/xorg-pkg-ver.mk: revision 1.9
sys/arch/i386/stand/lib/Makefile.inc: revision 1.17
sys/compat/common/Makefile.inc: revision 1.25
usr.bin/make/unit-tests/varquote.exp: revision 1.1, 1.2
sys/lib/libsa/Makefile.inc: revision 1.24
usr.bin/make/var.c: revision 1.220
sys/arch/ia64/stand/efi/libefi/Makefile.inc: revision 1.5
sys/arch/hppa/spmath/Makefile.inc: revision 1.10
usr.bin/make/unit-tests/varquote.mk: revision 1.1, 1.2
usr.bin/make/unit-tests/Makefile: revision 1.53
sys/lib/libkern/Makefile.inc: revision 1.45
sys/arch/acorn32/stand/lib/Makefile.inc: revision 1.4
sys/arch/m68k/fpsp/Makefile.inc: revision 1.21
usr.bin/make/make.1: revision 1.273
sys/lib/libz/Makefile.inc: revision 1.17

- Introduce :q modifier for make variables and make it double escape $'s so
that passing variables to recursive makes with :q works as expected.
- Adjust makefiles that use recursive make to use :q

Discussed on tech-toolchain@

XXX: pullup 8
 1.53.2.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.277.2.1 31-May-2021  cjep sync with head
 1.347.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 29-Aug-2020  rillig make(1): fix assertion failure for .SUFFIXES in archives

This occurred in the posix1.mk test, even though it is disabled in
unit-tests. But in tests/usr.bin/make it still runs. There, it should
have produced an "expected failure" but crashed instead.

The archive-suffix test is the stripped-down version of the posix1 test.
 1.3 15-Nov-2020  rillig make(1): clean up some tests

Fix some mistakes in comments.

Improve some comments to be easier understandable.

Inline variables that are irrelevant for the test at hand (RUN,
MAKE_CMD).

Remove references to functions and constants that have since been removed
or renamed.
 1.2 07-Nov-2020  rillig make(1): fix references to Var_SetWithFlags in tests
 1.1 29-Aug-2020  rillig make(1): fix assertion failure for .SUFFIXES in archives

This occurred in the posix1.mk test, even though it is disabled in
unit-tests. But in tests/usr.bin/make it still runs. There, it should
have produced an "expected failure" but crashed instead.

The archive-suffix test is the stripped-down version of the posix1 test.
 1.12 12-Jun-2025  rillig make: add program name to stack traces from sub-makes
 1.11 12-Jun-2025  rillig make: add quotes to "in directory" line in stack traces

The other lines in stack traces use quotes as well.
 1.10 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.9 10-Jan-2025  rillig tests/make: test expressions based on undefined variables

When an undefined variable is used in a conditional, make complains about
"Malformed conditional", which is wrong since the conditional is
well-formed but errors out during evaluation.

In order to fix this wrong error message and preserve the remaining
behavior, cover the places in which an expression is evaluated with
undefined expressions being an error (VARE_EVAL_DEFINED), but with
neither producing an error message nor handling errors. This combination
results in the same behavior as evaluating the expressions in the mode
that allows undefined variables to be used in expressions.
 1.8 27-Apr-2024  rillig branches: 1.8.2;
tests/make: test detection of static library files
 1.7 09-Oct-2020  rillig make(1): use consistent order in .OODATE in test archive.mk
 1.6 08-Oct-2020  rillig make(1): make individual targets in test archive.mk visible

This test still fails on FreeBSD, printing the "ar cru, ranlib" lines
twice, and I don't know why.

To get more insights into the inner details, without activating the full
-dA logging, split the output into paragraphs, one per target.

This change reveals another interesting detail: Dependencies without any
commands (in this case create-archive) don't inherit the commands from
.USEBEFORE and .USE sources.
 1.5 04-Sep-2020  rillig make(1): fix expected file for archive test

This test is currently disabled, therefore it didn't fail immediately.
 1.4 23-Aug-2020  rillig make(1): in archive test, use wildcard that matches more than 1 file

This is to make sure that the buffer used for "archive(member)" is
properly reset after each member.
 1.3 23-Aug-2020  rillig make(1): add test for wildcards in archive dependency
 1.2 16-Aug-2020  rillig make(1): fix archive test

At the beginning of that test, the library archive obviously does not
exist yet.

This test failure is a bit hard to detect since the test is disabled in
usr.bin/make, but not in tests/usr.bin/make. This is because the latter
just runs all .mk files as tests, no matter whether they are commented
out or not.
 1.1 27-Jul-2020  rillig make(1): add very basic test for archive handling

The whole code in arch.c had been uncovered by tests before.

The code coverage shows that neither the archive name nor the member
contain any $, even though archive.mk looks like it. It could be
necessary to place the variable assignments below the dependency line,
to force late evaluation.
 1.8.2.1 02-Aug-2025  perseant Sync with HEAD
 1.14 10-Jan-2025  rillig tests/make: test expressions based on undefined variables

When an undefined variable is used in a conditional, make complains about
"Malformed conditional", which is wrong since the conditional is
well-formed but errors out during evaluation.

In order to fix this wrong error message and preserve the remaining
behavior, cover the places in which an expression is evaluated with
undefined expressions being an error (VARE_EVAL_DEFINED), but with
neither producing an error message nor handling errors. This combination
results in the same behavior as evaluating the expressions in the mode
that allows undefined variables to be used in expressions.
 1.13 27-Apr-2024  rillig branches: 1.13.2;
tests/make: test detection of static library files
 1.12 09-Apr-2021  christos Don't use a shell pattern to copy files, copy them explicitly. When running
as non-root, [at]*.mk matches archive.mk which we already copied. This was
copied as 444 and trying to overwrite it gives EACCES.
 1.11 15-Nov-2020  rillig make(1): clean up some tests

Fix some mistakes in comments.

Improve some comments to be easier understandable.

Inline variables that are irrelevant for the test at hand (RUN,
MAKE_CMD).

Remove references to functions and constants that have since been removed
or renamed.
 1.10 09-Oct-2020  rillig make(1): use consistent order in .OODATE in test archive.mk
 1.9 08-Oct-2020  rillig make(1): make individual targets in test archive.mk visible

This test still fails on FreeBSD, printing the "ar cru, ranlib" lines
twice, and I don't know why.

To get more insights into the inner details, without activating the full
-dA logging, split the output into paragraphs, one per target.

This change reveals another interesting detail: Dependencies without any
commands (in this case create-archive) don't inherit the commands from
.USEBEFORE and .USE sources.
 1.8 07-Sep-2020  rillig make(1): fix archive test when .CURDIR != .PARSEDIR
 1.7 05-Sep-2020  rillig make(1): add tests for each debug option
 1.6 04-Sep-2020  rillig make(1): re-enable the archive test

The test had failed in the releng build because it assumed it were run
with .CURDIR == .PARSEDIR. This assumption is true when the tests are
run directly from usr.bin/make, but not when they are run from
tests/usr.bin/make.
 1.5 23-Aug-2020  rillig make(1): in archive test, use wildcard that matches more than 1 file

This is to make sure that the buffer used for "archive(member)" is
properly reset after each member.
 1.4 23-Aug-2020  rillig make(1): add test for wildcards in archive dependency
 1.3 16-Aug-2020  rillig make(1): fix archive test

At the beginning of that test, the library archive obviously does not
exist yet.

This test failure is a bit hard to detect since the test is disabled in
usr.bin/make, but not in tests/usr.bin/make. This is because the latter
just runs all .mk files as tests, no matter whether they are commented
out or not.
 1.2 15-Aug-2020  rillig make(1): fix archive test

Even though it is commented out in this Makefile, it is still run by
atf, on purpose. This test is broken on FreeBSD, but on NetBSD it
should still be run.

Without removing the archive first, it could be left over from a
previous test failure and thus be newer than all its members, leading to
${.OODATE} being empty.
 1.1 27-Jul-2020  rillig make(1): add very basic test for archive handling

The whole code in arch.c had been uncovered by tests before.

The code coverage shows that neither the archive name nor the member
contain any $, even though archive.mk looks like it. It could be
necessary to place the variable assignments below the dependency line,
to force late evaluation.
 1.13.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 29-Jun-2025  rillig branches: 1.3.4;
make: if a condition is erroneous, skip the whole .if/.endif
 1.2 29-Jun-2025  rillig tests/make: fix expected test output for backslashes

Right before the previous commit, I had removed the "all" target from
the test, as the test had parsing errors, making the "all" target
redundant.
 1.1 29-Jun-2025  rillig tests/make: test backslash at the end of a line and in the :M modifier

As described in PR bin/46139 by David A. Holland.
 1.3.4.2 02-Aug-2025  perseant Sync with HEAD
 1.3.4.1 29-Jun-2025  perseant file char-005c-reverse-solidus.exp was added on branch perseant-exfatfs on 2025-08-02 05:58:30 +0000
 1.2 29-Jun-2025  rillig branches: 1.2.4;
make: if a condition is erroneous, skip the whole .if/.endif
 1.1 29-Jun-2025  rillig tests/make: test backslash at the end of a line and in the :M modifier

As described in PR bin/46139 by David A. Holland.
 1.2.4.2 02-Aug-2025  perseant Sync with HEAD
 1.2.4.1 29-Jun-2025  perseant file char-005c-reverse-solidus.mk was added on branch perseant-exfatfs on 2025-08-02 05:58:30 +0000
 1.17 01-Jul-2025  rillig tests/make: detect unintended "expect" lines in the .mk files
 1.16 01-Jul-2025  rillig tests/make: require "expect" comments to start a line

Lua's string.gmatch function doesn't allow the anchor "^"; but its
string.gsub function does.
 1.15 30-Jun-2025  rillig tests/make: force expected lines to be listed in execution order

The diagnostics from the program to check the "expect" lines in the unit
test files were hard to follow since the "out-of-order" lines were
confusing. For out-of-order lines, state where they should be placed
instead.
 1.14 29-Jun-2025  rillig tests/make: sort missing messages using a stable algorithm

Lua's table.sort does not provide a stable sort. No idea how this could
go unnoticed for two years and a few days.

Noticed in directive-for-escape.mk, which has several diagnostics in the
same location, in the body of .for loops.
 1.13 13-Apr-2025  rillig tests/make: add tests for POSIX mode
 1.12 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.11 29-Mar-2025  rillig make: in stack traces from target commands, add the command level

A target can contain several commands, and these commands are likely to
contain the same expressions. To distinguish them, add one more line to
the stack trace, to narrow down the source of the error.
 1.10 11-Jan-2025  rillig tests/make: force correct order of expected messages
 1.9 20-Jul-2024  rillig make: don't run erroneous commands in compat mode

When there is a parse or evaluation error in an expression that becomes
part of the command, don't run that command, as the result of the failed
evaluation typically contains garbage characters. Skip the remaining
commands from that target as well, as they may depend on the erroneous
command.
 1.8 17-Dec-2023  rillig branches: 1.8.2;
tests/make: in 'expect' lines, require the complete text of the line
 1.7 23-Jun-2023  rillig tests/make: sort missing 'expect' comments by their location
 1.6 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.5 01-Jun-2023  rillig tests/make: clean up comments, extend a few tests
 1.4 09-May-2023  rillig make: skip syntactically wrong .for loops

When a .for loop cannot be interpreted correctly, for example when there
are no iteration variables or the number of words doesn't match the
iteration variables, skip the body of the .for loop instead of
interpreting it once.
 1.3 15-Apr-2022  rillig tests/make: adjust expectations to actual behavior

The bug in deptgt-silent-jobs.mk has been fixed, the debug logging for
comparing conditions and for deleting global variables has changed
intentionally.
 1.2 29-Jan-2022  rillig tests/make: extend and isolate tests for target-local variables

Reusing the target var-scope-local.o for several tests made the test
more difficult to understand than necessary. The test names '2' and '3'
didn't convey any meaning.

Instead, add more test targets that are named after what they test. Add
tests for each of the 5 variable assignment operators, to demonstrate an
inconsistency between '+=' and '?='.

Add tests for the built-in target-local variables as well and explain
the general concepts, in particular the exact point where target-local
expressions are expanded.

The lines in the expected output file are not generated in the same
order as they appear in the makefile, so allow the 'expect' lines in
non-linear order, in check-expect.lua.
 1.1 15-Jan-2022  rillig tests/make: ensure that the 'expect' comments in tests are correct

Based on tests/usr.bin/xlint/check-expect.lua.

For now, this extra check needs to be run manually.
 1.8.2.1 02-Aug-2025  perseant Sync with HEAD
 1.18 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.17 13-Jun-2025  rillig make: add on-demand inter-process stack traces

When debugging a build that heavily uses nested calls to sub-makes, the
chain of calls is useful to quickly assess the situation. If explicitly
requested, include the actions from any parent processes in the stack
traces.

Reviewed by: sjg
 1.16 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.15 29-Mar-2025  rillig make: in stack traces from target commands, add the command level

A target can contain several commands, and these commands are likely to
contain the same expressions. To distinguish them, add one more line to
the stack trace, to narrow down the source of the error.
 1.14 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.13 22-Jul-2024  rillig make: fix exit status for error in .BEGIN/.END prerequisite
 1.12 22-Jul-2024  rillig tests/make: demonstrate wrong exit status for .END dependency
 1.11 20-Jul-2024  rillig make: don't run erroneous commands in parallel mode
 1.10 20-Jul-2024  rillig tests/make: demonstrate failing dependency in parallel mode

In parallel mode, when generating the commands for a target, parse or
evaluation errors still continue generating and executing the commands.
And if the commands succeed, the targets that depend on this target are
still made.
 1.9 09-Jul-2024  rillig make: error out on parse/evaluation errors in shell commands

The expression ${VAR:X} has an unknown modifier ':X'. Previously, this
expression errored out when the expression was evaluated at parse time,
but not when the expression was evaluated when generating the commands
to bring a target up to date. The errors were previously reported, they
didn't affect the exit status, though.

Now, errors in expressions are handled in the same way, regardless of
the time at which they are evaluated.
 1.8 05-Jul-2024  rillig make: error out on unclosed expressions during parse time

In exchange, this adds location information.

For unnamed expressions, the value is no longer printed. This will be
added back in a follow-up commit.
 1.7 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.6 23-Apr-2024  rillig branches: 1.6.2;
make: clean up comments, code and tests
 1.5 20-Apr-2024  rillig make: provide more context information for parse/evaluate errors
 1.4 19-Nov-2023  rillig make: replace 'variable expression' with 'expression' in diagnostics
 1.3 25-Sep-2022  rillig tests/make: reduce trailing whitespace
 1.2 23-Feb-2021  rillig make: improve error message for unknown modifier

Back in 1995, the modifiers were all single-character, and it made sense
to print only the first character. Nowadays, with ':S', ':@var@...@',
'::=' and several others, a little more context is useful to see where
the exact error is. The actual modifier is still guessed, and the guess
may be wrong as soon as backslashes get involved, but it is still better
than before.
 1.1 27-Dec-2020  rillig make(1): add test for expansion errors in jobs mode

Since compat mode and jobs mode are implemented separately and vary in
lots of small details, each of them needs to be tested on its own.
 1.6.2.1 02-Aug-2025  perseant Sync with HEAD
 1.16 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.15 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.14 29-Mar-2025  rillig make: in stack traces from target commands, add the command level

A target can contain several commands, and these commands are likely to
contain the same expressions. To distinguish them, add one more line to
the stack trace, to narrow down the source of the error.
 1.13 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.12 22-Jul-2024  rillig make: fix exit status for error in .BEGIN/.END prerequisite
 1.11 22-Jul-2024  rillig tests/make: demonstrate wrong exit status for .END dependency
 1.10 20-Jul-2024  rillig make: don't run erroneous commands in parallel mode
 1.9 20-Jul-2024  rillig tests/make: demonstrate failing dependency in parallel mode

In parallel mode, when generating the commands for a target, parse or
evaluation errors still continue generating and executing the commands.
And if the commands succeed, the targets that depend on this target are
still made.
 1.8 09-Jul-2024  rillig make: error out on parse/evaluation errors in shell commands

The expression ${VAR:X} has an unknown modifier ':X'. Previously, this
expression errored out when the expression was evaluated at parse time,
but not when the expression was evaluated when generating the commands
to bring a target up to date. The errors were previously reported, they
didn't affect the exit status, though.

Now, errors in expressions are handled in the same way, regardless of
the time at which they are evaluated.
 1.7 05-Jul-2024  rillig make: error out on unclosed expressions during parse time

In exchange, this adds location information.

For unnamed expressions, the value is no longer printed. This will be
added back in a follow-up commit.
 1.6 05-Jul-2024  rillig tests/make: add expected messages for "Unclosed expression"
 1.5 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.4 23-Apr-2024  rillig branches: 1.4.2;
make: clean up comments, code and tests
 1.3 20-Apr-2024  rillig make: provide more context information for parse/evaluate errors
 1.2 25-Sep-2022  rillig tests/make: reduce trailing whitespace
 1.1 27-Dec-2020  rillig make(1): add test for expansion errors in jobs mode

Since compat mode and jobs mode are implemented separately and vary in
lots of small details, each of them needs to be tested on its own.
 1.4.2.1 02-Aug-2025  perseant Sync with HEAD
 1.13 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.12 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.11 29-Mar-2025  rillig make: in stack traces from target commands, add the command level

A target can contain several commands, and these commands are likely to
contain the same expressions. To distinguish them, add one more line to
the stack trace, to narrow down the source of the error.
 1.10 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.9 20-Jul-2024  rillig make: don't run erroneous commands in compat mode

When there is a parse or evaluation error in an expression that becomes
part of the command, don't run that command, as the result of the failed
evaluation typically contains garbage characters. Skip the remaining
commands from that target as well, as they may depend on the erroneous
command.
 1.8 05-Jul-2024  rillig make: error out on unclosed expressions during parse time

In exchange, this adds location information.

For unnamed expressions, the value is no longer printed. This will be
added back in a follow-up commit.
 1.7 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.6 23-Apr-2024  rillig branches: 1.6.2;
make: clean up comments, code and tests
 1.5 20-Apr-2024  rillig make: provide more context information for parse/evaluate errors
 1.4 19-Nov-2023  rillig make: replace 'variable expression' with 'expression' in diagnostics
 1.3 23-Feb-2021  rillig make: improve error message for unknown modifier

Back in 1995, the modifiers were all single-character, and it made sense
to print only the first character. Nowadays, with ':S', ':@var@...@',
'::=' and several others, a little more context is useful to see where
the exact error is. The actual modifier is still guessed, and the guess
may be wrong as soon as backslashes get involved, but it is still better
than before.
 1.2 02-Nov-2020  rillig make(1): error out on unclosed expressions after the colon
 1.1 02-Nov-2020  rillig make(1): add test for parse errors in commands in lint mode (-dL)

The difference to non-lint mode is that the exit status is now 2 instead
of 0.
 1.6.2.1 02-Aug-2025  perseant Sync with HEAD
 1.8 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.7 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.6 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.5 20-Jul-2024  rillig make: don't run erroneous commands in compat mode

When there is a parse or evaluation error in an expression that becomes
part of the command, don't run that command, as the result of the failed
evaluation typically contains garbage characters. Skip the remaining
commands from that target as well, as they may depend on the erroneous
command.
 1.4 05-Jul-2024  rillig make: error out on unclosed expressions during parse time

In exchange, this adds location information.

For unnamed expressions, the value is no longer printed. This will be
added back in a follow-up commit.
 1.3 05-Jul-2024  rillig tests/make: add expected messages for "Unclosed expression"
 1.2 23-Apr-2024  rillig branches: 1.2.2;
make: clean up comments, code and tests
 1.1 02-Nov-2020  rillig make(1): add test for parse errors in commands in lint mode (-dL)

The difference to non-lint mode is that the exit status is now 2 instead
of 0.
 1.2.2.1 02-Aug-2025  perseant Sync with HEAD
 1.17 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.16 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.15 29-Mar-2025  rillig make: in stack traces from target commands, add the command level

A target can contain several commands, and these commands are likely to
contain the same expressions. To distinguish them, add one more line to
the stack trace, to narrow down the source of the error.
 1.14 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.13 20-Jul-2024  rillig make: don't run erroneous commands in compat mode

When there is a parse or evaluation error in an expression that becomes
part of the command, don't run that command, as the result of the failed
evaluation typically contains garbage characters. Skip the remaining
commands from that target as well, as they may depend on the erroneous
command.
 1.12 09-Jul-2024  rillig make: error out on parse/evaluation errors in shell commands

The expression ${VAR:X} has an unknown modifier ':X'. Previously, this
expression errored out when the expression was evaluated at parse time,
but not when the expression was evaluated when generating the commands
to bring a target up to date. The errors were previously reported, they
didn't affect the exit status, though.

Now, errors in expressions are handled in the same way, regardless of
the time at which they are evaluated.
 1.11 05-Jul-2024  rillig make: error out on unclosed expressions during parse time

In exchange, this adds location information.

For unnamed expressions, the value is no longer printed. This will be
added back in a follow-up commit.
 1.10 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.9 23-Apr-2024  rillig branches: 1.9.2;
make: clean up comments, code and tests
 1.8 20-Apr-2024  rillig make: provide more context information for parse/evaluate errors
 1.7 19-Nov-2023  rillig make: replace 'variable expression' with 'expression' in diagnostics
 1.6 25-Sep-2022  rillig tests/make: reduce trailing whitespace
 1.5 23-Feb-2021  rillig make: improve error message for unknown modifier

Back in 1995, the modifiers were all single-character, and it made sense
to print only the first character. Nowadays, with ':S', ':@var@...@',
'::=' and several others, a little more context is useful to see where
the exact error is. The actual modifier is still guessed, and the guess
may be wrong as soon as backslashes get involved, but it is still better
than before.
 1.4 09-Nov-2020  rillig make(1): add test that parsing continues after a parse error
 1.3 02-Nov-2020  rillig make(1): error out on unclosed expressions after the colon
 1.2 02-Nov-2020  rillig make(1): add test for unclosed variable after a colon
 1.1 02-Nov-2020  rillig make(1): add test for parse errors in shell commands, compat mode
 1.9.2.1 02-Aug-2025  perseant Sync with HEAD
 1.13 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.12 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.11 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.10 20-Jul-2024  rillig make: don't run erroneous commands in compat mode

When there is a parse or evaluation error in an expression that becomes
part of the command, don't run that command, as the result of the failed
evaluation typically contains garbage characters. Skip the remaining
commands from that target as well, as they may depend on the erroneous
command.
 1.9 09-Jul-2024  rillig make: error out on parse/evaluation errors in shell commands

The expression ${VAR:X} has an unknown modifier ':X'. Previously, this
expression errored out when the expression was evaluated at parse time,
but not when the expression was evaluated when generating the commands
to bring a target up to date. The errors were previously reported, they
didn't affect the exit status, though.

Now, errors in expressions are handled in the same way, regardless of
the time at which they are evaluated.
 1.8 05-Jul-2024  rillig make: error out on unclosed expressions during parse time

In exchange, this adds location information.

For unnamed expressions, the value is no longer printed. This will be
added back in a follow-up commit.
 1.7 05-Jul-2024  rillig tests/make: add expected messages for "Unclosed expression"
 1.6 23-Apr-2024  rillig branches: 1.6.2;
make: clean up comments, code and tests
 1.5 25-Sep-2022  rillig tests/make: reduce trailing whitespace
 1.4 27-Dec-2020  rillig make(1): add test for expansion errors in jobs mode

Since compat mode and jobs mode are implemented separately and vary in
lots of small details, each of them needs to be tested on its own.
 1.3 09-Nov-2020  rillig make(1): add test that parsing continues after a parse error
 1.2 02-Nov-2020  rillig make(1): add test for unclosed variable after a colon
 1.1 02-Nov-2020  rillig make(1): add test for parse errors in shell commands, compat mode
 1.6.2.1 02-Aug-2025  perseant Sync with HEAD
 1.4 13-Jul-2024  rillig tests/make: demonstrate interrupting make in compat mode
 1.3 18-Mar-2023  sjg branches: 1.3.2;
make: handle .PHONY consitently on interrupt

JobDeleteTarget skips .PHONY targets
CompatDeleteTarget should do the same

This addresses https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=269663
 1.2 28-Aug-2020  rillig make(1): fix test for interrupted command execution

In the first version of this test, I had completely misunderstood the
whole topic.

To test the interrupt, the make process has to be interrupted, not the
shell. This generates the correct message that the target is removed.

The filename for .PHONY targets is removed even though .PHONY targets
usually don't correspond to a file. The message is only printed if
there actually is a corresponding file. That's why this message does
not appear when interrupting "make clean".

Finally, since files get created and removed during a single run of
make, the file cache needs to be disabled. This is done by prefixing
the filenames with "././", see Dir_FindFile.
 1.1 28-Aug-2020  rillig make(1): add test for interrupting a command
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.5 13-Jul-2024  rillig tests/make: demonstrate interrupting make in compat mode
 1.4 18-Mar-2023  sjg branches: 1.4.2;
make: handle .PHONY consitently on interrupt

JobDeleteTarget skips .PHONY targets
CompatDeleteTarget should do the same

This addresses https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=269663
 1.3 15-Nov-2020  rillig make(1): clean up some tests

Fix some mistakes in comments.

Improve some comments to be easier understandable.

Inline variables that are irrelevant for the test at hand (RUN,
MAKE_CMD).

Remove references to functions and constants that have since been removed
or renamed.
 1.2 28-Aug-2020  rillig make(1): fix test for interrupted command execution

In the first version of this test, I had completely misunderstood the
whole topic.

To test the interrupt, the make process has to be interrupted, not the
shell. This generates the correct message that the target is removed.

The filename for .PHONY targets is removed even though .PHONY targets
usually don't correspond to a file. The message is only printed if
there actually is a corresponding file. That's why this message does
not appear when interrupting "make clean".

Finally, since files get created and removed during a single run of
make, the file cache needs to be disabled. This is done by prefixing
the filenames with "././", see Dir_FindFile.
 1.1 28-Aug-2020  rillig make(1): add test for interrupting a command
 1.4.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 01-Feb-2021  rillig make: add test for reading from make's stdin

Just out of curiosity whether that really works. It does.
 1.1 01-Feb-2021  rillig make: add test for reading from make's stdin

Just out of curiosity whether that really works. It does.
 1.5 30-Jun-2025  rillig tests/make: force expected lines to be listed in execution order

The diagnostics from the program to check the "expect" lines in the unit
test files were hard to follow since the "out-of-order" lines were
confusing. For out-of-order lines, state where they should be placed
instead.
 1.4 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.3 01-Jun-2023  rillig branches: 1.3.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.2 04-Nov-2020  rillig make(1): fix line numbers in test output of cmdline-undefined.mk
 1.1 04-Nov-2020  rillig make(1): add test for undefined variables in command line arguments

The variable discardUndefined has an implicit negation in its name,
which makes it hard to understand. Plus, most of the time it is true.
It's better to have a flag that is false most of the time and has a
positive name.

On the first attempt of inverting that variable, I stumbled upon
MainParseArgs, which initially leaves discardUndefined == FALSE, and
after handling the dashed options, sets it to TRUE. This would make a
difference when more command line arguments would be added later via the
.MAKEFLAGS special target.

Upon further inspection, the only place where discardUndefined is used
is in VarAssign_EvalSubst in parse.c, and that place is not reachable
from any of the dashed options. Therefore, discardUndefined could
already be set at the very beginning of MainParseArgs or even when
initializing the global variable itself, without any observable
difference.

Not even the ::= variable modifier could do anything about this since it
is not reachable from the dashed command line options as well, and in
addition, it expands its right-hand side in any case, always discarding
undefined variables. Oh, these little inconsistencies everywhere.
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.6 30-Jun-2025  rillig tests/make: force expected lines to be listed in execution order

The diagnostics from the program to check the "expect" lines in the unit
test files were hard to follow since the "out-of-order" lines were
confusing. For out-of-order lines, state where they should be placed
instead.
 1.5 23-Apr-2024  rillig branches: 1.5.2;
make: clean up comments, code and tests
 1.4 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.3 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.2 04-Nov-2020  rillig make(1): negate discardUndefined to preserveUndefined
 1.1 04-Nov-2020  rillig make(1): add test for undefined variables in command line arguments

The variable discardUndefined has an implicit negation in its name,
which makes it hard to understand. Plus, most of the time it is true.
It's better to have a flag that is false most of the time and has a
positive name.

On the first attempt of inverting that variable, I stumbled upon
MainParseArgs, which initially leaves discardUndefined == FALSE, and
after handling the dashed options, sets it to TRUE. This would make a
difference when more command line arguments would be added later via the
.MAKEFLAGS special target.

Upon further inspection, the only place where discardUndefined is used
is in VarAssign_EvalSubst in parse.c, and that place is not reachable
from any of the dashed options. Therefore, discardUndefined could
already be set at the very beginning of MainParseArgs or even when
initializing the global variable itself, without any observable
difference.

Not even the ::= variable modifier could do anything about this since it
is not reachable from the dashed command line options as well, and in
addition, it expands its right-hand side in any case, always discarding
undefined variables. Oh, these little inconsistencies everywhere.
 1.5.2.1 02-Aug-2025  perseant Sync with HEAD
 1.5 29-Aug-2024  sjg make: unit-tests/cmdline do not remove TMPDIR

When running unit-tests in meta mode, removing TMPDIR while
still in use is fatal. Ensure that TMPBASE used by cmdline.mk
is a subdir of TMPDIR.
 1.4 10-Jun-2022  rillig branches: 1.4.4;
tests/make: demonstrate spaces and '#' in command line arguments
 1.3 09-Feb-2022  rillig tests/make: use more distinctive placeholder for TMPDIR
 1.2 06-Feb-2021  sjg Avoid test failures when more than one user run them.

Use a private TMPDIR
a subdir of .OBJDIR if using it
otherwise /tmp/uid${.MAKE.UID}
 1.1 28-Jul-2020  rillig make(1): add test for setting .OBJDIR via the command line
 1.4.4.1 02-Aug-2025  perseant Sync with HEAD
 1.7 29-Aug-2024  sjg make: unit-tests/cmdline do not remove TMPDIR

When running unit-tests in meta mode, removing TMPDIR while
still in use is fatal. Ensure that TMPBASE used by cmdline.mk
is a subdir of TMPDIR.
 1.6 18-Aug-2024  rillig tests/make: clean up private temporary directory after running tests

Fixes PR bin/58569.
 1.5 23-Apr-2024  rillig branches: 1.5.2;
make: clean up comments, code and tests
 1.4 10-Jun-2022  rillig tests/make: demonstrate spaces and '#' in command line arguments
 1.3 06-Feb-2021  sjg Avoid test failures when more than one user run them.

Use a private TMPDIR
a subdir of .OBJDIR if using it
otherwise /tmp/uid${.MAKE.UID}
 1.2 15-Nov-2020  rillig make(1): clean up some tests

Fix some mistakes in comments.

Improve some comments to be easier understandable.

Inline variables that are irrelevant for the test at hand (RUN,
MAKE_CMD).

Remove references to functions and constants that have since been removed
or renamed.
 1.1 28-Jul-2020  rillig make(1): add test for setting .OBJDIR via the command line
 1.5.2.1 02-Aug-2025  perseant Sync with HEAD
 1.4 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.3 11-Jul-2005  sjg Expected results were not updated for comment testing.
 1.2 18-Jun-2005  rpaulo Add a new test case to reflect the problem found on PR toolchain/30536.
Reviewed by sjg and hubertf.
 1.1 15-Jun-2005  rpaulo branches: 1.1.2;
Add a unit-test for comments.
Addition to PR bin/17732.
Approved by sjg and christos.
 1.1.2.6 24-Jul-2005  tron Pull up revision 1.3 (requested by rpaulo in ticket #608):
Expected results were not updated for comment testing.
 1.1.2.5 02-Jul-2005  tron Pull up revision 1.2 (requested by rpaulo in ticket #491):
Add a new test case to reflect the problem found on PR toolchain/30536.
Reviewed by sjg and hubertf.
 1.1.2.4 02-Jul-2005  tron Pull up revision 1.1 (requested by rpaulo in ticket #491):
Add a unit-test for comments.
Addition to PR bin/17732.
Approved by sjg and christos.
 1.1.2.3 16-Jun-2005  tron Backout ticket 458, it causes PR toolchain/30536.
 1.1.2.2 16-Jun-2005  tron Pull up revision 1.1 (requested by rpaulo in ticket #458):
Add a unit-test for comments.
Addition to PR bin/17732.
Approved by sjg and christos.
 1.1.2.1 15-Jun-2005  tron file comment was added on branch netbsd-3 on 2005-06-16 09:34:02 +0000
 1.2 07-Sep-2020  rillig make(1): extend and explain the test for comments
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.7 23-Apr-2024  rillig make: clean up comments, code and tests
 1.6 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.5 08-May-2022  rillig tests/make: migrate cond1 test to other, more specific tests

The tests in cond1 were a mixture of "everything related to conditions",
and the test cases were heavily dependent on each other, which made them
hard to understand. Move each test case to its corresponding
special-purpose test.
 1.4 23-Jan-2022  rillig tests/make: migrate modts to varmod-to-separator and explain
 1.3 15-Nov-2020  rillig make(1): clean up some tests

Fix some mistakes in comments.

Improve some comments to be easier understandable.

Inline variables that are irrelevant for the test at hand (RUN,
MAKE_CMD).

Remove references to functions and constants that have since been removed
or renamed.
 1.2 07-Sep-2020  rillig make(1): extend and explain the test for comments
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.4 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.3 13-Dec-2020  rillig branches: 1.3.8;
make(1): fix .ERROR_TARGET in compat -k mode (since 2010-04-07)
 1.2 13-Dec-2020  rillig make(1): add tests for variable expansion in .ERROR handling
 1.1 13-Dec-2020  rillig make(1): demonstrate wrong error handling in compat mode
 1.3.8.1 02-Aug-2025  perseant Sync with HEAD
 1.5 08-May-2022  rillig tests/make: migrate cond1 test to other, more specific tests

The tests in cond1 were a mixture of "everything related to conditions",
and the test cases were heavily dependent on each other, which made them
hard to understand. Move each test case to its corresponding
special-purpose test.
 1.4 07-May-2022  rillig make: rename Compat_Run to Compat_MakeAll

No functional change.
 1.3 13-Dec-2020  rillig make(1): fix .ERROR_TARGET in compat -k mode (since 2010-04-07)
 1.2 13-Dec-2020  rillig make(1): add tests for variable expansion in .ERROR handling
 1.1 13-Dec-2020  rillig make(1): demonstrate wrong error handling in compat mode
 1.8 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.7 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.6 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.5 01-Jun-2023  rillig branches: 1.5.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.4 21-Jan-2021  rillig make(1): fix debug output for comparison operators in conditionals

This produces fewer warnings than before, but these were edge cases that
probably didn't matter in practice. The "Malformaed conditional" is
still generated, the set of accepted conditionals is still the same.
 1.3 08-Nov-2020  rillig make(1): add test for comparison of large integers
 1.2 11-Sep-2020  rillig make(1): fix tests about nonexistent = and === operators
 1.1 23-Aug-2020  rillig make(1): add tests for numeric comparisons in .if directives
 1.5.2.1 02-Aug-2025  perseant Sync with HEAD
 1.9 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.8 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.7 07-Sep-2023  rillig branches: 1.7.2;
tests/make: fix test for conditions of the form 'a > b'
 1.6 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.5 08-Nov-2020  rillig make(1): add test for comparison of large integers
 1.4 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.3 11-Sep-2020  rillig make(1): fix tests about nonexistent = and === operators
 1.2 11-Sep-2020  rillig make(1): add tests for the unknown = and === operators
 1.1 23-Aug-2020  rillig make(1): add tests for numeric comparisons in .if directives
 1.7.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 23-Aug-2020  rillig make(1): add tests for numeric comparisons in .if directives
 1.3 07-Sep-2023  rillig tests/make: fix test for conditions of the form 'a > b'
 1.2 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.1 23-Aug-2020  rillig make(1): add tests for numeric comparisons in .if directives
 1.1 23-Aug-2020  rillig make(1): add tests for numeric comparisons in .if directives
 1.3 07-Sep-2023  rillig tests/make: fix test for conditions of the form 'a > b'
 1.2 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.1 23-Aug-2020  rillig make(1): add tests for numeric comparisons in .if directives
 1.1 23-Aug-2020  rillig make(1): add tests for numeric comparisons in .if directives
 1.3 07-Sep-2023  rillig tests/make: fix test for conditions of the form 'a > b'
 1.2 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.1 23-Aug-2020  rillig make(1): add tests for numeric comparisons in .if directives
 1.1 23-Aug-2020  rillig make(1): add tests for numeric comparisons in .if directives
 1.3 07-Sep-2023  rillig tests/make: fix test for conditions of the form 'a > b'
 1.2 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.1 23-Aug-2020  rillig make(1): add tests for numeric comparisons in .if directives
 1.1 23-Aug-2020  rillig make(1): add tests for numeric comparisons in .if directives
 1.3 07-Sep-2023  rillig tests/make: fix test for conditions of the form 'a > b'
 1.2 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.1 23-Aug-2020  rillig make(1): add tests for numeric comparisons in .if directives
 1.13 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.12 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.11 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.10 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.9 04-Mar-2023  rillig branches: 1.9.2;
tests/make: test very small and very large numbers in conditions
 1.8 04-Sep-2022  rillig make: add more details to error message for numeric comparison

Before:
String comparison operator must be either == or !=

After:
Comparison with '>=' requires both operands 'no' and '10' to be numeric

Noticed by martin@ in pkgsrc/textproc/py-pygments.
 1.7 03-Mar-2022  rillig make: make debug logging for comparisons less technical
 1.6 29-Jul-2021  rillig tests/make: test spaces around numbers in comparisons

Just to see whether it is possible to write a conditional in the form
${ ${A} < ${B} :? ${A} : ${B} }, that is, with leading and trailing
whitespace, to make it easier for humans to read the code.

It's not possible, the result of this computation cannot be used in
further numeric comparisons, at least not in .if directives. Leading
space would work, but trailing space wouldn't.

On the other hand, they would work in expressions of the form
${ ${A} < ${B} :? ... : ... } since in these, the condition is first
expanded and then parsed. But that is an implementation detail that is
not documented and it is also difficult to understand.
 1.5 21-Jan-2021  rillig make(1): replace warning + error with just an error in conditionals

Before, there was a "warning" for comparing strings using '<', which was
wrong. That warning was then followed by an error, after parsing the
whole conditional. This was only because it was easier to implement.

Replace the warning with an actual error. This only affects
conditionals in .if lines, the conditionals in the :? modifier such as
${"A" < "B":?smaller:greater} still print 2 errors.
 1.4 21-Jan-2021  rillig make(1): fix debug output for comparison operators in conditionals

This produces fewer warnings than before, but these were edge cases that
probably didn't matter in practice. The "Malformaed conditional" is
still generated, the set of accepted conditionals is still the same.
 1.3 08-Nov-2020  rillig make(1): add test for wrong comparison operator in conditional
 1.2 12-Sep-2020  rillig make(1): add test for Infinity and NaN

Neither is recognized by the make parser, which is good since the main
task of make is dependency resolution and text processing, not
calculating.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.9.2.1 02-Aug-2025  perseant Sync with HEAD
 1.9 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.8 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.7 04-Mar-2023  rillig branches: 1.7.2;
tests/make: test very small and very large numbers in conditions
 1.6 04-Sep-2022  rillig make: add more details to error message for numeric comparison

Before:
String comparison operator must be either == or !=

After:
Comparison with '>=' requires both operands 'no' and '10' to be numeric

Noticed by martin@ in pkgsrc/textproc/py-pygments.
 1.5 29-Jul-2021  rillig tests/make: test spaces around numbers in comparisons

Just to see whether it is possible to write a conditional in the form
${ ${A} < ${B} :? ${A} : ${B} }, that is, with leading and trailing
whitespace, to make it easier for humans to read the code.

It's not possible, the result of this computation cannot be used in
further numeric comparisons, at least not in .if directives. Leading
space would work, but trailing space wouldn't.

On the other hand, they would work in expressions of the form
${ ${A} < ${B} :? ... : ... } since in these, the condition is first
expanded and then parsed. But that is an implementation detail that is
not documented and it is also difficult to understand.
 1.4 08-Nov-2020  rillig make(1): add test for wrong comparison operator in conditional
 1.3 12-Sep-2020  rillig make(1): add test for Infinity and NaN

Neither is recognized by the make parser, which is good since the main
task of make is dependency resolution and text processing, not
calculating.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7.2.1 02-Aug-2025  perseant Sync with HEAD
 1.16 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.15 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.14 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.13 28-Mar-2023  rillig branches: 1.13.2;
tests/make: add expectations for string comparison errors
 1.12 04-Sep-2022  rillig make: add more details to error message for numeric comparison

Before:
String comparison operator must be either == or !=

After:
Comparison with '>=' requires both operands 'no' and '10' to be numeric

Noticed by martin@ in pkgsrc/textproc/py-pygments.
 1.11 21-Jan-2021  rillig make(1): replace warning + error with just an error in conditionals

Before, there was a "warning" for comparing strings using '<', which was
wrong. That warning was then followed by an error, after parsing the
whole conditional. This was only because it was easier to implement.

Replace the warning with an actual error. This only affects
conditionals in .if lines, the conditionals in the :? modifier such as
${"A" < "B":?smaller:greater} still print 2 errors.
 1.10 21-Jan-2021  rillig make(1): fix debug output for comparison operators in conditionals

This produces fewer warnings than before, but these were edge cases that
probably didn't matter in practice. The "Malformaed conditional" is
still generated, the set of accepted conditionals is still the same.
 1.9 19-Jan-2021  rillig make(1): add test for unsupported relational string comparisons
 1.8 15-Nov-2020  rillig make(1): clean up some tests

Fix some mistakes in comments.

Improve some comments to be easier understandable.

Inline variables that are irrelevant for the test at hand (RUN,
MAKE_CMD).

Remove references to functions and constants that have since been removed
or renamed.
 1.7 30-Oct-2020  rillig make(1): fix parse error in string literal in conditional

The string literal "${VAR} " had produced a "Malformed conditional", at
least since 2003. (That's the oldest make I have available for testing.)
Strange that nobody else noticed that in the last 17 years.
 1.6 30-Oct-2020  rillig make(1): add more test cases that fail in condition string literals
 1.5 30-Oct-2020  rillig make(1): demonstrate parse error in string interpolation in condition
 1.4 12-Sep-2020  rillig make(1): fix wording of parse error in conditionals

The word "should" is not appropriate for situations that eventually lead
to a parse error.
 1.3 11-Sep-2020  rillig make(1): fix tests about nonexistent = and === operators
 1.2 20-Aug-2020  rillig make(1): add test for string literals in comparisons
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.13.2.1 02-Aug-2025  perseant Sync with HEAD
 1.21 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.20 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.19 23-Apr-2024  rillig branches: 1.19.2;
make: clean up comments, code and tests
 1.18 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.17 28-Mar-2023  rillig tests/make: add expectations for string comparison errors
 1.16 08-May-2022  rillig tests/make: migrate cond1 test to other, more specific tests

The tests in cond1 were a mixture of "everything related to conditions",
and the test cases were heavily dependent on each other, which made them
hard to understand. Move each test case to its corresponding
special-purpose test.
 1.15 11-Dec-2021  rillig tests/make: proofread and clean up comments for function 'empty'

This prepares a refactoring for handling the function 'empty' in
conditionals like '.if'.

The function 'empty' is fundamentally different from all other functions
since it is parsed differently and passes its result on different path
than the other functions. Splitting up these code paths will untangle
the control flow of parsing a condition like 'empty(VARNAME)'. It will
also remove several ARGSUSED and MAKE_ATTR_UNUSED that make the current
code smell.
 1.14 19-Jan-2021  rillig make(1): add test for unsupported relational string comparisons
 1.13 15-Nov-2020  rillig make(1): clean up some tests

Fix some mistakes in comments.

Improve some comments to be easier understandable.

Inline variables that are irrelevant for the test at hand (RUN,
MAKE_CMD).

Remove references to functions and constants that have since been removed
or renamed.
 1.12 08-Nov-2020  rillig make(1): add test for comparing numbers with strings
 1.11 30-Oct-2020  rillig make(1): fix comments in test for string literals in conditions
 1.10 30-Oct-2020  rillig make(1): fix parse error in string literal in conditional

The string literal "${VAR} " had produced a "Malformed conditional", at
least since 2003. (That's the oldest make I have available for testing.)
Strange that nobody else noticed that in the last 17 years.
 1.9 30-Oct-2020  rillig make(1): add more test cases that fail in condition string literals
 1.8 30-Oct-2020  rillig make(1): add test for two variable expressions in a string literal
 1.7 30-Oct-2020  rillig make(1): demonstrate parse error in string interpolation in condition
 1.6 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.5 11-Sep-2020  rillig make(1): fix tests about nonexistent = and === operators
 1.4 11-Sep-2020  rillig make(1): add tests for the unknown = and === operators
 1.3 20-Aug-2020  rillig make(1): add test for string literals in comparisons
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.19.2.1 02-Aug-2025  perseant Sync with HEAD
 1.5 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.4 01-Jun-2023  rillig branches: 1.4.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.3 01-Jun-2023  rillig make: shorten function names, clean up comments

No functional change.
 1.2 11-Nov-2020  rillig make(1): add tests demonstrating bugs in TryParseNumber and EvalNotEmpty
 1.1 14-Sep-2020  rillig make(1): add tests for numbers in conditions
 1.4.2.1 02-Aug-2025  perseant Sync with HEAD
 1.6 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.5 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.4 01-Jun-2023  rillig make: shorten function names, clean up comments

No functional change.
 1.3 08-Sep-2022  rillig tests/make: document an edge case in evaluating conditionals
 1.2 11-Nov-2020  rillig make(1): add tests demonstrating bugs in TryParseNumber and EvalNotEmpty
 1.1 14-Sep-2020  rillig make(1): add tests for numbers in conditions
 1.8 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.7 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.6 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.5 01-Jun-2023  rillig branches: 1.5.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.4 01-Jun-2023  rillig tests/make: clean up comments, extend a few tests
 1.3 10-Dec-2021  rillig make: do not evaluate misplaced expressions in malformed conditions

This change only affects the behavior for parse errors. Syntactically
well-formed conditions work exactly as before.
 1.2 14-Dec-2020  rillig make(1): add test for variable expressions after a parse error

These variable expressions don't need to be expanded, and they aren't.
 1.1 14-Dec-2020  rillig make(1): add test for parsing the end of a condition
 1.5.2.1 02-Aug-2025  perseant Sync with HEAD
 1.8 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.7 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.6 19-Nov-2023  rillig branches: 1.6.2;
tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.5 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.4 01-Jun-2023  rillig tests/make: clean up comments, extend a few tests
 1.3 10-Dec-2021  rillig make: do not evaluate misplaced expressions in malformed conditions

This change only affects the behavior for parse errors. Syntactically
well-formed conditions work exactly as before.
 1.2 14-Dec-2020  rillig make(1): add test for variable expressions after a parse error

These variable expressions don't need to be expanded, and they aren't.
 1.1 14-Dec-2020  rillig make(1): add test for parsing the end of a condition
 1.6.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.6 10-Jan-2025  rillig tests/make: test expressions based on undefined variables

When an undefined variable is used in a conditional, make complains about
"Malformed conditional", which is wrong since the conditional is
well-formed but errors out during evaluation.

In order to fix this wrong error message and preserve the remaining
behavior, cover the places in which an expression is evaluated with
undefined expressions being an error (VARE_EVAL_DEFINED), but with
neither producing an error message nor handling errors. This combination
results in the same behavior as evaluating the expressions in the mode
that allows undefined variables to be used in expressions.
 1.5 15-Nov-2020  rillig branches: 1.5.8;
make(1): clean up some tests

Fix some mistakes in comments.

Improve some comments to be easier understandable.

Inline variables that are irrelevant for the test at hand (RUN,
MAKE_CMD).

Remove references to functions and constants that have since been removed
or renamed.
 1.4 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.3 23-Aug-2020  rillig make(1): add tests for functions in .if conditions
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5.8.1 02-Aug-2025  perseant Sync with HEAD
 1.13 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.12 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.11 06-Aug-2024  rillig make: add details to error messages about missing ')'
 1.10 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.9 23-Apr-2024  rillig branches: 1.9.2;
make: clean up comments, code and tests
 1.8 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.7 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.6 22-Jan-2021  rillig make(1): remove "warning" from missing closing parenthesis

This only affects the diagnostics for parse errors that involve a
missing closing parenthesis. Whether or not this is a parse error is
still the same.

It may look redundant to pass both the CondParser and the parsing
position pp to the functions, but that's necessary since during parsing,
not every code path updates the main parsing position immediately.
 1.5 15-Nov-2020  rillig make(1): clean up some tests

Fix some mistakes in comments.

Improve some comments to be easier understandable.

Inline variables that are irrelevant for the test at hand (RUN,
MAKE_CMD).

Remove references to functions and constants that have since been removed
or renamed.
 1.4 07-Nov-2020  rillig make(1): add test for parse error in function defined()
 1.3 20-Aug-2020  rillig make(1): add test for parsing functions in .if conditions
 1.2 20-Aug-2020  rillig make(1): add test for the function defined(...)
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.9.2.1 02-Aug-2025  perseant Sync with HEAD
 1.15 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.14 10-Jan-2025  rillig tests/make: test expressions based on undefined variables

When an undefined variable is used in a conditional, make complains about
"Malformed conditional", which is wrong since the conditional is
well-formed but errors out during evaluation.

In order to fix this wrong error message and preserve the remaining
behavior, cover the places in which an expression is evaluated with
undefined expressions being an error (VARE_EVAL_DEFINED), but with
neither producing an error message nor handling errors. This combination
results in the same behavior as evaluating the expressions in the mode
that allows undefined variables to be used in expressions.
 1.13 06-Aug-2024  rillig make: add details to error messages about missing ')'
 1.12 23-Apr-2024  rillig branches: 1.12.2;
make: clean up comments, code and tests
 1.11 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.10 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.9 08-May-2022  rillig tests/make: migrate cond1 test to other, more specific tests

The tests in cond1 were a mixture of "everything related to conditions",
and the test cases were heavily dependent on each other, which made them
hard to understand. Move each test case to its corresponding
special-purpose test.
 1.8 12-Dec-2021  rillig make: rename ParseFuncArg to ParseWord, update comments

No functional change.
 1.7 15-Nov-2020  rillig make(1): clean up some tests

Fix some mistakes in comments.

Improve some comments to be easier understandable.

Inline variables that are irrelevant for the test at hand (RUN,
MAKE_CMD).

Remove references to functions and constants that have since been removed
or renamed.
 1.6 07-Nov-2020  rillig make(1): add test for parse error in function defined()
 1.5 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.4 27-Sep-2020  rillig make(1): normalize whitespace in source code

There is no more space tab. Either only tabs or only spaces or tabs
followed by spaces, but not spaces followed by tabs.
 1.3 20-Aug-2020  rillig make(1): add test for the function defined(...)
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.12.2.1 02-Aug-2025  perseant Sync with HEAD
 1.11 11-Jun-2025  sjg make: check variable names for invalid characters

Variable names should not contain white-space.
As is; make quietly ignores gmake syntax like
$(addprefix -I, $(INCLUDE_DIR_LIST))
which means we are not doing what the makefile wants, and the
user has no clue.

CheckVarname is called only if there are no modifiers to be applied
as :L and others legitimately can handle white-space,
it will issue a warning if illegal characters are found.
Currently only white-space is checked.

The NetBSD build produces a few warnings - in one case a makefile
intended for gmake, and the other some dubious constructs by bsd.prog.mk
in support of ATF tests such as OBJS.${PROG} when PROG is actually a list.

Reviewed by: rillig
 1.10 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.9 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.8 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.7 28-Jun-2023  rillig branches: 1.7.2;
tests/make: extend test for the 'empty' function in conditions
 1.6 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.5 04-Mar-2023  rillig tests/make: improve explanations in test for 'empty' function
 1.4 11-Dec-2021  rillig tests/make: proofread and clean up comments for function 'empty'

This prepares a refactoring for handling the function 'empty' in
conditionals like '.if'.

The function 'empty' is fundamentally different from all other functions
since it is parsed differently and passes its result on different path
than the other functions. Splitting up these code paths will untangle
the control flow of parsing a condition like 'empty(VARNAME)'. It will
also remove several ARGSUSED and MAKE_ATTR_UNUSED that make the current
code smell.
 1.3 15-Nov-2020  rillig make(1): clean up some tests

Fix some mistakes in comments.

Improve some comments to be easier understandable.

Inline variables that are irrelevant for the test at hand (RUN,
MAKE_CMD).

Remove references to functions and constants that have since been removed
or renamed.
 1.2 07-Nov-2020  rillig make(1): add test for parse error in condition using empty()
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7.2.1 02-Aug-2025  perseant Sync with HEAD
 1.29 11-Jun-2025  sjg make: check variable names for invalid characters

Variable names should not contain white-space.
As is; make quietly ignores gmake syntax like
$(addprefix -I, $(INCLUDE_DIR_LIST))
which means we are not doing what the makefile wants, and the
user has no clue.

CheckVarname is called only if there are no modifiers to be applied
as :L and others legitimately can handle white-space,
it will issue a warning if illegal characters are found.
Currently only white-space is checked.

The NetBSD build produces a few warnings - in one case a makefile
intended for gmake, and the other some dubious constructs by bsd.prog.mk
in support of ATF tests such as OBJS.${PROG} when PROG is actually a list.

Reviewed by: rillig
 1.28 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.27 10-Jan-2025  rillig tests/make: test expressions based on undefined variables

When an undefined variable is used in a conditional, make complains about
"Malformed conditional", which is wrong since the conditional is
well-formed but errors out during evaluation.

In order to fix this wrong error message and preserve the remaining
behavior, cover the places in which an expression is evaluated with
undefined expressions being an error (VARE_EVAL_DEFINED), but with
neither producing an error message nor handling errors. This combination
results in the same behavior as evaluating the expressions in the mode
that allows undefined variables to be used in expressions.
 1.26 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.25 02-Jun-2024  rillig branches: 1.25.2;
make: sync VarEvalMode constant names with their debug log names
 1.24 19-Dec-2023  rillig make: clean up comments

No binary change, except for line numbers in assertions.
 1.23 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.22 11-Aug-2023  rillig tests/make: fix grammar in a test comment
 1.21 28-Jun-2023  rillig tests/make: extend test for the 'empty' function in conditions
 1.20 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.19 01-Jun-2023  rillig tests/make: clean up comments, extend a few tests
 1.18 04-Mar-2023  rillig tests/make: improve explanations in test for 'empty' function
 1.17 28-Dec-2021  rillig tests/make: test function names without following '('
 1.16 11-Dec-2021  rillig make: inline ParseEmptyArg into CondParser_FuncCallEmpty

No functional change.
 1.15 11-Dec-2021  rillig tests/make: proofread and clean up comments for function 'empty'

This prepares a refactoring for handling the function 'empty' in
conditionals like '.if'.

The function 'empty' is fundamentally different from all other functions
since it is parsed differently and passes its result on different path
than the other functions. Splitting up these code paths will untangle
the control flow of parsing a condition like 'empty(VARNAME)'. It will
also remove several ARGSUSED and MAKE_ATTR_UNUSED that make the current
code smell.
 1.14 11-Apr-2021  rillig make: clean up remaining references to VarEvalFlags

VarEvalFlags has been replaced with VarEvalMode. There were some
comments and tests that still referred to the old names.

No functional change.
 1.13 15-Mar-2021  rillig make: replace enum bit-field with struct bit-field for VarEvalFlags

This makes the code easier to read, especially in var.c. It also makes
debugging sessions easier since some debuggers don't show enum
bit-fields symbolically as soon as more than one bit is set.

The code outside var.c is basically unchanged, except that instead of
passing the individual flags, there are 4 predefined evaluation modes.
These suffice for all practical use cases. Only in the implementation
deep inside var.c, the value of the flags keepDollar and keepUndef
differs.

There is no way of passing the struct to EnumFlags_ToString, which means
the ToString function has to be spelled out explicitly. This allows for
fine-tuning the representation in the debug log, to reduce the amount of
uppercae letters.

No functional change.
 1.12 22-Feb-2021  rillig make: update constant names in comments

No functional change.
 1.11 28-Nov-2020  rillig make(1): move test for recursive variable to cond-func-empty

Previously, the documentation of that test was much too short to explain
all the effects that happened in the bug situation from 2020-06-28 until
2020-07-02.
 1.10 15-Nov-2020  rillig make(1): clean up some tests

Fix some mistakes in comments.

Improve some comments to be easier understandable.

Inline variables that are irrelevant for the test at hand (RUN,
MAKE_CMD).

Remove references to functions and constants that have since been removed
or renamed.
 1.9 07-Nov-2020  rillig make(1): add test for parse error in condition using empty()
 1.8 23-Sep-2020  rillig make(1): add tests for spaces in condition functions
 1.7 23-Sep-2020  rillig make(1): fix unexpected behavior in ::= variable modifier

Previously, the ::= modifier had returned an error value, which caused
the variable expression to be preserved. This behavior was not useful
in this case; it had only been intended to be used for undefined
variables.

To fix it, distinguish between parse errors, undefined variables and
regular empty strings.
 1.6 04-Sep-2020  rillig make(1): rename local functions for parsing conditions

The word "get" implies a cheap operation without side effects. Parsing
instead has lots of side effects, even if it's only that the parsing
position is updated.
 1.5 04-Sep-2020  rillig make(1): migrate get_mpt_arg to Var_ParsePP

This part is covered well by the unit tests. When I forgot to decrement
the linePtr, several of them failed reliably.
 1.4 04-Sep-2020  rillig make(1): add more explanation for undefined variable expressions
 1.3 03-Sep-2020  rillig make(1): add test for the empty function in conditionals
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.25.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.8 10-Jan-2025  rillig tests/make: test expressions based on undefined variables

When an undefined variable is used in a conditional, make complains about
"Malformed conditional", which is wrong since the conditional is
well-formed but errors out during evaluation.

In order to fix this wrong error message and preserve the remaining
behavior, cover the places in which an expression is evaluated with
undefined expressions being an error (VARE_EVAL_DEFINED), but with
neither producing an error message nor handling errors. This combination
results in the same behavior as evaluating the expressions in the mode
that allows undefined variables to be used in expressions.
 1.7 19-Nov-2023  rillig branches: 1.7.2;
tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.6 30-Nov-2020  rillig make(1): add test for directory cache and exists()
 1.5 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.4 28-Aug-2020  rillig make(1): extend test for the exists function in conditions
 1.3 23-Aug-2020  rillig make(1): add tests for functions in .if conditions
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 22-Nov-2020  rillig make(1): document the selection of the main target
 1.2 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.1 22-Nov-2020  rillig make(1): document the selection of the main target
 1.5 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.4 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.3 23-Jun-2023  rillig branches: 1.3.2;
make: warn about malformed patterns in ':M', ':N' and '.if make(...)'

These patterns shouldn't occur in practice, as their results are tricky
to predict. Generate a warning for now, and maybe an error later.

Reviewed by sjg@.
 1.2 25-Sep-2020  rillig make(1): add test for make() function in conditions
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.7 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.6 10-Jan-2025  rillig tests/make: test expressions based on undefined variables

When an undefined variable is used in a conditional, make complains about
"Malformed conditional", which is wrong since the conditional is
well-formed but errors out during evaluation.

In order to fix this wrong error message and preserve the remaining
behavior, cover the places in which an expression is evaluated with
undefined expressions being an error (VARE_EVAL_DEFINED), but with
neither producing an error message nor handling errors. This combination
results in the same behavior as evaluating the expressions in the mode
that allows undefined variables to be used in expressions.
 1.5 23-Jun-2023  rillig branches: 1.5.2;
make: warn about malformed patterns in ':M', ':N' and '.if make(...)'

These patterns shouldn't occur in practice, as their results are tricky
to predict. Generate a warning for now, and maybe an error later.

Reviewed by sjg@.
 1.4 22-Jun-2023  rillig make: clean up comments related to pattern matching
 1.3 25-Sep-2020  rillig make(1): add test for make() function in conditions
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 10-Jan-2025  rillig tests/make: test expressions based on undefined variables

When an undefined variable is used in a conditional, make complains about
"Malformed conditional", which is wrong since the conditional is
well-formed but errors out during evaluation.

In order to fix this wrong error message and preserve the remaining
behavior, cover the places in which an expression is evaluated with
undefined expressions being an error (VARE_EVAL_DEFINED), but with
neither producing an error message nor handling errors. This combination
results in the same behavior as evaluating the expressions in the mode
that allows undefined variables to be used in expressions.
 1.4 24-Oct-2020  rillig branches: 1.4.8;
make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.3 23-Aug-2020  rillig make(1): add tests for functions in .if conditions
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4.8.1 02-Aug-2025  perseant Sync with HEAD
 1.15 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.14 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.13 07-Aug-2024  rillig make: in erroneous conditions, report the non-expanded text

In a condition, when a function call expression is missing its closing
parenthesis, there's no point in having the expanded argument text in
the error message.

When parsing a bare word in a condition, the trailing space was included
in that word, which was inconsistent, as the leading space was not
included either. Removing the trailing space from the word reduces the
cases where a multiple-inclusion guard steps in, but only in an edge
case that is irrelevant in practice.
 1.12 07-Aug-2024  rillig tests/make: demonstrate unintended parsing of words in conditions

A word is not supposed to include its trailing space, as it doesn't
contain its leading space either.
 1.11 06-Aug-2024  rillig make: add details to error messages about missing ')'
 1.10 06-Jul-2024  rillig make: error out on conditions containing the operators '&' and '|'

These abbreviated variants of the '&&' and '||' operators were never
documented, so error out in non-lint mode as well.
 1.9 01-Jun-2023  rillig branches: 1.9.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.8 07-Jan-2022  rillig tests/make: fix documentation in cond-func.mk
 1.7 12-Dec-2021  rillig make: generate more specific error message on malformed conditional
 1.6 22-Jan-2021  rillig make(1): remove "warning" from missing closing parenthesis

This only affects the diagnostics for parse errors that involve a
missing closing parenthesis. Whether or not this is a parse error is
still the same.

It may look redundant to pass both the CondParser and the parsing
position pp to the functions, but that's necessary since during parsing,
not every code path updates the main parsing position immediately.
 1.5 15-Nov-2020  rillig make(1): clean up some tests

Fix some mistakes in comments.

Improve some comments to be easier understandable.

Inline variables that are irrelevant for the test at hand (RUN,
MAKE_CMD).

Remove references to functions and constants that have since been removed
or renamed.
 1.4 10-Nov-2020  rillig make(1): add tests for parsing conditionals, document a parsing bug
 1.3 10-Nov-2020  rillig make(1): add tests for edge cases in parsing conditionals
 1.2 08-Nov-2020  rillig make(1): add test for function argument with unbalanced braces
 1.1 20-Aug-2020  rillig make(1): add test for parsing functions in .if conditions
 1.9.2.1 02-Aug-2025  perseant Sync with HEAD
 1.19 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.18 07-Aug-2024  rillig make: in erroneous conditions, report the non-expanded text

In a condition, when a function call expression is missing its closing
parenthesis, there's no point in having the expanded argument text in
the error message.

When parsing a bare word in a condition, the trailing space was included
in that word, which was inconsistent, as the leading space was not
included either. Removing the trailing space from the word reduces the
cases where a multiple-inclusion guard steps in, but only in an edge
case that is irrelevant in practice.
 1.17 07-Aug-2024  rillig tests/make: demonstrate unintended parsing of words in conditions

A word is not supposed to include its trailing space, as it doesn't
contain its leading space either.
 1.16 06-Aug-2024  rillig make: add details to error messages about missing ')'
 1.15 06-Jul-2024  rillig make: error out on conditions containing the operators '&' and '|'

These abbreviated variants of the '&&' and '||' operators were never
documented, so error out in non-lint mode as well.
 1.14 19-Nov-2023  rillig branches: 1.14.2;
tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.13 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.12 10-May-2023  rillig tests/make: clean up comments in tests
 1.11 07-Jan-2022  rillig tests/make: fix documentation in cond-func.mk
 1.10 28-Dec-2021  rillig tests/make: test function names without following '('
 1.9 15-Nov-2020  rillig make(1): clean up some tests

Fix some mistakes in comments.

Improve some comments to be easier understandable.

Inline variables that are irrelevant for the test at hand (RUN,
MAKE_CMD).

Remove references to functions and constants that have since been removed
or renamed.
 1.8 10-Nov-2020  rillig make(1): add tests for parsing conditionals, document a parsing bug
 1.7 10-Nov-2020  rillig make(1): add tests for edge cases in parsing conditionals
 1.6 08-Nov-2020  rillig make(1): add test for function argument with unbalanced braces
 1.5 08-Nov-2020  rillig make(1): document what the directive ".if A&B" means
 1.4 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.3 27-Sep-2020  rillig make(1): normalize whitespace in source code

There is no more space tab. Either only tabs or only spaces or tabs
followed by spaces, but not spaces followed by tabs.
 1.2 23-Sep-2020  rillig make(1): add tests for spaces in condition functions
 1.1 20-Aug-2020  rillig make(1): add test for parsing functions in .if conditions
 1.14.2.1 02-Aug-2025  perseant Sync with HEAD
 1.13 30-Jun-2025  rillig tests/make: force expected lines to be listed in execution order

The diagnostics from the program to check the "expect" lines in the unit
test files were hard to follow since the "out-of-order" lines were
confusing. For out-of-order lines, state where they should be placed
instead.
 1.12 12-Jun-2025  rillig make: add program name to stack traces from sub-makes
 1.11 12-Jun-2025  rillig make: add quotes to "in directory" line in stack traces

The other lines in stack traces use quotes as well.
 1.10 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.9 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.8 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.7 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.6 30-Jun-2024  rillig make: error out on syntax error in conditions in ':?then:else' modifier

The 'Error' function only reports errors but does not affect the exit
status, the 'Parse_Error' function does, while providing more details to
find the cause of the syntax error.
 1.5 10-Dec-2023  rillig branches: 1.5.2;
make: remove redundant text from diagnostic about bad '?:' modifier
 1.4 19-Apr-2021  rillig make: use straight quotes for error 'Bad conditional expression'

This diagnostic was supposed to be an error, see ApplyModifier_IfElse.

When such an error occurs while the makefiles are read, make stops with
an error, as can be expected. But when such an error occurs later,
after all makefiles have been read, the message is printed but make does
not stop.

In lint mode (-dL), make stops in such a case. I didn't dare to make
this the default behavior, out of fear of breaking existing build
infrastructure, not only in NetBSD or pkgsrc, but also FreeBSD and other
operating systems that use the bmake distribution, generated from the
same source code.
 1.3 25-Jul-2020  rillig make(1): add test for undefined (or empty) variable in :? modifier
 1.2 01-May-2020  rillig usr.bin/make: fix test for late evaluated condition
 1.1 29-Apr-2020  rillig usr.bin/make: add test case for lazy conditions
 1.5.2.2 02-Aug-2025  perseant Sync with HEAD
 1.5.2.1 01-Jul-2024  perseant Sync with HEAD.
 1.10 30-Jun-2025  rillig tests/make: force expected lines to be listed in execution order

The diagnostics from the program to check the "expect" lines in the unit
test files were hard to follow since the "out-of-order" lines were
confusing. For out-of-order lines, state where they should be placed
instead.
 1.9 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.8 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.7 30-Jun-2024  rillig make: error out on syntax error in conditions in ':?then:else' modifier

The 'Error' function only reports errors but does not affect the exit
status, the 'Parse_Error' function does, while providing more details to
find the cause of the syntax error.
 1.6 10-Dec-2023  rillig branches: 1.6.2;
make: remove redundant text from diagnostic about bad '?:' modifier
 1.5 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.4 10-May-2023  rillig tests/make: clean up comments in tests
 1.3 15-Nov-2020  rillig make(1): clean up some tests

Fix some mistakes in comments.

Improve some comments to be easier understandable.

Inline variables that are irrelevant for the test at hand (RUN,
MAKE_CMD).

Remove references to functions and constants that have since been removed
or renamed.
 1.2 25-Jul-2020  rillig make(1): add test for undefined (or empty) variable in :? modifier
 1.1 29-Apr-2020  rillig usr.bin/make: add test case for lazy conditions
 1.6.2.2 02-Aug-2025  perseant Sync with HEAD
 1.6.2.1 01-Jul-2024  perseant Sync with HEAD.
 1.4 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.3 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.2 01-Jun-2023  rillig branches: 1.2.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.1 08-Nov-2020  rillig make(1): in lint mode, only allow '&&' and '||', not '&' and '|'

These variants of the condition operators are neither documented in the
manual page nor are they used in practice.
 1.2.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.2 01-Jun-2023  rillig branches: 1.2.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.1 08-Nov-2020  rillig make(1): in lint mode, only allow '&&' and '||', not '&' and '|'

These variants of the condition operators are neither documented in the
manual page nor are they used in practice.
 1.2.2.1 02-Aug-2025  perseant Sync with HEAD
 1.9 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.8 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.7 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.6 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.5 06-Jul-2024  rillig make: error out on conditions containing the operators '&' and '|'

These abbreviated variants of the '&&' and '||' operators were never
documented, so error out in non-lint mode as well.
 1.4 01-Jun-2023  rillig branches: 1.4.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.3 10-Dec-2021  rillig tests/make: add more comprehensive tests for short-circuit evaluation
 1.2 10-Sep-2020  rillig make(1): add test for the &, && and &&& operators
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4.2.1 02-Aug-2025  perseant Sync with HEAD
 1.13 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.12 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.11 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.10 06-Jul-2024  rillig make: error out on conditions containing the operators '&' and '|'

These abbreviated variants of the '&&' and '||' operators were never
documented, so error out in non-lint mode as well.
 1.9 17-Dec-2023  rillig branches: 1.9.2;
tests/make: in 'expect' lines, require the complete text of the line
 1.8 15-Aug-2023  rillig tests/make: show that '||' and '&&' must be preceded by whitespace
 1.7 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.6 10-Dec-2021  rillig tests/make: add more comprehensive tests for short-circuit evaluation
 1.5 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.4 10-Sep-2020  rillig make(1): add test for the &, && and &&& operators
 1.3 28-Aug-2020  rillig make(1): add tests for the &&, || and ! operators
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.9.2.1 02-Aug-2025  perseant Sync with HEAD
 1.9 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.8 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.7 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.6 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.5 01-Jun-2023  rillig branches: 1.5.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.4 19-Jan-2021  rillig make(1): demonstrate wrong return value in CondParser_Term
 1.3 15-Nov-2020  rillig make(1): add remarks to the tests about conditions
 1.2 15-Nov-2020  rillig make(1): add tests for the '!' operator in conditions
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5.2.1 02-Aug-2025  perseant Sync with HEAD
 1.10 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.9 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.8 01-Jun-2023  rillig branches: 1.8.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.7 19-Jan-2021  rillig make(1): demonstrate wrong return value in CondParser_Term
 1.6 15-Nov-2020  rillig make(1): add remarks to the tests about conditions
 1.5 15-Nov-2020  rillig make(1): add tests for the '!' operator in conditions
 1.4 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.3 28-Aug-2020  rillig make(1): add tests for the &&, || and ! operators
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.8.2.1 02-Aug-2025  perseant Sync with HEAD
 1.4 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.3 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.2 01-Jun-2023  rillig branches: 1.2.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.1 08-Nov-2020  rillig make(1): in lint mode, only allow '&&' and '||', not '&' and '|'

These variants of the condition operators are neither documented in the
manual page nor are they used in practice.
 1.2.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.2 01-Jun-2023  rillig branches: 1.2.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.1 08-Nov-2020  rillig make(1): in lint mode, only allow '&&' and '||', not '&' and '|'

These variants of the condition operators are neither documented in the
manual page nor are they used in practice.
 1.2.2.1 02-Aug-2025  perseant Sync with HEAD
 1.10 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.9 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.8 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.7 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.6 06-Jul-2024  rillig make: error out on conditions containing the operators '&' and '|'

These abbreviated variants of the '&&' and '||' operators were never
documented, so error out in non-lint mode as well.
 1.5 01-Jun-2023  rillig branches: 1.5.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.4 10-Dec-2021  rillig tests/make: add more comprehensive tests for short-circuit evaluation
 1.3 09-Dec-2021  rillig tests/make: prevent the bug from cond.c 1.283 from happening again
 1.2 10-Sep-2020  rillig make(1): add tests for the |, ||, ||| operators
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5.2.1 02-Aug-2025  perseant Sync with HEAD
 1.15 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.14 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.13 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.12 06-Jul-2024  rillig make: error out on conditions containing the operators '&' and '|'

These abbreviated variants of the '&&' and '||' operators were never
documented, so error out in non-lint mode as well.
 1.11 17-Dec-2023  rillig branches: 1.11.2;
tests/make: in 'expect' lines, require the complete text of the line
 1.10 15-Aug-2023  rillig tests/make: show that '||' and '&&' must be preceded by whitespace
 1.9 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.8 10-Dec-2021  rillig tests/make: add more comprehensive tests for short-circuit evaluation
 1.7 09-Dec-2021  rillig tests/make: prevent the bug from cond.c 1.283 from happening again
 1.6 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.5 11-Sep-2020  rillig make(1): fix comment in test for the || operator in conditions

Thanks to wiz for discovering this.
 1.4 10-Sep-2020  rillig make(1): add tests for the |, ||, ||| operators
 1.3 28-Aug-2020  rillig make(1): add tests for the &&, || and ! operators
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.11.2.1 02-Aug-2025  perseant Sync with HEAD
 1.10 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.9 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.8 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.7 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.6 01-Jun-2023  rillig branches: 1.6.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.5 04-Sep-2022  rillig make: add more details to error message for numeric comparison

Before:
String comparison operator must be either == or !=

After:
Comparison with '>=' requires both operands 'no' and '10' to be numeric

Noticed by martin@ in pkgsrc/textproc/py-pygments.
 1.4 22-Jan-2022  rillig tests/make: add a few more tests, mainly for special targets
 1.3 19-Jan-2021  rillig make(1): demonstrate wrong return value in CondParser_Term
 1.2 15-Nov-2020  rillig make(1): add remarks to the tests about conditions
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.6.2.1 02-Aug-2025  perseant Sync with HEAD
 1.9 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.8 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.7 01-Jun-2023  rillig branches: 1.7.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.6 04-Sep-2022  rillig make: add more details to error message for numeric comparison

Before:
String comparison operator must be either == or !=

After:
Comparison with '>=' requires both operands 'no' and '10' to be numeric

Noticed by martin@ in pkgsrc/textproc/py-pygments.
 1.5 22-Jan-2022  rillig tests/make: add a few more tests, mainly for special targets
 1.4 19-Jan-2021  rillig make(1): demonstrate wrong return value in CondParser_Term
 1.3 15-Nov-2020  rillig make(1): add remarks to the tests about conditions
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7.2.1 02-Aug-2025  perseant Sync with HEAD
 1.16 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.15 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.14 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.13 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.12 01-Jun-2023  rillig branches: 1.12.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.11 10-Dec-2021  rillig make: do not evaluate misplaced expressions in malformed conditions

This change only affects the behavior for parse errors. Syntactically
well-formed conditions work exactly as before.
 1.10 10-Dec-2021  rillig tests/make: extend test for parse errors in conditions
 1.9 19-Jan-2021  rillig make(1): add error handling for edge case in malformed conditions
 1.8 19-Jan-2021  rillig make(1): demonstrate missing error handling for malformed conditions
 1.7 15-Nov-2020  rillig make(1): add remarks to the tests about conditions
 1.6 15-Nov-2020  rillig make(1): add test for operator precedence using truth tables
 1.5 11-Sep-2020  rillig make(1): add rationale for evaluating expression after parse error
 1.4 11-Sep-2020  rillig make(1): fix line numbers from test result of the previous commit
 1.3 11-Sep-2020  rillig make(1): add test for evaluation of condition after parse error
 1.2 28-Aug-2020  rillig make(1): add test for unquoted string literals
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.12.2.1 02-Aug-2025  perseant Sync with HEAD
 1.18 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.17 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.16 01-Jun-2023  rillig branches: 1.16.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.15 10-Dec-2021  rillig make: do not evaluate misplaced expressions in malformed conditions

This change only affects the behavior for parse errors. Syntactically
well-formed conditions work exactly as before.
 1.14 10-Dec-2021  rillig tests/make: extend test for parse errors in conditions
 1.13 19-Jan-2021  rillig make(1): update references to the renamed CondParser functions
 1.12 19-Jan-2021  rillig make(1): add error handling for edge case in malformed conditions
 1.11 19-Jan-2021  rillig make(1): demonstrate missing error handling for malformed conditions
 1.10 15-Nov-2020  rillig make(1): add remarks to the tests about conditions
 1.9 15-Nov-2020  rillig make(1): add test for operator precedence using truth tables
 1.8 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.7 11-Sep-2020  rillig make(1): add rationale for evaluating expression after parse error
 1.6 11-Sep-2020  rillig make(1): add test for evaluation of condition after parse error
 1.5 11-Sep-2020  rillig make(1): rename CondGetString to CondParser_String

This describes the function's effect more accurately. The verb "get" is
not commonly associated to having side effects.
 1.4 28-Aug-2020  rillig make(1): add test for unquoted string literals
 1.3 28-Aug-2020  rillig make(1): add test for operator precedence in conditions
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.16.2.1 02-Aug-2025  perseant Sync with HEAD
 1.16 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.15 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.14 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.13 19-Oct-2023  rillig branches: 1.13.2;
tests/make: clean up, explain and reorganize several tests
 1.12 04-Mar-2023  rillig tests/make: use proper variable names in short-circuit test

The previous variable names V42, V66, iV1 and iV2 didn't carry enough
information to be readily readable, making the test hard to understand.

Rename the variables to be more expressive. While here, properly
explain what happened behind the scenes in 2020 and how the evaluation
of conditions was fixed after discovering the actual cause of the
unexpected error messages.
 1.11 01-Dec-2020  rillig make(1): adjust condition descriptions in test cond-short

Before, the conditions in the output had been expanded, which made them
illegible. The expanded conditions were unrealistic as well since the
evaluation flags differ between a condition and normal evaluation
(VARE_WANTRES, VARE_UNDEFERR).
 1.10 09-Jul-2020  sjg compare_expression: return after fetch lhs and rhs if !doEval

Otherwise we end up throwing warings/errors for valid
conditionals due to not expanding variables fully.

Add tests to catch this.

Reviewed by: rillig
 1.9 02-Jul-2020  rillig make(1): fix unnecessary evaluation of variables in :@var@ modifier
 1.8 02-Jul-2020  rillig make(1): fix unnecessary evaluation for :S :C := modifiers
 1.7 02-Jul-2020  rillig make(1): demonstrate some more cases for unintended evaluation
 1.6 02-Jul-2020  rillig make(1): fix unnecessary evaluation of :M and :N modifiers
 1.5 02-Jul-2020  rillig make(1): demonstrate another unintended variable evaluation
 1.4 02-Jul-2020  rillig make(1): fix edge case for evaluating unnecessary conditions
 1.3 02-Jul-2020  rillig make(1): demonstrate another unnecessary condition evaluation
 1.2 28-Jun-2020  rillig make(1): fix evaluation of unreachable conditions

Since 2015-10-11, make had evaluated unreachable conditions even though
the manual page said it didn't.
 1.1 28-Jun-2020  rillig make(1): demonstrate bug when evaluating conditions
 1.13.2.1 02-Aug-2025  perseant Sync with HEAD
 1.24 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.23 19-Nov-2023  rillig branches: 1.23.2;
tests/make: replace 'variable expressions' with 'expressions'
 1.22 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.21 19-Oct-2023  rillig tests/make: clean up, explain and reorganize several tests
 1.20 04-Mar-2023  rillig tests/make: use proper variable names in short-circuit test

The previous variable names V42, V66, iV1 and iV2 didn't carry enough
information to be readily readable, making the test hard to understand.

Rename the variables to be more expressive. While here, properly
explain what happened behind the scenes in 2020 and how the evaluation
of conditions was fixed after discovering the actual cause of the
unexpected error messages.
 1.19 27-Dec-2021  rillig make: clean up comments
 1.18 12-Dec-2021  rillig tests/make: add tests for irrelevant function calls
 1.17 07-Sep-2021  rillig tests/make: expand on the history of unnecessary evaluation
 1.16 14-Mar-2021  rillig tests/make: add test for short-circuit evaluation of modifiers
 1.15 01-Dec-2020  rillig make(1): document handling of irrelevant conditions before 2020-07-09
 1.14 01-Dec-2020  rillig make(1): adjust condition descriptions in test cond-short

Before, the conditions in the output had been expanded, which made them
illegible. The expanded conditions were unrealistic as well since the
evaluation flags differ between a condition and normal evaluation
(VARE_WANTRES, VARE_UNDEFERR).
 1.13 30-Nov-2020  rillig make(1): document how short-circuit evaluation behaved on 2020-07-03
 1.12 15-Nov-2020  rillig make(1): add remarks to the tests about conditions
 1.11 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.10 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.9 19-Aug-2020  rillig make(1): add empty lines to separate the test cases in cond-short
 1.8 19-Jul-2020  rillig make(1): add test for assignment operators in conditions
 1.7 09-Jul-2020  sjg compare_expression: return after fetch lhs and rhs if !doEval

Otherwise we end up throwing warings/errors for valid
conditionals due to not expanding variables fully.

Add tests to catch this.

Reviewed by: rillig
 1.6 02-Jul-2020  rillig make(1): demonstrate some more cases for unintended evaluation
 1.5 02-Jul-2020  rillig make(1): fix unnecessary evaluation of :M and :N modifiers
 1.4 02-Jul-2020  rillig make(1): demonstrate another unintended variable evaluation
 1.3 02-Jul-2020  rillig make(1): demonstrate another unnecessary condition evaluation
 1.2 28-Jun-2020  rillig make(1): fix evaluation of unreachable conditions

Since 2015-10-11, make had evaluated unreachable conditions even though
the manual page said it didn't.
 1.1 28-Jun-2020  rillig make(1): demonstrate bug when evaluating conditions
 1.23.2.1 02-Aug-2025  perseant Sync with HEAD
 1.11 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.10 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.9 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.8 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.7 01-Jun-2023  rillig branches: 1.7.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.6 04-Mar-2023  rillig tests/make: test very small and very large numbers in conditions
 1.5 27-Dec-2021  rillig make: clean up comments
 1.4 15-Nov-2020  rillig make(1): add remarks to the tests about conditions
 1.3 08-Nov-2020  rillig make(1): add test for hexadecimal numbers in conditionals
 1.2 14-Sep-2020  rillig make(1): add tests for numbers in conditions
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7.2.1 02-Aug-2025  perseant Sync with HEAD
 1.12 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.11 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.10 19-Nov-2023  rillig branches: 1.10.2;
tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.9 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.8 04-Mar-2023  rillig tests/make: test very small and very large numbers in conditions
 1.7 02-Jan-2022  rillig make: clean up nitpicks

In ParseWord, the expressions '*p' and 'ch' are the same.

In ParseDependencyTargetWord, clean up a wordy comment and join two
conditions.

In the test cond-token-number, clarify that make doesn't convert from
hex to decimal but only from hex to internal representation.

No functional change.
 1.6 27-Dec-2021  rillig make: clean up comments
 1.5 15-Nov-2020  rillig make(1): add remarks to the tests about conditions
 1.4 08-Nov-2020  rillig make(1): add test for hexadecimal numbers in conditionals
 1.3 14-Sep-2020  rillig make(1): add tests for numbers in conditions
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.10.2.1 02-Aug-2025  perseant Sync with HEAD
 1.25 06-Jul-2025  rillig make: complain about unfinished escape sequences or string literals
 1.24 06-Jul-2025  rillig tests/make: demonstrate missing error for unfinished word in condition
 1.23 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.22 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.21 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.20 19-Nov-2023  rillig branches: 1.20.2;
tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.19 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.18 14-Feb-2023  rillig make: don't interpret the return value of Var_Parse

The return value of Var_Parse is largely redundant to the returned
string. The idea behind the type VarParseResult was to migrate all call
sites to checking this return value instead of the returned string, but
that hasn't happened. Instead, the additional type only added more
complexity.

There was a single place where that return value was actually used, when
parsing conditions. And even in that case, ignoring the VarParseResult
added back an error message that previously hid bugs, in the test
cond-token-plain.mk.

Even though these error messages are redundant in the other tests, they
don't hurt as they don't happen often.
 1.17 25-Sep-2022  rillig tests/make: reduce trailing whitespace
 1.16 03-Mar-2022  rillig make: make debug logging for comparisons less technical
 1.15 08-Jan-2022  rillig make: fix reported line numbers of continuation lines (since 2002)

Previously, multi-line directives like '.info' or '.error' reported the
line number of their last line instead of their first line, which is
more usual. This also affected the debug log from '-dp'.
 1.14 30-Dec-2021  rillig tests/make: demonstrate edge case that evaluates an expression twice
 1.13 12-Dec-2021  rillig tests/make: refine comments for parsing and evaluating conditions
 1.12 21-Sep-2021  rillig make: do not allow unquoted 'left == right' after modifier ':?'

Having a static variable for state that clearly belongs in the parser
looked suspicious, and indeed it was wrong.

When the distinction between .if conditions and expressions of the form
${condition:?:} was added in cond.c 1.68 from 2015-05-05, a new unit
test was added, but it didn't cover this edge case. At that time, the
state of the condition parser consisted of a few global variables
instead of a separate data type, as would have been appropriate for
parsing nested conditions.
 1.11 21-Sep-2021  rillig tests/make: demonstrate unintended unquoted string in conditions
 1.10 21-Jun-2021  rillig make: fix grammar in error message for malformed conditional
 1.9 21-Jan-2021  rillig make(1): replace warning + error with just an error in conditionals

Before, there was a "warning" for comparing strings using '<', which was
wrong. That warning was then followed by an error, after parsing the
whole conditional. This was only because it was easier to implement.

Replace the warning with an actual error. This only affects
conditionals in .if lines, the conditionals in the :? modifier such as
${"A" < "B":?smaller:greater} still print 2 errors.
 1.8 21-Jan-2021  rillig make(1): fix debug output for comparison operators in conditionals

This produces fewer warnings than before, but these were edge cases that
probably didn't matter in practice. The "Malformaed conditional" is
still generated, the set of accepted conditionals is still the same.
 1.7 21-Jan-2021  rillig make(1): demonstrate parse error without error message in conditional
 1.6 21-Jan-2021  rillig make(1): add test case for bare word containing quotes
 1.5 21-Jan-2021  rillig make(1): add more tests for edge cases in conditionals
 1.4 21-Jan-2021  rillig make(1): add more tests for tokens in conditionals
 1.3 12-Sep-2020  rillig make(1): add tests for comparison tokens without whitespace
 1.2 11-Sep-2020  rillig make(1): add tests for really strange edge cases in conditions
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.20.2.1 02-Aug-2025  perseant Sync with HEAD
 1.23 06-Jul-2025  rillig make: complain about unfinished escape sequences or string literals
 1.22 06-Jul-2025  rillig tests/make: demonstrate missing error for unfinished word in condition
 1.21 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.20 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.19 19-Nov-2023  rillig branches: 1.19.2;
tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.18 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.17 14-Feb-2023  rillig make: don't interpret the return value of Var_Parse

The return value of Var_Parse is largely redundant to the returned
string. The idea behind the type VarParseResult was to migrate all call
sites to checking this return value instead of the returned string, but
that hasn't happened. Instead, the additional type only added more
complexity.

There was a single place where that return value was actually used, when
parsing conditions. And even in that case, ignoring the VarParseResult
added back an error message that previously hid bugs, in the test
cond-token-plain.mk.

Even though these error messages are redundant in the other tests, they
don't hurt as they don't happen often.
 1.16 25-Sep-2022  rillig tests/make: reduce trailing whitespace
 1.15 30-Dec-2021  rillig tests/make: demonstrate edge case that evaluates an expression twice
 1.14 12-Dec-2021  rillig tests/make: refine comments for parsing and evaluating conditions
 1.13 12-Dec-2021  rillig make: rename ParseFuncArg to ParseWord, update comments

No functional change.
 1.12 21-Sep-2021  rillig make: do not allow unquoted 'left == right' after modifier ':?'

Having a static variable for state that clearly belongs in the parser
looked suspicious, and indeed it was wrong.

When the distinction between .if conditions and expressions of the form
${condition:?:} was added in cond.c 1.68 from 2015-05-05, a new unit
test was added, but it didn't cover this edge case. At that time, the
state of the condition parser consisted of a few global variables
instead of a separate data type, as would have been appropriate for
parsing nested conditions.
 1.11 21-Sep-2021  rillig tests/make: demonstrate unintended unquoted string in conditions
 1.10 21-Jan-2021  rillig make(1): demonstrate parse error without error message in conditional
 1.9 21-Jan-2021  rillig make(1): add test case for bare word containing quotes
 1.8 21-Jan-2021  rillig make(1): add more tests for edge cases in conditionals
 1.7 21-Jan-2021  rillig make(1): add more tests for tokens in conditionals
 1.6 15-Nov-2020  rillig make(1): add remarks to the tests about conditions
 1.5 09-Nov-2020  rillig make(1): document handling of '#' and '\n' in conditionals
 1.4 12-Sep-2020  rillig make(1): add tests for comparison tokens without whitespace
 1.3 11-Sep-2020  rillig make(1): add tests for really strange edge cases in conditions
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.19.2.1 02-Aug-2025  perseant Sync with HEAD
 1.20 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.19 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.18 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.17 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.16 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.15 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.14 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.13 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.12 20-Apr-2024  rillig branches: 1.12.2;
make: provide more context information for parse/evaluate errors
 1.11 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.10 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.9 08-May-2022  rillig tests/make: fix typo in variable name
 1.8 08-May-2022  rillig tests/make: migrate cond1 test to other, more specific tests

The tests in cond1 were a mixture of "everything related to conditions",
and the test cases were heavily dependent on each other, which made them
hard to understand. Move each test case to its corresponding
special-purpose test.
 1.7 08-Jan-2022  rillig make: fix reported line numbers of continuation lines (since 2002)

Previously, multi-line directives like '.info' or '.error' reported the
line number of their last line instead of their first line, which is
more usual. This also affected the debug log from '-dp'.
 1.6 23-Feb-2021  rillig make: improve error message for unknown modifier

Back in 1995, the modifiers were all single-character, and it made sense
to print only the first character. Nowadays, with ':S', ':@var@...@',
'::=' and several others, a little more context is useful to see where
the exact error is. The actual modifier is still guessed, and the guess
may be wrong as soon as backslashes get involved, but it is still better
than before.
 1.5 21-Jan-2021  rillig make(1): add more tests for tokens in conditionals
 1.4 20-Dec-2020  rillig make(1): error out on unknown variable modifiers at parse time

Before, make printed an "error message" that did not include the word
error and thus was not easily identified as such. This "error message"
also did not influence the exit status in the default mode but only in
-dL mode. The error message also didn't include any line number
information and was thus rude.
 1.3 11-Nov-2020  rillig make(1): fix line numbers in test cond-token-string
 1.2 10-Nov-2020  rillig make(1): add more tests for parsing .if directives

The details of parsing are quite tricky and not documented in the manual
page. Record the current behavior to be a little safer in future
refactorings.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.12.2.1 02-Aug-2025  perseant Sync with HEAD
 1.17 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.16 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.15 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.14 11-Jan-2025  rillig tests/make: force correct order of expected messages
 1.13 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.12 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.11 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.10 20-Apr-2024  rillig branches: 1.10.2;
make: provide more context information for parse/evaluate errors
 1.9 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.8 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.7 01-Jun-2023  rillig tests/make: clean up comments, extend a few tests
 1.6 08-May-2022  rillig tests/make: fix typo in variable name
 1.5 08-May-2022  rillig tests/make: migrate cond1 test to other, more specific tests

The tests in cond1 were a mixture of "everything related to conditions",
and the test cases were heavily dependent on each other, which made them
hard to understand. Move each test case to its corresponding
special-purpose test.
 1.4 21-Jan-2021  rillig make(1): add more tests for tokens in conditionals
 1.3 10-Nov-2020  rillig make(1): add more tests for parsing .if directives

The details of parsing are quite tricky and not documented in the manual
page. Record the current behavior to be a little safer in future
refactorings.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.10.2.1 02-Aug-2025  perseant Sync with HEAD
 1.11 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.10 04-Apr-2025  rillig make: fix error message for undefined variable in conditional

Previously, only ${UNDEF} had the proper error message, while
${UNDEF:M*} still produced the wrong "Malformed conditional".
 1.9 04-Apr-2025  rillig tests/make: demonstrate wrong error message for undefined variable

Found by wiz in pkgsrc/x11/gtk3.
 1.8 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.7 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.6 10-Jan-2025  rillig tests/make: test expressions based on undefined variables

When an undefined variable is used in a conditional, make complains about
"Malformed conditional", which is wrong since the conditional is
well-formed but errors out during evaluation.

In order to fix this wrong error message and preserve the remaining
behavior, cover the places in which an expression is evaluated with
undefined expressions being an error (VARE_EVAL_DEFINED), but with
neither producing an error message nor handling errors. This combination
results in the same behavior as evaluating the expressions in the mode
that allows undefined variables to be used in expressions.
 1.5 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.4 01-Jun-2023  rillig branches: 1.4.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.3 15-Nov-2020  rillig make(1): add remarks to the tests about conditions
 1.2 20-Aug-2020  rillig make(1): add test for variable expressions in conditions
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4.2.1 02-Aug-2025  perseant Sync with HEAD
 1.14 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.13 04-Apr-2025  rillig make: fix error message for undefined variable in conditional

Previously, only ${UNDEF} had the proper error message, while
${UNDEF:M*} still produced the wrong "Malformed conditional".
 1.12 04-Apr-2025  rillig tests/make: demonstrate wrong error message for undefined variable

Found by wiz in pkgsrc/x11/gtk3.
 1.11 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.10 10-Jan-2025  rillig tests/make: test expressions based on undefined variables

When an undefined variable is used in a conditional, make complains about
"Malformed conditional", which is wrong since the conditional is
well-formed but errors out during evaluation.

In order to fix this wrong error message and preserve the remaining
behavior, cover the places in which an expression is evaluated with
undefined expressions being an error (VARE_EVAL_DEFINED), but with
neither producing an error message nor handling errors. This combination
results in the same behavior as evaluating the expressions in the mode
that allows undefined variables to be used in expressions.
 1.9 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.8 19-Nov-2023  rillig branches: 1.8.2;
tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.7 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.6 25-Apr-2021  rillig tests/make: add tests for ${...} without operator in conditions

These tests are already covered in cond-cmp-unary.mk, but my first guess
was to search for these tests in cond-token-var.mk, so keep them in both
tests.
 1.5 15-Nov-2020  rillig make(1): add remarks to the tests about conditions
 1.4 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.3 20-Aug-2020  rillig make(1): add test for variable expressions in conditions
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.8.2.1 02-Aug-2025  perseant Sync with HEAD
 1.10 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.9 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.8 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.7 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.6 01-Jun-2023  rillig branches: 1.6.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.5 14-Feb-2023  rillig make: don't interpret the return value of Var_Parse

The return value of Var_Parse is largely redundant to the returned
string. The idea behind the type VarParseResult was to migrate all call
sites to checking this return value instead of the returned string, but
that hasn't happened. Instead, the additional type only added more
complexity.

There was a single place where that return value was actually used, when
parsing conditions. And even in that case, ignoring the VarParseResult
added back an error message that previously hid bugs, in the test
cond-token-plain.mk.

Even though these error messages are redundant in the other tests, they
don't hurt as they don't happen often.
 1.4 15-Nov-2020  rillig make(1): add remarks to the tests about conditions
 1.3 14-Sep-2020  rillig make(1): remove obsolete comments from tests
 1.2 14-Sep-2020  rillig make(1): don't require nested variables to be defined in conditions

This code only applies to lint mode (-dL) for now. After a test phase
and a thorough check for possible side effects, it will be activated in
normal mode, too. Having this code in lint mode is required to run
src/build.sh, which relies a lot on using variables with undefined
nested variables in conditions.

In the default mode, any errors about nested undefined variables are not
printed since in Var_Subst, oldVars is true. Therefore, it is not urgent
to properly handle these nested variables correctly there.
 1.1 14-Sep-2020  rillig make(1): add test for undefined expressions in conditions in lint mode
 1.6.2.1 02-Aug-2025  perseant Sync with HEAD
 1.8 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.7 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.6 11-Jan-2025  rillig tests/make: force correct order of expected messages
 1.5 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.4 01-Jun-2023  rillig branches: 1.4.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.3 15-Nov-2020  rillig make(1): add remarks to the tests about conditions
 1.2 14-Sep-2020  rillig make(1): remove obsolete comments from tests
 1.1 14-Sep-2020  rillig make(1): add test for undefined expressions in conditions in lint mode
 1.4.2.1 02-Aug-2025  perseant Sync with HEAD
 1.6 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.5 06-Mar-2011  sjg Add unit tests to check that exists(some/dir/) works

Also fix handling of sysV substitutions when lhs and variable are empty.

Also that modifiers do not cause errors during conditional tests
when undefined variables should otherwise be ok.
Ie. .if defined(nosuch) && ${nosuch:Mx} != ""
 1.4 29-Oct-2008  sjg If Parse_Error is called after curFile is invalid, set it to a dummy
to avoid seg-fault. Also the NULL filename will cause ParseVErrorInternal
to skip trying to report file and line number info.

If CondToken is called outside the context of a .if etc, variables in
the expression being parsed will already be expanded, so allow for
an unqouted number to jump us back into the compare logic.
This allows ${${SomeNumber:U42} > 0:?True:False} to work anywhere.

Job_Finish should process postCommands if it has commands or children.
 1.3 13-Apr-2004  sjg branches: 1.3.2;
Allow "string" and "${varspec}" on lhs of conditionals.
This makes it possible to use expressions like
${("${LIST:Msomething"}):?present:absent}
it also makes treatment of lhs and rhs more consistent, and
makes CondToken easier to read.

Update unit-test/cond1 to test new features.
 1.2 08-Apr-2004  sjg Revised patch for catching extraneous .else's
We actually need to tack condTop and skipIfLevel.
Bump MAXIF while here.
Enhance the unit-test for conditionals to exercise more code.

PR: 24420
 1.1 08-Apr-2004  sjg Add check for extraneous .else's - based on patch from Arne H. Juul
in PR/24420.
Add a unit-test for conditionals.
Also in the unit-test makefile strip any .CURDIR in output.

PR: 24420
 1.3.2.4 10-May-2004  tron Pull up revision 1.3 (requested by sjg in ticket #282):
Allow "string" and "${varspec}" on lhs of conditionals.
This makes it possible to use expressions like
${("${LIST:Msomething"}):?present:absent}
it also makes treatment of lhs and rhs more consistent, and
makes CondToken easier to read.
Update unit-test/cond1 to test new features.
 1.3.2.3 10-May-2004  tron Pull up revision 1.2 (requested by sjg in ticket #282):
Revised patch for catching extraneous .else's
We actually need to tack condTop and skipIfLevel.
Bump MAXIF while here.
Enhance the unit-test for conditionals to exercise more code.
PR: 24420
 1.3.2.2 10-May-2004  tron Pull up revision 1.1 (requested by sjg in ticket #282):
Add check for extraneous .else's - based on patch from Arne H. Juul
in PR/24420.
Add a unit-test for conditionals.
Also in the unit-test makefile strip any .CURDIR in output.
PR: 24420
 1.3.2.1 13-Apr-2004  tron file cond1 was added on branch netbsd-2-0 on 2004-05-10 15:23:33 +0000
 1.6 08-May-2022  rillig tests/make: migrate cond1 test to other, more specific tests

The tests in cond1 were a mixture of "everything related to conditions",
and the test cases were heavily dependent on each other, which made them
hard to understand. Move each test case to its corresponding
special-purpose test.
 1.5 19-Apr-2021  rillig make: use straight quotes for error 'Bad conditional expression'

This diagnostic was supposed to be an error, see ApplyModifier_IfElse.

When such an error occurs while the makefiles are read, make stops with
an error, as can be expected. But when such an error occurs later,
after all makefiles have been read, the message is printed but make does
not stop.

In lint mode (-dL), make stops in such a case. I didn't dare to make
this the default behavior, out of fear of breaking existing build
infrastructure, not only in NetBSD or pkgsrc, but also FreeBSD and other
operating systems that use the bmake distribution, generated from the
same source code.
 1.4 21-Jan-2021  rillig make(1): replace warning + error with just an error in conditionals

Before, there was a "warning" for comparing strings using '<', which was
wrong. That warning was then followed by an error, after parsing the
whole conditional. This was only because it was easier to implement.

Replace the warning with an actual error. This only affects
conditionals in .if lines, the conditionals in the :? modifier such as
${"A" < "B":?smaller:greater} still print 2 errors.
 1.3 15-Nov-2020  rillig make(1): add remarks to the tests about conditions
 1.2 12-Sep-2020  rillig make(1): fix wording of parse error in conditionals

The word "should" is not appropriate for situations that eventually lead
to a parse error.
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.4 08-May-2022  rillig tests/make: migrate cond1 test to other, more specific tests

The tests in cond1 were a mixture of "everything related to conditions",
and the test cases were heavily dependent on each other, which made them
hard to understand. Move each test case to its corresponding
special-purpose test.
 1.3 15-Nov-2020  rillig make(1): add remarks to the tests about conditions
 1.2 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2 23-Oct-2020  rillig make(1): move tests from cond2.mk to varmod-ifelse.mk
 1.1 05-May-2015  sjg When evaluating condtionals from .if we want to require
that the lhs is a variable reference, a number or a quoted string.
This helps avoid subtle bugs caused by typos.

When conditionals are being evaluated during variable expansion
we cannot be as strict becuase lhs will already have been expanded.

We therefor pass a boolean to Cond_EvalExpression to tell it how
lhs should be treated.

Add unit-tests/cond2.mk to test the above

Reviewed by: christos, joerg
 1.3 23-Oct-2020  rillig make(1): move tests from cond2.mk to varmod-ifelse.mk
 1.2 02-Dec-2015  sjg Fix evaluation of defined(FOO) and ${FOO} > 0
add a unit-test to catch it.
 1.1 05-May-2015  sjg When evaluating condtionals from .if we want to require
that the lhs is a variable reference, a number or a quoted string.
This helps avoid subtle bugs caused by typos.

When conditionals are being evaluated during variable expansion
we cannot be as strict becuase lhs will already have been expanded.

We therefor pass a boolean to Cond_EvalExpression to tell it how
lhs should be treated.

Add unit-tests/cond2.mk to test the above

Reviewed by: christos, joerg
 1.3 23-Sep-2020  rillig make(1): remove debug output from counter tests

Now that the tests work as intended, the debug information is no longer
necessary. It was only intended to track down the cause of the
unexpected behavior.
 1.2 23-Sep-2020  rillig make(1): fix unexpected behavior in ::= variable modifier

Previously, the ::= modifier had returned an error value, which caused
the variable expression to be preserved. This behavior was not useful
in this case; it had only been intended to be used for undefined
variables.

To fix it, distinguish between parse errors, undefined variables and
regular empty strings.
 1.1 23-Sep-2020  rillig make(1): add variant of the counter test

I had expected that using the ::+= modifier instead of the ::= modifier
would work, since the assignment modifier for COUNTER no longer contains
a reference to itself. But instead of ending up at 4, the counter even
goes up to 6.
 1.5 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.4 17-Oct-2020  rillig make(1): document why the counter tests failed before 2020-09-23
 1.3 23-Sep-2020  rillig make(1): remove debug output from counter tests

Now that the tests work as intended, the debug information is no longer
necessary. It was only intended to track down the cause of the
unexpected behavior.
 1.2 23-Sep-2020  rillig make(1): fix unexpected behavior in ::= variable modifier

Previously, the ::= modifier had returned an error value, which caused
the variable expression to be preserved. This behavior was not useful
in this case; it had only been intended to be used for undefined
variables.

To fix it, distinguish between parse errors, undefined variables and
regular empty strings.
 1.1 23-Sep-2020  rillig make(1): add variant of the counter test

I had expected that using the ::+= modifier instead of the ::= modifier
would work, since the assignment modifier for COUNTER no longer contains
a reference to itself. But instead of ending up at 4, the counter even
goes up to 6.
 1.8 23-Sep-2020  rillig make(1): remove debug output from counter tests

Now that the tests work as intended, the debug information is no longer
necessary. It was only intended to track down the cause of the
unexpected behavior.
 1.7 23-Sep-2020  rillig make(1): fix unexpected behavior in ::= variable modifier

Previously, the ::= modifier had returned an error value, which caused
the variable expression to be preserved. This behavior was not useful
in this case; it had only been intended to be used for undefined
variables.

To fix it, distinguish between parse errors, undefined variables and
regular empty strings.
 1.6 22-Sep-2020  rillig make(1): move VAR_JUNK and VAR_KEEP away from VarFlags

These two flags have nothing to do with a variable. They are only used
while evaluating a variable expression.

While here, rename the flags and make their documentation more precise.
 1.5 13-Sep-2020  rillig make(1): shorten debug output of ApplyModifiers

Having the words "eflags" and "vflags" in the debug output was too
repetitive. That they are flags is made obvious by the '|' separator,
and the flags have clearly distinguishable names (VARE_* vs. VAR_*),
which lowers the chance for confusion.
 1.4 08-Aug-2020  rillig make(1): add debug logging for Var_Parse

This will hopefully help with tracking down why the "Undefined variable"
error message is not triggered.

There is some other non-obvious behavior nearby. In Parse_DoVar, the !=
assignment operator evaluates the variable using VARE_UNDEFERR, but
there is not even a warning for the following line:

!= echo err ${UNDEFINED} 1>&2
 1.3 08-Aug-2020  rillig make(1): add more detailed debug logging for variable modifiers

Before a modifier is applied to a variable, it is not yet parsed,
therefore it is only possible to log a rough estimate of the modifier.
But after applying it, the parsing position has advanced, and the full
modifier can be logged.

In addition, to fully understand how the modifiers work, it's not enough
to just know the variable names and values, there are also some flags
that influence how the modifiers behave. The most influential is
VARE_WANTRES.

Thanks to sjg for the extensive review and valuable feedback on the
first drafts.
 1.2 02-Aug-2020  rillig make(1): remove debug output from uncommitted code from test

Note to self: don't accept the test results when there are uncommitted
parts in the code.
 1.1 02-Aug-2020  rillig make(1): add test for nested VAR_SUBST assignments
 1.6 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.5 17-Oct-2020  rillig make(1): document why the counter tests failed before 2020-09-23
 1.4 23-Sep-2020  rillig make(1): remove debug output from counter tests

Now that the tests work as intended, the debug information is no longer
necessary. It was only intended to track down the cause of the
unexpected behavior.
 1.3 23-Sep-2020  rillig make(1): fix unexpected behavior in ::= variable modifier

Previously, the ::= modifier had returned an error value, which caused
the variable expression to be preserved. This behavior was not useful
in this case; it had only been intended to be used for undefined
variables.

To fix it, distinguish between parse errors, undefined variables and
regular empty strings.
 1.2 23-Sep-2020  rillig make(1): add variant of the counter test

I had expected that using the ::+= modifier instead of the ::= modifier
would work, since the assignment modifier for COUNTER no longer contains
a reference to itself. But instead of ending up at 4, the counter even
goes up to 6.
 1.1 02-Aug-2020  rillig make(1): add test for nested VAR_SUBST assignments
 1.4 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.3 01-Jun-2023  rillig branches: 1.3.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.2 25-Sep-2020  rillig make(1): fix missing check for duplicate commands in Parse_File
 1.1 25-Sep-2020  rillig make(1): add test for harmless bug in Parse_File

When there is a dependency group at the end of a top-level makefile,
this dependency group is not finished properly. This allows to add
further commands to the targets of this dependency group, which was not
intended.
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.5 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.4 27-Sep-2020  rillig make(1): fix CRLF line endings in unit tests
 1.3 25-Sep-2020  rillig make(1): fix grammar and style in test dep-colon-bug-cross-file
 1.2 25-Sep-2020  rillig make(1): fix missing check for duplicate commands in Parse_File
 1.1 25-Sep-2020  rillig make(1): add test for harmless bug in Parse_File

When there is a dependency group at the end of a top-level makefile,
this dependency group is not finished properly. This allows to add
further commands to the targets of this dependency group, which was not
intended.
 1.2 17-Oct-2020  rillig make(1): add test for "target: source; command"
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 17-Oct-2020  rillig make(1): add test for "target: source; command"
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 23-Oct-2020  rillig make(1): add test for the '::' dependency operator
 1.1 23-Oct-2020  rillig make(1): add test for the '::' dependency operator
 1.2 22-Aug-2020  rillig make(1): add test for :: in the main target
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.4 26-Sep-2020  rillig make(1): add test for '::' dependency operator with .ALLTARGETS
 1.3 22-Aug-2020  rillig make(1): add test for :: in the main target
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.4 25-May-2024  rillig branches: 1.4.2;
tests/make: rename temporary file

The filename extension '.inc' is reserved for files that are checked
into version control.
 1.3 20-Jan-2022  rillig make: fix filename in warning about duplicate script (since 2018-12-22)
 1.2 20-Jan-2022  rillig tests/make: refine test for wrong diagnostic line

To trigger the faulty code path, the file where the targets gets its
first command must be included via its relative path. That was the case
when running 'cd usr.bin/make && make test' but not when running the
tests via ATF.
 1.1 19-Jan-2022  rillig tests/make: demonstrate wrong location in diagnostic (since 2018-12-22)

When a target has multiple places where commands are defined, the
diagnostics mixed up the filename in some cases.
 1.4.2.1 02-Aug-2025  perseant Sync with HEAD
 1.4 25-May-2024  rillig tests/make: rename temporary file

The filename extension '.inc' is reserved for files that are checked
into version control.
 1.3 20-Jan-2022  rillig make: fix filename in warning about duplicate script (since 2018-12-22)
 1.2 20-Jan-2022  rillig tests/make: refine test for wrong diagnostic line

To trigger the faulty code path, the file where the targets gets its
first command must be included via its relative path. That was the case
when running 'cd usr.bin/make && make test' but not when running the
tests via ATF.
 1.1 19-Jan-2022  rillig tests/make: demonstrate wrong location in diagnostic (since 2018-12-22)

When a target has multiple places where commands are defined, the
diagnostics mixed up the filename in some cases.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 22-Aug-2020  rillig make(1): add test for "no target to make"
 1.1 22-Aug-2020  rillig make(1): add test for "no target to make"
 1.7 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.6 12-Jun-2025  rillig make: add program name to stack traces from sub-makes
 1.5 12-Jun-2025  rillig make: add quotes to "in directory" line in stack traces

The other lines in stack traces use quotes as well.
 1.4 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.3 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.2 19-Aug-2023  rillig branches: 1.2.2;
make: add more details to error message about invalid lines
 1.1 14-Dec-2021  rillig make: remove unreachable code for parsing the dependency operator

At the point where ParseDependencyOp is called, cp is guaranteed to
point to either ':' or '!'.

No functional change.
 1.2.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 14-Dec-2021  rillig make: remove unreachable code for parsing the dependency operator

At the point where ParseDependencyOp is called, cp is guaranteed to
point to either ':' or '!'.

No functional change.
 1.3 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.2 07-Dec-2020  rillig branches: 1.2.8;
make(1): fix exit status in -k mode if a dependency fails

Whether in -k mode or not, the exit status tells whether all requested
targets were made or not. If a dependency could not be made, the main
target was not made as well, therefore the exit status must be nonzero
in such a case.

This part of the code lacked proper unit tests until today. The unit
test deptgt-end-fail.mk is compatible with make>=2003 at least, allowing
to compare the output over time.

In 2003, in the ok-ok-ok-ok case, "Making all from all-dep." was printed
twice in a row, for whatever reason ... (40 minutes later) ... If I had
just made the two commands for 'all' and '.END' more distinguishable.
Back in 2003, the local variables for .END had not been initialized,
instead the .END node was run with the local variables of the last
preceding node. In this case, that node was 'all', therefore ${.TARGET}
had obviously expanded to 'all'.

Somewhere in 2004, the shell commands were no longer run with the -e
flag, which resulted in the "exit status $?" line to be printed in cases
that had stopped early before.

Somewhere in 2005, the local variables for the .END node had been fixed.
The variable ${.TARGET} now had the value '.END', just as expected. In
addition, the dependencies for the .END node were made, although without
getting their proper local variables. This resulted in the output
"Making out of nothing" instead of the expected "Making end-dep out of
nothing".

Still in 2005, in the test case "all=ok all-dep=ok end=ok end-dep=ERR",
the error code of the failed 'end-dep' was first reported as "*** Error
code 1 (continuing)". To compensate for this improvement, a new bug had
been introduced. The test case "all=ok all-dep=ok end=ERR end-dep=ERR"
had properly exited with status 1 on 2005-01-01, but on 2006-01-01 it
exited with status 0, thereby ignoring errors in the .END node.

Somewhere in 2008, some of the error messages (but not all) were
directed to stderr instead of stdout. The actual output stayed the same
though.

Somewhere in 2011, the dependency of the .END node got its own local
variables, and ${.TARGET} now expanded to 'end-dep', as expected.

Somewhere in 2016, the two empty lines between the "*** Error code 1
(continuing)" and the "Stop." got compressed into a single empty line.

On 2020-12-07 (that is, today), the exit status 1 has been restored in
the error cases, after it had been wrong for at least 14 years.
 1.1 23-Oct-2020  rillig make(1): add test for dependencies of the form '%.o: %.c'
 1.2.8.1 02-Aug-2025  perseant Sync with HEAD
 1.1 23-Oct-2020  rillig make(1): add test for dependencies of the form '%.o: %.c'
 1.10 14-Jan-2025  rillig make: simplify parsing of dependency lines

The evaluation modes that allow or deny undefined variables have the same
effect in this case, as Var_Subst does not return an error marker.
 1.9 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.8 09-Jul-2024  rillig make: error out on parse/evaluation errors in shell commands

The expression ${VAR:X} has an unknown modifier ':X'. Previously, this
expression errored out when the expression was evaluated at parse time,
but not when the expression was evaluated when generating the commands
to bring a target up to date. The errors were previously reported, they
didn't affect the exit status, though.

Now, errors in expressions are handled in the same way, regardless of
the time at which they are evaluated.
 1.7 02-Jun-2024  rillig branches: 1.7.2;
make: sync VarEvalMode constant names with their debug log names
 1.6 19-Nov-2023  rillig make: replace 'variable expression' with 'expression' in diagnostics
 1.5 13-Feb-2023  rillig tests/make: update test for evaluating undefined variables
 1.4 08-Sep-2020  rillig make(1): fix off-by-one error in SuffExpandChildren

In suff.c r1.144 from yesterday, in the line "cp += nested_p - cp", I
accidentally removed the "- 1". Since these "- 1" lines lead to slow
execution, each branch now increments the pointer separately by the
actually needed amount.

Fixing this bug posed way more new questions than it answered, and it
revealed an inconsistency in the parser about how characters are to be
escaped, and missing details in the documentation of Var_Parse, as well
as a parse error that unexpectedly doesn't stop make from continuing.
 1.3 03-Sep-2020  rillig make(1): add test for expansion of indirect variables in dependencies
 1.2 03-Sep-2020  rillig make: extend test for unresolved variables in dependencies

This is to ensure that the upcoming refactoring of Var_Parse in
SuffExpandChildren does not break anything.
 1.1 22-Aug-2020  rillig make(1): add test for deferred variable expansion in dependencies
 1.7.2.1 02-Aug-2025  perseant Sync with HEAD
 1.13 14-Jan-2025  rillig make: simplify parsing of dependency lines

The evaluation modes that allow or deny undefined variables have the same
effect in this case, as Var_Subst does not return an error marker.
 1.12 02-Jun-2024  rillig branches: 1.12.2;
make: sync VarEvalMode constant names with their debug log names
 1.11 19-Dec-2023  rillig make: clean up comments

No binary change, except for line numbers in assertions.
 1.10 19-Nov-2023  rillig tests/make: replace 'variable expressions' with 'expressions'
 1.9 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.8 10-May-2023  rillig tests/make: clean up comments in tests
 1.7 13-Feb-2023  rillig tests/make: update test for evaluating undefined variables
 1.6 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.5 13-Sep-2020  rillig make(1): explain why the dep-var test behaves differently in lint mode
 1.4 08-Sep-2020  rillig make(1): fix off-by-one error in SuffExpandChildren

In suff.c r1.144 from yesterday, in the line "cp += nested_p - cp", I
accidentally removed the "- 1". Since these "- 1" lines lead to slow
execution, each branch now increments the pointer separately by the
actually needed amount.

Fixing this bug posed way more new questions than it answered, and it
revealed an inconsistency in the parser about how characters are to be
escaped, and missing details in the documentation of Var_Parse, as well
as a parse error that unexpectedly doesn't stop make from continuing.
 1.3 03-Sep-2020  rillig make(1): add test for expansion of indirect variables in dependencies
 1.2 03-Sep-2020  rillig make: extend test for unresolved variables in dependencies

This is to ensure that the upcoming refactoring of Var_Parse in
SuffExpandChildren does not break anything.
 1.1 22-Aug-2020  rillig make(1): add test for deferred variable expansion in dependencies
 1.12.2.1 02-Aug-2025  perseant Sync with HEAD
 1.7 19-Jan-2022  rillig tests/make: demonstrate wrong location in diagnostic (since 2018-12-22)

When a target has multiple places where commands are defined, the
diagnostics mixed up the filename in some cases.
 1.6 14-Dec-2021  rillig make: remove unreachable code for parsing the dependency operator

At the point where ParseDependencyOp is called, cp is guaranteed to
point to either ':' or '!'.

No functional change.
 1.5 23-Oct-2020  rillig make(1): add test for dependencies of the form '%.o: %.c'
 1.4 23-Oct-2020  rillig make(1): add test for the '::' dependency operator
 1.3 25-Sep-2020  rillig make(1): add test for harmless bug in Parse_File

When there is a dependency group at the end of a top-level makefile,
this dependency group is not finished properly. This allows to add
further commands to the targets of this dependency group, which was not
intended.
 1.2 08-Sep-2020  rillig make(1): add test for wildcards in dependency declarations
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 21-Jun-2023  rillig tests/make: document how wildcards behave in a dependency declaration
 1.3 08-Sep-2020  rillig make(1): add test for wildcards in dependency declarations
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.3 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.2 13-Dec-2021  rillig branches: 1.2.4;
tests/make: extend tests for parsing makefiles
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2.4.1 02-Aug-2025  perseant Sync with HEAD
 1.4 01-Jun-2023  rillig tests/make: clean up comments, extend a few tests
 1.3 13-Dec-2021  rillig tests/make: extend tests for parsing makefiles
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 23-Oct-2020  rillig make(1): add test case in which .BEGIN depends on .END

Just for fun.
 1.2 27-Apr-2024  rillig make: clean up, test .NOPATH

Trim down the comments in the archive module, as they mainly repeated
the code. Trim down the binary code size in the archive module, as it
is rarely used.

In Var_Parse, delay two variable assignments until they are actually
needed.
 1.1 23-Oct-2020  rillig make(1): add test case in which .BEGIN depends on .END

Just for fun.
 1.2 05-Sep-2020  rillig make(1): add tests for some of the special sources
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 05-Sep-2020  rillig make(1): add tests for some of the special sources
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.3 26-Dec-2023  sjg branches: 1.3.2;
make: fix order of output in compat mode

Ensure that make's output is correctly ordered with the output of the
target's commands, even when the output does not go to a terminal.

Reviewed by: rillig
 1.2 29-Aug-2020  rillig make(1): add test for the special .IGNORE dependency source
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.5 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.4 29-Aug-2020  rillig make(1): explain the shuffled messages in the test output
 1.3 29-Aug-2020  rillig make(1): add test for the special .IGNORE dependency source
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 05-Sep-2020  rillig make(1): add tests for some of the special sources
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 05-Sep-2020  rillig make(1): add tests for some of the special sources
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 05-Sep-2020  rillig make(1): add tests for some of the special sources
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.3 05-Sep-2020  rillig make(1): add tests for some of the special sources
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 26-Jan-2022  rillig tests/make: test meta mode in jobs mode
 1.2 27-Nov-2020  rillig make(1): add very basic test about meta mode

This test is just meant to cover the existing code, it still needs to be
cleaned up to serve as a tutorial and to highlight the really
interesting points.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7 02-Mar-2022  sjg Add nofilemon to meta mode tests

The unit-tests for meta mode do not depend on filemon.
Adding nofilemon to .MAKE.MODE allows these to pass on
a system that would use filemon_dev but does not have
the module loaded.
 1.6 26-Jan-2022  rillig tests/make: test meta mode in jobs mode
 1.5 26-Jan-2022  rillig tests/make: remove unnecessary conditional processing for meta test

The .if/.else distracted from the main topic of the test and made it too
hard to see the main targets.
 1.4 27-Nov-2020  rillig make(1): clean up after a successful .META test
 1.3 27-Nov-2020  rillig make(1): add very basic test about meta mode

This test is just meant to cover the existing code, it still needs to be
cleaned up to serve as a tutorial and to highlight the really
interesting points.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 27-Apr-2024  rillig make: clean up, test .NOPATH

Trim down the comments in the archive module, as they mainly repeated
the code. Trim down the binary code size in the archive module, as it
is rarely used.

In Var_Parse, delay two variable assignments until they are actually
needed.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 27-Apr-2024  rillig make: clean up, test .NOPATH

Trim down the comments in the archive module, as they mainly repeated
the code. Trim down the binary code size in the archive module, as it
is rarely used.

In Var_Parse, delay two variable assignments until they are actually
needed.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 05-Sep-2020  rillig make(1): add tests for some of the special sources
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 05-Sep-2020  rillig make(1): add tests for some of the special sources
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7 18-Dec-2020  rillig make(1): spell nonexistent consistently
 1.6 18-Dec-2020  rillig make(1): use symbolic time for 0 in Make_Recheck

This makes the test depsrc-optional independent from the current time
zone.
 1.5 08-Nov-2020  rillig make(1): inline MakeAddChild into ExamineLater

This gets rid of a few void pointers and unspecific variable names like
"l" for the list that should have rather been called "examine" all the
time.

Add quotes around placeholders in debug messages. Especially for targets
like "all" the message had been syntactically misleading.
 1.4 08-Nov-2020  rillig make(1): fix debug output in out-of-date for cohorts (since 2003-11-14)

Before, a wrong cause for being out-of-date was printed in the debug log,
for optional cohorts. This was caused by having the same conditions
duplicated in the code, instead of putting them in a separate function.

Now the optional cohort is correctly identified as using the '::'
dependency operator.
 1.3 08-Nov-2020  rillig make(1): add test for wrong debug message in GNode_IsOODate
 1.2 05-Sep-2020  rillig make(1): add tests for some of the special sources
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 08-Nov-2020  rillig make(1): fix debug output in out-of-date for cohorts (since 2003-11-14)

Before, a wrong cause for being out-of-date was printed in the debug log,
for optional cohorts. This was caused by having the same conditions
duplicated in the code, instead of putting them in a separate function.

Now the optional cohort is correctly identified as using the '::'
dependency operator.
 1.4 08-Nov-2020  rillig make(1): add test for wrong debug message in GNode_IsOODate
 1.3 05-Sep-2020  rillig make(1): add tests for some of the special sources
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 05-Sep-2020  rillig make(1): add tests for some of the special sources
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 27-Apr-2024  rillig make: clean up, test .NOPATH

Trim down the comments in the archive module, as they mainly repeated
the code. Trim down the binary code size in the archive module, as it
is rarely used.

In Var_Parse, delay two variable assignments until they are actually
needed.
 1.3 05-Sep-2020  rillig make(1): add tests for some of the special sources
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 05-Sep-2020  rillig make(1): add tests for some of the special sources
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 05-Sep-2020  rillig make(1): add tests for some of the special sources
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 29-Aug-2020  rillig make(1): add tests for .SILENT, .BEGIN and .END
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 29-Aug-2020  rillig make(1): add tests for .SILENT, .BEGIN and .END
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 18-Apr-2022  rillig tests/make: extend tests for .USE and .USEBEFORE
 1.3 22-Aug-2020  rillig make(1): add test for correct command order in .USE sources
 1.2 22-Aug-2020  rillig make(1): add test for the special source .USE
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.6 18-Apr-2022  rillig tests/make: extend tests for .USE and .USEBEFORE
 1.5 28-Dec-2021  rillig make: do not treat .USEBEFORE as candidate for the main target

A .USE target is not a candidate, so .USEBEFORE shouldn't either.

Since make.h 1.36 from 2001-07-03. In that commit, OP_USEBEFORE should
have been added to OP_NOTARGET.
 1.4 22-Aug-2020  rillig make(1): add test for correct command order in .USE sources
 1.3 22-Aug-2020  rillig make(1): add test for the special source .USE
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 22-Aug-2020  rillig make(1): add test for combining :: and .USEBEFORE
 1.1 22-Aug-2020  rillig make(1): add test for combining :: and .USEBEFORE
 1.4 18-Apr-2022  rillig tests/make: extend tests for .USE and .USEBEFORE
 1.3 22-Aug-2020  rillig make(1): extend test for .USEBEFORE

When several .USEBEFORE targets are added to another target, they are
added in reverse order. But the commands of each .USEBEFORE target are
added in normal order.
 1.2 22-Aug-2020  rillig make(1): add test for the special source .USEBEFORE
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.9 18-Apr-2022  rillig tests/make: refine documentation of test for .USEBEFORE
 1.8 18-Apr-2022  rillig tests/make: extend tests for .USE and .USEBEFORE
 1.7 28-Dec-2021  rillig make: do not treat .USEBEFORE as candidate for the main target

A .USE target is not a candidate, so .USEBEFORE shouldn't either.

Since make.h 1.36 from 2001-07-03. In that commit, OP_USEBEFORE should
have been added to OP_NOTARGET.
 1.6 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.5 22-Aug-2020  rillig make(1): extend test for .USEBEFORE

When several .USEBEFORE targets are added to another target, they are
added in reverse order. But the commands of each .USEBEFORE target are
added in normal order.
 1.4 22-Aug-2020  rillig make(1): add test for the special source .USE
 1.3 22-Aug-2020  rillig make(1): add test for the special source .USEBEFORE
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 07-May-2022  rillig make: allow to randomize build order of targets

In complex dependency structures, when a build fails, a probable cause
is a missing dependency declaration between some files. In compat mode,
the build order is deterministic, in jobs mode, it is somewhat
deterministic. To explore more edge cases, add the line ".MAKE.MODE +=
randomize-targets" somewhere in the makefile.

Fixes PR bin/45226 by riastradh. Reviewed by christos.
 1.2 07-Sep-2020  rillig make(1): add test for the .WAIT dependency source
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 07-May-2022  rillig make: allow to randomize build order of targets

In complex dependency structures, when a build fails, a probable cause
is a missing dependency declaration between some files. In compat mode,
the build order is deterministic, in jobs mode, it is somewhat
deterministic. To explore more edge cases, add the line ".MAKE.MODE +=
randomize-targets" somewhere in the makefile.

Fixes PR bin/45226 by riastradh. Reviewed by christos.
 1.3 07-Sep-2020  rillig make(1): add test for the .WAIT dependency source
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 13-Dec-2021  rillig tests/make: extend tests for parsing makefiles
 1.2 22-Dec-2020  rillig make(1): add test for undefined variable in dependency declaration
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 13-Dec-2021  rillig tests/make: extend tests for parsing makefiles
 1.4 22-Dec-2020  rillig make(1): add test for undefined variable in dependency declaration
 1.3 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.2 24-Nov-2020  rillig branches: 1.2.8;
make(1): fix error handling for .BEGIN dependency in -k mode
 1.1 24-Nov-2020  rillig make(1): add test for bug in error handling of .BEGIN in -k mode
 1.2.8.1 02-Aug-2025  perseant Sync with HEAD
 1.1 24-Nov-2020  rillig make(1): add test for bug in error handling of .BEGIN in -k mode
 1.2 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.1 24-Nov-2020  rillig branches: 1.1.8;
make(1): add test for bug in error handling of .BEGIN in -k mode
 1.1.8.1 02-Aug-2025  perseant Sync with HEAD
 1.1 24-Nov-2020  rillig make(1): add test for bug in error handling of .BEGIN in -k mode
 1.6 30-Jun-2025  rillig tests/make: force expected lines to be listed in execution order

The diagnostics from the program to check the "expect" lines in the unit
test files were hard to follow since the "out-of-order" lines were
confusing. For out-of-order lines, state where they should be placed
instead.
 1.5 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.4 01-Jun-2023  rillig branches: 1.4.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.3 15-Nov-2020  rillig make(1): add tests for the .BEGIN node
 1.2 29-Aug-2020  rillig make(1): add tests for .SILENT, .BEGIN and .END
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4.2.1 02-Aug-2025  perseant Sync with HEAD
 1.8 30-Jun-2025  rillig tests/make: force expected lines to be listed in execution order

The diagnostics from the program to check the "expect" lines in the unit
test files were hard to follow since the "out-of-order" lines were
confusing. For out-of-order lines, state where they should be placed
instead.
 1.7 01-Jun-2023  rillig branches: 1.7.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.6 07-May-2022  rillig make: rename Compat_Run to Compat_MakeAll

No functional change.
 1.5 15-Nov-2020  rillig make(1): document why .BEGIN cannot be combined with .USE/.USEBEFORE
 1.4 15-Nov-2020  rillig make(1): add tests for the .BEGIN node
 1.3 29-Aug-2020  rillig make(1): add tests for .SILENT, .BEGIN and .END
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7.2.1 02-Aug-2025  perseant Sync with HEAD
 1.2 01-Dec-2021  rillig tests/make: test target '.DEFAULT'
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 01-Dec-2021  rillig tests/make: test target '.DEFAULT'
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.4 26-Dec-2023  sjg branches: 1.4.2;
make: fix order of output in compat mode

Ensure that make's output is correctly ordered with the output of the
target's commands, even when the output does not go to a terminal.

Reviewed by: rillig
 1.3 18-Mar-2023  sjg make: handle .PHONY consitently on interrupt

JobDeleteTarget skips .PHONY targets
CompatDeleteTarget should do the same

This addresses https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=269663
 1.2 25-Oct-2020  rillig make(1): add test for deleting targets using .DELETE_ON_ERROR
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4.2.1 02-Aug-2025  perseant Sync with HEAD
 1.4 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.3 25-Oct-2020  rillig make(1): add test for deleting targets using .DELETE_ON_ERROR
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.2 07-Dec-2020  rillig branches: 1.2.8;
make(1): don't make .END if the main targets already failed

This only applies to -k mode. By default, make exits earlier and skips
the .END node as well if an error occurs.
 1.1 06-Dec-2020  rillig make(1): add test for .END after failed main node
 1.2.8.1 02-Aug-2025  perseant Sync with HEAD
 1.2 07-Dec-2020  rillig make(1): don't make .END if the main targets already failed

This only applies to -k mode. By default, make exits earlier and skips
the .END node as well if an error occurs.
 1.1 06-Dec-2020  rillig make(1): add test for .END after failed main node
 1.3 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.2 24-Nov-2020  rillig branches: 1.2.8;
make(1): fix error handling for dependency of .END in -k mode

Fix one bug, find 4 new ones. All these bugs have been around since
2005-05-08, when dependencies on the .BEGIN, .END and .INTERRUPT nodes
were implemented. Before that, checking gn->made == ERROR was
appropriate, but adding the dependencies made ABORTED a new possible
error value from Compat_Make.
 1.1 24-Nov-2020  rillig make(1): add test for error in dependency of .END node in -k mode
 1.2.8.1 02-Aug-2025  perseant Sync with HEAD
 1.3 07-May-2022  rillig make: rename Compat_Run to Compat_MakeAll

No functional change.
 1.2 06-Dec-2020  rillig make(1): add test for .END after failed main node
 1.1 24-Nov-2020  rillig make(1): add test for error in dependency of .END node in -k mode
 1.7 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.6 07-Dec-2020  rillig branches: 1.6.8;
make(1): don't make .END if the main targets already failed

This only applies to -k mode. By default, make exits earlier and skips
the .END node as well if an error occurs.
 1.5 07-Dec-2020  rillig make(1): fix exit status in -k mode if a dependency fails

Whether in -k mode or not, the exit status tells whether all requested
targets were made or not. If a dependency could not be made, the main
target was not made as well, therefore the exit status must be nonzero
in such a case.

This part of the code lacked proper unit tests until today. The unit
test deptgt-end-fail.mk is compatible with make>=2003 at least, allowing
to compare the output over time.

In 2003, in the ok-ok-ok-ok case, "Making all from all-dep." was printed
twice in a row, for whatever reason ... (40 minutes later) ... If I had
just made the two commands for 'all' and '.END' more distinguishable.
Back in 2003, the local variables for .END had not been initialized,
instead the .END node was run with the local variables of the last
preceding node. In this case, that node was 'all', therefore ${.TARGET}
had obviously expanded to 'all'.

Somewhere in 2004, the shell commands were no longer run with the -e
flag, which resulted in the "exit status $?" line to be printed in cases
that had stopped early before.

Somewhere in 2005, the local variables for the .END node had been fixed.
The variable ${.TARGET} now had the value '.END', just as expected. In
addition, the dependencies for the .END node were made, although without
getting their proper local variables. This resulted in the output
"Making out of nothing" instead of the expected "Making end-dep out of
nothing".

Still in 2005, in the test case "all=ok all-dep=ok end=ok end-dep=ERR",
the error code of the failed 'end-dep' was first reported as "*** Error
code 1 (continuing)". To compensate for this improvement, a new bug had
been introduced. The test case "all=ok all-dep=ok end=ERR end-dep=ERR"
had properly exited with status 1 on 2005-01-01, but on 2006-01-01 it
exited with status 0, thereby ignoring errors in the .END node.

Somewhere in 2008, some of the error messages (but not all) were
directed to stderr instead of stdout. The actual output stayed the same
though.

Somewhere in 2011, the dependency of the .END node got its own local
variables, and ${.TARGET} now expanded to 'end-dep', as expected.

Somewhere in 2016, the two empty lines between the "*** Error code 1
(continuing)" and the "Stop." got compressed into a single empty line.

On 2020-12-07 (that is, today), the exit status 1 has been restored in
the error cases, after it had been wrong for at least 14 years.
 1.4 06-Dec-2020  rillig make(1): test all combinations of failed main and .END targets

Adding an individual test for each of the 16 combinations would have
been too much manual work, and it's not easy to come up with a good
naming scheme for all the tests, keeping them short and expressive at
the same time.
 1.3 06-Dec-2020  rillig make(1): add test for .END after failed main node
 1.2 24-Nov-2020  rillig make(1): fix missing "Stop." after failed .END node in -k mode
 1.1 24-Nov-2020  rillig make(1): add test for missing "Stop" after error in .END
 1.6.8.1 02-Aug-2025  perseant Sync with HEAD
 1.7 07-May-2022  rillig make: rename Compat_Run to Compat_MakeAll

No functional change.
 1.6 07-Dec-2020  rillig make(1): don't make .END if the main targets already failed

This only applies to -k mode. By default, make exits earlier and skips
the .END node as well if an error occurs.
 1.5 07-Dec-2020  rillig make(1): fix exit status in -k mode if a dependency fails

Whether in -k mode or not, the exit status tells whether all requested
targets were made or not. If a dependency could not be made, the main
target was not made as well, therefore the exit status must be nonzero
in such a case.

This part of the code lacked proper unit tests until today. The unit
test deptgt-end-fail.mk is compatible with make>=2003 at least, allowing
to compare the output over time.

In 2003, in the ok-ok-ok-ok case, "Making all from all-dep." was printed
twice in a row, for whatever reason ... (40 minutes later) ... If I had
just made the two commands for 'all' and '.END' more distinguishable.
Back in 2003, the local variables for .END had not been initialized,
instead the .END node was run with the local variables of the last
preceding node. In this case, that node was 'all', therefore ${.TARGET}
had obviously expanded to 'all'.

Somewhere in 2004, the shell commands were no longer run with the -e
flag, which resulted in the "exit status $?" line to be printed in cases
that had stopped early before.

Somewhere in 2005, the local variables for the .END node had been fixed.
The variable ${.TARGET} now had the value '.END', just as expected. In
addition, the dependencies for the .END node were made, although without
getting their proper local variables. This resulted in the output
"Making out of nothing" instead of the expected "Making end-dep out of
nothing".

Still in 2005, in the test case "all=ok all-dep=ok end=ok end-dep=ERR",
the error code of the failed 'end-dep' was first reported as "*** Error
code 1 (continuing)". To compensate for this improvement, a new bug had
been introduced. The test case "all=ok all-dep=ok end=ERR end-dep=ERR"
had properly exited with status 1 on 2005-01-01, but on 2006-01-01 it
exited with status 0, thereby ignoring errors in the .END node.

Somewhere in 2008, some of the error messages (but not all) were
directed to stderr instead of stdout. The actual output stayed the same
though.

Somewhere in 2011, the dependency of the .END node got its own local
variables, and ${.TARGET} now expanded to 'end-dep', as expected.

Somewhere in 2016, the two empty lines between the "*** Error code 1
(continuing)" and the "Stop." got compressed into a single empty line.

On 2020-12-07 (that is, today), the exit status 1 has been restored in
the error cases, after it had been wrong for at least 14 years.
 1.4 06-Dec-2020  rillig make(1): test all combinations of failed main and .END targets

Adding an individual test for each of the 16 combinations would have
been too much manual work, and it's not easy to come up with a good
naming scheme for all the tests, keeping them short and expressive at
the same time.
 1.3 06-Dec-2020  rillig make(1): add test for .END after failed main node
 1.2 24-Nov-2020  rillig make(1): add test for error in dependency of .END node in -k mode
 1.1 24-Nov-2020  rillig make(1): add test for missing "Stop" after error in .END
 1.1 23-Sep-2020  rillig make(1): fix assertion failure in -j mode with .END node

There had been two separate global variables for the .END node, and in
parallel mode, only the one in jobs.c was initialized.

The code in JobRun heads over to Compat_Make without calling Compat_Run
first, which left the variable ENDNode uninitialized.
 1.1 23-Sep-2020  rillig make(1): fix assertion failure in -j mode with .END node

There had been two separate global variables for the .END node, and in
parallel mode, only the one in jobs.c was initialized.

The code in JobRun heads over to Compat_Make without calling Compat_Run
first, which left the variable ENDNode uninitialized.
 1.4 23-Oct-2020  rillig make(1): add test for .END depending on another target
 1.3 22-Sep-2020  rillig make(1): add test for unintended double expansion of deferred commands
 1.2 29-Aug-2020  rillig make(1): add tests for .SILENT, .BEGIN and .END
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.6 23-Oct-2020  rillig make(1): add test for .END depending on another target
 1.5 23-Sep-2020  rillig make(1): fix assertion failure in -j mode with .END node

There had been two separate global variables for the .END node, and in
parallel mode, only the one in jobs.c was initialized.

The code in JobRun heads over to Compat_Make without calling Compat_Run
first, which left the variable ENDNode uninitialized.
 1.4 22-Sep-2020  rillig make(1): add test for unintended double expansion of deferred commands
 1.3 29-Aug-2020  rillig make(1): add tests for .SILENT, .BEGIN and .END
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.2 22-Jan-2022  rillig branches: 1.2.4;
tests/make: add a few more tests, mainly for special targets
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2.4.1 02-Aug-2025  perseant Sync with HEAD
 1.4 22-Jan-2022  rillig tests/make: add a few more tests, mainly for special targets
 1.3 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.2 22-Jan-2022  rillig branches: 1.2.4;
tests/make: add a few more tests, mainly for special targets
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2.4.1 02-Aug-2025  perseant Sync with HEAD
 1.4 22-Jan-2022  rillig tests/make: add a few more tests, mainly for special targets
 1.3 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 22-Jan-2022  rillig tests/make: add a few more tests, mainly for special targets
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 22-Jan-2022  rillig tests/make: add a few more tests, mainly for special targets
 1.3 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 23-Jan-2022  rillig tests/make: add a few more tests
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 23-Jan-2022  rillig tests/make: add a few more tests
 1.3 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.9 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.8 20-Dec-2023  rillig branches: 1.8.2;
make: fix confusing debug logging when deleting a variable

Be clear when deleting a variable is ignored and state the reason,
instead of only providing a keyword as a hint for insiders.
 1.7 26-Mar-2022  rillig make: add space after colon in debug logging for variables

These log messages are intended for human interpretation, so don't make
them unnecessarily hard to read.
 1.6 03-Mar-2022  rillig make: make debug logging for comparisons less technical
 1.5 05-Apr-2021  rillig make: in debug log, add space between scope and variable name

Without this space, the debug log looked more like line noise, even
though the only punctuation was a single innocent ':'. From a make
user's perspective, the variable name is a word of its own and should
not be visually glued to its namespace.
 1.4 15-Mar-2021  rillig make: change debug log for variable evaluation flags to lowercase

This makes them easier distinguishable from variable names since the
latter are usually uppercase.

No functional change outside debug mode.
 1.3 08-Nov-2020  rillig make(1): add more tests for parsing .MAKEFLAGS lines
 1.2 23-Oct-2020  rillig make(1): add test for dollar in .MAKEFLAGS target
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.8.2.1 02-Aug-2025  perseant Sync with HEAD
 1.9 19-Nov-2023  rillig tests/make: replace 'variable expressions' with 'expressions'
 1.8 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.7 29-Nov-2021  rillig tests/make: test escape sequences in string literals for .MAKEFLAGS

These escape sequences differ from those in string literals in
conditions. In "assignments" to .MAKEFLAGS, \n is a newline, while in a
line like '.if ${VAR} == "\n"', it is simply the letter 'n'.
 1.6 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.5 08-Nov-2020  rillig make(1): add more tests for parsing .MAKEFLAGS lines
 1.4 23-Oct-2020  rillig make(1): add test for dollar in .MAKEFLAGS target
 1.3 10-Sep-2020  rillig make(1): add test for .MAKEFLAGS
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 13-Dec-2021  rillig tests/make: extend tests for parsing makefiles
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 13-Dec-2021  rillig tests/make: extend tests for parsing makefiles
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.6 31-Oct-2024  rillig make: in the debug log, always qualify line number with filename

Previously, to find out the filename corresponding to a line number from
a 'Parsing' line, it was necessary to find the preceding
'SetFilenameVars' line, which was unnecessarily time-consuming and
distracting.

The 'filename:line' format matches the one used in PrintStackTrace, and
it differs from the one used in PrintLocation, as the former format is
more common in other tools.

Most of the affected unit tests only use the 'Parsing' lines to give
additional context to their debug log, so no structural changes there.
 1.5 28-Dec-2021  rillig branches: 1.5.4;
make: make debug logging for .ORDER more human-friendly

The interesting part of the .ORDER constraint is what is made before
what, so reveal this information in the debug log.

The debug output from the test looks a bit strange since it forces
'three' to be made before 'one', but that's because the test exercises
the edge case of introducing a circular dependency.
 1.4 28-Dec-2021  rillig make: make debug logging a bit more human-friendly

The previous log format "ParseReadLine (%d): '%s'" focused on the
implementation, it was not immediately obvious to a casual reader that
the number in parentheses was the line number. Additionally, having
both a colon and quotes in a log message is uncommon. The quotes have
been added in parse.c 1.127 from 2007-01-01.

The new log format "Parsing line %d: %s" is meant to be easier readable
by humans. The quotes are not needed since ParseReadLine always strips
trailing whitespace, leaving no room for ambiguities. The other log
messages follow common punctuation rules, which makes the beginning of
the line equally unambiguous. Before var.c 1.911 from 2021-04-05,
variable assignments were logged with the format "%s:%s = %s", without a
space after the colon.
 1.3 13-Dec-2021  rillig tests/make: extend tests for parsing makefiles
 1.2 17-Jun-2021  rillig tests/make: add test for circular dependency in .ORDER
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5.4.1 02-Aug-2025  perseant Sync with HEAD
 1.4 13-Dec-2021  rillig tests/make: extend tests for parsing makefiles
 1.3 17-Jun-2021  rillig tests/make: add test for circular dependency in .ORDER
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.4 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.3 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.2 13-Dec-2021  rillig branches: 1.2.4;
tests/make: extend tests for parsing makefiles
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2.4.1 02-Aug-2025  perseant Sync with HEAD
 1.4 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.3 13-Dec-2021  rillig branches: 1.3.4;
tests/make: extend tests for parsing makefiles
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3.4.1 02-Aug-2025  perseant Sync with HEAD
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 19-May-2024  sjg Dir_FindFile treat sysIncPath and defSysIncPath as special

Rather than play games with adding .DOTLAST and then having to
exclude that from .SYSPATH, just have Dir_FindFile check if
path is sysIncPath or defSysIncPath and behave as if .DOTLAST seen
and also skip the final search of .CURDIR.

Fix Dir_SetSYSPATH to use defSysIncPath if sysIncPath is empty.
 1.4 30-Apr-2024  sjg Subst DEFSYSPATH in deptgt-phony
 1.3 30-Apr-2024  sjg make: ensure '.include <makefile>' respects MAKESYSPATH

Since Dir_FindFile is used by '.include' and its variants,
and will first search .CURDIR unless the give path starts with
".DOTLAST".

Update unit-tests/opt-m-include-dir to test this.
 1.2 11-Feb-2022  rillig tests/make: reproduce filesystem lookup of .PHONY nodes

As described in PR toolchain/15164.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 11-Feb-2022  rillig tests/make: reproduce filesystem lookup of .PHONY nodes

As described in PR toolchain/15164.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 18-Apr-2022  rillig make: only switch to POSIX mode if '.POSIX:' is the first line

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html
says that in order to make a makefile POSIX-conforming, its first
non-comment line must be the special dependency line '.POSIX:' without
any source dependencies.

Previously, make switched to POSIX mode even if such a line occurred
anywhere else, which was allowed by POSIX but was deep in the
"unspecified behavior" area. For NetBSD make, there is no big
difference since it doesn't ship any <posix.mk> file, this change mainly
affects the bmake distribution.

Previously, makefiles that contain '.POSIX:' somewhere in the middle
could fail due to <posix.mk> resetting .SUFFIXES, among other things.

Suggested by Simon J. Gerraty, who also reviewed an earlier version of
this change.
 1.4 07-May-2022  rillig tests/make: document why deptgt-posix needs its own directory

As described in PR toolchain/15163, '.include <file>' first looks in the
current directory, using the system include path only as fallback.
 1.3 07-May-2022  rillig tests/make: clean up comments in test for .POSIX
 1.2 18-Apr-2022  sjg Never 'rm -rf ${TMPDIR}' when you cannot be sure what it is

Use a safer variable for a subdir of ${TMPDIR} that we know
we can remove safely.
 1.1 18-Apr-2022  rillig make: only switch to POSIX mode if '.POSIX:' is the first line

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html
says that in order to make a makefile POSIX-conforming, its first
non-comment line must be the special dependency line '.POSIX:' without
any source dependencies.

Previously, make switched to POSIX mode even if such a line occurred
anywhere else, which was allowed by POSIX but was deep in the
"unspecified behavior" area. For NetBSD make, there is no big
difference since it doesn't ship any <posix.mk> file, this change mainly
affects the bmake distribution.

Previously, makefiles that contain '.POSIX:' somewhere in the middle
could fail due to <posix.mk> resetting .SUFFIXES, among other things.

Suggested by Simon J. Gerraty, who also reviewed an earlier version of
this change.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 12-Feb-2022  rillig make: fix echoing of command with '-' in silent target in jobs mode

Since job.c 1.83 from 2003-12-20, the command had been echoed even if
the target had the attribute '.SILENT'.

In sh-flags.exp, each removed 'echo' command is below a target name
matching the pattern 'opt-?j????-tgt-??s-cmd-?i?', which means that the
target was marked as silent, either through a global '.SILENT'
declaration or the command line option '-s' or the attribute '.SILENT'
on the target.

Reported by Alan Barrett in PR#45356.
 1.1 12-Feb-2022  rillig tests/make: demonstrate bug for .SILENT in jobs mode (since 2003)

Reported 2011 in PR#45356.
 1.3 15-Apr-2022  rillig tests/make: adjust expectations to actual behavior

The bug in deptgt-silent-jobs.mk has been fixed, the debug logging for
comparing conditions and for deleting global variables has changed
intentionally.
 1.2 12-Feb-2022  rillig make: fix echoing of command with '-' in silent target in jobs mode

Since job.c 1.83 from 2003-12-20, the command had been echoed even if
the target had the attribute '.SILENT'.

In sh-flags.exp, each removed 'echo' command is below a target name
matching the pattern 'opt-?j????-tgt-??s-cmd-?i?', which means that the
target was marked as silent, either through a global '.SILENT'
declaration or the command line option '-s' or the attribute '.SILENT'
on the target.

Reported by Alan Barrett in PR#45356.
 1.1 12-Feb-2022  rillig tests/make: demonstrate bug for .SILENT in jobs mode (since 2003)

Reported 2011 in PR#45356.
 1.3 15-Nov-2020  rillig make(1): add loud target to the .SILENT test
 1.2 10-Sep-2020  rillig make(1): add test for .SILENT
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 15-Nov-2020  rillig make(1): add loud target to the .SILENT test
 1.3 10-Sep-2020  rillig make(1): add test for .SILENT
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 07-May-2025  rillig make: add end marker for -dg1, -dg2 and -dg3 debug log

The marker helps distinguish the output from sub-makes from the output
of the primary make.
 1.4 21-Nov-2020  rillig branches: 1.4.8;
make(1): test that suffixes can be listed in any order
 1.3 21-Oct-2020  rillig make(1): add suffix number to the debug log

Previously, I had taken that lonely number in the debug log for the
sNum, but it was the reference count.
 1.2 28-Aug-2020  rillig make(1): add test for the undocumented .NULL special dependency target
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4.8.1 02-Aug-2025  perseant Sync with HEAD
 1.4 21-Nov-2020  rillig make(1): test that suffixes can be listed in any order
 1.3 28-Aug-2020  rillig make(1): add test for the undocumented .NULL special dependency target
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.24 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.23 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.22 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.21 14-Jan-2025  rillig make: simplify parsing of dependency lines

The evaluation modes that allow or deny undefined variables have the same
effect in this case, as Var_Subst does not return an error marker.
 1.20 10-Jan-2025  rillig tests/make: test expressions based on undefined variables

When an undefined variable is used in a conditional, make complains about
"Malformed conditional", which is wrong since the conditional is
well-formed but errors out during evaluation.

In order to fix this wrong error message and preserve the remaining
behavior, cover the places in which an expression is evaluated with
undefined expressions being an error (VARE_EVAL_DEFINED), but with
neither producing an error message nor handling errors. This combination
results in the same behavior as evaluating the expressions in the mode
that allows undefined variables to be used in expressions.
 1.19 31-Oct-2024  rillig make: in the debug log, always qualify line number with filename

Previously, to find out the filename corresponding to a line number from
a 'Parsing' line, it was necessary to find the preceding
'SetFilenameVars' line, which was unnecessarily time-consuming and
distracting.

The 'filename:line' format matches the one used in PrintStackTrace, and
it differs from the one used in PrintLocation, as the former format is
more common in other tools.

Most of the affected unit tests only use the 'Parsing' lines to give
additional context to their debug log, so no structural changes there.
 1.18 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.17 06-Jul-2024  rillig tests/make: clean up tests

Prefer "expect+X" directives to be above the code generating them,
instead of "expect-X" directives below the code.

In varmod-edge.mk, separate the tests, as the common loop does not pull
its weight.
 1.16 05-Jul-2024  rillig make: in error messages, distinguish parsing from evaluating
 1.15 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.14 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.13 20-Apr-2024  rillig branches: 1.13.2;
make: provide more context information for parse/evaluate errors
 1.12 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.11 03-Jan-2023  rillig make: add more details to warning 'Extra targets ignored'

Seen in binutils/zlib/Makefile.in:1283, which defines both '.MAKE' and
'.PHONY' in the same line.
 1.10 28-Dec-2021  rillig make: make debug logging a bit more human-friendly

The previous log format "ParseReadLine (%d): '%s'" focused on the
implementation, it was not immediately obvious to a casual reader that
the number in parentheses was the line number. Additionally, having
both a colon and quotes in a log message is uncommon. The quotes have
been added in parse.c 1.127 from 2007-01-01.

The new log format "Parsing line %d: %s" is meant to be easier readable
by humans. The quotes are not needed since ParseReadLine always strips
trailing whitespace, leaving no room for ambiguities. The other log
messages follow common punctuation rules, which makes the beginning of
the line equally unambiguous. Before var.c 1.911 from 2021-04-05,
variable assignments were logged with the format "%s:%s = %s", without a
space after the colon.
 1.9 13-Dec-2021  rillig tests/make: extend tests for parsing makefiles
 1.8 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.7 23-Feb-2021  rillig make: improve error message for unknown modifier

Back in 1995, the modifiers were all single-character, and it made sense
to print only the first character. Nowadays, with ':S', ':@var@...@',
'::=' and several others, a little more context is useful to see where
the exact error is. The actual modifier is still guessed, and the guess
may be wrong as soon as backslashes get involved, but it is still better
than before.
 1.6 27-Dec-2020  rillig make(1): add test for ParseDependencyTargetWord
 1.5 15-Nov-2020  rillig make(1): add tests for edge cases when parsing directives
 1.4 14-Sep-2020  rillig make(1): in the deptgt test, describe what happens to the targets
 1.3 14-Sep-2020  rillig make(1): add test for the global variable 'targets' in parse.c
 1.2 14-Sep-2020  rillig make(1): add test for combining several special targets
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.13.2.1 02-Aug-2025  perseant Sync with HEAD
 1.24 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.23 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.22 10-Jan-2025  rillig tests/make: test expressions based on undefined variables

When an undefined variable is used in a conditional, make complains about
"Malformed conditional", which is wrong since the conditional is
well-formed but errors out during evaluation.

In order to fix this wrong error message and preserve the remaining
behavior, cover the places in which an expression is evaluated with
undefined expressions being an error (VARE_EVAL_DEFINED), but with
neither producing an error message nor handling errors. This combination
results in the same behavior as evaluating the expressions in the mode
that allows undefined variables to be used in expressions.
 1.21 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.20 06-Jul-2024  rillig tests/make: clean up tests

Prefer "expect+X" directives to be above the code generating them,
instead of "expect-X" directives below the code.

In varmod-edge.mk, separate the tests, as the common loop does not pull
its weight.
 1.19 05-Jul-2024  rillig make: in error messages, distinguish parsing from evaluating
 1.18 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.17 20-Apr-2024  rillig branches: 1.17.2;
make: provide more context information for parse/evaluate errors
 1.16 17-Dec-2023  rillig tests/make: in 'expect' lines, require the complete text of the line
 1.15 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.14 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.13 03-Jan-2023  rillig make: add more details to warning 'Extra targets ignored'

Seen in binutils/zlib/Makefile.in:1283, which defines both '.MAKE' and
'.PHONY' in the same line.
 1.12 13-Dec-2021  rillig tests/make: extend tests for parsing makefiles
 1.11 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.10 27-Dec-2020  rillig make(1): add test for ParseDependencyTargetWord
 1.9 15-Nov-2020  rillig make(1): add tests for edge cases when parsing directives
 1.8 18-Oct-2020  rillig make(1): rename Lst_Init to Lst_New

For the other types such as HashTable and Buffer, the Init function does
not allocate the memory for the structure itself, it only fills it.
 1.7 25-Sep-2020  rillig make(1): remove redundant variable inLine from parse.c

This variable has served at least 27 years bringing unnecessary
redundancy to the code. It was already redundant at 1993-03-21, when
the code was imported to NetBSD.
 1.6 25-Sep-2020  rillig make(1): rename ParseFinishLine to FinishDependencyGroup

Even after 27 or more years, it's not too late to fix bad function
names. This one for example does not finish a line but a dependency
group.
 1.5 14-Sep-2020  rillig make(1): in the deptgt test, describe what happens to the targets
 1.4 14-Sep-2020  rillig make(1): add test for the global variable 'targets' in parse.c
 1.3 14-Sep-2020  rillig make(1): add test for combining several special targets
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.17.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 22-Aug-2020  rillig make(1): add test for expanding wildcards in directories

This test covers DirExpandInt.
 1.1 22-Aug-2020  rillig make(1): add test for expanding wildcards in directories

This test covers DirExpandInt.
 1.7 31-Oct-2020  rillig make(1): add test for debug log for expansion of curly braces
 1.6 31-Oct-2020  rillig make(1): mark the output in test dir.mk with a prefix

This is needed to distinguish it from the debug log, which will be added
in the next commit.
 1.5 31-Jul-2020  rillig make(1): add a test for deeply nested brace dependency
 1.4 31-Jul-2020  rillig make(1): add more tests for expanding curly braces in dependencies
 1.3 31-Jul-2020  rillig make(1): fix regression and add test for empty brace expansion

This had been broken in r1.80 of dir.c, a few minutes ago.
 1.2 31-Jul-2020  rillig make(1): fix parsing of nested braces in dependency lines

Before, make could not parse {{thi,fou}r,fif}teen properly. It did
correctly split up the outer brace into "" + "{thi,fou}r,fif" + "teen",
but then, when expanding the inner braces, it interpreted the first
comma already as a separator, even though this comma was enclosed in
another set of braces.

This resulted in the wrong expansion "{thiteen", which produced the
error message. The next word "fouteen" was produced since the parser
stopped at the next closing brace. After this, parsing continued after
the closing brace, producing "rteen". Finally, the last expansion was
the correct "fifteen".
 1.1 31-Jul-2020  rillig make(1): add test for braces in dependency lines

The comment at DirExpandCurly says something about "recursively", but the
nested braces don't work.

The manual page only mentions that "{} may be used", but it keeps quiet
about the exact meaning and also doesn't mention any nesting.
 1.11 19-Dec-2023  rillig make: clean up comments

No binary change, except for line numbers in assertions.
 1.10 24-Jan-2023  sjg make: .SYSPATH: to add dirs to sysIncPath

.SYSPATH: with no sources will clear sysIncPath
otherwise sources are added

Reviewed by: rillig
 1.9 23-Jan-2021  rillig make(1): rename Dir_Expand to SearchPath_Expand

The main subject of this function is the search path. In this search
path the pattern is expanded.
 1.8 03-Nov-2020  rillig make(1): clean up unit tests
 1.7 31-Oct-2020  rillig make(1): add test for debug log for expansion of curly braces
 1.6 31-Oct-2020  rillig make(1): mark the output in test dir.mk with a prefix

This is needed to distinguish it from the debug log, which will be added
in the next commit.
 1.5 07-Sep-2020  rillig make(1): document that nested braces work as expected now
 1.4 31-Jul-2020  rillig make(1): add a test for deeply nested brace dependency
 1.3 31-Jul-2020  rillig make(1): add more tests for expanding curly braces in dependencies
 1.2 31-Jul-2020  rillig make(1): fix regression and add test for empty brace expansion

This had been broken in r1.80 of dir.c, a few minutes ago.
 1.1 31-Jul-2020  rillig make(1): add test for braces in dependency lines

The comment at DirExpandCurly says something about "recursively", but the
nested braces don't work.

The manual page only mentions that "{} may be used", but it keeps quiet
about the exact meaning and also doesn't mention any nesting.
 1.7 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.6 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.5 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.4 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.3 19-Aug-2023  rillig branches: 1.3.2;
make: add more details to error message about invalid lines
 1.2 23-Jan-2022  rillig tests/make: add a few more tests
 1.1 13-Sep-2020  rillig make(1): add tests for the various .include directives
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.5 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.4 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.3 19-Aug-2023  rillig branches: 1.3.2;
make: add more details to error message about invalid lines
 1.2 23-Jan-2022  rillig tests/make: add a few more tests
 1.1 13-Sep-2020  rillig make(1): add tests for the various .include directives
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.9 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.8 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.7 01-Jun-2023  rillig branches: 1.7.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.6 19-Dec-2020  rillig make(1): rewrite tests for misspelled .elif directive

Put the simple tests at the top, demonstrating that there are already
some cases in which the misspelled directive is detected. It's not
detected though if the surrounding conditional branch is skipped.
 1.5 12-Nov-2020  rillig make(1): move test for missing space after .if to correct file
 1.4 12-Nov-2020  rillig make(1): add test for missing space after .if directive
 1.3 10-Nov-2020  rillig make(1): add more tests for parsing .if directives

The details of parsing are quite tricky and not documented in the manual
page. Record the current behavior to be a little safer in future
refactorings.
 1.2 03-Nov-2020  rillig make(1): move tests from directives.mk to separate tests
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7.2.1 02-Aug-2025  perseant Sync with HEAD
 1.8 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.7 19-Dec-2020  rillig make(1): rewrite tests for misspelled .elif directive

Put the simple tests at the top, demonstrating that there are already
some cases in which the misspelled directive is detected. It's not
detected though if the surrounding conditional branch is skipped.
 1.6 12-Nov-2020  rillig make(1): move test for missing space after .if to correct file
 1.5 12-Nov-2020  rillig make(1): add test for missing space after .if directive
 1.4 10-Nov-2020  rillig make(1): add more tests for parsing .if directives

The details of parsing are quite tricky and not documented in the manual
page. Record the current behavior to be a little safer in future
refactorings.
 1.3 03-Nov-2020  rillig make(1): move tests from directives.mk to separate tests
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 09-Feb-2022  rillig make: fix mistakes, spelling and typos in comments and manual page

No binary change for -DNDEBUG.
 1.3 22-Jan-2022  rillig tests/make: explore edge cases involving .ifmake
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 22-Jan-2022  rillig tests/make: add a few more tests, mainly for special targets
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.8 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.7 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.6 01-Jun-2023  rillig branches: 1.6.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.5 09-Dec-2021  rillig make: remove period from end of error messages and warnings

The majority of the existing error messages and warnings does not
include a period at the end. Follow this style consistently.
 1.4 14-Dec-2020  rillig make(1): error out on .else with extraneous text
 1.3 13-Nov-2020  rillig make(1): in lint mode, check for ".else <cond>"
 1.2 29-Aug-2020  rillig make(1): add tests for .else and .for + .endif
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.6.2.1 02-Aug-2025  perseant Sync with HEAD
 1.9 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.8 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.7 14-Dec-2020  rillig make(1): error out on .else with extraneous text
 1.6 13-Nov-2020  rillig make(1): in lint mode, check for ".else <cond>"
 1.5 13-Nov-2020  rillig make(1): add more tests for parsing .else with argument
 1.4 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.3 29-Aug-2020  rillig make(1): add tests for .else and .for + .endif
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.2 01-Jun-2023  rillig branches: 1.2.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.1 30-Dec-2020  rillig make(1): add test for .endfor without corresponding .for
 1.2.2.1 02-Aug-2025  perseant Sync with HEAD
 1.2 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.1 30-Dec-2020  rillig make(1): add test for .endfor without corresponding .for
 1.7 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.6 01-Jun-2023  rillig branches: 1.6.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.5 01-Jun-2023  rillig tests/make: clean up comments, extend a few tests
 1.4 09-Dec-2021  rillig make: remove period from end of error messages and warnings

The majority of the existing error messages and warnings does not
include a period at the end. Follow this style consistently.
 1.3 14-Dec-2020  rillig make(1): error out if an '.endif' contains extraneous text
 1.2 14-Dec-2020  rillig make(1): add more tests for parsing .endif
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.6.2.1 02-Aug-2025  perseant Sync with HEAD
 1.7 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.6 01-Jun-2023  rillig tests/make: clean up comments, extend a few tests
 1.5 14-Dec-2020  rillig make(1): error out if an '.endif' contains extraneous text
 1.4 14-Dec-2020  rillig make(1): add more tests for parsing .endif
 1.3 12-Nov-2020  rillig make(1): add test for missing check on .endif with arguments
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.4 01-Jun-2023  rillig branches: 1.4.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.3 27-Jan-2021  rillig make(1): fix irrelevant message in -W mode
 1.2 26-Jan-2021  rillig make(1): demonstrate irrelevant message about warnings as errors
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4.2.1 02-Aug-2025  perseant Sync with HEAD
 1.6 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.5 27-Jan-2021  rillig make(1): fix irrelevant message in -W mode
 1.4 26-Jan-2021  rillig make(1): demonstrate irrelevant message about warnings as errors
 1.3 13-Dec-2020  rillig make(1): error out on misspelled directives

Before, make accepted misspellings like .warnings, .export-literally and
a few others, all of which are unlikely to occur in practice. See the
test directive-misspellings.mk for further details.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 13-Dec-2020  rillig make(1): error out on misspelled directives

Before, make accepted misspellings like .warnings, .export-literally and
a few others, all of which are unlikely to occur in practice. See the
test directive-misspellings.mk for further details.
 1.3 03-Nov-2020  rillig make(1): move tests from directives.mk to separate tests
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.9 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.8 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.7 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.6 19-Nov-2023  rillig branches: 1.6.2;
tests/make: test and explain exporting of variables
 1.5 20-Aug-2023  rillig tests/make: show a difference between 'export' and '.export'
 1.4 19-Aug-2023  rillig make: show realistic invalid line in error message

Previously, the error message 'Invalid line' showed only the expanded
line, which might or might not show the actual problem. To be more
helpful, add the unexpanded line to the error message in case they
differ.

Remove the special handling of invalid lines that result from merge
conflicts. RCS is not commonly used anymore, and mentioning CVS was too
specific. By echoing the whole line, the patterns '<<<<<<' and '>>>>>>'
are clear enough to hint at the problem.
 1.3 19-Aug-2023  rillig make: add more details to error message about invalid lines
 1.2 19-Aug-2023  rillig tests/make: provide instructions for reproducing bug in gmtime

The test is not enabled because its results differ too much between the
platforms.
 1.1 02-Oct-2020  rillig make(1): add tests for parsing and exporting variables

Once again, there are a few surprises deeply hidden inside the edge
cases.
 1.6.2.1 02-Aug-2025  perseant Sync with HEAD
 1.10 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.9 17-Dec-2023  rillig branches: 1.9.2;
tests/make: in 'expect' lines, require the complete text of the line
 1.8 19-Nov-2023  rillig tests/make: test and explain exporting of variables
 1.7 20-Aug-2023  rillig tests/make: show a difference between 'export' and '.export'
 1.6 19-Aug-2023  rillig make: show realistic invalid line in error message

Previously, the error message 'Invalid line' showed only the expanded
line, which might or might not show the actual problem. To be more
helpful, add the unexpanded line to the error message in case they
differ.

Remove the special handling of invalid lines that result from merge
conflicts. RCS is not commonly used anymore, and mentioning CVS was too
specific. By echoing the whole line, the patterns '<<<<<<' and '>>>>>>'
are clear enough to hint at the problem.
 1.5 19-Aug-2023  rillig make: add more details to error message about invalid lines
 1.4 19-Aug-2023  rillig tests/make: provide instructions for reproducing bug in gmtime

The test is not enabled because its results differ too much between the
platforms.
 1.3 17-Nov-2020  rillig make(1): fix test directive-export-gmake for dash

Dash only accepts environment variables whose names follow the usual
naming conventions. (I didn't look up the exact details.) In
particular, it rejects environment variables whose names start or end
with spaces.

This would result in an empty output from grep, in which case the exit
status from the shell command is non-zero, thus make prints an error
about this. This error message should not appear in the test output, to
keep the test output the same for all platforms.
 1.2 19-Oct-2020  rillig make(1): fix test directive-export-gmake.mk for dash
 1.1 02-Oct-2020  rillig make(1): add tests for parsing and exporting variables

Once again, there are a few surprises deeply hidden inside the edge
cases.
 1.9.2.1 02-Aug-2025  perseant Sync with HEAD
 1.21 14-Jan-2025  rillig make: simplify parsing of dependency lines

The evaluation modes that allow or deny undefined variables have the same
effect in this case, as Var_Subst does not return an error marker.
 1.20 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.19 31-Oct-2024  rillig make: in the debug log, always qualify line number with filename

Previously, to find out the filename corresponding to a line number from
a 'Parsing' line, it was necessary to find the preceding
'SetFilenameVars' line, which was unnecessarily time-consuming and
distracting.

The 'filename:line' format matches the one used in PrintStackTrace, and
it differs from the one used in PrintLocation, as the former format is
more common in other tools.

Most of the affected unit tests only use the 'Parsing' lines to give
additional context to their debug log, so no structural changes there.
 1.18 14-Apr-2024  rillig branches: 1.18.2;
make: add debug logging for .if and .for lines in -dp mode

This helps track down in which line a condition is evaluated.
 1.17 03-Mar-2022  rillig make: make debug logging for comparisons less technical
 1.16 10-Jan-2022  rillig make: add debug logging for capturing the output of external commands

This applies to all 4 situations in which the output of an external
command is used for modifying a variable or an expression:

* the assignment operator '!='
* the assignment modifier '::!='
* the SUN shell modifier ':sh'
* the other shell modifier ':!cmd!'

Previously, only the shell modifier ':!cmd!' had debug logging.

Suggested by Christoph Badura.
 1.15 28-Dec-2021  rillig make: make debug logging a bit more human-friendly

The previous log format "ParseReadLine (%d): '%s'" focused on the
implementation, it was not immediately obvious to a casual reader that
the number in parentheses was the line number. Additionally, having
both a colon and quotes in a log message is uncommon. The quotes have
been added in parse.c 1.127 from 2007-01-01.

The new log format "Parsing line %d: %s" is meant to be easier readable
by humans. The quotes are not needed since ParseReadLine always strips
trailing whitespace, leaving no room for ambiguities. The other log
messages follow common punctuation rules, which makes the beginning of
the line equally unambiguous. Before var.c 1.911 from 2021-04-05,
variable assignments were logged with the format "%s:%s = %s", without a
space after the colon.
 1.14 20-Nov-2021  rillig make: use correct plural form in debug message
 1.13 06-Apr-2021  rillig make: reduce verbosity of the -dv debug logging for standard cases

The verbosity was already removed from LogBeforeApply, now it is
consistent between LogBeforeApply and LogAfterApply.
 1.12 05-Apr-2021  rillig make: in debug log, add space between scope and variable name

Without this space, the debug log looked more like line noise, even
though the only punctuation was a single innocent ':'. From a make
user's perspective, the variable name is a word of its own and should
not be visually glued to its namespace.
 1.11 05-Apr-2021  rillig make: omit unnecessary details from -dv debug log

When an expression is based on a defined variable, it does not matter
whether the evaluation mode is "eval" or "eval-defined", therefore omit
these details to reduce confusion.
 1.10 05-Apr-2021  rillig make: be more verbose in -dv debug logging

The previous log output was too brief to be understandable. Give more
hints by describing each part of the expression when evaluating a
modifier. Distinguish between parse-only mode and eval mode since in
parse-only mode most of the details are irrelevant.
 1.9 05-Apr-2021  rillig make: clean up debug logging for ':M' and ':N'

Using square brackets as quotes was confusing since patterns can contain
square brackets themselves.

The debug logging for VarMatch was a bit too detailed. Having the
"before" and "after" states is enough for all practically relevant
cases.
 1.8 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.7 03-Apr-2021  rillig make: replace enum bit-set with struct bit-fields

This makes the code easier to read, especially when setting one of the
flags to false.

No functional change.
 1.6 03-Apr-2021  rillig make: remove VarFlags from debug logging

Before the introduction of ExprDefined, VarFlags contained whether the
expression was defined or not, which was useful to know since the final
value of the expression depends on this information. The other VarFlags
do not influence the evaluation, so there is no point logging them.
 1.5 15-Mar-2021  rillig make: change debug log for variable evaluation flags to lowercase

This makes them easier distinguishable from variable names since the
latter are usually uppercase.

No functional change outside debug mode.
 1.4 16-Feb-2021  rillig make: rename constants for VarFlags

The old prefix was "VAR_" and this prefix is used for several other
constants as well, which made it ambiguous.
 1.3 15-Feb-2021  rillig make: rename ExprDefined constants for debug logging
 1.2 02-Feb-2021  rillig make: replace VarExprFlags with VarExprStatus

The combination of !VEF_UNDEF && VEF_DEF was not possible, which made it
rather strange to model this state as a bit set.

The only functional change is the renamed constants in the debug output.

Using ENUM_VALUE_RTTI_2 felt like overengineering since it's harder to
understand than a simple array of names.
 1.1 29-Dec-2020  rillig make(1): add test that explains how variables are exported

Exporting the variables at the right time and with the correct values is
a subtle issue. The current implementation carefully marks variables as
ready to be exported, then exports them and at the same time tries to
export as few variables as possible, to avoid memory leaks. This test
describes and explains how all this works in detail.

This test also justifies that the call to Var_ReexportVars happens in
the make process itself, not in the child processes, no matter whether
these are created with vfork or (only theoretically) with plain fork.
This has changed in compat.c 1.217, job.c 1.390 and main.c 1.504 from
2020-12-27.
 1.18.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 03-Apr-2021  rillig make: replace enum bit-set with struct bit-fields

This makes the code easier to read, especially when setting one of the
flags to false.

No functional change.
 1.2 16-Feb-2021  rillig make: rename constants for VarFlags

The old prefix was "VAR_" and this prefix is used for several other
constants as well, which made it ambiguous.
 1.1 29-Dec-2020  rillig make(1): add test that explains how variables are exported

Exporting the variables at the right time and with the correct values is
a subtle issue. The current implementation carefully marks variables as
ready to be exported, then exports them and at the same time tries to
export as few variables as possible, to avoid memory leaks. This test
describes and explains how all this works in detail.

This test also justifies that the call to Var_ReexportVars happens in
the make process itself, not in the child processes, no matter whether
these are created with vfork or (only theoretically) with plain fork.
This has changed in compat.c 1.217, job.c 1.390 and main.c 1.504 from
2020-12-27.
 1.5 01-Jun-2024  rillig tests/make: test more modifiers and special variables
 1.4 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.3 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.2 03-Oct-2020  rillig make(1): add test for .export-literal
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.8 01-Jun-2024  rillig tests/make: test more modifiers and special variables
 1.7 13-Dec-2020  rillig make(1): error out on misspelled directives

Before, make accepted misspellings like .warnings, .export-literally and
a few others, all of which are unlikely to occur in practice. See the
test directive-misspellings.mk for further details.
 1.6 03-Nov-2020  rillig make(1): move tests from directives.mk to separate tests
 1.5 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.4 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.3 03-Oct-2020  rillig make(1): add test for .export-literal
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.9 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.8 01-Jun-2024  rillig branches: 1.8.2;
tests/make: require all expected messages to be listed in the .mk files
 1.7 01-Jun-2024  sjg make: add .export-all

An explicit syntax for exporting all global variables is much safer
than allowing .export with no argument to do the same.

Add .export-all and have .export with no argument throw a warning saying
to use .export-all

Reviewed by: rillig
 1.6 19-Nov-2023  rillig tests/make: test and explain exporting of variables
 1.5 20-Aug-2023  rillig tests/make: show a difference between 'export' and '.export'
 1.4 13-Dec-2020  rillig make(1): error out on misspelled directives

Before, make accepted misspellings like .warnings, .export-literally and
a few others, all of which are unlikely to occur in practice. See the
test directive-misspellings.mk for further details.
 1.3 12-Dec-2020  rillig make(1): extract ExportVars from Var_Export
 1.2 03-Nov-2020  rillig make(1): move tests from directives.mk to separate tests
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.8.2.1 02-Aug-2025  perseant Sync with HEAD
 1.12 01-Jun-2024  rillig tests/make: require all expected messages to be listed in the .mk files
 1.11 01-Jun-2024  sjg make: add .export-all

An explicit syntax for exporting all global variables is much safer
than allowing .export with no argument to do the same.

Add .export-all and have .export with no argument throw a warning saying
to use .export-all

Reviewed by: rillig
 1.10 19-Nov-2023  rillig tests/make: test and explain exporting of variables
 1.9 20-Aug-2023  rillig tests/make: show a difference between 'export' and '.export'
 1.8 16-Feb-2021  rillig make: test exporting a variable that itself depends on a subprocess

When the point that "isn't going to end well" is reached, the stacktrace
is quite long but still reasonable:

main
main_ReadFiles
ReadAllMakefiles
ReadMakefile directive-export.mk
Parse_File
ParseLine # line 3 has: _!= :;:
ParseVarassign
Parse_DoVar
VarAssign_Eval
VarAssign_EvalShell # because of the '!='
Cmd_Exec :;:
Var_ReexportVars # before starting the subprocess
ExportVar EMPTY_SHELL
ExportVarEnv # was only marked for export
Var_Subst ${EMPTY_SHELL} # to get the value to export
VarSubstExpr ${EMPTY_SHELL}
Var_Parse ${EMPTY_SHELL}
Var_Subst ${:sh} # since EMPTY_SHELL= ${:sh}
VarSubstExpr ${:sh}
Var_Parse ${:sh}
ApplyModifiers
ApplySingleModifier :sh
ApplyModifier
ApplyModifier_SunShell :sh
Cmd_Exec "" # empty command
Var_ReexportVars
ExportVar EMPTY_SHELL
ExportVarEnv # skipping this edge case
 1.7 16-Feb-2021  rillig make: clarify what .export ${:U} means
 1.6 13-Dec-2020  rillig make(1): error out on misspelled directives

Before, make accepted misspellings like .warnings, .export-literally and
a few others, all of which are unlikely to occur in practice. See the
test directive-misspellings.mk for further details.
 1.5 12-Dec-2020  rillig make(1): extract ExportVars from Var_Export
 1.4 03-Nov-2020  rillig make(1): move tests from directives.mk to separate tests
 1.3 29-Oct-2020  rillig make(1): add test for .export and Var_Delete
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.6 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.5 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.4 01-Jun-2023  rillig branches: 1.4.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.3 01-Jun-2023  rillig make: error out on a .break directive with arguments
 1.2 03-Sep-2022  rillig make: clean up handling of .break in .for loops

Move For_Break further up, as the functions in that file are sorted from
small to big. The cast from size_t to unsigned int is required by lint.

In parse.c, move the code into a separate function to keep
ParseDirective small. Its only job is to parse the directive and then
delegate to another function doing the actual work.

In the manual page, remove empty lines.

In the test, ensure that .break stops processing of the .for loop
immediately; anything after the .break is not processed anymore.
Replace ':=' with '=', as there is no need to evaluate '$i' early.
Check the expected value in the .mk file instead of the .exp file, to
keep the reading scope as small as possible.
 1.1 02-Sep-2022  sjg make: add .break to terminate .for loop early

When .break is encountered within a .for loop
it causes immediate termination.

Outside of a .for loop .break causes a parse error.

Reviewed by: christos
 1.4.2.1 02-Aug-2025  perseant Sync with HEAD
 1.5 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.4 01-Jun-2023  rillig make: error out on a .break directive with arguments
 1.3 24-Sep-2022  rillig tests/make: add test for .if/.for/.if/.break
 1.2 03-Sep-2022  rillig make: clean up handling of .break in .for loops

Move For_Break further up, as the functions in that file are sorted from
small to big. The cast from size_t to unsigned int is required by lint.

In parse.c, move the code into a separate function to keep
ParseDirective small. Its only job is to parse the directive and then
delegate to another function doing the actual work.

In the manual page, remove empty lines.

In the test, ensure that .break stops processing of the .for loop
immediately; anything after the .break is not processed anymore.
Replace ':=' with '=', as there is no need to evaluate '$i' early.
Check the expected value in the .mk file instead of the .exp file, to
keep the reading scope as small as possible.
 1.1 02-Sep-2022  sjg make: add .break to terminate .for loop early

When .break is encountered within a .for loop
it causes immediate termination.

Outside of a .for loop .break causes a parse error.

Reviewed by: christos
 1.5 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.4 31-May-2024  rillig branches: 1.4.2;
tests/make: replace or document .error in tests

The text 'Missing argument for ".error"' in an .exp file may be a hint
for an accidentally broken test, so eliminate them as far as possible.
 1.3 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.2 01-Jun-2023  rillig make: add more details to debug logging of .for loops
 1.1 23-May-2022  rillig tests/make: document and demonstrate .for i containing .if empty(i)

PR bin/43821 describes the inconsistency that in a '.for i' loop, the
condition '.if ${i:M*.c}' works since 2009 while the seemingly
equivalent condition '.if !empty(i:M*.c)' does not access the variable
'i' from the .for loop but instead the global 'i'.

Resolving this situation in a backwards-compatible and non-surprising
way is hard, as make has grown several features during the last 20 years
that interact in various edge cases. For now, document the most obvious
pitfalls.
 1.4.2.1 02-Aug-2025  perseant Sync with HEAD
 1.4 31-May-2024  rillig tests/make: replace or document .error in tests

The text 'Missing argument for ".error"' in an .exp file may be a hint
for an accidentally broken test, so eliminate them as far as possible.
 1.3 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.2 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.1 23-May-2022  rillig tests/make: document and demonstrate .for i containing .if empty(i)

PR bin/43821 describes the inconsistency that in a '.for i' loop, the
condition '.if ${i:M*.c}' works since 2009 while the seemingly
equivalent condition '.if !empty(i:M*.c)' does not access the variable
'i' from the .for loop but instead the global 'i'.

Resolving this situation in a backwards-compatible and non-surprising
way is hard, as make has grown several features during the last 20 years
that interact in various edge cases. For now, document the most obvious
pitfalls.
 1.14 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.13 03-May-2025  rillig make: miscellaneous cleanups
 1.12 30-Mar-2025  rillig make: if there is an error in the items of a .for loop, don't iterate
 1.11 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.10 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.9 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.8 06-Jul-2024  rillig tests/make: clean up tests

Prefer "expect+X" directives to be above the code generating them,
instead of "expect-X" directives below the code.

In varmod-edge.mk, separate the tests, as the common loop does not pull
its weight.
 1.7 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.6 20-Apr-2024  rillig branches: 1.6.2;
make: provide more context information for parse/evaluate errors
 1.5 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.4 09-May-2023  rillig make: skip syntactically wrong .for loops

When a .for loop cannot be interpreted correctly, for example when there
are no iteration variables or the number of words doesn't match the
iteration variables, skip the body of the .for loop instead of
interpreting it once.
 1.3 08-May-2023  rillig make: disallow characters like '$' in variable names in .for loops

Fixes PR 53146.
 1.2 23-Feb-2021  rillig make: improve error message for unknown modifier

Back in 1995, the modifiers were all single-character, and it made sense
to print only the first character. Nowadays, with ':S', ':@var@...@',
'::=' and several others, a little more context is useful to see where
the exact error is. The actual modifier is still guessed, and the guess
may be wrong as soon as backslashes get involved, but it is still better
than before.
 1.1 31-Dec-2020  rillig make(1): add test for error handling and expansion in .for loops
 1.6.2.1 02-Aug-2025  perseant Sync with HEAD
 1.18 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.17 03-May-2025  rillig make: miscellaneous cleanups
 1.16 30-Mar-2025  rillig make: if there is an error in the items of a .for loop, don't iterate
 1.15 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.14 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.13 06-Jul-2024  rillig tests/make: clean up tests

Prefer "expect+X" directives to be above the code generating them,
instead of "expect-X" directives below the code.

In varmod-edge.mk, separate the tests, as the common loop does not pull
its weight.
 1.12 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.11 01-Jun-2024  rillig branches: 1.11.2;
tests/make: test invalid character in a late .for variable name

This covers the cleanup code that frees the earlier variable names when
a late variable name is invalid.
 1.10 20-Apr-2024  rillig make: provide more context information for parse/evaluate errors
 1.9 19-Dec-2023  rillig make: clean up comments

No binary change, except for line numbers in assertions.
 1.8 17-Dec-2023  rillig tests/make: in 'expect' lines, require the complete text of the line
 1.7 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.6 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.5 09-May-2023  rillig make: skip syntactically wrong .for loops

When a .for loop cannot be interpreted correctly, for example when there
are no iteration variables or the number of words doesn't match the
iteration variables, skip the body of the .for loop instead of
interpreting it once.
 1.4 08-May-2023  rillig make: disallow characters like '$' in variable names in .for loops

Fixes PR 53146.
 1.3 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.2 04-Apr-2021  rillig make: rename ambiguous functions

These two functions have counterparts that include the word 'Do' in
their name, which is confusing.

No functional change.
 1.1 31-Dec-2020  rillig make(1): add test for error handling and expansion in .for loops
 1.11.2.1 02-Aug-2025  perseant Sync with HEAD
 1.35 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.34 11-Apr-2025  rillig make: convert more messages to the "file:123" format
 1.33 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.32 31-Oct-2024  rillig make: in the debug log, always qualify line number with filename

Previously, to find out the filename corresponding to a line number from
a 'Parsing' line, it was necessary to find the preceding
'SetFilenameVars' line, which was unnecessarily time-consuming and
distracting.

The 'filename:line' format matches the one used in PrintStackTrace, and
it differs from the one used in PrintLocation, as the former format is
more common in other tools.

Most of the affected unit tests only use the 'Parsing' lines to give
additional context to their debug log, so no structural changes there.
 1.31 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.30 07-Jul-2024  rillig tests/make: remove '# expect' lines from .exp file

These lines are only supposed to occur in .mk files.
 1.29 06-Jul-2024  rillig tests/make: clean up tests

Prefer "expect+X" directives to be above the code generating them,
instead of "expect-X" directives below the code.

In varmod-edge.mk, separate the tests, as the common loop does not pull
its weight.
 1.28 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.27 05-Jul-2024  rillig make: error out on unclosed expressions during parse time

In exchange, this adds location information.

For unnamed expressions, the value is no longer printed. This will be
added back in a follow-up commit.
 1.26 05-Jul-2024  rillig tests/make: add expected messages for "Unclosed expression"
 1.25 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.24 14-Apr-2024  rillig branches: 1.24.2;
make: add debug logging for .if and .for lines in -dp mode

This helps track down in which line a condition is evaluated.
 1.23 19-Nov-2023  rillig make: replace 'variable expression' with 'expression' in diagnostics
 1.22 23-Jun-2023  rillig tests/make: explain and extend tests for expansion in .for loops
 1.21 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.20 01-Jun-2023  rillig make: add more details to debug logging of .for loops
 1.19 09-May-2023  rillig make: skip syntactically wrong .for loops

When a .for loop cannot be interpreted correctly, for example when there
are no iteration variables or the number of words doesn't match the
iteration variables, skip the body of the .for loop instead of
interpreting it once.
 1.18 08-May-2023  rillig make: disallow characters like '$' in variable names in .for loops

Fixes PR 53146.
 1.17 12-Jun-2022  rillig make: document ExprLen, which is part of a .for loop

No binary change
 1.16 27-Jan-2022  rillig tests/make: add more edge cases for expansion of .for loop body
 1.15 27-Jan-2022  rillig tests/make: explain escaping in .for loops, add more test cases
 1.14 09-Jan-2022  rillig tests/make: add placeholders for .PARSEDIR and .INCLUDEDFROMDIR

When run via 'cd usr.bin/make/unit-tests && make test', the tests are in
the current directory. When run via ATF, the tests are in
/usr/tests/usr.bin/make/unit-tests, while the current directory is a
temporary directory. Allow both variants, plus others that may occur in
the bmake distribution.
 1.13 09-Jan-2022  rillig make: fix crash for newline in .for value in -dp mode (since yesterday)
 1.12 02-Sep-2021  rillig make: rename for_var_len to ExprLen

The text ${VAR} is not a variable, it's a variable expression.

No functional change.
 1.11 25-Jun-2021  rillig make: prevent newline injection in .for loops

When a value of a .for loop contained a literal newline, such as from
the expression ${.newline}, that newline was passed verbatim to the
"expanded current body" of the .for loop. There it was interpreted as a
literal newline, which ended the current line and started a new one.
This resulted in several syntax errors.

In cases like these, print a more precise error message.
 1.10 25-Jun-2021  rillig tests/make: demonstrate newline injection in .for loop
 1.9 24-Jun-2021  rillig tests/make: test .for loop over a variable named '$'

It's an impractical edge case, nevertheless it's accepted by make.
 1.8 23-Feb-2021  rillig make: improve error message for unclosed modifier

Replace "variable specification" with the more modern "variable
expression", reduce the number of parentheses, output more than a single
character for modifiers, make it obvious that in expressions such as
${:Serror}, the "" means a variable name.
 1.7 15-Feb-2021  rillig make: improve comments in test for expansions in .for loops
 1.6 25-Jan-2021  rillig make(1): rename struct For to struct ForLoop

This removes the ambiguity whether For_Free is meant to be a
module-exported function or a local function associate with that struct.
Rename the affected functions as well.
 1.5 24-Jan-2021  rillig make(1): describe expansion of nested variables in .for values

These edge cases are not documented anywhere, and their behavior is
non-intuitive. For now, just describe them, don't try to fix them.
There may be people out there relying on exactly this behavior.
 1.4 24-Jan-2021  rillig make(1): let the test directive-for-escape exit successfully

There is no reason for a non-zero exit status here.
 1.3 31-Dec-2020  rillig make(1): add test for common and edge cases in .for loop expansion
 1.2 31-Dec-2020  rillig make(1): add tests for extreme edge cases of .for loop expansion
 1.1 31-Dec-2020  rillig make(1): add test for error handling and expansion in .for loops
 1.24.2.1 02-Aug-2025  perseant Sync with HEAD
 1.30 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.29 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.28 07-Jul-2024  rillig tests/make: remove '# expect' lines from .exp file

These lines are only supposed to occur in .mk files.
 1.27 06-Jul-2024  rillig tests/make: clean up tests

Prefer "expect+X" directives to be above the code generating them,
instead of "expect-X" directives below the code.

In varmod-edge.mk, separate the tests, as the common loop does not pull
its weight.
 1.26 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.25 05-Jul-2024  rillig make: error out on unclosed expressions during parse time

In exchange, this adds location information.

For unnamed expressions, the value is no longer printed. This will be
added back in a follow-up commit.
 1.24 05-Jul-2024  rillig tests/make: add expected messages for "Unclosed expression"
 1.23 19-Nov-2023  rillig branches: 1.23.2;
tests/make: replace 'variable expressions' with 'expressions'
 1.22 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.21 23-Jun-2023  rillig tests/make: explain and extend tests for expansion in .for loops
 1.20 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.19 01-Jun-2023  rillig make: add more details to debug logging of .for loops
 1.18 09-May-2023  rillig make: skip syntactically wrong .for loops

When a .for loop cannot be interpreted correctly, for example when there
are no iteration variables or the number of words doesn't match the
iteration variables, skip the body of the .for loop instead of
interpreting it once.
 1.17 08-May-2023  rillig make: disallow characters like '$' in variable names in .for loops

Fixes PR 53146.
 1.16 12-Jun-2022  rillig make: document ExprLen, which is part of a .for loop

No binary change
 1.15 27-Jan-2022  rillig tests/make: add more edge cases for expansion of .for loop body
 1.14 27-Jan-2022  rillig tests/make: explain escaping in .for loops, add more test cases
 1.13 09-Jan-2022  rillig make: fix crash for newline in .for value in -dp mode (since yesterday)
 1.12 05-Dec-2021  rillig make: inline Str_Words into .for loop handling

This saves one memory allocation and a bit of copying, per .for loop.

No functional change.
 1.11 02-Sep-2021  rillig make: rename for_var_len to ExprLen

The text ${VAR} is not a variable, it's a variable expression.

No functional change.
 1.10 25-Jun-2021  rillig make: prevent newline injection in .for loops

When a value of a .for loop contained a literal newline, such as from
the expression ${.newline}, that newline was passed verbatim to the
"expanded current body" of the .for loop. There it was interpreted as a
literal newline, which ended the current line and started a new one.
This resulted in several syntax errors.

In cases like these, print a more precise error message.
 1.9 25-Jun-2021  rillig tests/make: demonstrate newline injection in .for loop
 1.8 24-Jun-2021  rillig tests/make: test .for loop over a variable named '$'

It's an impractical edge case, nevertheless it's accepted by make.
 1.7 15-Feb-2021  rillig make: improve comments in test for expansions in .for loops
 1.6 25-Jan-2021  rillig make(1): rename struct For to struct ForLoop

This removes the ambiguity whether For_Free is meant to be a
module-exported function or a local function associate with that struct.
Rename the affected functions as well.
 1.5 24-Jan-2021  rillig make(1): describe expansion of nested variables in .for values

These edge cases are not documented anywhere, and their behavior is
non-intuitive. For now, just describe them, don't try to fix them.
There may be people out there relying on exactly this behavior.
 1.4 24-Jan-2021  rillig make(1): let the test directive-for-escape exit successfully

There is no reason for a non-zero exit status here.
 1.3 31-Dec-2020  rillig make(1): add test for common and edge cases in .for loop expansion
 1.2 31-Dec-2020  rillig make(1): add tests for extreme edge cases of .for loop expansion
 1.1 31-Dec-2020  rillig make(1): add test for error handling and expansion in .for loops
 1.23.2.1 02-Aug-2025  perseant Sync with HEAD
 1.6 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.5 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.4 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.3 01-Jun-2023  rillig branches: 1.3.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.2 02-Jan-2022  rillig make: fix line number in error message about open conditionals
 1.1 29-Aug-2020  rillig make(1): add tests for .else and .for + .endif
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.2 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.1 29-Aug-2020  rillig make(1): add tests for .else and .for + .endif
 1.6 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.5 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.4 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.3 01-Jun-2023  rillig branches: 1.3.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.2 01-Sep-2021  rillig tests/make: fix test directive-for-if

The additional lines 'VAR1' and 'VAR3' were supposed to be there from
the beginning. I somehow managed to commit an inconsistent state of the
.mk and the .exp file.
 1.1 30-Aug-2021  rillig tests/make: explain where "${var}" in .for loops comes from
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.2 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.1 30-Aug-2021  rillig tests/make: explain where "${var}" in .for loops comes from
 1.6 30-Jun-2025  rillig tests/make: force expected lines to be listed in execution order

The diagnostics from the program to check the "expect" lines in the unit
test files were hard to follow since the "out-of-order" lines were
confusing. For out-of-order lines, state where they should be placed
instead.
 1.5 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.4 01-Jun-2023  rillig branches: 1.4.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.3 19-Dec-2020  rillig make(1): add test for backslash continuation lines in .for loops

This ensures that the line numbers for messages are the expected onces
in .for loops.

While experimenting with the backslash continuation lines, I noticed
that the reported line numbers for these are based on the number of
completely parsed physical lines, which nicely cancels out the + 1 that
has to be added for producing human-readable 1-based line numbers. It
would be more correct to report the parse errors on the first affected
line.
 1.2 19-Dec-2020  rillig make(1): fix line numbers in .for loops (since 2007-01-01)
 1.1 19-Dec-2020  rillig make(1): demonstrate wrong line numbers in .for loops, since 2007-01-01
 1.4.2.1 02-Aug-2025  perseant Sync with HEAD
 1.6 30-Jun-2025  rillig tests/make: force expected lines to be listed in execution order

The diagnostics from the program to check the "expect" lines in the unit
test files were hard to follow since the "out-of-order" lines were
confusing. For out-of-order lines, state where they should be placed
instead.
 1.5 01-Jun-2023  rillig branches: 1.5.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.4 08-May-2022  rillig tests/make: migrate cond1 test to other, more specific tests

The tests in cond1 were a mixture of "everything related to conditions",
and the test cases were heavily dependent on each other, which made them
hard to understand. Move each test case to its corresponding
special-purpose test.
 1.3 19-Dec-2020  rillig make(1): add test for backslash continuation lines in .for loops

This ensures that the line numbers for messages are the expected onces
in .for loops.

While experimenting with the backslash continuation lines, I noticed
that the reported line numbers for these are based on the number of
completely parsed physical lines, which nicely cancels out the + 1 that
has to be added for producing human-readable 1-based line numbers. It
would be more correct to report the parse errors on the first affected
line.
 1.2 19-Dec-2020  rillig make(1): fix line numbers in .for loops (since 2007-01-01)
 1.1 19-Dec-2020  rillig make(1): demonstrate wrong line numbers in .for loops, since 2007-01-01
 1.5.2.1 02-Aug-2025  perseant Sync with HEAD
 1.8 12-Jun-2025  rillig make: add program name to stack traces from sub-makes
 1.7 12-Jun-2025  rillig make: add quotes to "in directory" line in stack traces

The other lines in stack traces use quotes as well.
 1.6 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.5 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.4 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.3 01-Apr-2024  rillig branches: 1.3.2;
make: exit immediately after reading a null byte from a makefile

The chance of other garbage bytes in such a file is just too high.
 1.2 09-Dec-2021  rillig make: remove period from end of error messages and warnings

The majority of the existing error messages and warnings does not
include a period at the end. Follow this style consistently.
 1.1 19-Dec-2020  rillig make(1): add test for null byte in .for loop body
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.5 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.4 01-Apr-2024  rillig branches: 1.4.2;
make: exit immediately after reading a null byte from a makefile

The chance of other garbage bytes in such a file is just too high.
 1.3 12-Jun-2022  rillig tests/make: make test for null bytes in .for loop more readable
 1.2 08-May-2022  rillig tests/make: migrate cond1 test to other, more specific tests

The tests in cond1 were a mixture of "everything related to conditions",
and the test cases were heavily dependent on each other, which made them
hard to understand. Move each test case to its corresponding
special-purpose test.
 1.1 19-Dec-2020  rillig make(1): add test for null byte in .for loop body
 1.4.2.1 02-Aug-2025  perseant Sync with HEAD
 1.31 01-Jul-2025  rillig tests/make: require "expect" comments to start a line

Lua's string.gmatch function doesn't allow the anchor "^"; but its
string.gsub function does.
 1.30 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.29 30-Mar-2025  rillig make: if there is an error in the items of a .for loop, don't iterate
 1.28 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.27 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.26 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.25 06-Jul-2024  rillig tests/make: clean up tests

Prefer "expect+X" directives to be above the code generating them,
instead of "expect-X" directives below the code.

In varmod-edge.mk, separate the tests, as the common loop does not pull
its weight.
 1.24 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.23 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.22 20-Apr-2024  rillig branches: 1.22.2;
make: provide more context information for parse/evaluate errors
 1.21 06-Dec-2023  rillig tests/make: show how global variables are unaffected by .for loops
 1.20 19-Oct-2023  rillig tests/make: clean up, explain and reorganize several tests
 1.19 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.18 01-Jun-2023  rillig make: add more details to debug logging of .for loops
 1.17 10-May-2023  rillig tests/make: clean up tests for .for loops

Most of the tests from forloop.mk were already in directive-for.mk.
 1.16 09-May-2023  rillig make: skip syntactically wrong .for loops

When a .for loop cannot be interpreted correctly, for example when there
are no iteration variables or the number of words doesn't match the
iteration variables, skip the body of the .for loop instead of
interpreting it once.
 1.15 08-May-2023  rillig make: disallow characters like '$' in variable names in .for loops

Fixes PR 53146.
 1.14 08-May-2023  rillig tests/make: add more tests for unusual variable names in .for loops
 1.13 08-May-2023  rillig make: fix parsing of unusual line continuations in .for loops
 1.12 08-Jan-2022  rillig make: fix reported line numbers of continuation lines (since 2002)

Previously, multi-line directives like '.info' or '.error' reported the
line number of their last line instead of their first line, which is
more usual. This also affected the debug log from '-dp'.
 1.11 08-Jan-2022  rillig tests/make: demonstrate edge case in parsing .for loops
 1.10 02-Jan-2022  rillig tests/make: test edge cases in .for loops
 1.9 23-Feb-2021  rillig make: improve error message for unknown modifier

Back in 1995, the modifiers were all single-character, and it made sense
to print only the first character. Nowadays, with ':S', ':@var@...@',
'::=' and several others, a little more context is useful to see where
the exact error is. The actual modifier is still guessed, and the guess
may be wrong as soon as backslashes get involved, but it is still better
than before.
 1.8 27-Dec-2020  rillig make(1): add test for missing error handling in .for loop
 1.7 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.6 25-Oct-2020  rillig make(1): test funny character in .for variable names
 1.5 25-Oct-2020  rillig make(1): add test for escaping parentheses and braces in .for loops
 1.4 22-Sep-2020  rillig make(1): remove obsolete fix for PR bin/29985
 1.3 22-Sep-2020  rillig make(1): add test for .for loop from PR bin/29985
 1.2 14-Sep-2020  rillig make(1): add test for nested .for loops with the same variable name
 1.1 02-Sep-2020  rillig make(1): add test for the .for directive

For a long time, I had assumed that the iteration variables of a .for
loop are just normal global variables. This assumption was wrong but
didn't have any consequences.

The iteration variables of a .for loop can just be accessed like global
variables, therefore it is not obvious that they are implemented in a
completely different way.

There are some edge cases in conditions used inside .for loops, in which
the iteration variables cannot be used like normal variables. An
example is brought up in https://gnats.netbsd.org/47888, which observes
that the defined() and empty() functions in conditions only work with
variables but ignore the iteration "variables", simply because these are
not variables but only expressions.
 1.22.2.1 02-Aug-2025  perseant Sync with HEAD
 1.32 01-Jul-2025  rillig tests/make: require "expect" comments to start a line

Lua's string.gmatch function doesn't allow the anchor "^"; but its
string.gsub function does.
 1.31 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.30 30-Mar-2025  rillig make: if there is an error in the items of a .for loop, don't iterate
 1.29 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.28 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.27 06-Jul-2024  rillig tests/make: clean up tests

Prefer "expect+X" directives to be above the code generating them,
instead of "expect-X" directives below the code.

In varmod-edge.mk, separate the tests, as the common loop does not pull
its weight.
 1.26 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.25 20-Apr-2024  rillig branches: 1.25.2;
make: provide more context information for parse/evaluate errors
 1.24 06-Dec-2023  rillig tests/make: show how global variables are unaffected by .for loops
 1.23 19-Oct-2023  rillig tests/make: clean up, explain and reorganize several tests
 1.22 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.21 01-Jun-2023  rillig tests/make: clean up comments, extend a few tests
 1.20 10-May-2023  rillig tests/make: clean up tests for .for loops

Most of the tests from forloop.mk were already in directive-for.mk.
 1.19 09-May-2023  rillig make: skip syntactically wrong .for loops

When a .for loop cannot be interpreted correctly, for example when there
are no iteration variables or the number of words doesn't match the
iteration variables, skip the body of the .for loop instead of
interpreting it once.
 1.18 08-May-2023  rillig make: disallow characters like '$' in variable names in .for loops

Fixes PR 53146.
 1.17 08-May-2023  rillig tests/make: add more tests for unusual variable names in .for loops
 1.16 08-May-2023  rillig make: fix parsing of unusual line continuations in .for loops
 1.15 01-Oct-2022  rillig tests/make: make comment in test for .for easier to understand
 1.14 23-Aug-2022  rillig tests/make: demonstrate that .for variables take precedence
 1.13 15-Jan-2022  rillig tests/make: ensure that the 'expect' comments in tests are correct

Based on tests/usr.bin/xlint/check-expect.lua.

For now, this extra check needs to be run manually.
 1.12 08-Jan-2022  rillig tests/make: demonstrate edge case in parsing .for loops
 1.11 02-Jan-2022  rillig tests/make: test edge cases in .for loops
 1.10 27-Dec-2020  rillig make(1): add test for missing error handling in .for loop
 1.9 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.8 25-Oct-2020  rillig make(1): test funny character in .for variable names
 1.7 25-Oct-2020  rillig make(1): add test for escaping parentheses and braces in .for loops
 1.6 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.5 22-Sep-2020  rillig make(1): remove obsolete fix for PR bin/29985
 1.4 22-Sep-2020  rillig make(1): add test for .for loop from PR bin/29985
 1.3 14-Sep-2020  rillig make(1): add test for nested .for loops with the same variable name
 1.2 02-Sep-2020  rillig make(1): fix wrong comments in test for the .for loop

These comments were my original assumptions, which I wrote before
running the test and before looking at the implementation.
 1.1 02-Sep-2020  rillig make(1): add test for the .for directive

For a long time, I had assumed that the iteration variables of a .for
loop are just normal global variables. This assumption was wrong but
didn't have any consequences.

The iteration variables of a .for loop can just be accessed like global
variables, therefore it is not obvious that they are implemented in a
completely different way.

There are some edge cases in conditions used inside .for loops, in which
the iteration variables cannot be used like normal variables. An
example is brought up in https://gnats.netbsd.org/47888, which observes
that the defined() and empty() functions in conditions only work with
variables but ignore the iteration "variables", simply because these are
not variables but only expressions.
 1.25.2.1 02-Aug-2025  perseant Sync with HEAD
 1.7 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.6 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.5 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.4 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.3 19-Aug-2023  rillig branches: 1.3.2;
make: add more details to error message about invalid lines
 1.2 23-Jan-2022  rillig tests/make: add a few more tests
 1.1 13-Sep-2020  rillig make(1): add tests for the various .include directives
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.5 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.4 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.3 19-Aug-2023  rillig branches: 1.3.2;
make: add more details to error message about invalid lines
 1.2 23-Jan-2022  rillig tests/make: add a few more tests
 1.1 13-Sep-2020  rillig make(1): add tests for the various .include directives
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.2 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.1 10-Nov-2020  rillig branches: 1.1.8;
make(1): add more tests for parsing .if directives

The details of parsing are quite tricky and not documented in the manual
page. Record the current behavior to be a little safer in future
refactorings.
 1.1.8.1 02-Aug-2025  perseant Sync with HEAD
 1.2 03-Jan-2025  rillig tests/make: properly label deeply nested .if directives
 1.1 10-Nov-2020  rillig branches: 1.1.8;
make(1): add more tests for parsing .if directives

The details of parsing are quite tricky and not documented in the manual
page. Record the current behavior to be a little safer in future
refactorings.
 1.1.8.1 02-Aug-2025  perseant Sync with HEAD
 1.14 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.13 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.12 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.11 01-Jun-2023  rillig branches: 1.11.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.10 23-Jan-2022  rillig tests/make: add a few more tests
 1.9 09-Jan-2022  rillig tests/make: ensure that '.ifn' is an unknown directive

Due to the way DetermineKindOfConditional works, it could have been that
'.ifn' is treated like the negation of the plain '.if'.
 1.8 19-Dec-2020  rillig make(1): fix error message for .info/.warning/.error without argument

Previously, the error message was "Unknown directive", which was
obviously wrong. The new error message is "Missing argument".
 1.7 14-Dec-2020  rillig make(1): add tests for parsing .if conditions
 1.6 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.5 12-Nov-2020  rillig make(1): move test for missing space after .if to correct file
 1.4 10-Nov-2020  rillig make(1): add more tests for parsing .if directives

The details of parsing are quite tricky and not documented in the manual
page. Record the current behavior to be a little safer in future
refactorings.
 1.3 10-Nov-2020  rillig make(1): fix error message when parsing unknown .if (since 2005-05-01)
 1.2 10-Nov-2020  rillig make(1): add tests for parsing conditionals, document a parsing bug
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.11.2.1 02-Aug-2025  perseant Sync with HEAD
 1.14 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.13 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.12 01-Jun-2023  rillig branches: 1.12.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.11 23-Jan-2022  rillig tests/make: add a few more tests
 1.10 09-Jan-2022  rillig tests/make: ensure that '.ifn' is an unknown directive

Due to the way DetermineKindOfConditional works, it could have been that
'.ifn' is treated like the negation of the plain '.if'.
 1.9 19-Dec-2020  rillig make(1): fix error message for .info/.warning/.error without argument

Previously, the error message was "Unknown directive", which was
obviously wrong. The new error message is "Missing argument".
 1.8 14-Dec-2020  rillig make(1): add tests for parsing .if conditions
 1.7 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.6 12-Nov-2020  rillig make(1): move test for missing space after .if to correct file
 1.5 10-Nov-2020  rillig make(1): add more tests for parsing .if directives

The details of parsing are quite tricky and not documented in the manual
page. Record the current behavior to be a little safer in future
refactorings.
 1.4 10-Nov-2020  rillig make(1): fix error message when parsing unknown .if (since 2005-05-01)
 1.3 10-Nov-2020  rillig make(1): add tests for parsing conditionals, document a parsing bug
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.12.2.1 02-Aug-2025  perseant Sync with HEAD
 1.4 23-Jan-2022  rillig tests/make: add a few more tests
 1.3 21-Jan-2021  rillig make(1): add tests for string literals in .ifdef
 1.2 08-Nov-2020  rillig make(1): add test for function call in .ifdef directive
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 23-Jan-2022  rillig tests/make: add a few more tests
 1.4 21-Jan-2021  rillig make(1): add tests for string literals in .ifdef
 1.3 08-Nov-2020  rillig make(1): add test for function call in .ifdef directive
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.9 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.8 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.7 01-Jun-2023  rillig branches: 1.7.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.6 22-Jan-2022  rillig tests/make: explore edge cases involving .ifmake
 1.5 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.4 11-Nov-2020  rillig make(1): add test to cover the If_Eval call in EvalNotEmpty
 1.3 30-Aug-2020  rillig make(1): extend test for .ifmake and .MAKEFLAGS
 1.2 29-Aug-2020  rillig make(1): add test for the .ifmake directive
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7.2.1 02-Aug-2025  perseant Sync with HEAD
 1.12 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.11 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.10 09-Feb-2022  rillig make: fix mistakes, spelling and typos in comments and manual page

No binary change for -DNDEBUG.
 1.9 22-Jan-2022  rillig tests/make: explore edge cases involving .ifmake
 1.8 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.7 11-Nov-2020  rillig make(1): add test to cover the If_Eval call in EvalNotEmpty
 1.6 08-Nov-2020  rillig make(1): add test for .ifmake 0 and .ifmake 1
 1.5 06-Nov-2020  rillig make(1): fix indentation in test directive-ifmake
 1.4 30-Aug-2020  rillig make(1): extend test for .ifmake and .MAKEFLAGS
 1.3 29-Aug-2020  rillig make(1): add test for the .ifmake directive
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.6 19-Jun-2023  rillig branches: 1.6.2;
tests/make: test triple negation in '.ifndef'
 1.5 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.4 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.3 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.2 04-Oct-2020  rillig make(1): add tests for .ifndef and .ifnmake
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.6.2.1 02-Aug-2025  perseant Sync with HEAD
 1.9 19-Oct-2023  rillig tests/make: clean up, explain and reorganize several tests
 1.8 19-Jun-2023  rillig tests/make: test triple negation in '.ifndef'
 1.7 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.6 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.5 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.4 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.3 04-Oct-2020  rillig make(1): add tests for .ifndef and .ifnmake
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.3 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.2 04-Oct-2020  rillig make(1): add tests for .ifndef and .ifnmake
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.4 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.3 04-Oct-2020  rillig make(1): add tests for .ifndef and .ifnmake
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.6 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.5 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.4 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.3 01-Jun-2023  rillig branches: 1.3.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.2 13-Sep-2020  rillig make(1): fix line number in expected test result for .include
 1.1 13-Sep-2020  rillig make(1): add tests for the various .include directives
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.6 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.5 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.4 01-Jun-2023  rillig branches: 1.4.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.3 01-Feb-2021  rillig make: rename Parse_include_file to IncludeFile
 1.2 13-Sep-2020  rillig make(1): test another attempt at resuming from fatal errors
 1.1 13-Sep-2020  rillig make(1): add tests for the various .include directives
 1.4.2.1 02-Aug-2025  perseant Sync with HEAD
 1.17 11-Apr-2025  rillig make: convert more messages to the "file:123" format
 1.16 07-Aug-2024  rillig make: in erroneous conditions, report the non-expanded text

In a condition, when a function call expression is missing its closing
parenthesis, there's no point in having the expanded argument text in
the error message.

When parsing a bare word in a condition, the trailing space was included
in that word, which was inconsistent, as the leading space was not
included either. Removing the trailing space from the word reduces the
cases where a multiple-inclusion guard steps in, but only in an edge
case that is irrelevant in practice.
 1.15 07-Aug-2024  rillig tests/make: demonstrate unintended parsing of words in conditions

A word is not supposed to include its trailing space, as it doesn't
contain its leading space either.
 1.14 17-Dec-2023  rillig branches: 1.14.2;
tests/make: extend tests for include guards and empty expressions
 1.13 17-Dec-2023  rillig tests/make: add tests for spacing in multiple-inclusion guards
 1.12 19-Oct-2023  rillig tests/make: clean up, explain and reorganize several tests
 1.11 11-Aug-2023  rillig make: clean up multiple-inclusion guards

No functional change.
 1.10 21-Jun-2023  sjg Cleanup guard tests

The .PARSEFILE:tA tests add no value, the correct form
is ${.PARSEDIR:tA}/${.PARSEFILE} but even there :tA rarely matters.
 1.9 21-Jun-2023  rillig make: skip a file protected by a multiple-inclusion guard more often

In practice, the common situation is that a file is first included,
defines its multiple-inclusion guard and is then skipped instead of
being included again.

The other way round is that the multiple-inclusion guard is defined when
the file is included first. In that case, the file is now regarded as
guarded as well.
 1.8 21-Jun-2023  rillig tests/make: clean up and extend tests for multiple-inclusion guards

Multiple-inclusion guards can be defined either as variables or as
targets. Rename the variable tests so they include the word 'variable'.

Add tests to cover special characters in guard names (both variable and
target), just in case ParseVarnameGuard gets removed someday.

Document the pitfalls associated with choosing a naming scheme for
guards that leads to name clashes, such as with .PARSEFILE without
.PARSEDIR.
 1.7 21-Jun-2023  sjg Allow guard targets to use variables.

I commonly use __${.PARSEDIR:tA}__ where a unique guard
is needed, __${.PARSEDIR}__ is also useful in many cases.

Combination of patch from rillig and mine
 1.6 20-Jun-2023  rillig make: allow targets to be used as multiple-inclusion guards

This style is used by FreeBSD, among others.
 1.5 19-Jun-2023  rillig make: add tests for full code coverage of multiple-inclusion guards
 1.4 19-Jun-2023  rillig make: if a makefile is protected by a guard, only include it once

"looks reasonable" sjg@
 1.3 18-Jun-2023  rillig tests/make: clean up test for multiple-inclusion guards
 1.2 18-Jun-2023  rillig tests/make: extend test for multiple-inclusion guards
 1.1 16-Jun-2023  rillig tests/make: add test for multiple-inclusion guards
 1.14.2.1 02-Aug-2025  perseant Sync with HEAD
 1.19 11-Apr-2025  rillig make: convert more messages to the "file:123" format
 1.18 07-Aug-2024  rillig make: in erroneous conditions, report the non-expanded text

In a condition, when a function call expression is missing its closing
parenthesis, there's no point in having the expanded argument text in
the error message.

When parsing a bare word in a condition, the trailing space was included
in that word, which was inconsistent, as the leading space was not
included either. Removing the trailing space from the word reduces the
cases where a multiple-inclusion guard steps in, but only in an edge
case that is irrelevant in practice.
 1.17 07-Aug-2024  rillig tests/make: demonstrate unintended parsing of words in conditions

A word is not supposed to include its trailing space, as it doesn't
contain its leading space either.
 1.16 17-Dec-2023  rillig branches: 1.16.2;
tests/make: extend tests for include guards and empty expressions
 1.15 17-Dec-2023  rillig tests/make: add tests for spacing in multiple-inclusion guards
 1.14 17-Dec-2023  rillig make: clean up names of local variables

No binary change.
 1.13 19-Oct-2023  rillig tests/make: clean up, explain and reorganize several tests
 1.12 11-Aug-2023  rillig make: clean up multiple-inclusion guards

No functional change.
 1.11 21-Jun-2023  sjg Cleanup guard tests

The .PARSEFILE:tA tests add no value, the correct form
is ${.PARSEDIR:tA}/${.PARSEFILE} but even there :tA rarely matters.
 1.10 21-Jun-2023  rillig make: skip a file protected by a multiple-inclusion guard more often

In practice, the common situation is that a file is first included,
defines its multiple-inclusion guard and is then skipped instead of
being included again.

The other way round is that the multiple-inclusion guard is defined when
the file is included first. In that case, the file is now regarded as
guarded as well.
 1.9 21-Jun-2023  rillig tests/make: clean up and extend tests for multiple-inclusion guards

Multiple-inclusion guards can be defined either as variables or as
targets. Rename the variable tests so they include the word 'variable'.

Add tests to cover special characters in guard names (both variable and
target), just in case ParseVarnameGuard gets removed someday.

Document the pitfalls associated with choosing a naming scheme for
guards that leads to name clashes, such as with .PARSEFILE without
.PARSEDIR.
 1.8 21-Jun-2023  sjg Allow guard targets to use variables.

I commonly use __${.PARSEDIR:tA}__ where a unique guard
is needed, __${.PARSEDIR}__ is also useful in many cases.

Combination of patch from rillig and mine
 1.7 20-Jun-2023  rillig make: allow targets to be used as multiple-inclusion guards

This style is used by FreeBSD, among others.
 1.6 19-Jun-2023  rillig make: add tests for full code coverage of multiple-inclusion guards
 1.5 19-Jun-2023  rillig make: if a makefile is protected by a guard, only include it once

"looks reasonable" sjg@
 1.4 18-Jun-2023  rillig tests/make: clean up test for multiple-inclusion guards
 1.3 18-Jun-2023  rillig tests/make: align variable name in test for multiple-inclusion guards
 1.2 18-Jun-2023  rillig tests/make: extend test for multiple-inclusion guards
 1.1 16-Jun-2023  rillig tests/make: add test for multiple-inclusion guards
 1.16.2.1 02-Aug-2025  perseant Sync with HEAD
 1.18 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.17 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.16 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.15 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.14 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.13 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.12 20-Apr-2024  rillig branches: 1.12.2;
make: provide more context information for parse/evaluate errors
 1.11 19-Aug-2023  rillig make: add more details to error message about invalid lines
 1.10 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.9 03-Mar-2022  rillig make: make debug logging for comparisons less technical
 1.8 14-Dec-2021  rillig tests/make: disable test that behaves differently in ATF
 1.7 14-Dec-2021  rillig tests/make: test traditional include directive
 1.6 03-Dec-2021  rillig tests/make: demonstrate .include with erroneous expression
 1.5 03-Dec-2021  rillig tests/make: test .include with expressions
 1.4 03-Nov-2020  rillig make(1): move tests from directives.mk to separate tests
 1.3 31-Oct-2020  rillig make(1): fix off-by-one bug in ParseTrackInput (since 2015-11-26)
 1.2 31-Oct-2020  rillig make(1): add test for off-by-one bug in ParseTrackInput
 1.1 13-Sep-2020  rillig make(1): add tests for the various .include directives
 1.12.2.1 02-Aug-2025  perseant Sync with HEAD
 1.20 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.19 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.18 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.17 11-Jan-2025  rillig tests/make: force correct order of expected messages
 1.16 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.15 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.14 20-Apr-2024  rillig branches: 1.14.2;
make: provide more context information for parse/evaluate errors
 1.13 19-Aug-2023  rillig make: add more details to error message about invalid lines
 1.12 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.11 15-Jan-2022  rillig tests/make: ensure that the 'expect' comments in tests are correct

Based on tests/usr.bin/xlint/check-expect.lua.

For now, this extra check needs to be run manually.
 1.10 07-Jan-2022  rillig make: fix null pointer when including empty file (since 2022-01-01)

Calling malloc(0) may return a null pointer, but callers of bmake_malloc
do not expect that.

Reported by Chris Pinnock, found by cross-compiling NetBSD on OpenBSD,
where tools/groff creates Makefile.dep files of size 0.
 1.9 14-Dec-2021  rillig tests/make: disable test that behaves differently in ATF
 1.8 14-Dec-2021  rillig tests/make: test traditional include directive
 1.7 03-Dec-2021  rillig tests/make: demonstrate .include with erroneous expression
 1.6 03-Dec-2021  rillig tests/make: test .include with expressions
 1.5 21-Nov-2020  rillig make(1): add test for .include with trailing garbage in the line
 1.4 03-Nov-2020  rillig make(1): move tests from directives.mk to separate tests
 1.3 31-Oct-2020  rillig make(1): fix off-by-one bug in ParseTrackInput (since 2015-11-26)
 1.2 31-Oct-2020  rillig make(1): add test for off-by-one bug in ParseTrackInput
 1.1 13-Sep-2020  rillig make(1): add tests for the various .include directives
 1.14.2.1 02-Aug-2025  perseant Sync with HEAD
 1.10 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.9 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.8 01-Jun-2023  rillig branches: 1.8.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.7 08-Jan-2022  rillig make: fix reported line numbers of continuation lines (since 2002)

Previously, multi-line directives like '.info' or '.error' reported the
line number of their last line instead of their first line, which is
more usual. This also affected the debug log from '-dp'.
 1.6 19-Dec-2020  rillig make(1): fix error message for .info/.warning/.error without argument

Previously, the error message was "Unknown directive", which was
obviously wrong. The new error message is "Missing argument".
 1.5 19-Dec-2020  rillig make(1): add test for backslash continuation lines in .for loops

This ensures that the line numbers for messages are the expected onces
in .for loops.

While experimenting with the backslash continuation lines, I noticed
that the reported line numbers for these are based on the number of
completely parsed physical lines, which nicely cancels out the + 1 that
has to be added for producing human-readable 1-based line numbers. It
would be more correct to report the parse errors on the first affected
line.
 1.4 13-Dec-2020  rillig make(1): error out on misspelled directives

Before, make accepted misspellings like .warnings, .export-literally and
a few others, all of which are unlikely to occur in practice. See the
test directive-misspellings.mk for further details.
 1.3 15-Nov-2020  rillig make(1): add tests for edge cases when parsing directives
 1.2 03-Nov-2020  rillig make(1): move tests from directives.mk to separate tests
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.8.2.1 02-Aug-2025  perseant Sync with HEAD
 1.11 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.10 08-May-2022  rillig tests/make: migrate cond1 test to other, more specific tests

The tests in cond1 were a mixture of "everything related to conditions",
and the test cases were heavily dependent on each other, which made them
hard to understand. Move each test case to its corresponding
special-purpose test.
 1.9 08-Jan-2022  rillig make: fix reported line numbers of continuation lines (since 2002)

Previously, multi-line directives like '.info' or '.error' reported the
line number of their last line instead of their first line, which is
more usual. This also affected the debug log from '-dp'.
 1.8 19-Dec-2020  rillig make(1): fix error message for .info/.warning/.error without argument

Previously, the error message was "Unknown directive", which was
obviously wrong. The new error message is "Missing argument".
 1.7 19-Dec-2020  rillig make(1): add test for backslash continuation lines in .for loops

This ensures that the line numbers for messages are the expected onces
in .for loops.

While experimenting with the backslash continuation lines, I noticed
that the reported line numbers for these are based on the number of
completely parsed physical lines, which nicely cancels out the + 1 that
has to be added for producing human-readable 1-based line numbers. It
would be more correct to report the parse errors on the first affected
line.
 1.6 13-Dec-2020  rillig make(1): adjust timestamps in unit tests

These could not be known before the previous commit.
 1.5 13-Dec-2020  rillig make(1): error out on misspelled directives

Before, make accepted misspellings like .warnings, .export-literally and
a few others, all of which are unlikely to occur in practice. See the
test directive-misspellings.mk for further details.
 1.4 15-Nov-2020  rillig make(1): add tests for edge cases when parsing directives
 1.3 03-Nov-2020  rillig make(1): move tests from directives.mk to separate tests
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.4 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.3 01-Jun-2023  rillig branches: 1.3.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.2 13-Dec-2020  rillig make(1): error out on misspelled directives

Before, make accepted misspellings like .warnings, .export-literally and
a few others, all of which are unlikely to occur in practice. See the
test directive-misspellings.mk for further details.
 1.1 13-Dec-2020  rillig make(1): add test for misspelled directives

This test allows the other directive-* tests to focus on the purpose of
the individual directive, allowing these tests to continue after
parsing, without errors.
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.5 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.4 01-Jun-2023  rillig branches: 1.4.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.3 13-Dec-2020  rillig make(1): adjust timestamps in unit tests

These could not be known before the previous commit.
 1.2 13-Dec-2020  rillig make(1): error out on misspelled directives

Before, make accepted misspellings like .warnings, .export-literally and
a few others, all of which are unlikely to occur in practice. See the
test directive-misspellings.mk for further details.
 1.1 13-Dec-2020  rillig make(1): add test for misspelled directives

This test allows the other directive-* tests to focus on the purpose of
the individual directive, allowing these tests to continue after
parsing, without errors.
 1.4.2.1 02-Aug-2025  perseant Sync with HEAD
 1.7 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.6 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.5 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.4 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.3 19-Aug-2023  rillig branches: 1.3.2;
make: add more details to error message about invalid lines
 1.2 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.1 13-Sep-2020  rillig make(1): add tests for the various .include directives
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.7 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.6 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.5 19-Aug-2023  rillig branches: 1.5.2;
make: add more details to error message about invalid lines
 1.4 23-Jan-2022  rillig tests/make: add a few more tests
 1.3 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.2 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.1 13-Sep-2020  rillig make(1): add tests for the various .include directives
 1.5.2.1 02-Aug-2025  perseant Sync with HEAD
 1.15 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.14 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.13 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.12 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.11 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.10 20-Apr-2024  rillig branches: 1.10.2;
make: provide more context information for parse/evaluate errors
 1.9 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.8 08-Jan-2022  rillig make: fix reported line numbers of continuation lines (since 2002)

Previously, multi-line directives like '.info' or '.error' reported the
line number of their last line instead of their first line, which is
more usual. This also affected the debug log from '-dp'.
 1.7 23-Feb-2021  rillig make: improve error message for unknown modifier

Back in 1995, the modifiers were all single-character, and it made sense
to print only the first character. Nowadays, with ':S', ':@var@...@',
'::=' and several others, a little more context is useful to see where
the exact error is. The actual modifier is still guessed, and the guess
may be wrong as soon as backslashes get involved, but it is still better
than before.
 1.6 16-Feb-2021  rillig make: demonstrate inconsistency in .undef of an exported variable
 1.5 22-Dec-2020  rillig make(1): allow .undef to undefine multiple variables at once

Since make doesn't support variable names containing spaces, this edge
case is not enough reason to stop this feature. Having multiple
variable names as arguments nicely aligns with other directives such as
.for and .export.
 1.4 19-Dec-2020  rillig make(1): error out if .undef has not exactly 1 argument
 1.3 13-Dec-2020  rillig make(1): error out on misspelled directives

Before, make accepted misspellings like .warnings, .export-literally and
a few others, all of which are unlikely to occur in practice. See the
test directive-misspellings.mk for further details.
 1.2 03-Nov-2020  rillig make(1): move tests from directives.mk to separate tests
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.10.2.1 02-Aug-2025  perseant Sync with HEAD
 1.17 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.16 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.15 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.14 20-Apr-2024  rillig branches: 1.14.2;
make: provide more context information for parse/evaluate errors
 1.13 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.12 26-Mar-2022  rillig make: fix crash on .undef of an environment variable (since 2020-10-06)
 1.11 25-Mar-2022  rillig tests/make: test .undef for exported global variables
 1.10 16-Feb-2021  rillig make: demonstrate inconsistency in .undef of an exported variable
 1.9 22-Dec-2020  rillig make(1): allow .undef to undefine multiple variables at once

Since make doesn't support variable names containing spaces, this edge
case is not enough reason to stop this feature. Having multiple
variable names as arguments nicely aligns with other directives such as
.for and .export.
 1.8 19-Dec-2020  rillig make(1): error out if .undef has not exactly 1 argument
 1.7 19-Dec-2020  rillig make(1): add tests for undefining variables with exotic names
 1.6 13-Dec-2020  rillig make(1): error out on misspelled directives

Before, make accepted misspellings like .warnings, .export-literally and
a few others, all of which are unlikely to occur in practice. See the
test directive-misspellings.mk for further details.
 1.5 03-Nov-2020  rillig make(1): move tests from directives.mk to separate tests
 1.4 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.3 23-Aug-2020  rillig make(1): move test for .undef into separate file
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.14.2.1 02-Aug-2025  perseant Sync with HEAD
 1.15 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.14 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.13 01-Jun-2023  rillig branches: 1.13.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.12 26-Mar-2022  rillig make: add space after colon in debug logging for variables

These log messages are intended for human interpretation, so don't make
them unnecessarily hard to read.
 1.11 06-Apr-2021  rillig make: reduce verbosity of the -dv debug logging for standard cases

The verbosity was already removed from LogBeforeApply, now it is
consistent between LogBeforeApply and LogAfterApply.
 1.10 05-Apr-2021  rillig make: in debug log, add space between scope and variable name

Without this space, the debug log looked more like line noise, even
though the only punctuation was a single innocent ':'. From a make
user's perspective, the variable name is a word of its own and should
not be visually glued to its namespace.
 1.9 05-Apr-2021  rillig make: omit unnecessary details from -dv debug log

When an expression is based on a defined variable, it does not matter
whether the evaluation mode is "eval" or "eval-defined", therefore omit
these details to reduce confusion.
 1.8 05-Apr-2021  rillig make: be more verbose in -dv debug logging

The previous log output was too brief to be understandable. Give more
hints by describing each part of the expression when evaluating a
modifier. Distinguish between parse-only mode and eval mode since in
parse-only mode most of the details are irrelevant.
 1.7 03-Apr-2021  rillig make: remove VarFlags from debug logging

Before the introduction of ExprDefined, VarFlags contained whether the
expression was defined or not, which was useful to know since the final
value of the expression depends on this information. The other VarFlags
do not influence the evaluation, so there is no point logging them.
 1.6 15-Mar-2021  rillig make: change debug log for variable evaluation flags to lowercase

This makes them easier distinguishable from variable names since the
latter are usually uppercase.

No functional change outside debug mode.
 1.5 15-Feb-2021  rillig make: rename ExprDefined constants for debug logging
 1.4 12-Dec-2020  rillig make(1): error out on misspelled .export directives
 1.3 12-Dec-2020  rillig make(1): error out on misspelled .unexport-env
 1.2 06-Dec-2020  rillig make(1): add test for directive unexport-env
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.13.2.1 02-Aug-2025  perseant Sync with HEAD
 1.9 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.8 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.7 12-Dec-2020  rillig make(1): error out on misspelled .export directives
 1.6 12-Dec-2020  rillig make(1): error out on misspelled .unexport-env
 1.5 06-Dec-2020  rillig make(1): fix comment in test for directive unexport-env
 1.4 06-Dec-2020  rillig make(1): add test for directive unexport-env
 1.3 03-Nov-2020  rillig make(1): move tests from directives.mk to separate tests
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.9 30-Jun-2025  rillig tests/make: force expected lines to be listed in execution order

The diagnostics from the program to check the "expect" lines in the unit
test files were hard to follow since the "out-of-order" lines were
confusing. For out-of-order lines, state where they should be placed
instead.
 1.8 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.7 01-Jun-2023  rillig branches: 1.7.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.6 13-Dec-2020  rillig make(1): error out on misspelled directives

Before, make accepted misspellings like .warnings, .export-literally and
a few others, all of which are unlikely to occur in practice. See the
test directive-misspellings.mk for further details.
 1.5 12-Dec-2020  rillig make(1): error out on misspelled .export directives
 1.4 03-Nov-2020  rillig make(1): move tests from directives.mk to separate tests
 1.3 30-Oct-2020  sjg Fix directive-unexport to focus only on the variables we care about
 1.2 30-Oct-2020  rillig make(1): add test for an edge case of .unexport
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7.2.1 02-Aug-2025  perseant Sync with HEAD
 1.9 30-Jun-2025  rillig tests/make: force expected lines to be listed in execution order

The diagnostics from the program to check the "expect" lines in the unit
test files were hard to follow since the "out-of-order" lines were
confusing. For out-of-order lines, state where they should be placed
instead.
 1.8 01-Jun-2023  rillig branches: 1.8.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.7 13-Dec-2020  rillig make(1): error out on misspelled directives

Before, make accepted misspellings like .warnings, .export-literally and
a few others, all of which are unlikely to occur in practice. See the
test directive-misspellings.mk for further details.
 1.6 12-Dec-2020  rillig make(1): error out on misspelled .export directives
 1.5 03-Nov-2020  rillig make(1): move tests from directives.mk to separate tests
 1.4 30-Oct-2020  sjg Fix directive-unexport to focus only on the variables we care about
 1.3 30-Oct-2020  rillig make(1): add test for an edge case of .unexport
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.8.2.1 02-Aug-2025  perseant Sync with HEAD
 1.9 01-Jul-2025  rillig tests/make: require "expect" comments to start a line

Lua's string.gmatch function doesn't allow the anchor "^"; but its
string.gsub function does.
 1.8 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.7 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.6 01-Jun-2023  rillig branches: 1.6.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.5 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.4 19-Dec-2020  rillig make(1): fix error message for .info/.warning/.error without argument

Previously, the error message was "Unknown directive", which was
obviously wrong. The new error message is "Missing argument".
 1.3 13-Dec-2020  rillig make(1): error out on misspelled directives

Before, make accepted misspellings like .warnings, .export-literally and
a few others, all of which are unlikely to occur in practice. See the
test directive-misspellings.mk for further details.
 1.2 03-Nov-2020  rillig make(1): move tests from directives.mk to separate tests
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.6.2.1 02-Aug-2025  perseant Sync with HEAD
 1.10 01-Jul-2025  rillig tests/make: require "expect" comments to start a line

Lua's string.gmatch function doesn't allow the anchor "^"; but its
string.gsub function does.
 1.9 17-Dec-2023  rillig branches: 1.9.2;
tests/make: in 'expect' lines, require the complete text of the line
 1.8 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.7 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.6 19-Dec-2020  rillig make(1): fix error message for .info/.warning/.error without argument

Previously, the error message was "Unknown directive", which was
obviously wrong. The new error message is "Missing argument".
 1.5 13-Dec-2020  rillig make(1): adjust timestamps in unit tests

These could not be known before the previous commit.
 1.4 13-Dec-2020  rillig make(1): error out on misspelled directives

Before, make accepted misspellings like .warnings, .export-literally and
a few others, all of which are unlikely to occur in practice. See the
test directive-misspellings.mk for further details.
 1.3 03-Nov-2020  rillig make(1): move tests from directives.mk to separate tests
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.9.2.1 02-Aug-2025  perseant Sync with HEAD
 1.12 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.11 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.10 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.9 19-Aug-2023  rillig branches: 1.9.2;
make: show realistic invalid line in error message

Previously, the error message 'Invalid line' showed only the expanded
line, which might or might not show the actual problem. To be more
helpful, add the unexpanded line to the error message in case they
differ.

Remove the special handling of invalid lines that result from merge
conflicts. RCS is not commonly used anymore, and mentioning CVS was too
specific. By echoing the whole line, the patterns '<<<<<<' and '>>>>>>'
are clear enough to hint at the problem.
 1.8 19-Aug-2023  rillig make: add more details to error message about invalid lines
 1.7 26-Mar-2022  rillig make: avoid trailing whitespace in debug log for variables

Since trailing whitespace is invisible, describe the variable value in
words to make it visible.
 1.6 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.5 13-Dec-2021  rillig tests/make: extend tests for parsing makefiles
 1.4 05-Apr-2021  rillig make: in debug log, add space between scope and variable name

Without this space, the debug log looked more like line noise, even
though the only punctuation was a single innocent ':'. From a make
user's perspective, the variable name is a word of its own and should
not be visually glued to its namespace.
 1.3 15-Nov-2020  rillig make(1): add tests for edge cases when parsing directives
 1.2 03-Nov-2020  rillig make(1): move tests from directives.mk to separate tests
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.9.2.1 02-Aug-2025  perseant Sync with HEAD
 1.10 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.9 19-Nov-2023  rillig branches: 1.9.2;
tests/make: replace 'variable expressions' with 'expressions'
 1.8 19-Aug-2023  rillig make: show realistic invalid line in error message

Previously, the error message 'Invalid line' showed only the expanded
line, which might or might not show the actual problem. To be more
helpful, add the unexpanded line to the error message in case they
differ.

Remove the special handling of invalid lines that result from merge
conflicts. RCS is not commonly used anymore, and mentioning CVS was too
specific. By echoing the whole line, the patterns '<<<<<<' and '>>>>>>'
are clear enough to hint at the problem.
 1.7 19-Aug-2023  rillig make: add more details to error message about invalid lines
 1.6 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.5 13-Dec-2021  rillig tests/make: extend tests for parsing makefiles
 1.4 15-Nov-2020  rillig make(1): add tests for edge cases when parsing directives
 1.3 03-Nov-2020  rillig make(1): move tests from directives.mk to separate tests
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.9.2.1 02-Aug-2025  perseant Sync with HEAD
 1.6 03-Nov-2020  rillig make(1): move tests from directives.mk to separate tests
 1.5 28-Jul-2020  rillig make(1): add test for including a nonexistent or empty file
 1.4 28-Jul-2020  rillig make(1): add tests for unknown indented directives

It's quite expected that the .${:Uinfo} is not yet expanded when the
directive is parsed, otherwise the directive would have been accepted.
The surprising thing is that it is expanded at the point where the error
message is generated.
 1.3 28-Jul-2020  rillig make(1): when parsing an unknown directive, print the directive name
 1.2 28-Jul-2020  rillig make(1): refine test for detecting misspellings in directives

The names of directives are only checked if the lines are actually
relevant. In all other cases, the amount of work is reduced to the bare
minimum, which is just to scan for line continuations.
 1.1 27-Jul-2020  rillig make(1): add tests for parsing directives like .if and .info
 1.7 03-Nov-2020  rillig make(1): move tests from directives.mk to separate tests
 1.6 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.5 28-Jul-2020  rillig make(1): add test for including a nonexistent or empty file
 1.4 28-Jul-2020  rillig make(1): add test about possibly ambiguous suffix rule
 1.3 28-Jul-2020  rillig make(1): add tests for unknown indented directives

It's quite expected that the .${:Uinfo} is not yet expanded when the
directive is parsed, otherwise the directive would have been accepted.
The surprising thing is that it is expanded at the point where the error
message is generated.
 1.2 28-Jul-2020  rillig make(1): refine test for detecting misspellings in directives

The names of directives are only checked if the lines are actually
relevant. In all other cases, the amount of work is reduced to the bare
minimum, which is just to scan for line continuations.
 1.1 27-Jul-2020  rillig make(1): add tests for parsing directives like .if and .info
 1.4 03-Nov-2020  rillig make(1): in tests, replace "dollar character" with "dollar sign"
 1.3 17-May-2020  rillig usr.bin/make: fix test for dollar and backslash at eol

The previous version of this test relied on the way how the shell
interprets a lonely backslash at the end of the line. The NetBSD and
FreeBSD shells print the backslash, while Bash doesn't.

While here, make the escaping a bit simpler and align the test
descriptions with the actual test data.
 1.2 10-May-2020  rillig usr.bin/make: fix typo in dollar test
 1.1 10-May-2020  rillig usr.bin/make: add tests for surprising dollar removal
 1.4 03-Nov-2020  rillig make(1): in tests, replace "dollar character" with "dollar sign"
 1.3 17-May-2020  rillig usr.bin/make: fix test for dollar and backslash at eol

The previous version of this test relied on the way how the shell
interprets a lonely backslash at the end of the line. The NetBSD and
FreeBSD shells print the backslash, while Bash doesn't.

While here, make the escaping a bit simpler and align the test
descriptions with the actual test data.
 1.2 10-May-2020  rillig usr.bin/make: fix typo in dollar test
 1.1 10-May-2020  rillig usr.bin/make: add tests for surprising dollar removal
 1.2 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.1 08-Apr-2010  sjg Process .ERROR the same as .BEGIN, .END etc
so that it cannot be the default target.
Add unit-tests for .info - .error, and .ERROR.
 1.3 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.2 25-Oct-2015  sjg branches: 1.2.28;
PrintOnError: fflush stdout before running .ERROR

produces more consistent results in unit-tests.
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2.28.1 02-Aug-2025  perseant Sync with HEAD
 1.3 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.2 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.1 26-Feb-2006  apb Make ".WAIT" apply recursively to all children of nodes on the right
hand side of the .WAIT, except when the recursive interpretation would
cause a cycle in the dependency graph.

Discussed in tech-toolchain. Reviewed by christos, sjg.
 1.2 08-Oct-2017  sjg Ensure consistent results on different platforms.

With cycle.1.99 being written to stdout and
make: Graph cycles through `cycle.2.*`
to stderr, the order in which they are captured
varies on some platforms.
By redirecting stderr through the same pipe
as stdout we get more consistent result.
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.3 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.2 08-Oct-2017  sjg Ensure consistent results on different platforms.

With cycle.1.99 being written to stdout and
make: Graph cycles through `cycle.2.*`
to stderr, the order in which they are captured
varies on some platforms.
By redirecting stderr through the same pipe
as stdout we get more consistent result.
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2 04-Aug-2025  sjg Use printf rather than echo -n
 1.1 04-Aug-2025  sjg echo.inc make ECHO_SCRIPT reusable
 1.2 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.1 25-Jul-2020  rillig make(1): add tests for previously uncovered code
 1.6 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.5 04-Feb-2021  rillig make: rename context and ctxt to scope

This continues the previous commit, in which VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE were renamed.

Renaming the variable 'ctxt' was trivial since that word is used nowhere
else. In the comments though, each occurrence of the word 'context' had
to be checked individually since the word 'context' was not only used
for referring to a variable scope. It is also used to distinguish
different situations where characters are escaped in a certain way
('parsing context') and in a few other expressions.
 1.4 09-Nov-2020  rillig make(1): in tests, move command line arguments into the test proper
 1.3 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.2 27-Jul-2020  rillig make(1): add test for unsetting an environment variable in -e mode
 1.1 25-Jul-2020  rillig make(1): add tests for previously uncovered code
 1.3 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2 24-May-2010  sjg Don't missinterpret targets that start with .info
 1.1 08-Apr-2010  sjg Process .ERROR the same as .BEGIN, .END etc
so that it cannot be the default target.
Add unit-tests for .info - .error, and .ERROR.
 1.5 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.4 01-Jun-2023  rillig branches: 1.4.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.3 03-Nov-2020  rillig make(1): clean up tests error.mk and escape.mk
 1.2 28-Sep-2020  sjg Ensure that parse errors report 'stopped in'
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.4.2.1 02-Aug-2025  perseant Sync with HEAD
 1.4 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.3 03-Nov-2020  rillig make(1): clean up tests error.mk and escape.mk
 1.2 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.8 19-Oct-2023  rillig tests/make: clean up, explain and reorganize several tests
 1.7 09-Sep-2014  apb Add a test for backslash-newline at the very end of a command script.
 1.6 09-Sep-2014  apb Change @echo to echo in several places in escape.mk,
to make it easier to spot changes in what make sends to the shell.
Adjust escape.out to match.
 1.5 24-Aug-2014  apb In either a variable assignmentor a command, backslash-backslash-newline
does not escape the newline. This is compatible with gmake.
 1.4 24-Aug-2014  apb Our practice is that an even number of backslashes before a newline
in a variable assignment simply stores the backslashes as part of the
value, and treats the newline as though it was not escaped. This
is compatible with GNU make.
 1.3 24-Aug-2014  apb Our practice, despite what POSIX might say, is that "\#"
in a variable assignment stores "#" as part of the value.
The "\" is not taken literally, and the "#" does not begin a comment.
 1.2 24-Aug-2014  apb Adjust tests to correct for the fact that end-of-line comments
in variable assignments should not be included in the value.

Also fix more typos.
 1.1 24-Aug-2014  apb Add tests for backslash escaping in make(1).

Many of these tests fail, and I have populated the escape.exp file with
the results that I expect, not with the results that make(1) actually
produces.

Also update the set lists for these tests.
 1.15 19-Oct-2023  rillig tests/make: clean up, explain and reorganize several tests
 1.14 03-Nov-2020  rillig make(1): clean up tests error.mk and escape.mk
 1.13 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.12 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.11 07-Jan-2020  rillig usr.bin/make: fix typos in comment
 1.10 09-Sep-2014  apb branches: 1.10.16;
Add a test for backslash-newline at the very end of a command script.
 1.9 09-Sep-2014  apb Change @echo to echo in several places in escape.mk,
to make it easier to spot changes in what make sends to the shell.
Adjust escape.out to match.
 1.8 24-Aug-2014  apb In either a variable assignmentor a command, backslash-backslash-newline
does not escape the newline. This is compatible with gmake.
 1.7 24-Aug-2014  apb Our practice is that an even number of backslashes before a newline
in a variable assignment simply stores the backslashes as part of the
value, and treats the newline as though it was not escaped. This
is compatible with GNU make.
 1.6 24-Aug-2014  apb Our practice, despite what POSIX might say, is that "\#"
in a variable assignment stores "#" as part of the value.
The "\" is not taken literally, and the "#" does not begin a comment.
 1.5 24-Aug-2014  apb Convert the variable printing tests to use .USE rules,
to ensure that the value printed always comes from the expected variable.
 1.4 24-Aug-2014  apb Adjust tests to correct for the fact that end-of-line comments
in variable assignments should not be included in the value.

Also fix more typos.
 1.3 24-Aug-2014  apb Fix more typos in variable names.
 1.2 24-Aug-2014  apb Fix typos in variable names, and in a comment.
 1.1 24-Aug-2014  apb Add tests for backslash escaping in make(1).

Many of these tests fail, and I have populated the escape.exp file with
the results that I expect, not with the results that make(1) actually
produces.

Also update the set lists for these tests.
 1.10.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.2 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.1 05-Oct-2007  sjg branches: 1.1.2;
Add the ability to .export variables to the environment.
 1.1.2.2 06-Nov-2007  matt sync with HEAD
 1.1.2.1 05-Oct-2007  matt file export was added on branch matt-armv6 on 2007-11-06 23:36:04 +0000
 1.3 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2 21-Apr-2010  sjg If we do .export (all) and have any variables that involve :sh
we will hit an error (var is recursive) while trying to evaluate that.
Fix, and add a unit test for this.
 1.1 05-Oct-2007  sjg branches: 1.1.2;
Add the ability to .export variables to the environment.
 1.1.2.2 06-Nov-2007  matt sync with HEAD
 1.1.2.1 05-Oct-2007  matt file export-all was added on branch matt-armv6 on 2007-11-06 23:36:05 +0000
 1.2 10-Apr-2015  sjg export-all.mk should be including export.mk
sadly some shells do not grok named signals.
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.6 01-Jun-2024  sjg make: add .export-all

An explicit syntax for exporting all global variables is much safer
than allowing .export with no argument to do the same.

Add .export-all and have .export with no argument throw a warning saying
to use .export-all

Reviewed by: rillig
 1.5 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.4 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.3 27-Jul-2020  rillig make(1): prepare test for .export to show all exported variables

Currently the unit tests don't cover exporting of local variables like
.TARGET or @. To see the effects, all exported variables must be listed
by the tests.
 1.2 10-Apr-2015  sjg export-all.mk should be including export.mk
sadly some shells do not grok named signals.
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.1 22-Mar-2013  sjg branches: 1.1.4; 1.1.10;
Add unit-test for export-env and gmake export
 1.1.10.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.10.1 22-Mar-2013  yamt file export-env was added on branch yamt-pagecache on 2014-05-22 11:42:46 +0000
 1.1.4.2 23-Jun-2013  tls resync from head
 1.1.4.1 22-Mar-2013  tls file export-env was added on branch tls-maxphys on 2013-06-23 06:29:01 +0000
 1.2 18-Feb-2016  sjg Add .export-literal to avoid the need for $$ dance when trying to put
unexpanded variables into environment.

Reviewed by: christos
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.5 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.4 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.3 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.2 18-Feb-2016  sjg Add .export-literal to avoid the need for $$ dance when trying to put
unexpanded variables into environment.

Reviewed by: christos
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.1 07-Aug-2020  rillig make(1): add test for exporting variables
 1.4 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.3 13-Sep-2020  rillig make(1): fix explanations in test for exporting variables
 1.2 08-Aug-2020  rillig make(1): clean up Var_UnExport

Mark the parameter as constant since it is not modified.

Remove tests for '\n' since these can never succeed.

newenv can never be NULL since neither of bmake_malloc or bmake_realloc
returns NULL.

Improve variable names: vlist was too unexpressive.

Add debug logging since unexporting variables is an uncommon operation
that directly affects the observable environment of the child processes.

Fix CRLF line endings in a few unit tests.
 1.1 07-Aug-2020  rillig make(1): add test for exporting variables
 1.7 09-Feb-2022  rillig tests/make: use more distinctive placeholder for TMPDIR
 1.6 06-Feb-2021  sjg Avoid test failures when more than one user run them.

Use a private TMPDIR
a subdir of .OBJDIR if using it
otherwise /tmp/uid${.MAKE.UID}
 1.5 10-Oct-2020  sjg Limit output of export tests to POSIX compatible env vars
 1.4 22-Aug-2020  sjg Add .SHELL as read-only variable

The .SHELL variable represents the shellPath used to run
scripts.

Reviewed by: rillig, christos
 1.3 27-Jul-2020  rillig make(1): add test for exporting single-character variables
 1.2 27-Jul-2020  rillig make(1): prepare test for .export to show all exported variables

Currently the unit tests don't cover exporting of local variables like
.TARGET or @. To see the effects, all exported variables must be listed
by the tests.
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.12 09-Sep-2022  sjg Handle deprecation of egrep
 1.11 05-Dec-2021  rillig tests/make: migrate to jemalloc > 100

When I started working on usr.bin/make in 2020, I used NetBSD 8, which
used jemalloc 100.

After updating to NetBSD 8 to 9.99.x, the debugging options for jemalloc
stopped working since MALLOC_OPTIONS had been replaced with MALLOC_CONF
in 2019.

Enable malloc debugging again, to reliably reproduce the use-after-free
for the variable modifier ':@'.
 1.10 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.9 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.8 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.7 17-Oct-2020  rillig make(1): document why the ampersand is not listed in export.exp
 1.6 27-Sep-2020  rillig make(1): run tests with jemalloc debugging enabled

This protects against very simple memory allocation bugs such as
migrating Lst_ForEachUntil to Lst_ForEach without remembering that
Lst_ForEachUntil can handle the situation where the current list node is
removed from the list, but Lst_ForEach cannot. This happens in
Make_ExpandUse, for example.
 1.5 08-Aug-2020  rillig make(1): clean up Var_UnExport

Mark the parameter as constant since it is not modified.

Remove tests for '\n' since these can never succeed.

newenv can never be NULL since neither of bmake_malloc or bmake_realloc
returns NULL.

Improve variable names: vlist was too unexpressive.

Add debug logging since unexporting variables is an uncommon operation
that directly affects the observable environment of the child processes.

Fix CRLF line endings in a few unit tests.
 1.4 28-Jul-2020  sjg Use egrep rather than grep -E

Also we need to exclude noise that some shells include.
This is why the original test restricted itself to checking
for UT_* in env.
 1.3 27-Jul-2020  rillig make(1): add test for exporting single-character variables
 1.2 27-Jul-2020  rillig make(1): prepare test for .export to show all exported variables

Currently the unit tests don't cover exporting of local variables like
.TARGET or @. To see the effects, all exported variables must be listed
by the tests.
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.1 19-Jun-2012  sjg branches: 1.1.4;
Add unit-tests for .for
 1.1.4.2 30-Oct-2012  yamt sync with head
 1.1.4.1 19-Jun-2012  yamt file forloop was added on branch yamt-pagecache on 2012-10-30 19:00:23 +0000
 1.5 10-May-2023  rillig tests/make: clean up tests for .for loops

Most of the tests from forloop.mk were already in directive-for.mk.
 1.4 03-Nov-2020  rillig make(1): in test forloop.mk, replace shell execution with .info

It's easier to read in the code, and the output has line information to
better relate the output to the code.
 1.3 25-Oct-2020  rillig make(1): use complete words in error message for .for loop
 1.2 01-May-2020  rillig usr.bin/make: add test demonstrating that .for stops at newline
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.8 10-May-2023  rillig tests/make: clean up tests for .for loops

Most of the tests from forloop.mk were already in directive-for.mk.
 1.7 03-Nov-2020  rillig make(1): in test forloop.mk, replace shell execution with .info

It's easier to read in the code, and the output has line information to
better relate the output to the code.
 1.6 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.5 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.4 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.3 02-Sep-2020  rillig make(1): fix typo in unit test for the .for loop
 1.2 01-May-2020  rillig usr.bin/make: add test demonstrating that .for stops at newline
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.1 07-Oct-2009  sjg The parser used to break dependency lines at ';' without regard
for substitution patterns. This (perhaps coupled with the
new handling of .for variables in ${:U<value>...) caused interesting
results for lines like:

.for file in ${LIST}
for-subst: ${file:S;^;${here}/;g}

add a unit-test to keep an eye on this.
 1.2 01-Jun-2023  rillig tests/make: clean up comments, extend a few tests
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.4 01-Jun-2023  rillig tests/make: clean up comments, extend a few tests
 1.3 03-Nov-2020  rillig make(1): document the interesting part of the test forsubst.mk
 1.2 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.3 07-May-2025  rillig make: add end marker for -dg1, -dg2 and -dg3 debug log

The marker helps distinguish the output from sub-makes from the output
of the primary make.
 1.2 02-Feb-2021  rillig branches: 1.2.8;
make: remove overengineered Enum_ValueToString

For printing the status of a GNode, there was already made_name (now
renamed to GNodeMade_Name), which prints user-friendly text instead of
the bare enum constant names.

To do this change confidently, I first had to demonstrate that the
output really affects something other than just the word "UNMADE". There
had not been a test for that case before, and the test immediately
discovered a bug in the -dg2 and -dg3 options. This bug is one of the
oldest in make, dating back to at least 1993.
 1.1 07-Nov-2020  rillig make(1): add test for OP_SUBMAKE
 1.2.8.1 02-Aug-2025  perseant Sync with HEAD
 1.1 07-Nov-2020  rillig make(1): add test for OP_SUBMAKE
 1.1 03-Oct-2020  rillig make(1): add test demonstrating the Towers of Hanoi puzzle

It's not the primary task of make to handle procedure calls with
parameters, combined with lexical scoping, therefore the code does not
look as straight-forward or clean as in other programming languages. It
feels more like squeezing a programming problem from the imperative
world into the world of declarative dependencies.

A more idiomatic way of implementing this puzzle should be as a
dependency graph since that's both the natural structure of the puzzle
and the primary domain of make. Something like having a main target
"hanoi-5" that depends on intermediate targets of the form
"move-1.2.3.4.5-_._._._._-_._._._._", each representing a single
configuration of the stacks. These targets could be generated
dynamically. A benefit of this implementation would be that the puzzle
could be resumed from an arbitrary configuration, just just from the
initial configuration.
 1.5 19-Oct-2023  rillig tests/make: clean up, explain and reorganize several tests
 1.4 19-Jan-2023  rillig tests/make: remove dependency on expr(1) from a test

This saves 124 calls to the shell.
 1.3 08-May-2022  rillig tests/make: add test for option '-X', clean up comments
 1.2 08-Jan-2022  rillig tests/make: test line numbers in debug output for parsing files
 1.1 03-Oct-2020  rillig make(1): add test demonstrating the Towers of Hanoi puzzle

It's not the primary task of make to handle procedure calls with
parameters, combined with lexical scoping, therefore the code does not
look as straight-forward or clean as in other programming languages. It
feels more like squeezing a programming problem from the imperative
world into the world of declarative dependencies.

A more idiomatic way of implementing this puzzle should be as a
dependency graph since that's both the natural structure of the puzzle
and the primary domain of make. Something like having a main target
"hanoi-5" that depends on intermediate targets of the form
"move-1.2.3.4.5-_._._._._-_._._._._", each representing a single
configuration of the stacks. These targets could be generated
dynamically. A benefit of this implementation would be that the puzzle
could be resumed from an arbitrary configuration, just just from the
initial configuration.
 1.2 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.1 07-Apr-2011  joerg Add the :hash modifier to compute a 32bit hash of an variable.
This uses MurmurHash3 to get a reasonable collission-free hash with
small code. The result is endian neutral.
 1.2 04-Sep-2020  rillig make(1): extend tests for the :hash variable modifier

The previous test vectors didn't contain any hash with a leading zero.
This could have been a simple programming mistake by using %8x instead
of the intended %08x. Using snprintf wouldn't have been possible anyway
since the hex digits are printed in little-endian order, but without
reversing the bits of each digit. Kind of unusual, but doesn't affect
the distribution of the hashes.
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2 04-Sep-2020  rillig make(1): extend tests for the :hash variable modifier

The previous test vectors didn't contain any hash with a leading zero.
This could have been a simple programming mistake by using %8x instead
of the intended %08x. Using snprintf wouldn't have been possible anyway
since the hex digits are printed in little-endian order, but without
reversing the bits of each digit. Kind of unusual, but doesn't affect
the distribution of the hashes.
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2 07-Aug-2020  rillig make(1): enable test for .IMPSRC

Having this test disabled was very confusing since its content didn't
match the actual behavior, and this also differs from the GNU make
behavior.
 1.1 23-Aug-2014  christos PR/46096: Jarmo Jaakkola: fix many problems with dependencies (PR 49086)

Quite extensive rewrite of the Suff module. Some ripple effects into
Parse and Targ modules too.

Dependency searches in general were made to honor explicit rules so
implicit and explicit sources are no longer applied on targets that
do not invoke a transformation rule.

Archive member dependency search was rewritten. Explicit rules now
work properly and $(.TARGET) is set correctly. POSIX semantics for
lib(member.o) and .s1.a rules are supported.

.SUFFIXES list maintenance was rewritten so that scanning of existing
rules works when suffixes are added and that clearing the suffix list
removes single suffix rules too. Transformation rule nodes are now
mixed with regular nodes so they are available as regular targets too
if needed (especially after the known suffixes are cleared).

The .NULL target was documented in the manual page, especially to
warn against using it when a single suffix rule would work.
A deprecation warning was also added to the manual and make also
warns the user if it encounters .NULL.

Search for suffix rules no longer allows the explicit dependencies
to override the selected transformation rule. A check is made in
the search that the transformation that would be tried does not
already exist in the chain. This prevents getting stuck in an infinite
loop under specific circumstances. Local variables are now set
before node's children are expanded so dynamic sources work in
multi-stage transformations. Make_HandleUse() no longer expands
the added children for transformation nodes, preventing triple
expansion and allowing the Suff module to properly postpone their
expansion until proper values are set for the local variables.

Directory prefix is no longer removed from $(.PREFIX) if the target
is found via directory search.

The last rule defined is now used instead of the first one (POSIX
requirement) in case a rule is defined multiple times. Everything
defined in the first instance is undone, but things added "globally"
are honored. To implement this, each node tracks attribute bits
which have been set by special targets (global) instead of special
sources (local). They also track dependencies that were added by
a rule with commands (local) instead of rule with no commands (global).

New attribute, OP_FROM_SYS_MK is introduced. It is set on all targets
found in system makefiles so that they are not eligible to become
the main target. We cannot just set OP_NOTMAIN because it is one of
the attributes inherited from transformation and .USE rules and would
make any eligible target that uses a built-in inference rule ineligible.

The $(.IMPSRC) local variable now works like in gmake: it is set to
the first prerequisite for explicit rules. For implicit rules it
is still the implied source.

The manual page is improved regarding the fixed features. Test cases
for the fixed problems are added.

Other improvements in the Suff module include:
- better debug messages for transformation rule search (length of
the chain is now visualized by indentation)
- Suff structures are created, destroyed and moved around by a set
of maintenance functions so their reference counts are easier
to track (this also gets rid of a lot of code duplication)
- some unreasonably long functions were split into smaller ones
- many local variables had their names changed to describe their
purpose instead of their type
 1.3 07-Aug-2020  rillig make(1): enable test for .IMPSRC

Having this test disabled was very confusing since its content didn't
match the actual behavior, and this also differs from the GNU make
behavior.
 1.2 30-Aug-2014  sjg Replace use of $() with ${}
$() means something special to the shell, so ${} reduces confusion
and is used almost exclusively in the rest of the makefiles.

Discussed with: christos
 1.1 23-Aug-2014  christos PR/46096: Jarmo Jaakkola: fix many problems with dependencies (PR 49086)

Quite extensive rewrite of the Suff module. Some ripple effects into
Parse and Targ modules too.

Dependency searches in general were made to honor explicit rules so
implicit and explicit sources are no longer applied on targets that
do not invoke a transformation rule.

Archive member dependency search was rewritten. Explicit rules now
work properly and $(.TARGET) is set correctly. POSIX semantics for
lib(member.o) and .s1.a rules are supported.

.SUFFIXES list maintenance was rewritten so that scanning of existing
rules works when suffixes are added and that clearing the suffix list
removes single suffix rules too. Transformation rule nodes are now
mixed with regular nodes so they are available as regular targets too
if needed (especially after the known suffixes are cleared).

The .NULL target was documented in the manual page, especially to
warn against using it when a single suffix rule would work.
A deprecation warning was also added to the manual and make also
warns the user if it encounters .NULL.

Search for suffix rules no longer allows the explicit dependencies
to override the selected transformation rule. A check is made in
the search that the transformation that would be tried does not
already exist in the chain. This prevents getting stuck in an infinite
loop under specific circumstances. Local variables are now set
before node's children are expanded so dynamic sources work in
multi-stage transformations. Make_HandleUse() no longer expands
the added children for transformation nodes, preventing triple
expansion and allowing the Suff module to properly postpone their
expansion until proper values are set for the local variables.

Directory prefix is no longer removed from $(.PREFIX) if the target
is found via directory search.

The last rule defined is now used instead of the first one (POSIX
requirement) in case a rule is defined multiple times. Everything
defined in the first instance is undone, but things added "globally"
are honored. To implement this, each node tracks attribute bits
which have been set by special targets (global) instead of special
sources (local). They also track dependencies that were added by
a rule with commands (local) instead of rule with no commands (global).

New attribute, OP_FROM_SYS_MK is introduced. It is set on all targets
found in system makefiles so that they are not eligible to become
the main target. We cannot just set OP_NOTMAIN because it is one of
the attributes inherited from transformation and .USE rules and would
make any eligible target that uses a built-in inference rule ineligible.

The $(.IMPSRC) local variable now works like in gmake: it is set to
the first prerequisite for explicit rules. For implicit rules it
is still the implied source.

The manual page is improved regarding the fixed features. Test cases
for the fixed problems are added.

Other improvements in the Suff module include:
- better debug messages for transformation rule search (length of
the chain is now visualized by indentation)
- Suff structures are created, destroyed and moved around by a set
of maintenance functions so their reference counts are easier
to track (this also gets rid of a lot of code duplication)
- some unreasonably long functions were split into smaller ones
- many local variables had their names changed to describe their
purpose instead of their type
 1.15 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.14 31-Oct-2024  rillig make: in the debug log, always qualify line number with filename

Previously, to find out the filename corresponding to a line number from
a 'Parsing' line, it was necessary to find the preceding
'SetFilenameVars' line, which was unnecessarily time-consuming and
distracting.

The 'filename:line' format matches the one used in PrintStackTrace, and
it differs from the one used in PrintLocation, as the former format is
more common in other tools.

Most of the affected unit tests only use the 'Parsing' lines to give
additional context to their debug log, so no structural changes there.
 1.13 01-Jun-2023  rillig branches: 1.13.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.12 19-Jan-2023  rillig tests/make: rename files that are not test cases
 1.11 09-Jan-2022  rillig make: remove redundant lines from stack traces

These lines repeated the information from the .for loop line above them.
 1.10 08-Jan-2022  rillig make: add details about .for loop variables to stack traces

The stack traces are enabled with the debug logging option '-dp'.
 1.9 08-Jan-2022  rillig make: fix stack traces in -dp mode (since 2021-01-26)

Previously, the stack traces omitted some lines that seemed to be
redundant. As a result, the stack traces contained confusing line
numbers.
 1.8 28-Dec-2021  rillig make: make debug logging a bit more human-friendly

The previous log format "ParseReadLine (%d): '%s'" focused on the
implementation, it was not immediately obvious to a casual reader that
the number in parentheses was the line number. Additionally, having
both a colon and quotes in a log message is uncommon. The quotes have
been added in parse.c 1.127 from 2007-01-01.

The new log format "Parsing line %d: %s" is meant to be easier readable
by humans. The quotes are not needed since ParseReadLine always strips
trailing whitespace, leaving no room for ambiguities. The other log
messages follow common punctuation rules, which makes the beginning of
the line equally unambiguous. Before var.c 1.911 from 2021-04-05,
variable assignments were logged with the format "%s:%s = %s", without a
space after the colon.
 1.7 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.6 26-Jan-2021  rillig make(1): in -dp mode, print stack trace with each diagnostic

This makes it easier to track down where a warning or an error
originated from. This information could be further enriched for .for
loops, to also include the variable names and their values. For now,
it's good enough to replace the large comment describing how a stack
trace _could_ be generated with actual code that implements that idea.

The syntax of the locations is <filename>:<lineno>, which intentionally
differs from the traditional "<filename>" line <lineno>, since the
former is more widely supported by editors and IDEs.

Having this stacktrace information is especially intended for
complicated systems built upon make, such as pkgsrc.
 1.5 14-Sep-2020  rillig make(1): describe how Parse_Error might print stack traces

In deeply nested include chains and .for loops this may be a useful
feature. It's a little tricky to generate an intuitive stack trace,
though not impossible. This explanation also serves as a detailed
documentation about how the .include and .for directives are
implemented.
 1.4 05-Sep-2020  rillig make(1): fix .INCLUDEDFROMDIR/.INCLUDEDFROMFILE
 1.3 05-Sep-2020  rillig make(1): add test for .INCLUDEDFILE combined with .for loops

The .for loops are implemented as a special kind of .include, therefore
they affect the .INCLUDEDFROM variable.
 1.2 05-Sep-2020  rillig make(1): make test for .INCLUDEDFROMDIR simpler

The .info and .warning directives provide exactly the early expansion
that this test needs. No more .for for getting a snapshot of a
variable.
 1.1 17-May-2020  rillig usr.bin/make: demonstrate actual behavior of .INCLUDEDFROMFILE
 1.13.2.1 02-Aug-2025  perseant Sync with HEAD
 1.9 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.8 19-Jan-2023  rillig tests/make: rename files that are not test cases
 1.7 08-Jan-2022  rillig make: fix stack traces in -dp mode (since 2021-01-26)

Previously, the stack traces omitted some lines that seemed to be
redundant. As a result, the stack traces contained confusing line
numbers.
 1.6 22-Jan-2021  rillig make(1): fix test for .INCLUDEDFROMFILE

The test did not test the intended variable before.

If the implementation of the .INCLUDEDFROMFILE had been wrong before,
the test would have succeeded nevertheless since it tested whether the
variable named "include-main.mk" was defined, which was obviously never
the case since that's the value of the variable, not the name.
 1.5 05-Sep-2020  rillig make(1): fix .INCLUDEDFROMDIR/.INCLUDEDFROMFILE
 1.4 05-Sep-2020  rillig make(1): add test for .INCLUDEDFILE combined with .for loops

The .for loops are implemented as a special kind of .include, therefore
they affect the .INCLUDEDFROM variable.
 1.3 05-Sep-2020  rillig make(1): make test for .INCLUDEDFROMDIR simpler

The .info and .warning directives provide exactly the early expansion
that this test needs. No more .for for getting a snapshot of a
variable.
 1.2 27-Jul-2020  rillig make(1): document where to fix the .INCLUDEDFROM bug
 1.1 17-May-2020  rillig usr.bin/make: demonstrate actual behavior of .INCLUDEDFROMFILE
 1.1 19-Jan-2023  rillig tests/make: rename files that are not test cases
 1.10 19-Jan-2023  rillig tests/make: rename files that are not test cases
 1.9 08-Jan-2022  rillig make: fix stack traces in -dp mode (since 2021-01-26)

Previously, the stack traces omitted some lines that seemed to be
redundant. As a result, the stack traces contained confusing line
numbers.
 1.8 07-Jan-2022  rillig make: rename IFile and its fields to match their actual content

For lines that use backslash continuation, the human-readable line
number does not equal the number of raw lines that have been read from
the file.

The big comment in PrintStackTrace has become outdated, it still
referred to first_lineno. Due to the bugs documented in
opt-debug-parse.mk, that function needs to be redone completely.

No functional change.
 1.7 02-Nov-2020  rillig make(1): remove word "Ptr" from variable names

Whether or not a variable is a pointer is obvious from the context.
Since the introduction of function prototypes in C90, this information
is checked by the compiler and no longer needs to be encoded in the
variable names.
 1.6 25-Oct-2020  rillig make(1): rename type Vector to PtrVector

This allows the name Vector to be used for a more generic vector type,
which will be added soon.
 1.5 18-Oct-2020  rillig make(1): rename Stack to Vector

Both Var_Dump and GetActuallyIncludingFile access more than only the top
item of the stack, therefore it is more honest to rename the data type.
 1.4 14-Sep-2020  rillig make(1): describe how Parse_Error might print stack traces

In deeply nested include chains and .for loops this may be a useful
feature. It's a little tricky to generate an intuitive stack trace,
though not impossible. This explanation also serves as a detailed
documentation about how the .include and .for directives are
implemented.
 1.3 05-Sep-2020  rillig make(1): add test for .INCLUDEDFILE combined with .for loops

The .for loops are implemented as a special kind of .include, therefore
they affect the .INCLUDEDFROM variable.
 1.2 05-Sep-2020  rillig make(1): make test for .INCLUDEDFROMDIR simpler

The .info and .warning directives provide exactly the early expansion
that this test needs. No more .for for getting a snapshot of a
variable.
 1.1 17-May-2020  rillig usr.bin/make: demonstrate actual behavior of .INCLUDEDFROMFILE
 1.1 19-Jan-2023  rillig tests/make: rename files that are not test cases
 1.5 19-Jan-2023  rillig tests/make: rename files that are not test cases
 1.4 26-Jan-2021  rillig make(1): in -dp mode, print stack trace with each diagnostic

This makes it easier to track down where a warning or an error
originated from. This information could be further enriched for .for
loops, to also include the variable names and their values. For now,
it's good enough to replace the large comment describing how a stack
trace _could_ be generated with actual code that implements that idea.

The syntax of the locations is <filename>:<lineno>, which intentionally
differs from the traditional "<filename>" line <lineno>, since the
former is more widely supported by editors and IDEs.

Having this stacktrace information is especially intended for
complicated systems built upon make, such as pkgsrc.
 1.3 05-Sep-2020  rillig make(1): add test for .INCLUDEDFILE combined with .for loops

The .for loops are implemented as a special kind of .include, therefore
they affect the .INCLUDEDFROM variable.
 1.2 05-Sep-2020  rillig make(1): make test for .INCLUDEDFROMDIR simpler

The .info and .warning directives provide exactly the early expansion
that this test needs. No more .for for getting a snapshot of a
variable.
 1.1 17-May-2020  rillig usr.bin/make: demonstrate actual behavior of .INCLUDEDFROMFILE
 1.2 14-Nov-2020  rillig make(1): test ignoring errors from shell commands in jobs mode
 1.1 07-Nov-2020  rillig make(1): add test for job command flags
 1.2 14-Nov-2020  rillig make(1): test ignoring errors from shell commands in jobs mode
 1.1 07-Nov-2020  rillig make(1): add test for job command flags
 1.2 29-Sep-2020  rillig make(1): fix test job-output-long-lines

The test failed on Linux since the test relied on the two child
processes interleaving each other. This is not guaranteed to happen
though.
 1.1 27-Sep-2020  rillig make(1): add test for merging long lines of job output
 1.4 01-Nov-2020  rillig make(1): reduce amount of work in test job-output-long-lines.mk

The effect that some of the separator lines start at the end of another
line is still visible.
 1.3 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.2 29-Sep-2020  rillig make(1): fix test job-output-long-lines

The test failed on Linux since the test relied on the two child
processes interleaving each other. This is not guaranteed to happen
though.
 1.1 27-Sep-2020  rillig make(1): add test for merging long lines of job output
 1.4 03-Sep-2022  rillig make: fix handling of null bytes in the output in jobs mode

The test job-output-null failed occasionally, depending on the exact
timing of the child's write and make's read.
 1.3 12-Sep-2021  rillig tests/make: make output of test job-output-null clearer

Having 5 times the word 'hello' in the output doesn't help at
understanding the test and how the output was produced.

Bash 5 sometimes makes this test fail by adding '2b' and '2c' to the
output.
 1.2 03-Jul-2021  rillig tests/make: make test job-output-null more portable

Previously, the test dependend on implementation details of the system's
printf command.

Thank you sjg for the detailed analysis on macOS, FreeBSD and Linux.
 1.1 15-Apr-2021  rillig tests/make: demonstrate handling of null bytes
 1.4 03-Sep-2022  rillig make: fix handling of null bytes in the output in jobs mode

The test job-output-null failed occasionally, depending on the exact
timing of the child's write and make's read.
 1.3 12-Sep-2021  rillig tests/make: make output of test job-output-null clearer

Having 5 times the word 'hello' in the output doesn't help at
understanding the test and how the output was produced.

Bash 5 sometimes makes this test fail by adding '2b' and '2c' to the
output.
 1.2 03-Jul-2021  rillig tests/make: make test job-output-null more portable

Previously, the test dependend on implementation details of the system's
printf command.

Thank you sjg for the detailed analysis on macOS, FreeBSD and Linux.
 1.1 15-Apr-2021  rillig tests/make: demonstrate handling of null bytes
 1.2 13-Jun-2025  rillig branches: 1.2.4;
make: do not discard empty lines in the output of a command
 1.1 05-Jun-2025  rillig make: remove empty line from diagnostic, add tests for output handling

The warning for the invalid internal option "-J" does not need a
trailing newline, as that is provided by Parse_Error already.

Having this newline in the output demonstrated a previously unknown bug
in handling the output of child commands in parallel mode. There, empty
lines are randomly discarded, depending on the chunks in which the
output from the child process is copied to make's stdout. See
job-output.mk for a demonstration.

The test for the Korn shell did not run the Korn shell in error handling
mode, as the error handling mode only affects the parallel mode but the
test didn't switch to that mode.

After fixing the shell-ksh.mk test, the single '"' in the output looked
suspicious, and indeed, the shell-csh.mk test had the same problem of
filtering more characters from the output than intended.
 1.2.4.2 02-Aug-2025  perseant Sync with HEAD
 1.2.4.1 13-Jun-2025  perseant file job-output.exp was added on branch perseant-exfatfs on 2025-08-02 05:58:35 +0000
 1.2 13-Jun-2025  rillig branches: 1.2.4;
make: do not discard empty lines in the output of a command
 1.1 05-Jun-2025  rillig make: remove empty line from diagnostic, add tests for output handling

The warning for the invalid internal option "-J" does not need a
trailing newline, as that is provided by Parse_Error already.

Having this newline in the output demonstrated a previously unknown bug
in handling the output of child commands in parallel mode. There, empty
lines are randomly discarded, depending on the chunks in which the
output from the child process is copied to make's stdout. See
job-output.mk for a demonstration.

The test for the Korn shell did not run the Korn shell in error handling
mode, as the error handling mode only affects the parallel mode but the
test didn't switch to that mode.

After fixing the shell-ksh.mk test, the single '"' in the output looked
suspicious, and indeed, the shell-csh.mk test had the same problem of
filtering more characters from the output than intended.
 1.2.4.2 02-Aug-2025  perseant Sync with HEAD
 1.2.4.1 13-Jun-2025  perseant file job-output.mk was added on branch perseant-exfatfs on 2025-08-02 05:58:35 +0000
 1.3 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.2 16-Jun-2021  rillig branches: 1.2.4;
make: fix error handling in jobs mode

By using the same error handling code as in the branch for non-empty
commands, the behavior is the same again as before 2021-01-29.
 1.1 16-Jun-2021  rillig tests/make: demonstrate wrong error handling in jobs mode
 1.2.4.1 02-Aug-2025  perseant Sync with HEAD
 1.1 16-Jun-2021  rillig tests/make: demonstrate wrong error handling in jobs mode
 1.1 29-Jan-2021  rillig make(1): demonstrate unnecessary creation of empty files in jobs mode
 1.2 30-Jan-2021  rillig make(1): add test for combining the options -j, -n, -t

This is a preparation for refactoring the complicated condition in
JobStart.
 1.1 29-Jan-2021  rillig make(1): demonstrate unnecessary creation of empty files in jobs mode
 1.3 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.2 07-Jan-2024  sjg branches: 1.2.2;
make: more consistent error messages

Move %s: progname from Job_CheckCommands to Fatal
to avoid is being repeated when Job_CheckCommands is passed Error.

This means some errors from var also report progname (and level)
which is useful.

Reviewed by: rillig
 1.1 01-Dec-2020  rillig make(1): add tests for suppressing "stopped in"

These tests demonstrate the unwanted behavior described in PR bin/55578
and PR bin/55832.
 1.2.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 01-Dec-2020  rillig make(1): add tests for suppressing "stopped in"

These tests demonstrate the unwanted behavior described in PR bin/55578
and PR bin/55832.
 1.5 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.4 07-Jan-2024  sjg branches: 1.4.2;
make: more consistent error messages

Move %s: progname from Job_CheckCommands to Fatal
to avoid is being repeated when Job_CheckCommands is passed Error.

This means some errors from var also report progname (and level)
which is useful.

Reviewed by: rillig
 1.3 08-Jan-2021  sjg Ensure PrintOnError always reports 'stopped in' on first call.

We may still suppress the rest of the noise if shouldDieQuietly
says to, but the 'stopped in' output is too important to lose.
Avoid repeating it though in the same process.

For the case of aborting due to failure detected elsewhere,
exit 6 so we have a clue.

PR: 55578
Reviewed by:
 1.2 07-Jan-2021  sjg Remove .MAKE from nested target which is not a sub-make

This does not fix the issue, just makes the unit-test more accurate.

PR: 55578
Reviewed by: rillig
 1.1 01-Dec-2020  rillig make(1): add tests for suppressing "stopped in"

These tests demonstrate the unwanted behavior described in PR bin/55578
and PR bin/55832.
 1.4.2.1 02-Aug-2025  perseant Sync with HEAD
 1.2 07-Jan-2021  sjg Remove .MAKE from nested target which is not a sub-make

This does not fix the issue, just makes the unit-test more accurate.

PR: 55578
Reviewed by: rillig
 1.1 01-Dec-2020  rillig make(1): add tests for suppressing "stopped in"

These tests demonstrate the unwanted behavior described in PR bin/55578
and PR bin/55832.
 1.3 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.2 07-Jan-2024  sjg branches: 1.2.2;
make: more consistent error messages

Move %s: progname from Job_CheckCommands to Fatal
to avoid is being repeated when Job_CheckCommands is passed Error.

This means some errors from var also report progname (and level)
which is useful.

Reviewed by: rillig
 1.1 01-Dec-2020  rillig make(1): add tests for suppressing "stopped in"

These tests demonstrate the unwanted behavior described in PR bin/55578
and PR bin/55832.
 1.2.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 01-Dec-2020  rillig make(1): add tests for suppressing "stopped in"

These tests demonstrate the unwanted behavior described in PR bin/55578
and PR bin/55832.
 1.8 29-Mar-2025  rillig make: in stack traces from target commands, add the command level

A target can contain several commands, and these commands are likely to
contain the same expressions. To distinguish them, add one more line to
the stack trace, to narrow down the source of the error.
 1.7 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.6 20-Jul-2024  rillig make: don't run erroneous commands in compat mode

When there is a parse or evaluation error in an expression that becomes
part of the command, don't run that command, as the result of the failed
evaluation typically contains garbage characters. Skip the remaining
commands from that target as well, as they may depend on the erroneous
command.
 1.5 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.4 20-Apr-2024  rillig branches: 1.4.2;
make: provide more context information for parse/evaluate errors
 1.3 09-Dec-2021  rillig make: remove period from end of error messages and warnings

The majority of the existing error messages and warnings does not
include a period at the end. Follow this style consistently.
 1.2 01-Nov-2020  rillig make(1): in lint mode, exit with error status on errors

Calling Parse_Error during parsing has always led to a nonzero exit
status. Calling Parse_Error later, when expanding the shell commands,
has had no effect on the exit status. Neither had calling Error.

To make make a reliable tool, it has to report errors as they occur.
Enable this strict behavior in lint mode for now. Lint mode has to be
enabled explicitly, preserving the default behavior.
 1.1 03-Aug-2020  rillig make(1): in lint mode, disallow dynamic variable names in :@ modifier

This is an extremely obscure feature that hopefully nobody ever
considered using.
 1.4.2.1 02-Aug-2025  perseant Sync with HEAD
 1.5 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.4 30-Jan-2021  rillig make(1): update documentation of test lint.mk
 1.3 15-Sep-2020  rillig make(1): move flags for lint test into the test itself
 1.2 08-Aug-2020  rillig make(1): clean up Var_UnExport

Mark the parameter as constant since it is not modified.

Remove tests for '\n' since these can never succeed.

newenv can never be NULL since neither of bmake_malloc or bmake_realloc
returns NULL.

Improve variable names: vlist was too unexpressive.

Add debug logging since unexporting variables is an uncommon operation
that directly affects the observable environment of the child processes.

Fix CRLF line endings in a few unit tests.
 1.1 03-Aug-2020  rillig make(1): in lint mode, disallow dynamic variable names in :@ modifier

This is an extremely obscure feature that hopefully nobody ever
considered using.
 1.5 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.4 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.3 03-Oct-2020  rillig make(1): do not export variable names starting with '-'

By convention, names of environment variables consist of uppercase
letters and underscores. Most of them start with an uppercase letter.
In a few cases, the names also contain lowercase letters, such as in
http_proxy.

Variable names starting with a hyphen are confusing and might be
mistaken as command line options. Therefore don't export these.

This also affects a few edge cases that don't occur in practice, such as
setting .MAKE.EXPORTED=-env or .MAKE.EXPORTED=-literal. These had not
worked as expected anyway.
 1.2 03-Oct-2020  rillig make(1): explain the purpose of the test make-exported
 1.1 09-Aug-2020  rillig make(1): add test for non-obvious .MAKE.EXPORTED edge case
 1.7 09-Sep-2022  sjg Handle deprecation of egrep
 1.6 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.5 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.4 03-Oct-2020  rillig make(1): ignore -env and -literal in assignments to .MAKE.EXPORTED

Previously, assigning the string "-env" to the variable .MAKE.EXPORTED
had the same effect as the .export-env directive. This was only due to
a sloppy implementation, not by design.

For the string "-literal" and the directive .export-literal, the
situation was even worse since the actually executed code was a wild
mixture between .export and .export-literal that in the end exported the
expanded form of the variable. Therefore there was no practical use
case of this implementation flaw.
 1.3 03-Oct-2020  rillig make(1): do not export variable names starting with '-'

By convention, names of environment variables consist of uppercase
letters and underscores. Most of them start with an uppercase letter.
In a few cases, the names also contain lowercase letters, such as in
http_proxy.

Variable names starting with a hyphen are confusing and might be
mistaken as command line options. Therefore don't export these.

This also affects a few edge cases that don't occur in practice, such as
setting .MAKE.EXPORTED=-env or .MAKE.EXPORTED=-literal. These had not
worked as expected anyway.
 1.2 03-Oct-2020  rillig make(1): explain the purpose of the test make-exported
 1.1 09-Aug-2020  rillig make(1): add test for non-obvious .MAKE.EXPORTED edge case
 1.4 11-Apr-2025  rillig make: use "file:123" format in meta mode
 1.3 27-Jan-2022  sjg branches: 1.3.4;
Allow local variable assignments in dependency lines

The variable is set in the context of the target.
This syntax has been supported by gmake for ~ever.
If necessary a makefile can set .MAKE.TARGET_LOCAL_VARIABLES=false
to disable this.

Expose GetBooleanExpr so parse.c can use it.
 1.2 14-Jan-2022  sjg Add unit-test for .MAKE.META.CMP_FILTER
 1.1 30-Nov-2020  sjg Add some tests for meta mode
 1.3.4.1 02-Aug-2025  perseant Sync with HEAD
 1.6 02-Mar-2022  sjg Add nofilemon to meta mode tests

The unit-tests for meta mode do not depend on filemon.
Adding nofilemon to .MAKE.MODE allows these to pass on
a system that would use filemon_dev but does not have
the module loaded.
 1.5 09-Feb-2022  rillig make: fix mistakes, spelling and typos in comments and manual page

No binary change for -DNDEBUG.
 1.4 27-Jan-2022  sjg Allow local variable assignments in dependency lines

The variable is set in the context of the target.
This syntax has been supported by gmake for ~ever.
If necessary a makefile can set .MAKE.TARGET_LOCAL_VARIABLES=false
to disable this.

Expose GetBooleanExpr so parse.c can use it.
 1.3 14-Jan-2022  sjg Add unit-test for .MAKE.META.CMP_FILTER
 1.2 05-Dec-2020  sjg Don't let gcov mess up results
 1.1 30-Nov-2020  sjg Add some tests for meta mode
 1.2 25-Feb-2023  sjg make: meta-ignore tests will not work if TMPDIR is /tmp

Since /tmp and /var/tmp are always part of .MAKE.META.IGNORE_PATHS
the varname-dot-make-meta-ignore_* tests will not work
if TMPDIR is either (or subdir) of those.
 1.1 23-Feb-2023  sjg Add unit-tests for .MAKE.META.IGNORE_*

These unit-tests should only be run if TEST_MAKE
has a valid .MAKE.PATH_FILEMON to indicate that filemon is
supported.

All three tests use the same meta-ignore.inc
which runs three sub-makes

one to initialize the target .meta file
two to ignore a file using .MAKE.META.IGNORE_{PATHS,PATTERNS,FILTER}
three to verify that without .MAKE.META.IGNORE_* the target is out of date.

Fix the order of _SED_CMDS to avoid errors when ${MAKE:T} appears in
.OBJDIR
 1.3 05-Aug-2025  sjg meta-output.mk diff output

We construct output such that it should match what we
can extract from output.meta, so diff the two.
This way the test cannot pass if meta.c is capturing
something inaccurately - other than the trailing newline.
 1.2 04-Aug-2025  sjg meta-output.mk: Allow for echo that does not support -n

On latest Darwin, /bin/sh builtin echo does not do -n

There will be others, so test if echo -n works and adjust.

Capture only the command output from the meta file so
that results can be consistent whether echo -n works or not.
 1.1 03-Aug-2025  sjg make: ensure output captured in meta file is accurate

In CollectOutput() a newline before the end of job->outBuf
results in a short write to stdout, but meta_job_output()
was recording the entire string in the meta file, so on
next call the left overs would be duplicated in the meta file.

Pass a length to meta_job_output() if it should only report part of
the data in meta file.
 1.5 05-Aug-2025  sjg meta-output.mk diff output

We construct output such that it should match what we
can extract from output.meta, so diff the two.
This way the test cannot pass if meta.c is capturing
something inaccurately - other than the trailing newline.
 1.4 04-Aug-2025  sjg Use printf rather than echo -n
 1.3 04-Aug-2025  sjg echo.inc make ECHO_SCRIPT reusable
 1.2 04-Aug-2025  sjg meta-output.mk: Allow for echo that does not support -n

On latest Darwin, /bin/sh builtin echo does not do -n

There will be others, so test if echo -n works and adjust.

Capture only the command output from the meta file so
that results can be consistent whether echo -n works or not.
 1.1 03-Aug-2025  sjg make: ensure output captured in meta file is accurate

In CollectOutput() a newline before the end of job->outBuf
results in a short write to stdout, but meta_job_output()
was recording the entire string in the meta file, so on
next call the left overs would be duplicated in the meta file.

Pass a length to meta_job_output() if it should only report part of
the data in meta file.
 1.2 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.1 06-Mar-2011  sjg Add unit tests to check that exists(some/dir/) works

Also fix handling of sysV substitutions when lhs and variable are empty.

Also that modifiers do not cause errors during conditional tests
when undefined variables should otherwise be ok.
Ie. .if defined(nosuch) && ${nosuch:Mx} != ""
 1.2 08-Oct-2020  rillig make(1): move test for .CURDIR from misc.mk to varname-dot-curname.mk
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2 08-Oct-2020  rillig make(1): move test for .CURDIR from misc.mk to varname-dot-curname.mk
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.3 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2 11-May-2006  sjg Remove the modterm case from moderrs, the syntax errors
generated by /bin/sh on other systems are not consistent.
 1.1 11-May-2006  sjg Extract the variable modifier logic to a separate function.
This cuts Var_Parse in half! and allows the modifier logic to
be used recursively - when getting modifiers via variables.

Add new unit-test, to check that certain error cases are handled
correctly.
 1.54 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.53 30-Mar-2025  rillig make: fix error message for invalid ":[...]" modifier

The unparsed value of the modifier argument can already be seen in the
stack trace, but the modifier argument may contain expressions and the
expanded value of these expressions was hidden up to now. See the EMPTY
test at the bottom of varmod-select-words.mk for details.
 1.52 30-Mar-2025  rillig make: let the ":t" modifiers fall back to the ":from=to" modifier

Suggested by https://bugs.freebsd.org/285726.

This means that the ":t" modifiers cannot have future extensions that
include a "=", as that may break existing code.
 1.51 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.50 29-Mar-2025  rillig make: stop parsing after seeing an unknown modifier in an expression

Previously, after an expression such as ${VAR:Z::::}, make detected the
unknown modifier ":Z" and then continued parsing, which produced
unnecessary follow-up error messages. It was also necessary to
distinguish the error cases when logging the result of an applied
modifier in -dv mode.

Unify the error handling cases of a syntax error, an evaluation error
and an unknown modifier, to avoid the unnecessary follow-up error
messages.

The test in varmod-edge.mk now produces ":}" from the erroneous
expression, which may be misleading and thus will be looked at in a
follow-up commit.

The general idea of this patch was reviewed by sjg, I made a few
nonsubstantial changes after the review.
 1.49 29-Mar-2025  rillig make: fix error message for unclosed expression

Even in an unclosed expression such as "${VAR:from=to", the modifier
":from=to" needs to be recognized as such, instead of giving an error
message about an "Unknown modifier ":from=to"".
 1.48 29-Mar-2025  rillig make: add more details to error message about unfinished modifier

These details allow to quickly see the place where the syntax error is,
based on the surrounding lines from the stack trace.
 1.47 29-Mar-2025  rillig make: add details about indirect modifiers to the stack traces

Previously, the error message "Unfinished modifier (',' missing)" from
moderrs.mk didn't provide enough context to understand where and why the
comma was missing.
 1.46 29-Mar-2025  rillig make: in stack traces from target commands, add the command level

A target can contain several commands, and these commands are likely to
contain the same expressions. To distinguish them, add one more line to
the stack trace, to narrow down the source of the error.
 1.45 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.44 20-Jul-2024  rillig make: don't run erroneous commands in compat mode

When there is a parse or evaluation error in an expression that becomes
part of the command, don't run that command, as the result of the failed
evaluation typically contains garbage characters. Skip the remaining
commands from that target as well, as they may depend on the erroneous
command.
 1.43 20-Jul-2024  rillig tests/make: remove redundant context information

The affected target is already mentioned in the line containing the
error message.
 1.42 09-Jul-2024  rillig make: error out on parse/evaluation errors in shell commands

The expression ${VAR:X} has an unknown modifier ':X'. Previously, this
expression errored out when the expression was evaluated at parse time,
but not when the expression was evaluated when generating the commands
to bring a target up to date. The errors were previously reported, they
didn't affect the exit status, though.

Now, errors in expressions are handled in the same way, regardless of
the time at which they are evaluated.
 1.41 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.40 05-Jul-2024  rillig make: error out on unclosed expressions during parse time

In exchange, this adds location information.

For unnamed expressions, the value is no longer printed. This will be
added back in a follow-up commit.
 1.39 04-Jul-2024  rillig make: error out on the "Bad modifier" error message

Previously, the "Bad modifier" error message did not affect make's exit
status. As a side effect, this kind of error now gets more context
information.
 1.38 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.37 30-Jun-2024  rillig make: error out on some more syntax errors

Previously, these errors only produced a message on stderr. They only
affected make's exit status when they were evaluated at parse time, but
not when evaluating the commands for a specific target right before
executing them.

The affected syntax errors are:
* invalid regular expressions in the ':C' modifier
* out-of-range references to regex groups in the ':C' modifier
* unfinished modifiers
 1.36 30-Jun-2024  rillig tests/make: replace 'want' comments with 'expect' directives

The 'want' comments needed to be cross-checked manually, which was
error-prone, as can be seen in the "Unknown modifier" messages that got
out of sync.
 1.35 20-Apr-2024  rillig branches: 1.35.2;
make: provide more context information for parse/evaluate errors
 1.34 19-Nov-2023  rillig tests/make: replace 'variable expressions' with 'expressions'
 1.33 19-Nov-2023  rillig make: replace 'variable expression' with 'expression' in diagnostics
 1.32 21-Jun-2021  rillig tests/make: remove unnecessary -dL from moderrs.mk

It was only needed for the test for unmatched subexpressions in the
modifier ':C'. That test has been moved to varmod-subst-regex.mk.
 1.31 21-Jun-2021  rillig tests/make: move and extend test for unmatched '\1' in ':C'

This test lived together with a few unrelated tests in moderrs.mk, it is
better placed in varmod-subst-regex.mk though.

While here, extend, document and explain the test since its purpose was
not obvious from reading the code alone.
 1.30 21-Jun-2021  sjg Do not report unmatched regex subexpressions

It is not always an error for a subexpression to have not matched,
since the regex library can/does not convey how many matches are
expected, only report an error if opts.strict (-dL)

Reviewed by: christos
 1.29 23-Feb-2021  rillig make: improve error message for bad modifier in variable expression

The improvement is especially noteable for variable expressions based on
the empty variable, see moderrs.exp:103.
 1.28 23-Feb-2021  rillig make: add test for confusing error message for bad modifier

In the expression ${:U}, the variable name is empty. Since these
expressions are generated by .for loops, the error messages for them
must not end with a trailing space. Putting the variable name in quotes
helps against that.
 1.27 23-Feb-2021  rillig make: improve error message for unclosed modifier

Replace "variable specification" with the more modern "variable
expression", reduce the number of parentheses, output more than a single
character for modifiers, make it obvious that in expressions such as
${:Serror}, the "" means a variable name.
 1.26 23-Feb-2021  rillig make: improve error message for unknown modifier

Back in 1995, the modifiers were all single-character, and it made sense
to print only the first character. Nowadays, with ':S', ':@var@...@',
'::=' and several others, a little more context is useful to see where
the exact error is. The actual modifier is still guessed, and the guess
may be wrong as soon as backslashes get involved, but it is still better
than before.
 1.25 23-Feb-2021  rillig make: quote ':S' in error message about missing delimiter
 1.24 23-Feb-2021  rillig make: add quotes around variable name in an error message
 1.23 01-Nov-2020  rillig make(1): treat malformed :range, :ts and :[...] as errors

Before, integer overflow in the :[1..2] modifier had not been detected,
and the actual behavior varied between ILP64 and LP64I32 machines.

Before, the :ts modifier accepted character literals like \012345 and
\x1F600, which don't fit in a single character and were thus truncated.

Before, the :range modifier issued an "Unknown modifier" error message
for :range=x, which was not quite correct. The error message in this
case is now "Invalid number".
 1.22 01-Nov-2020  rillig make(1): demonstrate parsing bugs in test moderrs.mk

When a malformed variable expression is parsed, the remaining part of
the expression is passed unmodified to the output. This is unexpected
and wrong.
 1.21 01-Nov-2020  rillig make(1): renumber the tests in moderrs.mk, remove duplicates
 1.20 01-Nov-2020  rillig make(1): make test names in moderrs.mk more descriptive
 1.19 01-Nov-2020  rillig make(1): precisely describe the expected output in the test moderrs.mk

By making "want:" the same length as "make:", the remaining text in
these lines can be compared easily.
 1.18 01-Nov-2020  rillig make(1): separate sections of moderrs.mk with empty lines
 1.17 01-Nov-2020  rillig make(1): add section headings to the test moderrs.mk
 1.16 25-Aug-2020  rillig make(1): move test for the ::= modifier to varmod-assign
 1.15 09-Aug-2020  rillig make(1): improve test for undefined subexpression in :C modifier

In the previous test output, it was unnecessarily hard to see what
happens because of the many empty strings. Enclosing the capturing
groups in parentheses helps against this.
 1.14 09-Aug-2020  rillig make(1): add test for undefined subexpression in the :C modifier
 1.13 08-Aug-2020  rillig make(1): improve error message in case of unfinished modifiers

The previous error message "Unclosed substitution" was wrong for several
reasons.

It is not about "unclosed", but about "unfinished" since in the
:@var@...@ modifier the missing '@' does not really close anything.

The word "substitution" may have originated in a time where :S and
:from=to were the only modifiers, and these were indeed substitutions,
but several other modifiers aren't.

The :S and :C modifiers allow an arbitrary delimiter, therefore it is
helpful to enclose the delimiter in quotes, just in case someone chooses
')' or '{' or even ' ' as delimiter.
 1.12 31-Jul-2020  rillig make(1): add test for parsing an incomplete :t modifier

This looks a lot like undefined behavior, just like in :S and :C before.
 1.11 31-Jul-2020  rillig make(1): fix undefined behavior when parsing malformed :C modifier

Same as in the :S modifier.
 1.10 31-Jul-2020  rillig make(1): fix undefined behavior in malformed :S modifier

The unit tests failed on Ubuntu, and by looking closely at the code, it
was trivial to see the out-of-bounds memory read.

Other modifiers may have the same problem and will be inspected later.
 1.9 29-Jul-2020  rillig make(1): fix segfault when evaluating ${::=value}

The bug had been in the handling of the SysV modifier for many years, but
it had not been triggered since the "parsing position for the next
modifier" had been initialized to a non-NULL pointer.

In var.v r1.350, this pointer had been initialized to NULL instead since
every ApplyModifier function must set it in every case where it returns
anything except "default_case".

There might have been a slight chance of tricking make to output a wrong
error message, but nothing worse.
 1.8 29-Jul-2020  rillig make(1): add enough tests to cover the ApplyModifier functions

Only a few return statements are still missing from the code coverage.

In ApplyModifier_Assign, the test for an empty variable name is skipped
for now since it segfaults.

In ApplyModifier_SysV after the second ParseModifierPart, the branch for
the missing delimiter is not reached since this case is already checked
for in the first part of the function. To trigger this branch, a
specially crafted, unrealistic string needs to be created, and that's too
complicated for the moment.
 1.7 29-Jul-2020  rillig make(1): add unit tests for parse errors in modifiers
 1.6 28-Jul-2020  rillig make(1): add test for modifier part with unbalanced braces
 1.5 26-Jul-2020  rillig make(1): add tests for :!...! parse errors
 1.4 26-Jul-2020  rillig make(1): add test for missing input validation in :[123] modifier
 1.3 26-Jul-2020  rillig make(1): fix missing error message about missing @ delimiter

This had been broken since 2020-07-03, during a "refactoring".
 1.2 26-Jul-2020  rillig make(1): add test about missing delimiters in :@ modifier

These error conditions have been broken since var.c 1.236 on 2020-07-03.
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.35.2.2 02-Aug-2025  perseant Sync with HEAD
 1.35.2.1 01-Jul-2024  perseant Sync with HEAD.
 1.47 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.46 30-Mar-2025  rillig make: let the ":t" modifiers fall back to the ":from=to" modifier

Suggested by https://bugs.freebsd.org/285726.

This means that the ":t" modifiers cannot have future extensions that
include a "=", as that may break existing code.
 1.45 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.44 29-Mar-2025  rillig make: stop parsing after seeing an unknown modifier in an expression

Previously, after an expression such as ${VAR:Z::::}, make detected the
unknown modifier ":Z" and then continued parsing, which produced
unnecessary follow-up error messages. It was also necessary to
distinguish the error cases when logging the result of an applied
modifier in -dv mode.

Unify the error handling cases of a syntax error, an evaluation error
and an unknown modifier, to avoid the unnecessary follow-up error
messages.

The test in varmod-edge.mk now produces ":}" from the erroneous
expression, which may be misleading and thus will be looked at in a
follow-up commit.

The general idea of this patch was reviewed by sjg, I made a few
nonsubstantial changes after the review.
 1.43 29-Mar-2025  rillig make: fix error message for unclosed expression

Even in an unclosed expression such as "${VAR:from=to", the modifier
":from=to" needs to be recognized as such, instead of giving an error
message about an "Unknown modifier ":from=to"".
 1.42 29-Mar-2025  rillig make: add more details to error message about unfinished modifier

These details allow to quickly see the place where the syntax error is,
based on the surrounding lines from the stack trace.
 1.41 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.40 20-Jul-2024  rillig make: don't run erroneous commands in compat mode

When there is a parse or evaluation error in an expression that becomes
part of the command, don't run that command, as the result of the failed
evaluation typically contains garbage characters. Skip the remaining
commands from that target as well, as they may depend on the erroneous
command.
 1.39 20-Jul-2024  rillig tests/make: remove redundant context information

The affected target is already mentioned in the line containing the
error message.
 1.38 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.37 05-Jul-2024  rillig make: error out on unclosed expressions during parse time

In exchange, this adds location information.

For unnamed expressions, the value is no longer printed. This will be
added back in a follow-up commit.
 1.36 05-Jul-2024  rillig tests/make: add expected messages for "Unclosed expression"
 1.35 04-Jul-2024  rillig make: error out on the "Bad modifier" error message

Previously, the "Bad modifier" error message did not affect make's exit
status. As a side effect, this kind of error now gets more context
information.
 1.34 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.33 30-Jun-2024  rillig make: error out on some more syntax errors

Previously, these errors only produced a message on stderr. They only
affected make's exit status when they were evaluated at parse time, but
not when evaluating the commands for a specific target right before
executing them.

The affected syntax errors are:
* invalid regular expressions in the ':C' modifier
* out-of-range references to regex groups in the ':C' modifier
* unfinished modifiers
 1.32 30-Jun-2024  rillig tests/make: replace 'want' comments with 'expect' directives

The 'want' comments needed to be cross-checked manually, which was
error-prone, as can be seen in the "Unknown modifier" messages that got
out of sync.
 1.31 19-Nov-2023  rillig branches: 1.31.2;
tests/make: replace 'variable expressions' with 'expressions'
 1.30 21-Jun-2021  rillig tests/make: remove unnecessary -dL from moderrs.mk

It was only needed for the test for unmatched subexpressions in the
modifier ':C'. That test has been moved to varmod-subst-regex.mk.
 1.29 21-Jun-2021  rillig tests/make: move and extend test for unmatched '\1' in ':C'

This test lived together with a few unrelated tests in moderrs.mk, it is
better placed in varmod-subst-regex.mk though.

While here, extend, document and explain the test since its purpose was
not obvious from reading the code alone.
 1.28 21-Jun-2021  sjg Do not report unmatched regex subexpressions

It is not always an error for a subexpression to have not matched,
since the regex library can/does not convey how many matches are
expected, only report an error if opts.strict (-dL)

Reviewed by: christos
 1.27 23-Feb-2021  rillig make: add test for confusing error message for bad modifier

In the expression ${:U}, the variable name is empty. Since these
expressions are generated by .for loops, the error messages for them
must not end with a trailing space. Putting the variable name in quotes
helps against that.
 1.26 23-Feb-2021  rillig make: improve error message for unclosed modifier

Replace "variable specification" with the more modern "variable
expression", reduce the number of parentheses, output more than a single
character for modifiers, make it obvious that in expressions such as
${:Serror}, the "" means a variable name.
 1.25 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.24 01-Nov-2020  rillig make(1): treat malformed :range, :ts and :[...] as errors

Before, integer overflow in the :[1..2] modifier had not been detected,
and the actual behavior varied between ILP64 and LP64I32 machines.

Before, the :ts modifier accepted character literals like \012345 and
\x1F600, which don't fit in a single character and were thus truncated.

Before, the :range modifier issued an "Unknown modifier" error message
for :range=x, which was not quite correct. The error message in this
case is now "Invalid number".
 1.23 01-Nov-2020  rillig make(1): demonstrate parsing bugs in test moderrs.mk

When a malformed variable expression is parsed, the remaining part of
the expression is passed unmodified to the output. This is unexpected
and wrong.
 1.22 01-Nov-2020  rillig make(1): renumber the tests in moderrs.mk, remove duplicates
 1.21 01-Nov-2020  rillig make(1): make test names in moderrs.mk more descriptive
 1.20 01-Nov-2020  rillig make(1): precisely describe the expected output in the test moderrs.mk

By making "want:" the same length as "make:", the remaining text in
these lines can be compared easily.
 1.19 01-Nov-2020  rillig make(1): separate sections of moderrs.mk with empty lines
 1.18 01-Nov-2020  rillig make(1): add section headings to the test moderrs.mk
 1.17 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.16 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.15 25-Aug-2020  rillig make(1): move test for the ::= modifier to varmod-assign
 1.14 09-Aug-2020  rillig make(1): improve test for undefined subexpression in :C modifier

In the previous test output, it was unnecessarily hard to see what
happens because of the many empty strings. Enclosing the capturing
groups in parentheses helps against this.
 1.13 09-Aug-2020  rillig make(1): add test for undefined subexpression in the :C modifier
 1.12 08-Aug-2020  rillig make(1): improve error message in case of unfinished modifiers

The previous error message "Unclosed substitution" was wrong for several
reasons.

It is not about "unclosed", but about "unfinished" since in the
:@var@...@ modifier the missing '@' does not really close anything.

The word "substitution" may have originated in a time where :S and
:from=to were the only modifiers, and these were indeed substitutions,
but several other modifiers aren't.

The :S and :C modifiers allow an arbitrary delimiter, therefore it is
helpful to enclose the delimiter in quotes, just in case someone chooses
')' or '{' or even ' ' as delimiter.
 1.11 31-Jul-2020  rillig make(1): remove outdated comment from unit test

It had indeed been undefined behavior and was fixed in var.c r1.359 today
in the morning.
 1.10 31-Jul-2020  rillig make(1): add test for parsing an incomplete :t modifier

This looks a lot like undefined behavior, just like in :S and :C before.
 1.9 31-Jul-2020  rillig make(1): fix undefined behavior when parsing malformed :C modifier

Same as in the :S modifier.
 1.8 29-Jul-2020  rillig make(1): fix segfault when evaluating ${::=value}

The bug had been in the handling of the SysV modifier for many years, but
it had not been triggered since the "parsing position for the next
modifier" had been initialized to a non-NULL pointer.

In var.v r1.350, this pointer had been initialized to NULL instead since
every ApplyModifier function must set it in every case where it returns
anything except "default_case".

There might have been a slight chance of tricking make to output a wrong
error message, but nothing worse.
 1.7 29-Jul-2020  rillig make(1): add enough tests to cover the ApplyModifier functions

Only a few return statements are still missing from the code coverage.

In ApplyModifier_Assign, the test for an empty variable name is skipped
for now since it segfaults.

In ApplyModifier_SysV after the second ParseModifierPart, the branch for
the missing delimiter is not reached since this case is already checked
for in the first part of the function. To trigger this branch, a
specially crafted, unrealistic string needs to be created, and that's too
complicated for the moment.
 1.6 29-Jul-2020  rillig make(1): add unit tests for parse errors in modifiers
 1.5 28-Jul-2020  rillig make(1): add test for modifier part with unbalanced braces
 1.4 26-Jul-2020  rillig make(1): add tests for :!...! parse errors
 1.3 26-Jul-2020  rillig make(1): add test for missing input validation in :[123] modifier
 1.2 26-Jul-2020  rillig make(1): add test about missing delimiters in :@ modifier

These error conditions have been broken since var.c 1.236 on 2020-07-03.
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.31.2.2 02-Aug-2025  perseant Sync with HEAD
 1.31.2.1 01-Jul-2024  perseant Sync with HEAD.
 1.3 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2 07-Sep-2009  sjg PR: 41998

:Ufu\:goo

should expand to fu:goo even when it appears in :M${:Ufu\:goo}
When scanning for :M do not compress \: if we know we have
to call Var_Subst.
 1.1 20-Feb-2004  sjg Fix :M so that modifiers in nested variables don't terminate parsing
early. Add a unit-test to verify it works and keeps working.
Re-jig the unit-tests so that all are sub makefiles.
 1.5 16-Jun-2023  rillig tests/make: clean up tests for the ':M' and ':S' modifiers
 1.4 16-Aug-2020  rillig make(1): move tests for the :M modifier into separate files

The test for the different escaping has been adjusted to actually show
the different parsing results in the test output. To do this, it had to
get its own file since it needs the -dv debug flag and specialized
post-processing.
 1.3 21-Apr-2017  sjg Str_Match: fix closure tests for [^] and add unit-test.
 1.2 13-Apr-2017  sjg Add test case for :M[^A-Z]
 1.1 21-Aug-2014  apb branches: 1.1.2; 1.1.4;
Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.1.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.1.2.1 26-Apr-2017  pgoyette Sync with HEAD
 1.10 16-Jun-2023  rillig tests/make: clean up tests for the ':M' and ':S' modifiers
 1.9 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.8 16-Aug-2020  rillig make(1): move tests for the :M modifier into separate files

The test for the different escaping has been adjusted to actually show
the different parsing results in the test output. To do this, it had to
get its own file since it needs the -dv debug flag and specialized
post-processing.
 1.7 01-Aug-2020  rillig make(1): add test for inconsistent interpretation of :M and :N modifiers
 1.6 15-Jun-2020  rillig make(1): fix performance problem in specially crafted :M modifier

This fix was previously suspected to make the vax build fail. The next
build succeeded though, and it started 2 hours before this fix was
reverted.
 1.5 14-Jun-2020  rillig usr.bin/make: revert performance improvement

That change might be the cause of a build failure for vax.
http://releng.netbsd.org/builds/HEAD/202006131940Z/ builds fine.
http://releng.netbsd.org/builds/HEAD/202006141020Z/ doesn't.

The build fails with:
/home/source/ab/HEAD/src/external/gpl3/gcc/dist/gcc/machmode.h:524:28:
error: 'mode_size_inline' was not declared in this scope
 1.4 13-Jun-2020  rillig usr.bin/make: make Str_Match faster for repeated asterisks

Conceptually related to https://en.wikipedia.org/wiki/ReDoS.
 1.3 21-Apr-2017  sjg Str_Match: fix closure tests for [^] and add unit-test.
 1.2 13-Apr-2017  sjg Add test case for :M[^A-Z]
 1.1 21-Aug-2014  apb branches: 1.1.2; 1.1.4;
Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.1.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.1.2.1 26-Apr-2017  pgoyette Sync with HEAD
 1.8 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.7 11-Apr-2011  sjg Add a test case for sysV modifier subst
 1.6 23-Apr-2010  sjg PR: 42850
Reviewed by:

Reduced the "expected to exist" dirs in path to just
/ /bin and /tmp
and change the "not expected to exist" dir to something
even less likely.
Add a comment to suggest why.
 1.5 22-Apr-2010  sjg PR: 42850
Reviewed by:

modmisc: since we apply an exists() test to $paths, be conservative
in what we expect.

Run the unit tests with -r -m / so that we do not fail if there
is no sys.mk present.
 1.4 11-May-2006  sjg Extract the variable modifier logic to a separate function.
This cuts Var_Parse in half! and allows the modifier logic to
be used recursively - when getting modifiers via variables.

Add new unit-test, to check that certain error cases are handled
correctly.
 1.3 26-Feb-2006  wiz Fix typo.
 1.2 26-Feb-2006  sjg Using ./bin in the test case, causes problems when 'make test' is
run from 'unit-tests' rather than the parent dir.
 1.1 26-Feb-2006  sjg Update man page and add test case for specifying modifiers via variable.
Also allow said variable to appear anywhere in the modifier list.
 1.48 16-Jun-2023  rillig tests/make: clean up tests for the ':M' and ':S' modifiers
 1.47 20-Dec-2020  rillig make(1): move tests for indirect modifiers around

The next commit will error out on unknown modifiers and influence the
exit status. The test modmisc.mk contains both parse time tests and run
time tests. To prevent the latter from being run, the parse error is
moved to varmod-indirect.mk, which only contains parse time tests.
 1.46 23-Aug-2020  rillig make(1): move tests for the :tu and :_ modifiers into separate files
 1.45 23-Aug-2020  rillig make(1): move tests for :hash :range :localtime into separate files
 1.44 23-Aug-2020  rillig make(1): move tests for :H :E :R :T into separate files
 1.43 16-Aug-2020  rillig make(1): move tests for the :gmtime and ::= modifiers to separate files
 1.42 16-Aug-2020  rillig make(1): move tests for :S, :C, :@ from modmisc to their separate tests
 1.41 09-Aug-2020  rillig make(1): add test that demonstrates possible delimiters for :S
 1.40 09-Aug-2020  rillig make(1): explain the mod-subst-dollar test
 1.39 09-Aug-2020  rillig make(1): add another test case for mod-subst-dollar

Having only 8 dollar signs does not prove anything. It might still be
the result of 3 substitutions in a row. Having 5 substitutions in a row
is less likely though.
 1.38 08-Aug-2020  rillig make(1): add test for the :gmtime modifier with indirect time
 1.37 08-Aug-2020  rillig make(1): add test for unknown sub-modifier of the :S modifier
 1.36 07-Aug-2020  rillig make(1): add tests for creative variable names in the :@ modifier
 1.35 01-Aug-2020  rillig make(1): fix error message when regcomp fails

If regcomp fails, it's not the regex substitution that is erroneous, but
the regex compilation.
 1.34 01-Aug-2020  rillig make(1): add tests for indirect modifiers
 1.33 31-Jul-2020  rillig make(1): add test for chaining the :S modifier without colon
 1.32 29-Jul-2020  rillig make(1): remove unnecessary assignments to st->next

No change in the size of the resulting binary. Apparently GCC already
knew these assignments were redundant.
 1.31 29-Jul-2020  rillig make(1): add unit tests for parse errors in modifiers
 1.30 27-Jul-2020  rillig make(1): replace macros with functions

Having the hidden parameter st->endc in the macro made it unnecessarily
difficult to understand the code.
 1.29 26-Jul-2020  rillig make(1): use consistent test names in modmisc.mk
 1.28 25-Jul-2020  rillig make(1): add test for brk_string with more than 50 words
 1.27 23-Jul-2020  rillig make(1): fix wrong warning about missing delimiter
 1.26 23-Jul-2020  rillig make(1): demonstrate wrong error message about missing delimiter

The current practice of setting st->delim at the beginning of each
modifier and resetting it again at the end produces too many error
messages. In this case, there is no missing delimiter.
 1.25 21-Jul-2020  rillig make(1): add test for :S,,sep

The empty string does not match anywhere. In other implementations of
string replacement, an empty string matches at every position of the
source string.

This only works for the :S modifier. The :C modifier does not allow an
empty search pattern.
 1.24 21-Jul-2020  rillig make(1): add test for :Q and .newline
 1.23 20-Jul-2020  rillig make(1): fix edge cases with $ at the end of the :@ modifier

In both parts of the :@ modifier, by passing &pflags to
ParseModifierPart, a final $ was interpreted as an anchor, which only
makes sense in the :S and :C modifiers.

This edge case is neither used by src nor by pkgsrc, except for the unit
tests that have been adjusted.
 1.22 20-Jul-2020  rillig make(1): add test for nested assignments

This test demonstrates that in ApplyModifier_Assign, the call to
ParseModifierPart must get its pflags.
 1.21 20-Jul-2020  rillig make(1): add test for :tu modifier with spaces
 1.20 20-Jul-2020  rillig make(1): make modifier handling simpler

Implementing a modifier such as :S or :M should not be concerned with
separating the words of the resulting string. Ideally this should be
done in the same way by all modifiers.

Before, the :R (filename root) modifier added a separator even if the
resulting filename root was an empty string. The chances that this
change in behavior breaks anything are epsilon.

The :@ modifier, if it appeared after a :ts modifier, did not use the
word separator from the :ts modifier (which all other modifiers do) but
always added a space. This behavior has been preserved for now. It's an
unnecessary inconsistency though.

In contrast to Buffer, the newly added SepBuf uses size_t for memory
sizes and also uses the conventional parameter order (mem, memsize)
instead of the unusual (memsize, mem).
 1.19 19-Jul-2020  rillig make(1): add tests for the ::= modifiers
 1.18 19-Jul-2020  rillig make(1): add tests for maximum number of capturing groups in :C
 1.17 19-Jul-2020  rillig make(1): fix off-by-one error in :C modifier

Previously this off-by-one error had invoked undefined behavior.
Until today there was no corresponding unit test though.
 1.16 19-Jul-2020  rillig make(1): demonstrate off-by-one bug in :C modifier
 1.15 19-Jul-2020  rillig make(1): add test for stray dollar signs in :@ modifier
 1.14 04-Jul-2020  rillig make(1): ignore system-specific error message from regcomp in test

NetBSD 8 has: repetition-operator operand invalid
Ubuntu has: Invalid preceding regular expression
 1.13 04-Jul-2020  rillig make(1): add tests for dollar characters in modifiers
 1.12 04-Jul-2020  rillig make(1): expand the test for variable expansion in the :@ modifier
 1.11 04-Jul-2020  rillig make(1): add debugging output for :@ modifier

The inner working of the :@ modifier is quite tricky. To understand what
really happens, it helps to look at each word as it is being modified.
 1.10 04-Jul-2020  rillig make(1): add test for an obscure edge case of using the :@ modifier
 1.9 04-Jul-2020  rillig make(1): add tests for the :S and :C modifiers
 1.8 03-Jul-2020  rillig make(1): clean up documentation, small refactorings for variables

- document the callback for VarModify
- clearly mark the callbacks
- shorten the documentation for some callback functions
- fix the documentation of VarSYSVMatch
- remove unnecessary null check from VarLoopExpand
- add test for applying modifiers to empty strings
 1.7 03-Jul-2020  rillig make(1): add expected test result for modmisc
 1.6 03-Jul-2020  rillig make(1): fix bug in :E modifier, introduced in r1.239 today

That case was not covered by the tests before.
 1.5 03-Jul-2020  rillig make(1): add test for :R modifier
 1.4 03-Jul-2020  rillig make(1): add more tests for :H, :T and :E modifiers
 1.3 03-Jul-2020  rillig make(1): add test for :H and :T modifiers with several words
 1.2 03-Jul-2020  rillig make(1): add missing test for the :H and :T modifiers
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.53 16-Jun-2023  rillig tests/make: clean up tests for the ':M' and ':S' modifiers
 1.52 20-Dec-2020  rillig make(1): move tests for indirect modifiers around

The next commit will error out on unknown modifiers and influence the
exit status. The test modmisc.mk contains both parse time tests and run
time tests. To prevent the latter from being run, the parse error is
moved to varmod-indirect.mk, which only contains parse time tests.
 1.51 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.50 03-Nov-2020  rillig make(1): clean up unit tests
 1.49 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.48 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.47 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.46 23-Aug-2020  rillig make(1): move tests for the :tu and :_ modifiers into separate files
 1.45 23-Aug-2020  rillig make(1): move tests for :hash :range :localtime into separate files
 1.44 23-Aug-2020  rillig make(1): move tests for :H :E :R :T into separate files
 1.43 16-Aug-2020  rillig make(1): move tests for the :gmtime and ::= modifiers to separate files
 1.42 16-Aug-2020  rillig make(1): move tests for :S, :C, :@ from modmisc to their separate tests
 1.41 09-Aug-2020  rillig make(1): add more tests for Cmd_Exec
 1.40 09-Aug-2020  rillig make(1): add test for null byte in the output of a command
 1.39 09-Aug-2020  rillig make(1): add test that demonstrates possible delimiters for :S
 1.38 09-Aug-2020  rillig make(1): explain the mod-subst-dollar test
 1.37 09-Aug-2020  rillig make(1): add another test case for mod-subst-dollar

Having only 8 dollar signs does not prove anything. It might still be
the result of 3 substitutions in a row. Having 5 substitutions in a row
is less likely though.
 1.36 08-Aug-2020  rillig make(1): add test for the :gmtime modifier with indirect time
 1.35 08-Aug-2020  rillig make(1): add test for unknown sub-modifier of the :S modifier
 1.34 07-Aug-2020  rillig make(1): add tests for creative variable names in the :@ modifier
 1.33 03-Aug-2020  rillig make(1): in lint mode, disallow dynamic variable names in :@ modifier

This is an extremely obscure feature that hopefully nobody ever
considered using.
 1.32 01-Aug-2020  rillig make(1): add test for empty indirect modifier
 1.31 01-Aug-2020  rillig make(1): add tests for indirect modifiers
 1.30 31-Jul-2020  rillig make(1): add test for chaining the :S modifier without colon
 1.29 29-Jul-2020  rillig make(1): remove unnecessary assignments to st->next

No change in the size of the resulting binary. Apparently GCC already
knew these assignments were redundant.
 1.28 29-Jul-2020  rillig make(1): add unit tests for parse errors in modifiers
 1.27 27-Jul-2020  rillig make(1): replace macros with functions

Having the hidden parameter st->endc in the macro made it unnecessarily
difficult to understand the code.
 1.26 26-Jul-2020  rillig make(1): add basic tests for the :S modifier
 1.25 26-Jul-2020  rillig make(1): fix bug in :S modifier from 2020-07-19
 1.24 26-Jul-2020  rillig make(1): demonstrate bug in the :S modifier with the 1 modifier

The bug has been introduced in var.c r1.268 on 2020-07-19.
 1.23 26-Jul-2020  rillig make(1): use consistent test names in modmisc.mk
 1.22 25-Jul-2020  rillig make(1): add test for brk_string with more than 50 words
 1.21 23-Jul-2020  rillig make(1): demonstrate wrong error message about missing delimiter

The current practice of setting st->delim at the beginning of each
modifier and resetting it again at the end produces too many error
messages. In this case, there is no missing delimiter.
 1.20 21-Jul-2020  rillig make(1): add test for :S,,sep

The empty string does not match anywhere. In other implementations of
string replacement, an empty string matches at every position of the
source string.

This only works for the :S modifier. The :C modifier does not allow an
empty search pattern.
 1.19 21-Jul-2020  rillig make(1): add test for :Q and .newline
 1.18 20-Jul-2020  rillig make(1): add test for nested assignments

This test demonstrates that in ApplyModifier_Assign, the call to
ParseModifierPart must get its pflags.
 1.17 20-Jul-2020  rillig make(1): add test for :tu modifier with spaces
 1.16 19-Jul-2020  rillig make(1): add tests for the ::= modifiers
 1.15 19-Jul-2020  rillig make(1): add tests for maximum number of capturing groups in :C
 1.14 19-Jul-2020  rillig make(1): demonstrate off-by-one bug in :C modifier
 1.13 19-Jul-2020  rillig make(1): add test for stray dollar signs in :@ modifier
 1.12 04-Jul-2020  rillig make(1): add tests for dollar characters in modifiers
 1.11 04-Jul-2020  rillig make(1): expand the test for variable expansion in the :@ modifier
 1.10 04-Jul-2020  rillig make(1): add debugging output for :@ modifier

The inner working of the :@ modifier is quite tricky. To understand what
really happens, it helps to look at each word as it is being modified.
 1.9 04-Jul-2020  rillig make(1): add test for an obscure edge case of using the :@ modifier
 1.8 04-Jul-2020  rillig make(1): add tests for the :S and :C modifiers
 1.7 03-Jul-2020  rillig make(1): clean up documentation, small refactorings for variables

- document the callback for VarModify
- clearly mark the callbacks
- shorten the documentation for some callback functions
- fix the documentation of VarSYSVMatch
- remove unnecessary null check from VarLoopExpand
- add test for applying modifiers to empty strings
 1.6 03-Jul-2020  rillig make(1): fix bug in :E modifier, introduced in r1.239 today

That case was not covered by the tests before.
 1.5 03-Jul-2020  rillig make(1): add test for :R modifier
 1.4 03-Jul-2020  rillig make(1): add more tests for :H, :T and :E modifiers
 1.3 03-Jul-2020  rillig make(1): add test for :H and :T modifiers with several words
 1.2 03-Jul-2020  rillig make(1): add missing test for the :H and :T modifiers
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.3 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2 05-Oct-2007  sjg Add the ability to .export variables to the environment.
 1.1 01-Jun-2005  sjg branches: 1.1.12;
Add :Ox for random ordering, based on patch from
Mike M. Volokhov <mishka@apk.od.ua>
 1.1.12.1 06-Nov-2007  matt sync with HEAD
 1.4 16-Aug-2020  rillig make(1): move tests for the :Ox modifier into separate file

The test has been extended by ensuring that the shuffled words are still
the same. Comparing two shuffled lists is probabilistic, but comparing
their sorted results is not, therefore that's completely sensible to do.

When writing this test, by coincidence I discovered how to generate the
"Undefined variable" error message. Unfortunately, the error message is
wrong since the variable NUMBERS is defined at that point. In summary,
that error message is shown when it shouldn't, and when it should it is
not shown. Still, I'm glad that I finally found it.
 1.3 16-Aug-2020  rillig make(1): move tests for the :O and :Or modifiers into separate files
 1.2 09-Jun-2020  sjg Add test case for :Or
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.5 16-Aug-2020  rillig make(1): move tests for the :Ox modifier into separate file

The test has been extended by ensuring that the shuffled words are still
the same. Comparing two shuffled lists is probabilistic, but comparing
their sorted results is not, therefore that's completely sensible to do.

When writing this test, by coincidence I discovered how to generate the
"Undefined variable" error message. Unfortunately, the error message is
wrong since the variable NUMBERS is defined at that point. In summary,
that error message is shown when it shouldn't, and when it should it is
not shown. Still, I'm glad that I finally found it.
 1.4 16-Aug-2020  rillig make(1): move tests for the :O and :Or modifiers into separate files
 1.3 09-Jun-2020  sjg Add test case for :Or
 1.2 07-Jan-2020  rillig usr.bin/make: document probabilities for random test failures

Side node: this test will never fail between 2024-04-15 and 2024-07-06.
 1.1 21-Aug-2014  apb branches: 1.1.16;
Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.1.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.3 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2 07-Jun-2011  sjg Some systems (eg. MirBSD) use a ksh, with an echo which cannot
be used for things containing \x: etc.
Check for print or printf as builtin and use if available.
Note that a builtin will fail, if make decides a shell is not needed.
 1.1 20-Feb-2004  sjg branches: 1.1.54;
Fix :M so that modifiers in nested variables don't terminate parsing
early. Add a unit-test to verify it works and keeps working.
Re-jig the unit-tests so that all are sub makefiles.
 1.1.54.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.7 23-Jan-2022  rillig tests/make: migrate modts to varmod-to-separator and explain
 1.6 23-Feb-2021  rillig make: improve error message for bad modifier in variable expression

The improvement is especially noteable for variable expressions based on
the empty variable, see moderrs.exp:103.
 1.5 31-Aug-2020  rillig make(1): move some of the :ts tests into a separate file

The successful cases can be easily tested in the .if conditions. Around
these conditions, there is enough space for explaining the test cases
and their purpose.

The failure cases have been left in the file for now since they still
produce unwanted characters in the output. These characters are not
produced when the parse error occurs in a conditional.
 1.4 19-Jul-2020  rillig make(1): add more tests for :ts modifier
 1.3 19-Jul-2020  rillig make(1): demonstrate inconsistent :ts behavior among modifiers
 1.2 07-Mar-2016  sjg For :ts numeric escapes \x* is hex, anything else is octal.
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.9 23-Jan-2022  rillig tests/make: migrate modts to varmod-to-separator and explain
 1.8 03-Nov-2020  rillig make(1): clean up unit tests
 1.7 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.6 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.5 31-Aug-2020  rillig make(1): move some of the :ts tests into a separate file

The successful cases can be easily tested in the .if conditions. Around
these conditions, there is enough space for explaining the test cases
and their purpose.

The failure cases have been left in the file for now since they still
produce unwanted characters in the output. These characters are not
produced when the parse error occurs in a conditional.
 1.4 19-Jul-2020  rillig make(1): add more tests for :ts modifier
 1.3 19-Jul-2020  rillig make(1): demonstrate inconsistent :ts behavior among modifiers
 1.2 07-Mar-2016  sjg For :ts numeric escapes \x* is hex, anything else is octal.
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.1 27-Sep-2003  sjg Implement :[] modifier to allow picking a range of words out of a variable.
Also :tW and a W flag to :C and :S to allow treating value as a single word.
Add unit tests for the above, and fix some corner cases.
Based on patches supplied by Alan Barrett <apb@cequrux.com>
 1.5 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.4 14-Mar-2021  rillig make: add test for edge case in modifier ':[...]'

TryParseIntBase0 wrongly returns successful for a string that does not
start with a number at all. Its only caller, ApplyModifier_Words,
already handles all error cases properly.

No functional change.
 1.3 23-Feb-2021  rillig make: improve error message for bad modifier in variable expression

The improvement is especially noteable for variable expressions based on
the empty variable, see moderrs.exp:103.
 1.2 01-Nov-2020  rillig make(1): add tests for the variable modifiers :[words] and :range
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.7 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.6 14-Mar-2021  rillig make: add test for edge case in modifier ':[...]'

TryParseIntBase0 wrongly returns successful for a string that does not
start with a number at all. Its only caller, ApplyModifier_Words,
already handles all error cases properly.

No functional change.
 1.5 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.4 01-Nov-2020  rillig make(1): add tests for the variable modifiers :[words] and :range
 1.3 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.2 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.6 12-Jun-2025  rillig make: use a common style for unexpected error messages

In enomem, report the actual error instead of a fixed ENOMEM.
 1.5 09-Feb-2022  rillig branches: 1.5.4;
make: prefix the warning about read-only .OBJDIR with a colon

For consistency with the other warnings.
 1.4 09-Feb-2022  rillig tests/make: use more distinctive placeholder for TMPDIR
 1.3 04-Jul-2021  sjg Do not assume /tmp is safe to use if TMPDIR is set
 1.2 06-Feb-2021  sjg Avoid test failures when more than one user run them.

Use a private TMPDIR
a subdir of .OBJDIR if using it
otherwise /tmp/uid${.MAKE.UID}
 1.1 12-Nov-2020  sjg Pass a writable flag to Main_SetObjdir to control writable check

For curdir and an explicit .OBJDIR target, we allow for
the directory to be read-only.
During InitObjdir we otherwise default to requiring objdir to be
writable - this can be controlled by env variable
MAKE_OBJDIR_CHECK_WRITABLE

Add unit-tests/objdir-writable

Reviewed by: christos rillig
 1.5.4.1 02-Aug-2025  perseant Sync with HEAD
 1.7 09-Feb-2022  rillig tests/make: remove redundant 'echo' from variable assignments

Before main.c 1.231 from 2014-09-09, a variable assignment using the
operator '!=' generated a warning "Couldn't read shell's output" if the
output of the command was empty. The simplest way to suppress this
wrong warning was to add an empty 'echo' to the command. This hack is
no longer needed.
 1.6 09-Feb-2022  rillig make: fix mistakes, spelling and typos in comments and manual page

No binary change for -DNDEBUG.
 1.5 04-Jul-2021  sjg Do not assume /tmp is safe to use if TMPDIR is set
 1.4 14-Nov-2020  sjg Remove RO_OBJDIR when done
 1.3 13-Nov-2020  rillig make(1): in lint mode, check for ".else <cond>"
 1.2 12-Nov-2020  sjg Use explicit MAKEOBJDIR to avoid tripping over /usr/obj
 1.1 12-Nov-2020  sjg Pass a writable flag to Main_SetObjdir to control writable check

For curdir and an explicit .OBJDIR target, we allow for
the directory to be read-only.
During InitObjdir we otherwise default to requiring objdir to be
writable - this can be controlled by env variable
MAKE_OBJDIR_CHECK_WRITABLE

Add unit-tests/objdir-writable

Reviewed by: christos rillig
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 02-Apr-2024  rillig tests/make: remove test for overly long chdir argument

On Cygwin, the path '/././..././' is normalized before being passed to
the child 'make' process. Since overly long pathnames are not required
to be supported on all platforms, remove the test.
 1.3 27-Dec-2020  rillig make(1): exit 2 on technical errors

This allows the -q option to distinguish errors from out-of-date
targets. Granted, it's an edge case but it should be solved
consistently anyway.

The majority of cases in which make exits with exit status 1, even in -q
mode, is when there are parse errors. These have been kept as-is for
now as they affect many of the unit tests.

The technical errors, on the other hand, occur so rarely that it's hard
to write reliable tests for them that fail consistently on all platforms
supported by make.
 1.2 14-Nov-2020  rillig make(1): add tests for the command line option -C
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7 02-Apr-2024  rillig tests/make: remove test for overly long chdir argument

On Cygwin, the path '/././..././' is normalized before being passed to
the child 'make' process. Since overly long pathnames are not required
to be supported on all platforms, remove the test.
 1.6 18-May-2021  sjg Do not trust that /nonexistent does not exist

Use /nonexistent.${.MAKE.PID} to avoid failure when
/nonexistent actually exists.
 1.5 15-Nov-2020  sjg branches: 1.5.2;
Avoid problem with /usr/obj
 1.4 14-Nov-2020  rillig make(1): add tests for the command line option -C
 1.3 14-Nov-2020  rillig make(1): document since when the -C option is available
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5.2.1 31-May-2021  cjep sync with head
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.3 03-Mar-2022  rillig make: make debug logging for comparisons less technical
 1.2 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.3 15-Apr-2022  rillig tests/make: adjust expectations to actual behavior

The bug in deptgt-silent-jobs.mk has been fixed, the debug logging for
comparing conditions and for deleting global variables has changed
intentionally.
 1.2 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.2 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.6 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.5 26-Apr-2024  rillig branches: 1.5.2;
make: in parallel mode, print the directory in which a job failed

When multiple targets run in parallel, the "stopped in" line may be
several lines away from the "Failed target" line, making them hard to
correlate.
 1.4 28-Nov-2021  rillig make: with the option -de in jobs mode, output expanded commands

This helps tracking down the actual cause of build failures in build
systems like NetBSD's build.sh that use highly abstracted commands that
are mainly defined in terms of variables.
 1.3 27-Nov-2021  rillig tests/make: demonstrate unhelpful debug log in case of errors

The releng build job that runs lint fails. It outputs the usage message
of lint, which doesn't include the failing option. After that, make
outputs:

*** Failed target: lint-cgdconfig
*** Failed commands:
${LINT} ${LINTFLAGS} \
${_LDFLAGS.${:Ucgdconfig}:C/-L[ ]*/-L/Wg:M-L*} \
${LOBJS.${:Ucgdconfig}} ${_LDADD.${:Ucgdconfig}}

Make doesn't output the expanded command, therefore the log doesn't show
the offending option '-pthread' that leads to the usage message.
 1.2 27-Apr-2021  rillig make: remove stray space in -de output in jobs mode

In compat mode, having a space in this place makes sense to align the
target name with the command. In jobs mode, since each command is
listed in a separate line, there is no need for the double space.
 1.1 27-Apr-2021  rillig tests/make: test the combination of -de with -j1

The test cases are the same as in opt-debug-errors.mk. The output
differs in several details though.

Even though the option '-k' is given (which is the default for any tests
that don't override it in unit-tests/Makefile), there is no message
"(continuing)" anywhere.

The failed target is printed twice. Once before the failed commands,
once after. This redundancy is not necessary and may be removed in a
follow-up commit.

The printed commands are in their unexpanded form, which may or may not
be more helpful than the expanded and space-normalized form of compat
mode. Either way, this is an unnecessary inconsistency between compat
mode and jobs mode.

In jobs mode, the message "make: stopped in $dir" is printed for each
failure, which is helpful since each of the jobs may have started in a
separate directory.
 1.5.2.1 02-Aug-2025  perseant Sync with HEAD
 1.2 27-Nov-2021  rillig tests/make: demonstrate unhelpful debug log in case of errors

The releng build job that runs lint fails. It outputs the usage message
of lint, which doesn't include the failing option. After that, make
outputs:

*** Failed target: lint-cgdconfig
*** Failed commands:
${LINT} ${LINTFLAGS} \
${_LDFLAGS.${:Ucgdconfig}:C/-L[ ]*/-L/Wg:M-L*} \
${LOBJS.${:Ucgdconfig}} ${_LDADD.${:Ucgdconfig}}

Make doesn't output the expanded command, therefore the log doesn't show
the offending option '-pthread' that leads to the usage message.
 1.1 27-Apr-2021  rillig tests/make: test the combination of -de with -j1

The test cases are the same as in opt-debug-errors.mk. The output
differs in several details though.

Even though the option '-k' is given (which is the default for any tests
that don't override it in unit-tests/Makefile), there is no message
"(continuing)" anywhere.

The failed target is printed twice. Once before the failed commands,
once after. This redundancy is not necessary and may be removed in a
follow-up commit.

The printed commands are in their unexpanded form, which may or may not
be more helpful than the expanded and space-normalized form of compat
mode. Either way, this is an unnecessary inconsistency between compat
mode and jobs mode.

In jobs mode, the message "make: stopped in $dir" is printed for each
failure, which is helpful since each of the jobs may have started in a
separate directory.
 1.4 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.3 07-Dec-2020  rillig branches: 1.3.8;
make(1): fix exit status in -k mode if a dependency fails

Whether in -k mode or not, the exit status tells whether all requested
targets were made or not. If a dependency could not be made, the main
target was not made as well, therefore the exit status must be nonzero
in such a case.

This part of the code lacked proper unit tests until today. The unit
test deptgt-end-fail.mk is compatible with make>=2003 at least, allowing
to compare the output over time.

In 2003, in the ok-ok-ok-ok case, "Making all from all-dep." was printed
twice in a row, for whatever reason ... (40 minutes later) ... If I had
just made the two commands for 'all' and '.END' more distinguishable.
Back in 2003, the local variables for .END had not been initialized,
instead the .END node was run with the local variables of the last
preceding node. In this case, that node was 'all', therefore ${.TARGET}
had obviously expanded to 'all'.

Somewhere in 2004, the shell commands were no longer run with the -e
flag, which resulted in the "exit status $?" line to be printed in cases
that had stopped early before.

Somewhere in 2005, the local variables for the .END node had been fixed.
The variable ${.TARGET} now had the value '.END', just as expected. In
addition, the dependencies for the .END node were made, although without
getting their proper local variables. This resulted in the output
"Making out of nothing" instead of the expected "Making end-dep out of
nothing".

Still in 2005, in the test case "all=ok all-dep=ok end=ok end-dep=ERR",
the error code of the failed 'end-dep' was first reported as "*** Error
code 1 (continuing)". To compensate for this improvement, a new bug had
been introduced. The test case "all=ok all-dep=ok end=ERR end-dep=ERR"
had properly exited with status 1 on 2005-01-01, but on 2006-01-01 it
exited with status 0, thereby ignoring errors in the .END node.

Somewhere in 2008, some of the error messages (but not all) were
directed to stderr instead of stdout. The actual output stayed the same
though.

Somewhere in 2011, the dependency of the .END node got its own local
variables, and ${.TARGET} now expanded to 'end-dep', as expected.

Somewhere in 2016, the two empty lines between the "*** Error code 1
(continuing)" and the "Stop." got compressed into a single empty line.

On 2020-12-07 (that is, today), the exit status 1 has been restored in
the error cases, after it had been wrong for at least 14 years.
 1.2 06-Sep-2020  rillig make(1): add test for the -de option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.3.8.1 02-Aug-2025  perseant Sync with HEAD
 1.2 06-Sep-2020  rillig make(1): add test for the -de option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.11 09-Aug-2025  rillig tests/make: fix typo
 1.10 06-Jul-2025  rillig tests/make: describe how to read a file into a variable
 1.9 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.8 30-Jun-2024  rillig make: error out on some more syntax errors

Previously, these errors only produced a message on stderr. They only
affected make's exit status when they were evaluated at parse time, but
not when evaluating the commands for a specific target right before
executing them.

The affected syntax errors are:
* invalid regular expressions in the ':C' modifier
* out-of-range references to regex groups in the ':C' modifier
* unfinished modifiers
 1.7 01-Jun-2023  rillig branches: 1.7.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.6 03-Mar-2022  rillig make: make debug logging for comparisons less technical
 1.5 11-Jan-2022  rillig tests/make: clean up after test for option '-dF'

When the file for the debug log cannot be opened, make exits
immediately. This doesn't give the test a chance to clean up the
temporary log file.

Instead of trying to treat a regular file as a directory and create a
file in it, assume that the directory /nonexistent-$uuid is actually
nonexistent. This leads to the same kind of error message, independent
of strerror(3).
 1.4 09-Jan-2022  rillig tests/make: test output channels for parse errors and other errors
 1.3 27-Dec-2021  rillig make: remove usage message if the debug file cannot be opened

Since a non-writable file is not a syntax error, there is no point in
showing the usage in this situation. Showing the usage may have been a
copy-and-paste mistake from a few lines below, when this option was
added back in main.c 1.133 from 2006-10-15.
 1.2 27-Dec-2021  rillig tests/make: cover a debug log file that cannot be opened
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.7.2.2 02-Aug-2025  perseant Sync with HEAD
 1.7.2.1 01-Jul-2024  perseant Sync with HEAD.
 1.13 09-Aug-2025  rillig tests/make: fix typo
 1.12 06-Jul-2025  rillig tests/make: describe how to read a file into a variable
 1.11 30-Jun-2024  rillig make: error out on some more syntax errors

Previously, these errors only produced a message on stderr. They only
affected make's exit status when they were evaluated at parse time, but
not when evaluating the commands for a specific target right before
executing them.

The affected syntax errors are:
* invalid regular expressions in the ':C' modifier
* out-of-range references to regex groups in the ':C' modifier
* unfinished modifiers
 1.10 19-Nov-2023  rillig branches: 1.10.2;
tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.9 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.8 11-Jan-2022  rillig tests/make: clean up after test for option '-dF'

When the file for the debug log cannot be opened, make exits
immediately. This doesn't give the test a chance to clean up the
temporary log file.

Instead of trying to treat a regular file as a directory and create a
file in it, assume that the directory /nonexistent-$uuid is actually
nonexistent. This leads to the same kind of error message, independent
of strerror(3).
 1.7 09-Jan-2022  rillig tests/make: test output channels for parse errors and other errors
 1.6 28-Dec-2021  rillig tests/make: clean up after test 'opt-debug-file'
 1.5 27-Dec-2021  rillig tests/make: cover a debug log file that cannot be opened
 1.4 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.3 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.2 03-Oct-2020  rillig make(1): add test for the -dF option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.10.2.2 02-Aug-2025  perseant Sync with HEAD
 1.10.2.1 01-Jul-2024  perseant Sync with HEAD.
 1.5 01-Jun-2023  rillig make: add more details to debug logging of .for loops
 1.4 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.3 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.2 03-Oct-2020  rillig make(1): add test for the -df debug option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.4 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.3 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.2 03-Oct-2020  rillig make(1): add test for the -df debug option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.3 05-Sep-2020  rillig make(1): move test for -dg1 from opt-debug-g1 to opt-debug-graph1
 1.2 29-Aug-2020  rillig make(1): fix test opt-debug-g1

Including the directory cache made the test output fragile.
 1.1 27-Aug-2020  rillig make(1): add test for the -dg1 option
 1.2 05-Sep-2020  rillig make(1): move test for -dg1 from opt-debug-g1 to opt-debug-graph1
 1.1 27-Aug-2020  rillig make(1): add test for the -dg1 option
 1.14 07-May-2025  rillig make: add end marker for -dg1, -dg2 and -dg3 debug log

The marker helps distinguish the output from sub-makes from the output
of the primary make.
 1.13 07-May-2024  sjg branches: 1.13.2;
make: all command line overrides go in .MAKEOVERRIDES

Not all variables that start with '.' are internals,
and unless they are explicitly flagged as internal should go
into .MAKEOVERRIDES

Update varname-dot-makeoverrides to check this.

Also avoid using SCOPE_CMDLINE when ReadOnly will do.
 1.12 09-Sep-2023  sjg Add .MAKE.JOBS.C to indicate wether -jC is supported
 1.11 24-Jan-2023  sjg make: .SYSPATH: to add dirs to sysIncPath

.SYSPATH: with no sources will clear sysIncPath
otherwise sources are added

Reviewed by: rillig
 1.10 26-Mar-2022  rillig make: avoid trailing whitespace in debug log for variables

Since trailing whitespace is invisible, describe the variable value in
words to make it visible.
 1.9 02-Feb-2021  rillig make: remove overengineered Enum_ValueToString

For printing the status of a GNode, there was already made_name (now
renamed to GNodeMade_Name), which prints user-friendly text instead of
the bare enum constant names.

To do this change confidently, I first had to demonstrate that the
output really affects something other than just the word "UNMADE". There
had not been a test for that case before, and the test immediately
discovered a bug in the -dg2 and -dg3 options. This bug is one of the
oldest in make, dating back to at least 1993.
 1.8 04-Dec-2020  rillig make(1): use fixed format for debug output of the directory cache

The previous output format had a %-20s conversion specifier. This
produced different output depending on the length of the pathname, which
was too difficult to normalize. By moving the directory name to the
end, it is no longer necessary to fill up any space, and the numbers are
always aligned properly.

As a result, 3 of the unit tests no longer need any special
postprocessing of their output.
 1.7 25-Nov-2020  sjg Add .MAKE.UID and .MAKE.GID
 1.6 23-Nov-2020  rillig make(1): make output of test opt-debug-graph1 consistent

The output from the directory cache made the regular NetBSD build fail
because the pathname to the working directory differs, thus affecting
the spacing.

This time, document why the directory cache needs to be excluded from
the output.
 1.5 22-Nov-2020  rillig make(1): add more output to test for -dg1

Previously, the variables section had been omitted. This was because
the variables had been output in hashcode order until 2020-10-18, and
because some of the variable values are specific to the test environment
or the individual run (MACHINE_ARCH, MAKE.PPID).
 1.4 25-Sep-2020  rillig make(1): fix missing check for duplicate commands in Parse_File
 1.3 05-Sep-2020  rillig make(1): remove trailing whitespace in -dg1 debug output
 1.2 05-Sep-2020  rillig make(1): move test for -dg1 from opt-debug-g1 to opt-debug-graph1
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.13.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 05-Sep-2020  rillig make(1): remove trailing whitespace in -dg1 debug output
 1.2 05-Sep-2020  rillig make(1): move test for -dg1 from opt-debug-g1 to opt-debug-graph1
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.10 07-May-2025  rillig make: add end marker for -dg1, -dg2 and -dg3 debug log

The marker helps distinguish the output from sub-makes from the output
of the primary make.
 1.9 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.8 07-May-2024  sjg branches: 1.8.2;
make: all command line overrides go in .MAKEOVERRIDES

Not all variables that start with '.' are internals,
and unless they are explicitly flagged as internal should go
into .MAKEOVERRIDES

Update varname-dot-makeoverrides to check this.

Also avoid using SCOPE_CMDLINE when ReadOnly will do.
 1.7 09-Sep-2023  sjg Add .MAKE.JOBS.C to indicate wether -jC is supported
 1.6 24-Jan-2023  sjg make: .SYSPATH: to add dirs to sysIncPath

.SYSPATH: with no sources will clear sysIncPath
otherwise sources are added

Reviewed by: rillig
 1.5 26-Mar-2022  rillig make: avoid trailing whitespace in debug log for variables

Since trailing whitespace is invisible, describe the variable value in
words to make it visible.
 1.4 02-Feb-2021  rillig make: remove overengineered Enum_ValueToString

For printing the status of a GNode, there was already made_name (now
renamed to GNodeMade_Name), which prints user-friendly text instead of
the bare enum constant names.

To do this change confidently, I first had to demonstrate that the
output really affects something other than just the word "UNMADE". There
had not been a test for that case before, and the test immediately
discovered a bug in the -dg2 and -dg3 options. This bug is one of the
oldest in make, dating back to at least 1993.
 1.3 02-Feb-2021  rillig make: when exiting due to an error, print graph information

The code now does what the manual page has been promising since at least
1993.
 1.2 02-Feb-2021  rillig make: demonstrate that neither -dg2 nor -dg3 produces debug output
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.8.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 02-Feb-2021  rillig make: when exiting due to an error, print graph information

The code now does what the manual page has been promising since at least
1993.
 1.2 02-Feb-2021  rillig make: demonstrate that neither -dg2 nor -dg3 produces debug output
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.10 07-May-2025  rillig make: add end marker for -dg1, -dg2 and -dg3 debug log

The marker helps distinguish the output from sub-makes from the output
of the primary make.
 1.9 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.8 07-May-2024  sjg branches: 1.8.2;
make: all command line overrides go in .MAKEOVERRIDES

Not all variables that start with '.' are internals,
and unless they are explicitly flagged as internal should go
into .MAKEOVERRIDES

Update varname-dot-makeoverrides to check this.

Also avoid using SCOPE_CMDLINE when ReadOnly will do.
 1.7 09-Sep-2023  sjg Add .MAKE.JOBS.C to indicate wether -jC is supported
 1.6 24-Jan-2023  sjg make: .SYSPATH: to add dirs to sysIncPath

.SYSPATH: with no sources will clear sysIncPath
otherwise sources are added

Reviewed by: rillig
 1.5 26-Mar-2022  rillig make: avoid trailing whitespace in debug log for variables

Since trailing whitespace is invisible, describe the variable value in
words to make it visible.
 1.4 02-Feb-2021  rillig make: remove overengineered Enum_ValueToString

For printing the status of a GNode, there was already made_name (now
renamed to GNodeMade_Name), which prints user-friendly text instead of
the bare enum constant names.

To do this change confidently, I first had to demonstrate that the
output really affects something other than just the word "UNMADE". There
had not been a test for that case before, and the test immediately
discovered a bug in the -dg2 and -dg3 options. This bug is one of the
oldest in make, dating back to at least 1993.
 1.3 02-Feb-2021  rillig make: when exiting due to an error, print graph information

The code now does what the manual page has been promising since at least
1993.
 1.2 02-Feb-2021  rillig make: demonstrate that neither -dg2 nor -dg3 produces debug output
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.8.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 02-Feb-2021  rillig make: when exiting due to an error, print graph information

The code now does what the manual page has been promising since at least
1993.
 1.2 02-Feb-2021  rillig make: demonstrate that neither -dg2 nor -dg3 produces debug output
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.8 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.7 07-Jul-2024  rillig make: don't track hash table chain lengths during lookup

The chain lengths are only used for debugging purposes, so avoid the
extra cost at each lookup. Instead, calculate the maximum chain length
only when it is actually requested in -dh mode.

The reported number changes slightly: Before, it was the length of the
chain that was actually traversed to find an entry, up to that entry,
now it is the length of the largest chain in the table, no matter if it
was actually accessed or not.
 1.6 31-May-2024  rillig branches: 1.6.2;
tests/make: replace or document .error in tests

The text 'Missing argument for ".error"' in an .exp file may be a hint
for an accidentally broken test, so eliminate them as far as possible.
 1.5 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.4 27-Jan-2022  sjg numEntries can vary
 1.3 22-Jan-2022  rillig make: add missing newline after "cannot continue" message

It was wrong of Parse_File to output an unfinished line and hope for
some other code to finish it. As demonstrated in the test, PrintOnError
did not do that in the case of additional debug output.

To keep the overall behavior as close as possible to before, the other
callers of PrintOnError now have to pass the newline themselves. Passing
strings that start with newlines but don't end with them looked
suspicious anyway.
 1.2 22-Jan-2022  rillig tests/make: add a few more tests
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.6.2.1 02-Aug-2025  perseant Sync with HEAD
 1.5 31-May-2024  rillig tests/make: replace or document .error in tests

The text 'Missing argument for ".error"' in an .exp file may be a hint
for an accidentally broken test, so eliminate them as far as possible.
 1.4 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.3 22-Jan-2022  rillig make: add missing newline after "cannot continue" message

It was wrong of Parse_File to output an unfinished line and hope for
some other code to finish it. As demonstrated in the test, PrintOnError
did not do that in the case of additional debug output.

To keep the overall behavior as close as possible to before, the other
callers of PrintOnError now have to pass the newline themselves. Passing
strings that start with newlines but don't end with them looked
suspicious anyway.
 1.2 22-Jan-2022  rillig tests/make: add a few more tests
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.15 09-May-2025  rillig make: unify debug messages for parallel mode

Always print the process status in hex, with a leading "0x", to avoid
confusion for status 127f, which looks suspiciously decimal.

Prefix all process IDs with "pid", to be able to filter them easily.

Omit trailing whitespace when printing a command.
 1.14 09-May-2025  rillig make: replace magic numbers in job debug log with descriptive names
 1.13 03-May-2025  rillig make: use uniform debug log messages for the token pool
 1.12 02-May-2025  rillig make: in the debug log, replace magic numbers with identifiers
 1.11 22-Apr-2025  rillig make: group the code for handling the job token pool
 1.10 12-Dec-2020  rillig branches: 1.10.8;
make(1): move Job.xtraced to ShellWriter

This flag was placed wrong in the Job since it is only necessary as long
as the shell commands are written to the shell file.

Resetting it in JobStart and JobExec was completely misguided since that
is far away from writing the shell commands; this should have been done
in JobPrintCommands instead.

The status of this flag doesn't need to be printed in debugging mode
since it is controlled by a single command line option (-dx) and does
not interact with all the other switches.
 1.9 10-Dec-2020  rillig make(1): split JobFlags into separate fields

Having all these flags in a single bitmask makes it harder to see where
exactly they can possibly be used since their state could also be
modified using the unsuspicious job->flags = 0. Using individual names
just leaves the single memset, and that is only used during
initialization.
 1.8 19-Nov-2020  rillig make(1): fix test opt-debug-jobs when compiled with dash as shell

make USER_CPPFLAGS=-DDEFSHELL_CUSTOM='\"/usr/pkg/bin/dash\"'
 1.7 12-Nov-2020  rillig make(1): avoid race condition in test opt-debug-jobs

Thanks sjg for finding this and suggesting the fix.
 1.6 08-Nov-2020  rillig make(1): clean up debug output for running jobs

There is no remote anymore, therefore mentioning locally is redundant.
It was a bad idea anyway to build format strings that work with parts of
words.
 1.5 08-Oct-2020  rillig make(1): fix test opt-debug-jobs on non-native platforms
 1.4 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.3 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.2 03-Oct-2020  rillig make(1): add test for the -dj debug option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.10.8.1 02-Aug-2025  perseant Sync with HEAD
 1.6 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.5 12-Nov-2020  rillig make(1): avoid race condition in test opt-debug-jobs

Thanks sjg for finding this and suggesting the fix.
 1.4 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.3 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.2 03-Oct-2020  rillig make(1): add test for the -dj debug option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.26 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.25 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.24 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.23 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.22 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.21 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.20 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.19 20-Apr-2024  rillig branches: 1.19.2;
make: provide more context information for parse/evaluate errors
 1.18 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.17 14-Feb-2023  rillig make: don't interpret the return value of Var_Parse

The return value of Var_Parse is largely redundant to the returned
string. The idea behind the type VarParseResult was to migrate all call
sites to checking this return value instead of the returned string, but
that hasn't happened. Instead, the additional type only added more
complexity.

There was a single place where that return value was actually used, when
parsing conditions. And even in that case, ignoring the VarParseResult
added back an error message that previously hid bugs, in the test
cond-token-plain.mk.

Even though these error messages are redundant in the other tests, they
don't hurt as they don't happen often.
 1.16 14-Mar-2021  rillig make: fix wrong expression evaluation in -dL mode

The modifier ':C' now only compiles the regular expression if the result
of the expression is actually needed.

Several other modifiers have the same bug of evaluating the expression
in cases where this is not needed. It just doesn't show up because they
don't have any noticeable side effects, other than wasting CPU time.
This affects irrelevant conditions as well.
 1.15 14-Mar-2021  rillig make: demonstrate wrong expression evaluation in -dL mode
 1.14 23-Feb-2021  rillig make: improve error message for unknown modifier

Back in 1995, the modifiers were all single-character, and it made sense
to print only the first character. Nowadays, with ':S', ':@var@...@',
'::=' and several others, a little more context is useful to see where
the exact error is. The actual modifier is still guessed, and the guess
may be wrong as soon as backslashes get involved, but it is still better
than before.
 1.13 20-Dec-2020  rillig make(1): error out on unknown variable modifiers at parse time

Before, make printed an "error message" that did not include the word
error and thus was not easily identified as such. This "error message"
also did not influence the exit status in the default mode but only in
-dL mode. The error message also didn't include any line number
information and was thus rude.
 1.12 20-Dec-2020  rillig make(1): remove wrong error message for indirect modifier in lint mode
 1.11 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.10 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.9 03-Oct-2020  rillig make(1): in lint mode, reject modifiers without delimiter

The expression ${VAR:LPL} must now be written as ${VAR:L:P:L}. The
manual page has never documented that some modifiers don't need to be
delimited by ':' and others need to. That would have been unnecessarily
confusing anyway.
 1.8 03-Oct-2020  rillig make(1): add test for variable modifiers without delimiter
 1.7 14-Sep-2020  rillig make(1): fix wrong error for undefined variables in lint mode
 1.6 14-Sep-2020  rillig make(1): add test for wrong error in lint mode for undefined variable
 1.5 14-Sep-2020  rillig make(1): remove obsolete comments from tests
 1.4 13-Sep-2020  rillig make(1): in lint mode, report undefined variables in conditions
 1.3 13-Sep-2020  rillig make(1): suppress wrong "Malformed conditional" for undefined variables

This only has an effect in lint mode right now.
 1.2 13-Sep-2020  rillig make(1): in lint mode, improve error handling for undefined variables

It's a first step for improving the error message that make prints.
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.19.2.1 02-Aug-2025  perseant Sync with HEAD
 1.25 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.24 04-Apr-2025  rillig make: fix error message for undefined variable in conditional

Previously, only ${UNDEF} had the proper error message, while
${UNDEF:M*} still produced the wrong "Malformed conditional".
 1.23 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.22 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.21 11-Jan-2025  rillig tests/make: force correct order of expected messages
 1.20 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.19 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.18 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.17 20-Apr-2024  rillig branches: 1.17.2;
make: provide more context information for parse/evaluate errors
 1.16 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.15 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.14 14-Mar-2021  rillig make: fix wrong expression evaluation in -dL mode

The modifier ':C' now only compiles the regular expression if the result
of the expression is actually needed.

Several other modifiers have the same bug of evaluating the expression
in cases where this is not needed. It just doesn't show up because they
don't have any noticeable side effects, other than wasting CPU time.
This affects irrelevant conditions as well.
 1.13 14-Mar-2021  rillig make: demonstrate wrong expression evaluation in -dL mode
 1.12 20-Dec-2020  rillig make(1): remove wrong error message for indirect modifier in lint mode
 1.11 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.10 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.9 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.8 03-Oct-2020  rillig make(1): add test for variable modifiers without delimiter
 1.7 14-Sep-2020  rillig make(1): fix wrong error for undefined variables in lint mode
 1.6 14-Sep-2020  rillig make(1): add test for wrong error in lint mode for undefined variable
 1.5 14-Sep-2020  rillig make(1): in lint mode, allow undefined variables in dependency lines

This is needed to get past the first few seconds in a src/build.sh run.

The nest obstacle is src/tools/Makefile.gnuhost:30, where the variable
MODULE is undefined even though that file says in line 3 that MODULE is
expected to be set. It has been saying this since 2001, but since make
didn't have the corresponding check enabled, this didn't break the
build.
 1.4 14-Sep-2020  rillig make(1): remove obsolete comments from tests
 1.3 13-Sep-2020  rillig make(1): in lint mode, report undefined variables in conditions
 1.2 13-Sep-2020  rillig make(1): in lint mode, improve error handling for undefined variables

It's a first step for improving the error message that make prints.
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.17.2.1 02-Aug-2025  perseant Sync with HEAD
 1.4 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.3 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.2 03-Oct-2020  rillig make(1): add test for the -dl command line option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.5 19-Dec-2023  rillig make: clean up comments

No binary change, except for line numbers in assertions.
 1.4 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.3 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.2 03-Oct-2020  rillig make(1): add test for the -dl command line option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.14 11-Apr-2025  rillig make: convert more messages to the "file:123" format
 1.13 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.12 31-Oct-2024  rillig make: in the debug log, always qualify line number with filename

Previously, to find out the filename corresponding to a line number from
a 'Parsing' line, it was necessary to find the preceding
'SetFilenameVars' line, which was unnecessarily time-consuming and
distracting.

The 'filename:line' format matches the one used in PrintStackTrace, and
it differs from the one used in PrintLocation, as the former format is
more common in other tools.

Most of the affected unit tests only use the 'Parsing' lines to give
additional context to their debug log, so no structural changes there.
 1.11 14-Apr-2024  rillig branches: 1.11.2;
make: add debug logging for .if and .for lines in -dp mode

This helps track down in which line a condition is evaluated.
 1.10 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.9 09-Jan-2022  rillig tests/make: add placeholders for .PARSEDIR and .INCLUDEDFROMDIR

When run via 'cd usr.bin/make/unit-tests && make test', the tests are in
the current directory. When run via ATF, the tests are in
/usr/tests/usr.bin/make/unit-tests, while the current directory is a
temporary directory. Allow both variants, plus others that may occur in
the bmake distribution.
 1.8 09-Jan-2022  rillig make: remove redundant lines from stack traces

These lines repeated the information from the .for loop line above them.
 1.7 08-Jan-2022  rillig make: add details about .for loop variables to stack traces

The stack traces are enabled with the debug logging option '-dp'.
 1.6 08-Jan-2022  rillig make: fix stack traces in -dp mode (since 2021-01-26)

Previously, the stack traces omitted some lines that seemed to be
redundant. As a result, the stack traces contained confusing line
numbers.
 1.5 08-Jan-2022  rillig make: fix line number in debug log after returning from a file

The parser returns to the next line, not to the current line.
 1.4 08-Jan-2022  rillig tests/make: test line numbers in debug output for parsing files
 1.3 08-Jan-2022  rillig make: fix reported line numbers of continuation lines (since 2002)

Previously, multi-line directives like '.info' or '.error' reported the
line number of their last line instead of their first line, which is
more usual. This also affected the debug log from '-dp'.
 1.2 02-Jan-2022  rillig tests/make: demonstrate bugs in PrintStackTrace
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.11.2.1 02-Aug-2025  perseant Sync with HEAD
 1.8 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.7 09-Feb-2022  rillig make: fix mistakes, spelling and typos in comments and manual page

No binary change for -DNDEBUG.
 1.6 08-Jan-2022  rillig make: add details about .for loop variables to stack traces

The stack traces are enabled with the debug logging option '-dp'.
 1.5 08-Jan-2022  rillig make: fix stack traces in -dp mode (since 2021-01-26)

Previously, the stack traces omitted some lines that seemed to be
redundant. As a result, the stack traces contained confusing line
numbers.
 1.4 08-Jan-2022  rillig make: fix line number in debug log after returning from a file

The parser returns to the next line, not to the current line.
 1.3 08-Jan-2022  rillig tests/make: test line numbers in debug output for parsing files
 1.2 02-Jan-2022  rillig tests/make: demonstrate bugs in PrintStackTrace
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.6 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.5 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.4 10-Jan-2025  rillig tests/make: test expressions based on undefined variables

When an undefined variable is used in a conditional, make complains about
"Malformed conditional", which is wrong since the conditional is
well-formed but errors out during evaluation.

In order to fix this wrong error message and preserve the remaining
behavior, cover the places in which an expression is evaluated with
undefined expressions being an error (VARE_EVAL_DEFINED), but with
neither producing an error message nor handling errors. This combination
results in the same behavior as evaluating the expressions in the mode
that allows undefined variables to be used in expressions.
 1.3 26-Mar-2022  rillig branches: 1.3.4;
make: avoid trailing whitespace in debug log for variables

Since trailing whitespace is invisible, describe the variable value in
words to make it visible.
 1.2 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.3.4.1 02-Aug-2025  perseant Sync with HEAD
 1.5 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.4 10-Jan-2025  rillig tests/make: test expressions based on undefined variables

When an undefined variable is used in a conditional, make complains about
"Malformed conditional", which is wrong since the conditional is
well-formed but errors out during evaluation.

In order to fix this wrong error message and preserve the remaining
behavior, cover the places in which an expression is evaluated with
undefined expressions being an error (VARE_EVAL_DEFINED), but with
neither producing an error message nor handling errors. This combination
results in the same behavior as evaluating the expressions in the mode
that allows undefined variables to be used in expressions.
 1.3 19-Nov-2023  rillig branches: 1.3.2;
tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.2 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.2 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.2 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.1 05-Sep-2020  rillig make(1): add tests for each debug option
 1.5 05-Apr-2021  rillig make: in debug log, add space between scope and variable name

Without this space, the debug log looked more like line noise, even
though the only punctuation was a single innocent ':'. From a make
user's perspective, the variable name is a word of its own and should
not be visually glued to its namespace.
 1.4 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.3 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.2 03-Oct-2020  rillig make(1): allow to disable debug logging options

This is only intended for the unit tests, to selectively enable and
disable debug logging as needed. Previously the tests for debug logging
required complicated postprocessing that was not obvious when looking at
the test .mk file alone, but was specified externally in
unit-tests/Makefile.

This is the simplest possible implementation. Another variant would
have been to selectively disable individual debug logging options, but
that would have made the code more complicated.

The -dL option is not affected by -d0 since that is not really a debug
option, even if it is implemented as one.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.4 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.3 03-Oct-2020  rillig make(1): allow to disable debug logging options

This is only intended for the unit tests, to selectively enable and
disable debug logging as needed. Previously the tests for debug logging
required complicated postprocessing that was not obvious when looking at
the test .mk file alone, but was specified externally in
unit-tests/Makefile.

This is the simplest possible implementation. Another variant would
have been to selectively disable individual debug logging options, but
that would have made the code more complicated.

The -dL option is not affected by -d0 since that is not really a debug
option, even if it is implemented as one.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 12-Jun-2022  rillig tests/make: demonstrate what happens for 'make -DVAR=value'
 1.3 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 25-Sep-2022  rillig tests/make: fix test for option '-e' (broken since 2022-01-23)
 1.3 26-Mar-2022  rillig make: clean up comments
 1.2 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 26-Mar-2022  rillig make: clean up comments
 1.3 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.13 12-Jun-2025  rillig make: add program name to stack traces from sub-makes
 1.12 12-Jun-2025  rillig make: add quotes to "in directory" line in stack traces

The other lines in stack traces use quotes as well.
 1.11 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.10 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.9 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.8 01-Apr-2024  rillig branches: 1.8.2;
make: exit immediately after reading a null byte from a makefile

The chance of other garbage bytes in such a file is just too high.
 1.7 22-Dec-2020  rillig make(1): re-add improved assertion in ParseGetLine
 1.6 22-Dec-2020  rillig make(1): fix assertion failure for files without trailing newline

Previously, mmapped files didn't always have the final newline added.
Only those that ended at a page boundary did.

This confused ParseRawLine, which assumed (and since parse.c 1.510 from
moments ago also asserted) that every line ends with a newline, which
allows the code to assume that after a backslash, there is at least one
other character in the buffer, thereby preventing an out-of-bounds read.

This bug had been there at least since parse.c 1.170 from 2010-12-25
04:57:07, maybe even earlier, I didn't check.

Now line_end always points to the trailing newline, which allows
ParseGetLine to overwrite that character to end the string.
 1.5 07-Dec-2020  rillig make(1): fix exit status in -k mode if a dependency fails

Whether in -k mode or not, the exit status tells whether all requested
targets were made or not. If a dependency could not be made, the main
target was not made as well, therefore the exit status must be nonzero
in such a case.

This part of the code lacked proper unit tests until today. The unit
test deptgt-end-fail.mk is compatible with make>=2003 at least, allowing
to compare the output over time.

In 2003, in the ok-ok-ok-ok case, "Making all from all-dep." was printed
twice in a row, for whatever reason ... (40 minutes later) ... If I had
just made the two commands for 'all' and '.END' more distinguishable.
Back in 2003, the local variables for .END had not been initialized,
instead the .END node was run with the local variables of the last
preceding node. In this case, that node was 'all', therefore ${.TARGET}
had obviously expanded to 'all'.

Somewhere in 2004, the shell commands were no longer run with the -e
flag, which resulted in the "exit status $?" line to be printed in cases
that had stopped early before.

Somewhere in 2005, the local variables for the .END node had been fixed.
The variable ${.TARGET} now had the value '.END', just as expected. In
addition, the dependencies for the .END node were made, although without
getting their proper local variables. This resulted in the output
"Making out of nothing" instead of the expected "Making end-dep out of
nothing".

Still in 2005, in the test case "all=ok all-dep=ok end=ok end-dep=ERR",
the error code of the failed 'end-dep' was first reported as "*** Error
code 1 (continuing)". To compensate for this improvement, a new bug had
been introduced. The test case "all=ok all-dep=ok end=ERR end-dep=ERR"
had properly exited with status 1 on 2005-01-01, but on 2006-01-01 it
exited with status 0, thereby ignoring errors in the .END node.

Somewhere in 2008, some of the error messages (but not all) were
directed to stderr instead of stdout. The actual output stayed the same
though.

Somewhere in 2011, the dependency of the .END node got its own local
variables, and ${.TARGET} now expanded to 'end-dep', as expected.

Somewhere in 2016, the two empty lines between the "*** Error code 1
(continuing)" and the "Stop." got compressed into a single empty line.

On 2020-12-07 (that is, today), the exit status 1 has been restored in
the error cases, after it had been wrong for at least 14 years.
 1.4 06-Dec-2020  rillig make(1): error out on null bytes in makefiles

Makefiles are text files, they must not contain null bytes.

The previous code in this area was rotten anyway. It assumed that
buf_end could be NULL even if buf_ptr was a valid pointer, which is no
longer true, probably since a few years already.

Continuing parsing after a null byte does not make sense. If there's a
null byte in a text file, that file is corrupted, and parsing it leads
to unintended effects easily. Therefore the only sensible action is to
stop parsing immediately.

The check whether cf->readMore could be null was outdated as well, which
previously made the fatal error impossible to reach. Because of the
missing unit tests, nobody noticed this though.

The "exit status 0" in opt-file.exp is worring but that's due to another
bug and will be fixed in a follow-up commit.
 1.3 06-Dec-2020  rillig make(1): add test for makefile containing null bytes
 1.2 06-Dec-2020  rillig make(1): test parsing a makefile that ends in a backslash
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.8.2.1 02-Aug-2025  perseant Sync with HEAD
 1.16 01-Apr-2024  rillig make: exit immediately after reading a null byte from a makefile

The chance of other garbage bytes in such a file is just too high.
 1.15 26-Mar-2022  rillig make: clean up comments
 1.14 09-Dec-2021  rillig make: add back support for jemalloc 100

The ports sun2 and vax default to jemalloc 100, as opposed to the rest
of the ports, which use jemalloc 510. Some developers choose to use
jemalloc 100, so let them run the tests with memory debugging as well.

Suggested by mrg on source-changes-d.
 1.13 05-Dec-2021  rillig tests/make: migrate to jemalloc > 100

When I started working on usr.bin/make in 2020, I used NetBSD 8, which
used jemalloc 100.

After updating to NetBSD 8 to 9.99.x, the debugging options for jemalloc
stopped working since MALLOC_OPTIONS had been replaced with MALLOC_CONF
in 2019.

Enable malloc debugging again, to reliably reproduce the use-after-free
for the variable modifier ':@'.
 1.12 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.11 22-Dec-2020  rillig make(1): fix comment in test about null bytes in makefiles
 1.10 22-Dec-2020  rillig make(1): re-add improved assertion in ParseGetLine
 1.9 22-Dec-2020  rillig make(1): clean up after test opt-file
 1.8 22-Dec-2020  rillig make(1): fix assertion failure for files without trailing newline

Previously, mmapped files didn't always have the final newline added.
Only those that ended at a page boundary did.

This confused ParseRawLine, which assumed (and since parse.c 1.510 from
moments ago also asserted) that every line ends with a newline, which
allows the code to assume that after a backslash, there is at least one
other character in the buffer, thereby preventing an out-of-bounds read.

This bug had been there at least since parse.c 1.170 from 2010-12-25
04:57:07, maybe even earlier, I didn't check.

Now line_end always points to the trailing newline, which allows
ParseGetLine to overwrite that character to end the string.
 1.7 06-Dec-2020  rillig make(1): document undefined behavior from 2014

Earlier versions of make didn't know the -v option to print the expanded
value of a variable. To make the test runnable by older makes as well,
switch to -V instead, which has been available much longer.
 1.6 06-Dec-2020  rillig make(1): error out on null bytes in makefiles

Makefiles are text files, they must not contain null bytes.

The previous code in this area was rotten anyway. It assumed that
buf_end could be NULL even if buf_ptr was a valid pointer, which is no
longer true, probably since a few years already.

Continuing parsing after a null byte does not make sense. If there's a
null byte in a text file, that file is corrupted, and parsing it leads
to unintended effects easily. Therefore the only sensible action is to
stop parsing immediately.

The check whether cf->readMore could be null was outdated as well, which
previously made the fatal error impossible to reach. Because of the
missing unit tests, nobody noticed this though.

The "exit status 0" in opt-file.exp is worring but that's due to another
bug and will be fixed in a follow-up commit.
 1.5 06-Dec-2020  rillig make(1): document how make behaved for null bytes in the makefile
 1.4 06-Dec-2020  rillig make(1): add test for makefile containing null bytes
 1.3 06-Dec-2020  rillig make(1): test parsing a makefile that ends in a backslash
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 18-Oct-2020  rillig make(1): switch some tests to line-buffered stdout

On Alpine Linux, the output was not in the same order as on NetBSD,
at least since bmake-20200902.

The mixture of block-buffered output from child processes and make
itself was hard to predict anyway. Switching to line-buffered stdout
improves the stability of the tests.
 1.2 23-Aug-2020  rillig make(1): add tests for the -i -k -v -V -W options
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 09-Nov-2020  rillig make(1): in tests, move command line arguments into the test proper
 1.4 18-Oct-2020  rillig make(1): switch some tests to line-buffered stdout

On Alpine Linux, the output was not in the same order as on NetBSD,
at least since bmake-20200902.

The mixture of block-buffered output from child processes and make
itself was hard to predict anyway. Switching to line-buffered stdout
improves the stability of the tests.
 1.3 23-Aug-2020  rillig make(1): add tests for the -i -k -v -V -W options
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.12 02-Jul-2025  rillig make: shorten diagnostic for invalid -J option

In the manual page, there's more space to properly explain the
complexity behind the warning.
 1.11 16-Jun-2025  rillig make: in a warning without location information, print the stack trace

Without further context, a warning like the following is hard to track
back:

> nbmake[4]: warning: Invalid character " " in variable name
> "if ,"LSAN_OPTIONS=""
 1.10 13-Jun-2025  rillig make: new sentence, new line
 1.9 05-Jun-2025  rillig make: remove empty line from diagnostic, add tests for output handling

The warning for the invalid internal option "-J" does not need a
trailing newline, as that is provided by Parse_Error already.

Having this newline in the output demonstrated a previously unknown bug
in handling the output of child commands in parallel mode. There, empty
lines are randomly discarded, depending on the chunks in which the
output from the child process is copied to make's stdout. See
job-output.mk for a demonstration.

The test for the Korn shell did not run the Korn shell in error handling
mode, as the error handling mode only affects the parallel mode but the
test didn't switch to that mode.

After fixing the shell-ksh.mk test, the single '"' in the output looked
suspicious, and indeed, the shell-csh.mk test had the same problem of
filtering more characters from the output than intended.
 1.8 28-May-2025  sjg make: delay warning about bogus -J flag

In MainParseArgJobsInternal just set bogusJflag to indicate
that the descriptors passed were invalid.

By the time we get to InitMaxJobs the command line and indeed
the makefile have had a chance to put us in compat mode,
in which case the warning is unnecessary.
Add suggestion of -B if compat mode is desired in the sub-make.

Reviewed by: rillig
 1.7 26-May-2025  rillig make: show contents of MAKEFLAGS in the stack trace

When the internal -J option refers to a closed file descriptor, it's
helpful to know what the MAKEFLAGS environment variable contains, in
addition to the executed command line. Same for parse errors in
variable assignments from the command line.
 1.6 23-May-2025  rillig make: add current directory to error messages from MAKEFLAGS

While parsing the additional command line arguments from the MAKEFLAGS
environment variable, the current directory was not initialized yet, so
swap the order.

As a side effect, this change would allow a "-m .../share/mk" option,
with a literal magic "...", thus looking up the system directory in any
ancestor directory of the current directory. This idea sounds unreliable
enough that probably nobody will try this in practice.
 1.5 23-May-2025  rillig make: warn when falling from parallel mode back to compat mode

Falling back may run fewer jobs than intended, thus increasing the build's
wall time.

Falling back may run more jobs than intended, when a sub-make creates
its own and independent token pool, thus overloading the system.

Warn in both cases. Since the -J option is internal, it is not obvious
how to fix the situation, so provide detailed instructions on the
possible fixes and their effects.
 1.4 11-May-2025  rillig make: clean up error message for malformed internal -J option

There's no point printing the usage, as the problem is typically
somewhere else. Reword the message to be easier to parse.
 1.3 11-May-2025  rillig tests/make: document internal option for parallel mode

In several places in the NetBSD build, a subdir target invokes
${MAKEDIRTARGET}, assuming that this sub-make would coordinate the
number of parallel jobs with its parent make. But since that command
neither contains the plain word "make" nor the expression "${MAKE}", the
sub-make falls back to compat mode.
 1.2 23-Jan-2022  rillig branches: 1.2.4;
tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2.4.1 02-Aug-2025  perseant Sync with HEAD
 1.6 23-May-2025  rillig make: warn when falling from parallel mode back to compat mode

Falling back may run fewer jobs than intended, thus increasing the build's
wall time.

Falling back may run more jobs than intended, when a sub-make creates
its own and independent token pool, thus overloading the system.

Warn in both cases. Since the -J option is internal, it is not obvious
how to fix the situation, so provide detailed instructions on the
possible fixes and their effects.
 1.5 11-May-2025  rillig make: clean up error message for malformed internal -J option

There's no point printing the usage, as the problem is typically
somewhere else. Reword the message to be easier to parse.
 1.4 11-May-2025  rillig tests/make: document internal option for parallel mode

In several places in the NetBSD build, a subdir target invokes
${MAKEDIRTARGET}, assuming that this sub-make would coordinate the
number of parallel jobs with its parent make. But since that command
neither contains the plain word "make" nor the expression "${MAKE}", the
sub-make falls back to compat mode.
 1.3 23-Jan-2022  rillig branches: 1.3.4;
tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3.4.1 02-Aug-2025  perseant Sync with HEAD
 1.6 10-Dec-2020  rillig make(1): name Shell fields consistently

They are all templates with a single %s placeholder, so embed this
unambiguously in the variable name. The previous variable names didn't
provide any clue that echoCmd, execIgnore and errExit had a lot in
common.
 1.5 09-Dec-2020  rillig make(1): clean up test output of opt-jobs-no-action
 1.4 09-Dec-2020  rillig make(1): remove noise from test output of opt-jobs-no-action
 1.3 09-Dec-2020  rillig make(1): refine test for combining -j1 and -n
 1.2 09-Dec-2020  rillig make(1): add more tests for combining -j1 and -n
 1.1 09-Dec-2020  rillig make(1): add test for combining -j1 with -n
 1.10 08-May-2022  rillig tests/make: migrate cond1 test to other, more specific tests

The tests in cond1 were a mixture of "everything related to conditions",
and the test cases were heavily dependent on each other, which made them
hard to understand. Move each test case to its corresponding
special-purpose test.
 1.9 04-Apr-2021  rillig make: rename ambiguous functions

These two functions have counterparts that include the word 'Do' in
their name, which is confusing.

No functional change.
 1.8 10-Dec-2020  rillig make(1): name Shell fields consistently

They are all templates with a single %s placeholder, so embed this
unambiguously in the variable name. The previous variable names didn't
provide any clue that echoCmd, execIgnore and errExit had a lot in
common.
 1.7 09-Dec-2020  rillig make(1): clean up test output of opt-jobs-no-action
 1.6 09-Dec-2020  rillig make(1): remove noise from test output of opt-jobs-no-action
 1.5 09-Dec-2020  rillig make(1): split the -j -n test into separate targets

The manual page says that in -j mode when the shell does not have ErrCtl
(and none of the default shells has that), the command prefix '-'
"affects the entire job", but this seems to be wrong. At least, there
is no change in the output from before, when all commands had been in
the same target.
 1.4 09-Dec-2020  rillig make(1): add test for the -n option combined with RunFlags
 1.3 09-Dec-2020  rillig make(1): refine test for combining -j1 and -n
 1.2 09-Dec-2020  rillig make(1): add more tests for combining -j1 and -n
 1.1 09-Dec-2020  rillig make(1): add test for combining -j1 with -n
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7 20-May-2025  sjg Revert export of MAKEFLAGS from Cmd_Exec

Until we work out what the issue is.
Revert related unit-test changes as well
 1.6 18-May-2025  rillig tests/make: test exporting of MAKEFLAGS in compat and parallel mode
 1.5 10-Sep-2023  sjg branches: 1.5.2;
make: skip -jC tests unless .MAKE.JOBS.C is yes
 1.4 10-Sep-2023  rillig make: add more details to usage message of -j option
 1.3 10-Sep-2023  rillig tests/make: add tests for parsing the -j option
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5.2.1 02-Aug-2025  perseant Sync with HEAD
 1.2 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.1 12-Feb-2022  rillig branches: 1.1.4;
tests/make: document the history of bugs in '-k' mode

Reported in PR#49720 in 2015, fixed independently in compat.c 1.199 from
2020-12-07.
 1.1.4.1 02-Aug-2025  perseant Sync with HEAD
 1.3 02-Apr-2024  rillig tests/make: pass PATH onto child processes

This fixes the tests on some Cygwin variant where the shell does not
initialize the PATH environment variable when it's missing.
 1.2 12-Feb-2022  rillig tests/make: clean up comments in test for indirect -k failures

See PR#49720.
 1.1 12-Feb-2022  rillig tests/make: document the history of bugs in '-k' mode

Reported in PR#49720 in 2015, fixed independently in compat.c 1.199 from
2020-12-07.
 1.3 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.2 07-Dec-2020  rillig branches: 1.2.8;
make(1): fix wrong exit status for multiple failed main targets
 1.1 07-Dec-2020  rillig make(1): add test for wrong exit status 0 after failed targets with -k
 1.2.8.1 02-Aug-2025  perseant Sync with HEAD
 1.1 07-Dec-2020  rillig make(1): add test for wrong exit status 0 after failed targets with -k
 1.5 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.4 07-Dec-2020  rillig branches: 1.4.8;
make(1): fix exit status in -k mode if a dependency fails

Whether in -k mode or not, the exit status tells whether all requested
targets were made or not. If a dependency could not be made, the main
target was not made as well, therefore the exit status must be nonzero
in such a case.

This part of the code lacked proper unit tests until today. The unit
test deptgt-end-fail.mk is compatible with make>=2003 at least, allowing
to compare the output over time.

In 2003, in the ok-ok-ok-ok case, "Making all from all-dep." was printed
twice in a row, for whatever reason ... (40 minutes later) ... If I had
just made the two commands for 'all' and '.END' more distinguishable.
Back in 2003, the local variables for .END had not been initialized,
instead the .END node was run with the local variables of the last
preceding node. In this case, that node was 'all', therefore ${.TARGET}
had obviously expanded to 'all'.

Somewhere in 2004, the shell commands were no longer run with the -e
flag, which resulted in the "exit status $?" line to be printed in cases
that had stopped early before.

Somewhere in 2005, the local variables for the .END node had been fixed.
The variable ${.TARGET} now had the value '.END', just as expected. In
addition, the dependencies for the .END node were made, although without
getting their proper local variables. This resulted in the output
"Making out of nothing" instead of the expected "Making end-dep out of
nothing".

Still in 2005, in the test case "all=ok all-dep=ok end=ok end-dep=ERR",
the error code of the failed 'end-dep' was first reported as "*** Error
code 1 (continuing)". To compensate for this improvement, a new bug had
been introduced. The test case "all=ok all-dep=ok end=ERR end-dep=ERR"
had properly exited with status 1 on 2005-01-01, but on 2006-01-01 it
exited with status 0, thereby ignoring errors in the .END node.

Somewhere in 2008, some of the error messages (but not all) were
directed to stderr instead of stdout. The actual output stayed the same
though.

Somewhere in 2011, the dependency of the .END node got its own local
variables, and ${.TARGET} now expanded to 'end-dep', as expected.

Somewhere in 2016, the two empty lines between the "*** Error code 1
(continuing)" and the "Stop." got compressed into a single empty line.

On 2020-12-07 (that is, today), the exit status 1 has been restored in
the error cases, after it had been wrong for at least 14 years.
 1.3 18-Oct-2020  rillig make(1): switch some tests to line-buffered stdout

On Alpine Linux, the output was not in the same order as on NetBSD,
at least since bmake-20200902.

The mixture of block-buffered output from child processes and make
itself was hard to predict anyway. Switching to line-buffered stdout
improves the stability of the tests.
 1.2 23-Aug-2020  rillig make(1): add tests for the -i -k -v -V -W options
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4.8.1 02-Aug-2025  perseant Sync with HEAD
 1.6 07-Dec-2020  rillig make(1): fix exit status in -k mode if a dependency fails

Whether in -k mode or not, the exit status tells whether all requested
targets were made or not. If a dependency could not be made, the main
target was not made as well, therefore the exit status must be nonzero
in such a case.

This part of the code lacked proper unit tests until today. The unit
test deptgt-end-fail.mk is compatible with make>=2003 at least, allowing
to compare the output over time.

In 2003, in the ok-ok-ok-ok case, "Making all from all-dep." was printed
twice in a row, for whatever reason ... (40 minutes later) ... If I had
just made the two commands for 'all' and '.END' more distinguishable.
Back in 2003, the local variables for .END had not been initialized,
instead the .END node was run with the local variables of the last
preceding node. In this case, that node was 'all', therefore ${.TARGET}
had obviously expanded to 'all'.

Somewhere in 2004, the shell commands were no longer run with the -e
flag, which resulted in the "exit status $?" line to be printed in cases
that had stopped early before.

Somewhere in 2005, the local variables for the .END node had been fixed.
The variable ${.TARGET} now had the value '.END', just as expected. In
addition, the dependencies for the .END node were made, although without
getting their proper local variables. This resulted in the output
"Making out of nothing" instead of the expected "Making end-dep out of
nothing".

Still in 2005, in the test case "all=ok all-dep=ok end=ok end-dep=ERR",
the error code of the failed 'end-dep' was first reported as "*** Error
code 1 (continuing)". To compensate for this improvement, a new bug had
been introduced. The test case "all=ok all-dep=ok end=ERR end-dep=ERR"
had properly exited with status 1 on 2005-01-01, but on 2006-01-01 it
exited with status 0, thereby ignoring errors in the .END node.

Somewhere in 2008, some of the error messages (but not all) were
directed to stderr instead of stdout. The actual output stayed the same
though.

Somewhere in 2011, the dependency of the .END node got its own local
variables, and ${.TARGET} now expanded to 'end-dep', as expected.

Somewhere in 2016, the two empty lines between the "*** Error code 1
(continuing)" and the "Stop." got compressed into a single empty line.

On 2020-12-07 (that is, today), the exit status 1 has been restored in
the error cases, after it had been wrong for at least 14 years.
 1.5 09-Nov-2020  rillig make(1): in tests, move command line arguments into the test proper
 1.4 18-Oct-2020  rillig make(1): switch some tests to line-buffered stdout

On Alpine Linux, the output was not in the same order as on NetBSD,
at least since bmake-20200902.

The mixture of block-buffered output from child processes and make
itself was hard to predict anyway. Switching to line-buffered stdout
improves the stability of the tests.
 1.3 23-Aug-2020  rillig make(1): add tests for the -i -k -v -V -W options
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 01-Sep-2020  rillig make(1): add test for the -m option, the special .../ path
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 30-Apr-2024  sjg make: ensure '.include <makefile>' respects MAKESYSPATH

Since Dir_FindFile is used by '.include' and its variants,
and will first search .CURDIR unless the give path starts with
".DOTLAST".

Update unit-tests/opt-m-include-dir to test this.
 1.4 01-Sep-2020  rillig make(1): add test for the -m option, the special .../ path
 1.3 01-Sep-2020  rillig make(1): add test for -m option with special argument .../
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 09-Dec-2020  rillig make(1): add test for the -n option combined with RunFlags
 1.1 09-Dec-2020  rillig make(1): add test for the -n option combined with RunFlags
 1.1 30-Jan-2021  rillig make(1): add test for combining the options -j, -n, -t

This is a preparation for refactoring the complicated condition in
JobStart.
 1.1 30-Jan-2021  rillig make(1): add test for combining the options -j, -n, -t

This is a preparation for refactoring the complicated condition in
JobStart.
 1.2 19-Aug-2020  rillig make(1): add test for the -n option
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 09-Nov-2020  rillig make(1): in tests, move command line arguments into the test proper
 1.3 19-Aug-2020  rillig make(1): add test for the -n option
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 17-Aug-2022  rillig make: fix exit status for '-q' (since 1994)
 1.3 17-Aug-2022  rillig tests/make: demonstrate wrong exit status for '-q' (since 1994)

Reported by Jeroen Ruigrok van der Werven via private mail.
 1.2 19-Aug-2020  rillig make(1): add test for the -q option
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7 18-Aug-2022  rillig tests/make: fix test for option '-q' in ATF mode

When running 'make test' in usr.bin/make, MAKE is set to '$PWD/make',
and when that file is used as a dependency, everything works as
expected.

When running the tests via ATF, MAKE is set to simply 'make', based on
argv[0]. Using 'make' as a dependency searches in the current directory
but not in /usr/bin, so the file is not found, which makes the
"up-to-date" target out of date.

Switch the dependeny from ${MAKE} to ${MAKEFILE}, as that file does not
involve any $PATH magic and is also guaranteed to be older than the
'up-to-date' file that is created while running the test.
 1.6 17-Aug-2022  rillig make: fix exit status for '-q' (since 1994)
 1.5 17-Aug-2022  rillig tests/make: demonstrate wrong exit status for '-q' (since 1994)

Reported by Jeroen Ruigrok van der Werven via private mail.
 1.4 09-Nov-2020  rillig make(1): in tests, move command line arguments into the test proper
 1.3 19-Aug-2020  rillig make(1): add test for the -q option
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 14-Nov-2020  rillig make(1): add test for the -t option in jobs mode
 1.3 18-May-2025  rillig make: rename variables, remove now-redundant comments
 1.2 30-Jan-2021  rillig branches: 1.2.8;
make(1): explain test opt-touch-jobs
 1.1 14-Nov-2020  rillig make(1): add test for the -t option in jobs mode
 1.2.8.1 02-Aug-2025  perseant Sync with HEAD
 1.3 14-Nov-2020  rillig make(1): add test for touching a .MAKE target
 1.2 14-Nov-2020  rillig make(1): add test for the command line option -t
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 14-Nov-2020  rillig make(1): add test for touching a .MAKE target
 1.3 14-Nov-2020  rillig make(1): add test for the command line option -t
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 09-May-2025  rillig make: replace bitset in trace output with descriptive node attributes
 1.3 09-May-2025  rillig tests/make: add more details to trace output file
 1.2 03-Dec-2021  rillig branches: 1.2.4;
tests/make: test option '-T' for tracing job events
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2.4.1 02-Aug-2025  perseant Sync with HEAD
 1.6 09-May-2025  rillig tests/make: add more details to trace output file
 1.5 06-Dec-2021  rillig branches: 1.5.4;
tests/make: clean up after testing the option '-T'
 1.4 04-Dec-2021  rillig tests/make: fix test for option '-T'

When run via ATF, the test makefile is not in the current directory.
 1.3 03-Dec-2021  rillig tests/make: test option '-T' for tracing job events
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5.4.1 02-Aug-2025  perseant Sync with HEAD
 1.2 23-Aug-2020  rillig make(1): add tests for the -i -k -v -V -W options
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 09-Nov-2020  rillig make(1): in tests, move command line arguments into the test proper
 1.3 23-Aug-2020  rillig make(1): add tests for the -i -k -v -V -W options
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 23-Aug-2020  rillig make(1): add tests for the -i -k -v -V -W options
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 09-Nov-2020  rillig make(1): in tests, move command line arguments into the test proper
 1.3 23-Aug-2020  rillig make(1): add tests for the -i -k -v -V -W options
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 23-Dec-2021  rillig tests/make: explain the current behavior of the option '--version'
 1.2 08-May-2022  rillig tests/make: add test for option '-X', clean up comments
 1.1 23-Dec-2021  rillig tests/make: explain the current behavior of the option '--version'
 1.7 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.6 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.5 01-Jun-2023  rillig branches: 1.5.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.4 27-Jan-2021  rillig make(1): fix irrelevant message in -W mode
 1.3 09-Nov-2020  rillig make(1): in tests, move command line arguments into the test proper
 1.2 23-Aug-2020  rillig make(1): add tests for the -i -k -v -V -W options
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5.2.1 02-Aug-2025  perseant Sync with HEAD
 1.6 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.5 27-Jan-2021  rillig make(1): fix irrelevant message in -W mode
 1.4 09-Nov-2020  rillig make(1): in tests, move command line arguments into the test proper
 1.3 23-Aug-2020  rillig make(1): add tests for the -i -k -v -V -W options
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 22-Jan-2022  rillig tests/make: add a few more tests
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 27-Jan-2022  sjg Do not allow /usr/obj to cause failure.
 1.3 22-Jan-2022  rillig tests/make: add a few more tests
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 08-May-2022  rillig tests/make: add test for option '-X', clean up comments
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 08-May-2022  rillig tests/make: add test for option '-X', clean up comments
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.9 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.8 07-Dec-2020  rillig branches: 1.8.8;
make(1): fix wrong exit status for multiple failed main targets
 1.7 18-Nov-2020  sjg Always use -r -f /dev/null when not intending to read a makefile
 1.6 15-Nov-2020  rillig make(1): add test for passing MAKEFLAGS to sub-makes
 1.5 15-Nov-2020  sjg Avoid reading unexpected makefiles
 1.4 14-Nov-2020  rillig make(1): document the -S option

This option has been available at least since 1993-03-21, and for the
same time it has been undocumented.
 1.3 14-Nov-2020  rillig make(1): fix trailing whitespace in usage (since 2009-08-27)
 1.2 14-Nov-2020  rillig make(1): add tests for edge cases in parsing the command line
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.8.8.1 02-Aug-2025  perseant Sync with HEAD
 1.7 25-Feb-2023  rillig make: rename function for parsing command line options

No binary change.
 1.6 18-Nov-2020  sjg Always use -r -f /dev/null when not intending to read a makefile
 1.5 15-Nov-2020  rillig make(1): add test for passing MAKEFLAGS to sub-makes
 1.4 15-Nov-2020  sjg Avoid reading unexpected makefiles
 1.3 14-Nov-2020  rillig make(1): add tests for edge cases in parsing the command line
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.1 09-Nov-2012  sjg branches: 1.1.2; 1.1.4;
Add a unit-test for .ORDER
 1.1.4.2 16-Jan-2013  yamt sync with (a bit old) head
 1.1.4.1 09-Nov-2012  yamt file order was added on branch yamt-pagecache on 2013-01-16 05:34:06 +0000
 1.1.2.2 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.1.2.1 09-Nov-2012  tls file order was added on branch tls-maxphys on 2012-11-20 03:02:58 +0000
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2 09-Nov-2020  rillig make(1): in tests, move command line arguments into the test proper
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.7 18-Feb-2023  rillig make: fix parsing of unevaluated subexpressions with unbalanced '{}'

Since var.c 1.323 from 2020-07-26, modifiers containing unbalanced
braces or parentheses were parsed differently, depending on whether they
were relevant or not.

For example, the expression '${VAR:...}' is enclosed with braces. When
this expression has a modifier ':S,},}},g' that would double each '}' in
that expression, the parser got confused:

If the expression was relevant, the modifier was parsed as usual, taking
into account that the 3 '}' in the modifier are ordinary characters.

If the expression was irrelevant, the parser only counted the '{' and
the '}', without taking into account that a '}' might be escaped by a
'\' or be an ordinary character. Parsing therefore stopped at the first
'}', assuming it would finish the expression '${VAR:S,}'.

This parsing mode of only counting balanced '{' and '}' makes sense for
the modifier ':@var@...@', which expands each word of the expression
using the template from the '...'. These templates tend to be simple
enough that counting the '{' and '}' suffices.
 1.6 14-Feb-2023  rillig make: remove redundant type VarParseResult

No functional change.
 1.5 25-Sep-2022  rillig tests/make: document how variable evaluation needs to be tested

It's about 100_000 combinations to cover the basic edge cases.
 1.4 23-Aug-2022  rillig make: revert parsing of modifier parts (since 2022-08-08)

The modifier ':@var@body@' parses the body in parse-only mode and later
uses Var_Subst on it, in which each literal '$' must be written as '$$'.

Trying to parse the loop body using Var_Parse treated the text
'$${var:-0}' as a single '$' followed by the expression '${var:-0}',
wrongly complaining about the 'Unknown modifier "-0"'.

Found by sjg.
 1.3 08-Aug-2022  rillig make: fix parsing of modifiers containing unbalanced subexpressions
 1.2 06-Aug-2022  rillig tests/make: demonstrate bug in parsing of modifier parts

In the modifier ':S,from,to,', parsing the two parts 'from' and 'to' of
the modifier differs depending on whether the expression is actually
evaluated or merely parsed. This not only applies to the ':S' modifier,
but also to ':C', ':@var@body@', ':!cmd!', ':[...]', ':?:', '::=' and
':from=to'.
 1.1 04-Oct-2020  rillig make(1): add tests for parsing assignments, especially :sh

Luckily nobody uses the :sh variable assignment modifier since its
syntactical variant != is simpler.
 1.10 02-Jun-2024  rillig make: sync VarEvalMode constant names with their debug log names
 1.9 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.8 18-Feb-2023  rillig make: fix parsing of unevaluated subexpressions with unbalanced '{}'

Since var.c 1.323 from 2020-07-26, modifiers containing unbalanced
braces or parentheses were parsed differently, depending on whether they
were relevant or not.

For example, the expression '${VAR:...}' is enclosed with braces. When
this expression has a modifier ':S,},}},g' that would double each '}' in
that expression, the parser got confused:

If the expression was relevant, the modifier was parsed as usual, taking
into account that the 3 '}' in the modifier are ordinary characters.

If the expression was irrelevant, the parser only counted the '{' and
the '}', without taking into account that a '}' might be escaped by a
'\' or be an ordinary character. Parsing therefore stopped at the first
'}', assuming it would finish the expression '${VAR:S,}'.

This parsing mode of only counting balanced '{' and '}' makes sense for
the modifier ':@var@...@', which expands each word of the expression
using the template from the '...'. These templates tend to be simple
enough that counting the '{' and '}' suffices.
 1.7 14-Feb-2023  rillig make: remove redundant type VarParseResult

No functional change.
 1.6 25-Sep-2022  rillig tests/make: document how variable evaluation needs to be tested

It's about 100_000 combinations to cover the basic edge cases.
 1.5 23-Aug-2022  rillig make: revert parsing of modifier parts (since 2022-08-08)

The modifier ':@var@body@' parses the body in parse-only mode and later
uses Var_Subst on it, in which each literal '$' must be written as '$$'.

Trying to parse the loop body using Var_Parse treated the text
'$${var:-0}' as a single '$' followed by the expression '${var:-0}',
wrongly complaining about the 'Unknown modifier "-0"'.

Found by sjg.
 1.4 08-Aug-2022  rillig tests/make: document history of bug in parsing unbalanced expressions

The bug was introduced in var.c 1.323, which merged two flags that
sounded as if they had been exact opposites: VAR_NOSUBST (later named
VARE_NOSUBST) and VARE_WANTRES.

Before that commit, the branch where make only counted braces instead of
properly parsing the nested expression was only taken in the modifiers
':@var@body@' and '::=', but not in ':S' and ':C'.

After merging the two flags, the modifier parts of ':S' and ':C' had to
be balanced as well, otherwise parsing would fail in cases where the
expression was only parsed, not evaluated.
 1.3 08-Aug-2022  rillig make: fix parsing of modifiers containing unbalanced subexpressions
 1.2 06-Aug-2022  rillig tests/make: demonstrate bug in parsing of modifier parts

In the modifier ':S,from,to,', parsing the two parts 'from' and 'to' of
the modifier differs depending on whether the expression is actually
evaluated or merely parsed. This not only applies to the ':S' modifier,
but also to ':C', ':@var@body@', ':!cmd!', ':[...]', ':?:', '::=' and
':from=to'.
 1.1 04-Oct-2020  rillig make(1): add tests for parsing assignments, especially :sh

Luckily nobody uses the :sh variable assignment modifier since its
syntactical variant != is simpler.
 1.9 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.8 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.7 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.6 19-Aug-2023  rillig branches: 1.6.2;
make: show realistic invalid line in error message

Previously, the error message 'Invalid line' showed only the expanded
line, which might or might not show the actual problem. To be more
helpful, add the unexpanded line to the error message in case they
differ.

Remove the special handling of invalid lines that result from merge
conflicts. RCS is not commonly used anymore, and mentioning CVS was too
specific. By echoing the whole line, the patterns '<<<<<<' and '>>>>>>'
are clear enough to hint at the problem.
 1.5 19-Aug-2023  rillig make: add more details to error message about invalid lines
 1.4 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.3 24-Jul-2022  rillig make: fix out-of-bounds read when parsing an invalid line

Reported by Robert Morris in https://bugs.freebsd.org/265119.

Since 2021-12-14.
 1.2 22-Jan-2022  rillig tests/make: add a few more tests
 1.1 13-Dec-2021  rillig tests/make: extend tests for parsing makefiles
 1.6.2.1 02-Aug-2025  perseant Sync with HEAD
 1.8 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.7 19-Aug-2023  rillig branches: 1.7.2;
make: show realistic invalid line in error message

Previously, the error message 'Invalid line' showed only the expanded
line, which might or might not show the actual problem. To be more
helpful, add the unexpanded line to the error message in case they
differ.

Remove the special handling of invalid lines that result from merge
conflicts. RCS is not commonly used anymore, and mentioning CVS was too
specific. By echoing the whole line, the patterns '<<<<<<' and '>>>>>>'
are clear enough to hint at the problem.
 1.6 19-Aug-2023  rillig make: add more details to error message about invalid lines
 1.5 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.4 28-Apr-2023  rillig tests/make: add tests for target-local variables

While here, move a test from var-scope-local.mk to parse.mk since that
test is not related to variables.
 1.3 24-Jul-2022  rillig make: fix out-of-bounds read when parsing an invalid line

Reported by Robert Morris in https://bugs.freebsd.org/265119.

Since 2021-12-14.
 1.2 22-Jan-2022  rillig tests/make: add a few more tests
 1.1 13-Dec-2021  rillig tests/make: extend tests for parsing makefiles
 1.7.2.1 02-Aug-2025  perseant Sync with HEAD
 1.2 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.1 29-Sep-2011  sjg Make sure .PHONY targets get .TARGET set.
This wasn't happening when a dependency of .END.
Set .PREFIX too and add a unit-test.

PR: 43534
 1.3 07-Aug-2020  rillig make(1): enable test phony-end

This at least documents the actual behavior. Not sure what the expected
behavior is and why.
 1.2 23-Aug-2014  christos fix output based on new sources
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.1 07-May-2004  sjg branches: 1.1.2;
Remove use of sh -e when running in compat mode.
Its not posix compliant and serves very little purpose.
With this change compat and jobs modes are consistent wrt how
they treat each line of a script.

Add support for the '+' command line prefix as required by posix.
Lines prefixed with '+' are executed even when -n is given.
[Actually posix says they should also be done for -q and -t]

PR:
Reviewed by: jmc
 1.1.2.2 10-May-2004  tron Pull up revision 1.1 (requested by sjg in ticket #282):
Remove use of sh -e when running in compat mode.
Its not posix compliant and serves very little purpose.
With this change compat and jobs modes are consistent wrt how
they treat each line of a script.
Add support for the '+' command line prefix as required by posix.
Lines prefixed with '+' are executed even when -n is given.
[Actually posix says they should also be done for -q and -t]
PR:
Reviewed by: jmc
 1.1.2.1 07-May-2004  tron file posix was added on branch netbsd-2-0 on 2004-05-10 15:52:24 +0000
 1.1 13-Apr-2025  rillig branches: 1.1.4;
tests/make: add tests for POSIX mode
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 13-Apr-2025  perseant file posix-execution.exp was added on branch perseant-exfatfs on 2025-08-02 05:58:36 +0000
 1.1 13-Apr-2025  rillig branches: 1.1.4;
tests/make: add tests for POSIX mode
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 13-Apr-2025  perseant file posix-execution.mk was added on branch perseant-exfatfs on 2025-08-02 05:58:36 +0000
 1.2 13-Apr-2025  rillig branches: 1.2.4;
make: after entering POSIX mode, don't leave it again
 1.1 13-Apr-2025  rillig tests/make: add tests for POSIX mode
 1.2.4.2 02-Aug-2025  perseant Sync with HEAD
 1.2.4.1 13-Apr-2025  perseant file posix-expansion.exp was added on branch perseant-exfatfs on 2025-08-02 05:58:36 +0000
 1.2 13-Apr-2025  rillig branches: 1.2.4;
make: after entering POSIX mode, don't leave it again
 1.1 13-Apr-2025  rillig tests/make: add tests for POSIX mode
 1.2.4.2 02-Aug-2025  perseant Sync with HEAD
 1.2.4.1 13-Apr-2025  perseant file posix-expansion.mk was added on branch perseant-exfatfs on 2025-08-02 05:58:36 +0000
 1.1 13-Apr-2025  rillig branches: 1.1.4;
tests/make: add tests for POSIX mode
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 13-Apr-2025  perseant file posix-varassign.exp was added on branch perseant-exfatfs on 2025-08-02 05:58:37 +0000
 1.1 13-Apr-2025  rillig branches: 1.1.4;
tests/make: add tests for POSIX mode
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 13-Apr-2025  perseant file posix-varassign.mk was added on branch perseant-exfatfs on 2025-08-02 05:58:37 +0000
 1.4 13-Apr-2025  rillig tests/make: add tests for POSIX mode
 1.3 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.2 07-Dec-2020  rillig branches: 1.2.8;
make(1): fix exit status in -k mode if a dependency fails

Whether in -k mode or not, the exit status tells whether all requested
targets were made or not. If a dependency could not be made, the main
target was not made as well, therefore the exit status must be nonzero
in such a case.

This part of the code lacked proper unit tests until today. The unit
test deptgt-end-fail.mk is compatible with make>=2003 at least, allowing
to compare the output over time.

In 2003, in the ok-ok-ok-ok case, "Making all from all-dep." was printed
twice in a row, for whatever reason ... (40 minutes later) ... If I had
just made the two commands for 'all' and '.END' more distinguishable.
Back in 2003, the local variables for .END had not been initialized,
instead the .END node was run with the local variables of the last
preceding node. In this case, that node was 'all', therefore ${.TARGET}
had obviously expanded to 'all'.

Somewhere in 2004, the shell commands were no longer run with the -e
flag, which resulted in the "exit status $?" line to be printed in cases
that had stopped early before.

Somewhere in 2005, the local variables for the .END node had been fixed.
The variable ${.TARGET} now had the value '.END', just as expected. In
addition, the dependencies for the .END node were made, although without
getting their proper local variables. This resulted in the output
"Making out of nothing" instead of the expected "Making end-dep out of
nothing".

Still in 2005, in the test case "all=ok all-dep=ok end=ok end-dep=ERR",
the error code of the failed 'end-dep' was first reported as "*** Error
code 1 (continuing)". To compensate for this improvement, a new bug had
been introduced. The test case "all=ok all-dep=ok end=ERR end-dep=ERR"
had properly exited with status 1 on 2005-01-01, but on 2006-01-01 it
exited with status 0, thereby ignoring errors in the .END node.

Somewhere in 2008, some of the error messages (but not all) were
directed to stderr instead of stdout. The actual output stayed the same
though.

Somewhere in 2011, the dependency of the .END node got its own local
variables, and ${.TARGET} now expanded to 'end-dep', as expected.

Somewhere in 2016, the two empty lines between the "*** Error code 1
(continuing)" and the "Stop." got compressed into a single empty line.

On 2020-12-07 (that is, today), the exit status 1 has been restored in
the error cases, after it had been wrong for at least 14 years.
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2.8.1 02-Aug-2025  perseant Sync with HEAD
 1.5 13-Apr-2025  rillig tests/make: duplicate ".POSIX:" lines don't hurt anymore

Fixed in parse.c 1.743 from a few minutes ago.
 1.4 13-Apr-2025  rillig tests/make: add tests for POSIX mode
 1.3 23-Jan-2022  rillig branches: 1.3.4;
tests/make: run nested makes with -r to reduce side effects
 1.2 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.3.4.1 02-Aug-2025  perseant Sync with HEAD
 1.4 30-Aug-2014  sjg Replace use of $() with ${}
$() means something special to the shell, so ${} reduces confusion
and is used almost exclusively in the rest of the makefiles.

Discussed with: christos
 1.3 29-Aug-2014  sjg posix1.mk and suffixes.mk need to cleanup in order to achieve
repeatable results.
posix1.mk's lib.a target still looks dubious.
 1.2 23-Aug-2014  christos fix output based on new sources
 1.1 23-Aug-2014  christos Convert test in PR/49085
 1.6 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.5 27-Sep-2020  rillig make(1): normalize whitespace in source code

There is no more space tab. Either only tabs or only spaces or tabs
followed by spaces, but not spaces followed by tabs.
 1.4 10-Aug-2020  rillig make(1): clean up temporary files after posix1.mk test
 1.3 30-Aug-2014  sjg Replace use of $() with ${}
$() means something special to the shell, so ${} reduces confusion
and is used almost exclusively in the rest of the makefiles.

Discussed with: christos
 1.2 29-Aug-2014  sjg posix1.mk and suffixes.mk need to cleanup in order to achieve
repeatable results.
posix1.mk's lib.a target still looks dubious.
 1.1 23-Aug-2014  christos Convert test in PR/49085
 1.2 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.1 31-Mar-2008  sjg If the name passed to Var_Exists contains '$' run it through Var_Subst.
 1.2 07-Dec-2020  rillig make(1): add tests and tutorial for the ?= assignment operator
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.4 07-Dec-2020  rillig make(1): add tests and tutorial for the ?= assignment operator
 1.3 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.2 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.6 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.5 19-Oct-2023  rillig branches: 1.5.2;
tests/make: clean up, explain and reorganize several tests
 1.4 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.3 09-Nov-2020  rillig make(1): in tests, move command line arguments into the test proper
 1.2 06-Aug-2020  sjg Update test result
 1.1 06-Aug-2020  rillig make(1): add test for unintended "recursive variable" in -dL mode
 1.5.2.1 02-Aug-2025  perseant Sync with HEAD
 1.8 02-Jun-2024  rillig make: sync VarEvalMode constant names with their debug log names
 1.7 19-Oct-2023  rillig tests/make: clean up, explain and reorganize several tests
 1.6 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.5 15-Mar-2021  rillig make: replace enum bit-field with struct bit-field for VarEvalFlags

This makes the code easier to read, especially in var.c. It also makes
debugging sessions easier since some debuggers don't show enum
bit-fields symbolically as soon as more than one bit is set.

The code outside var.c is basically unchanged, except that instead of
passing the individual flags, there are 4 predefined evaluation modes.
These suffice for all practical use cases. Only in the implementation
deep inside var.c, the value of the flags keepDollar and keepUndef
differs.

There is no way of passing the struct to EnumFlags_ToString, which means
the ToString function has to be spelled out explicitly. This allows for
fine-tuning the representation in the debug log, to reduce the amount of
uppercae letters.

No functional change.
 1.4 09-Nov-2020  rillig make(1): in tests, move command line arguments into the test proper
 1.3 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.2 06-Aug-2020  rillig make(1): add rationale and expected behavior to "recursive" test
 1.1 06-Aug-2020  rillig make(1): add test for unintended "recursive variable" in -dL mode
 1.5 07-Dec-2020  rillig make(1): normalize output of test sh-dots for non-native mode
 1.4 25-Oct-2020  rillig make(1): add tests for generating the ... command indirectly
 1.3 18-Oct-2020  rillig make(1): switch some tests to line-buffered stdout

On Alpine Linux, the output was not in the same order as on NetBSD,
at least since bmake-20200902.

The mixture of block-buffered output from child processes and make
itself was hard to predict anyway. Switching to line-buffered stdout
improves the stability of the tests.
 1.2 29-Aug-2020  rillig make(1): fix sh-dots test

The exact output depends on the shell. Some shells prefix the error
message with their name, some don't.
 1.1 22-Aug-2020  rillig make(1): add test for the special "..." in shell commands
 1.4 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.3 25-Oct-2020  rillig make(1): add tests for generating the ... command indirectly
 1.2 18-Oct-2020  rillig make(1): switch some tests to line-buffered stdout

On Alpine Linux, the output was not in the same order as on NetBSD,
at least since bmake-20200902.

The mixture of block-buffered output from child processes and make
itself was hard to predict anyway. Switching to line-buffered stdout
improves the stability of the tests.
 1.1 22-Aug-2020  rillig make(1): add test for the special "..." in shell commands
 1.8 13-Jun-2025  rillig tests/make: fix race condition in debug output in parallel mode

Discovered in ATF run on evbearmv7hf.
 1.7 09-May-2025  rillig make: unify debug messages for parallel mode

Always print the process status in hex, with a leading "0x", to avoid
confusion for status 127f, which looks suspiciously decimal.

Prefix all process IDs with "pid", to be able to filter them easily.

Omit trailing whitespace when printing a command.
 1.6 09-May-2025  rillig make: replace magic numbers in job debug log with descriptive names
 1.5 03-May-2025  rillig make: use uniform debug log messages for the token pool
 1.4 02-May-2025  rillig make: in the debug log, replace magic numbers with identifiers
 1.3 22-Apr-2025  rillig make: group the code for handling the job token pool
 1.2 13-Dec-2020  sjg branches: 1.2.8;
Prune job debug output that may appear out of order.

A race between child and parent means that we cannot
guarantee whether all child output is seen before we call
JobClosePipes, thus intervening debug output can appear
before or after the last child output.
 1.1 12-Dec-2020  rillig make(1): add test for a shell with error control

None of the predefined shells has error control, and the corresponding
code had not been covered by the existing unit tests.
 1.2.8.1 02-Aug-2025  perseant Sync with HEAD
 1.1 12-Dec-2020  rillig make(1): add test for a shell with error control

None of the predefined shells has error control, and the corresponding
code had not been covered by the existing unit tests.
 1.4 12-Feb-2022  rillig make: fix echoing of command with '-' in silent target in jobs mode

Since job.c 1.83 from 2003-12-20, the command had been echoed even if
the target had the attribute '.SILENT'.

In sh-flags.exp, each removed 'echo' command is below a target name
matching the pattern 'opt-?j????-tgt-??s-cmd-?i?', which means that the
target was marked as silent, either through a global '.SILENT'
declaration or the command line option '-s' or the attribute '.SILENT'
on the target.

Reported by Alan Barrett in PR#45356.
 1.3 12-Dec-2020  rillig make(1): reduce number of test cases in sh-flags.mk

The field job->echo is initialized in JobStart (and in JobOpenTmpFile).
After that, it is not modified anymore. Therefore it is not necessary
to run these test cases redundantly.

The field job->ignerr, on the other hand, is modified later on. For
these cases, the many remaining test cases are still needed.
 1.2 10-Dec-2020  rillig make(1): fix test for command flags

The "false" is supposed to be run not only if the command has the '-'
flag, but also if the target is marked as .IGNORE or if the command line
option -i is given.

After the failed command, the remaining commands are skipped, therefore
the final echo for the empty line had to be moved up, at the beginning
of the target.
 1.1 10-Dec-2020  rillig make(1): test all combinations of switches for running commands

The code in JobPrintSpecials is rather complicated and contains
surprising interaction between some of the switches.

To see the exact effects of the switches, record the current state and
its output, to prevent accidental breakage during the upcoming
refactorings.
 1.4 12-Dec-2020  rillig make(1): reduce number of test cases in sh-flags.mk

The field job->echo is initialized in JobStart (and in JobOpenTmpFile).
After that, it is not modified anymore. Therefore it is not necessary
to run these test cases redundantly.

The field job->ignerr, on the other hand, is modified later on. For
these cases, the many remaining test cases are still needed.
 1.3 12-Dec-2020  rillig make(1): demonstrate that -s and .SILENT have the same effect
 1.2 10-Dec-2020  rillig make(1): fix test for command flags

The "false" is supposed to be run not only if the command has the '-'
flag, but also if the target is marked as .IGNORE or if the command line
option -i is given.

After the failed command, the remaining commands are skipped, therefore
the final echo for the empty line had to be moved up, at the beginning
of the target.
 1.1 10-Dec-2020  rillig make(1): test all combinations of switches for running commands

The code in JobPrintSpecials is rather complicated and contains
surprising interaction between some of the switches.

To see the exact effects of the switches, record the current state and
its output, to prevent accidental breakage during the upcoming
refactorings.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.2 11-Dec-2020  rillig branches: 1.2.8;
make(1): add tests for comments and non-comments in jobs mode
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2.8.1 02-Aug-2025  perseant Sync with HEAD
 1.4 16-Apr-2021  rillig make: use distinct wording for writing to the shell commands file

The word 'write' now means to write to the file that holds the shell
commands to be run later.

The word 'print' is now used exclusively for handling the output of the
child commands and printing them to make's stdout.

No functional change.
 1.3 11-Dec-2020  rillig make(1): add tests for comments and non-comments in jobs mode
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 19-Jan-2023  rillig tests/make: add tests for whitespace in leading '@+-'
 1.3 09-Nov-2020  rillig make(1): add test for repeating the leading '@' in shell commands
 1.2 22-Aug-2020  rillig make(1): add test for suppressing the output of the command using @
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.6 19-Jan-2023  rillig tests/make: add tests for whitespace in leading '@+-'
 1.5 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.4 09-Nov-2020  rillig make(1): add test for repeating the leading '@' in shell commands
 1.3 22-Aug-2020  rillig make(1): add test for suppressing the output of the command using @
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 26-Dec-2023  sjg make: fix order of output in compat mode

Ensure that make's output is correctly ordered with the output of the
target's commands, even when the output does not go to a terminal.

Reviewed by: rillig
 1.2 19-Jan-2023  rillig tests/make: add tests for whitespace in leading '@+-'
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 19-Jan-2023  rillig tests/make: add tests for whitespace in leading '@+-'
 1.3 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 19-Jan-2023  rillig tests/make: add tests for whitespace in leading '@+-'
 1.2 23-Aug-2020  rillig make(1): add test for + commands with the -n command line option
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 19-Jan-2023  rillig tests/make: add tests for whitespace in leading '@+-'
 1.4 09-Nov-2020  rillig make(1): in tests, move command line arguments into the test proper
 1.3 23-Aug-2020  rillig make(1): add test for + commands with the -n command line option
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 07-Dec-2020  rillig make(1): normalize output of test sh-dots for non-native mode
 1.3 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 03-Oct-2020  rillig make(1): demonstrate naive output filtering with csh in parallel mode
 1.4 03-Oct-2020  rillig make(1): fix shell definition for csh

The bug has been there since at least 1993-03-21. This is strong
evidence that nobody has ever used the csh in parallel mode.
 1.3 03-Oct-2020  rillig make(1): demonstrate wrong output when using csh in parallel mode
 1.2 03-Oct-2020  rillig make(1): refine test for printing commands using csh
 1.1 03-Oct-2020  rillig make(1): add tests for the various supported shells
 1.10 05-Jun-2025  rillig make: remove empty line from diagnostic, add tests for output handling

The warning for the invalid internal option "-J" does not need a
trailing newline, as that is provided by Parse_Error already.

Having this newline in the output demonstrated a previously unknown bug
in handling the output of child commands in parallel mode. There, empty
lines are randomly discarded, depending on the chunks in which the
output from the child process is copied to make's stdout. See
job-output.mk for a demonstration.

The test for the Korn shell did not run the Korn shell in error handling
mode, as the error handling mode only affects the parallel mode but the
test didn't switch to that mode.

After fixing the shell-ksh.mk test, the single '"' in the output looked
suspicious, and indeed, the shell-csh.mk test had the same problem of
filtering more characters from the output than intended.
 1.9 25-May-2024  rillig branches: 1.9.2;
make: minimize local variables around a vfork call

Passing all relevant values as arguments allows to remove the 'volatile'
qualifiers.
 1.8 04-Apr-2021  rillig make: rename ambiguous functions

These two functions have counterparts that include the word 'Do' in
their name, which is confusing.

No functional change.
 1.7 13-Dec-2020  sjg Avoid noise when csh does not exist
 1.6 10-Dec-2020  rillig make(1): rename commandShell to shell

The word 'command' was not necessary for understanding the variable.
 1.5 19-Oct-2020  rillig make(1): fix test shell-csh in case no csh is available
 1.4 03-Oct-2020  rillig make(1): demonstrate naive output filtering with csh in parallel mode
 1.3 03-Oct-2020  rillig make(1): demonstrate wrong output when using csh in parallel mode
 1.2 03-Oct-2020  rillig make(1): refine test for printing commands using csh
 1.1 03-Oct-2020  rillig make(1): add tests for the various supported shells
 1.9.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 03-Oct-2020  rillig make(1): add tests for the various supported shells
 1.1 03-Oct-2020  rillig make(1): add tests for the various supported shells
 1.2 05-Jun-2025  rillig make: remove empty line from diagnostic, add tests for output handling

The warning for the invalid internal option "-J" does not need a
trailing newline, as that is provided by Parse_Error already.

Having this newline in the output demonstrated a previously unknown bug
in handling the output of child commands in parallel mode. There, empty
lines are randomly discarded, depending on the chunks in which the
output from the child process is copied to make's stdout. See
job-output.mk for a demonstration.

The test for the Korn shell did not run the Korn shell in error handling
mode, as the error handling mode only affects the parallel mode but the
test didn't switch to that mode.

After fixing the shell-ksh.mk test, the single '"' in the output looked
suspicious, and indeed, the shell-csh.mk test had the same problem of
filtering more characters from the output than intended.
 1.1 03-Oct-2020  rillig branches: 1.1.8;
make(1): add tests for the various supported shells
 1.1.8.1 02-Aug-2025  perseant Sync with HEAD
 1.2 05-Jun-2025  rillig make: remove empty line from diagnostic, add tests for output handling

The warning for the invalid internal option "-J" does not need a
trailing newline, as that is provided by Parse_Error already.

Having this newline in the output demonstrated a previously unknown bug
in handling the output of child commands in parallel mode. There, empty
lines are randomly discarded, depending on the chunks in which the
output from the child process is copied to make's stdout. See
job-output.mk for a demonstration.

The test for the Korn shell did not run the Korn shell in error handling
mode, as the error handling mode only affects the parallel mode but the
test didn't switch to that mode.

After fixing the shell-ksh.mk test, the single '"' in the output looked
suspicious, and indeed, the shell-csh.mk test had the same problem of
filtering more characters from the output than intended.
 1.1 03-Oct-2020  rillig branches: 1.1.8;
make(1): add tests for the various supported shells
 1.1.8.1 02-Aug-2025  perseant Sync with HEAD
 1.1 03-Oct-2020  rillig make(1): add tests for the various supported shells
 1.2 24-Dec-2023  sjg Compat_RunCommand call Shell_Init is shellPath is NULL

Since .SHELL is potentially used in compat mode as well,
the man page description should not imply it is only used in jobs mode.

Remove path="sh" from shell-sh unit-test - and it would have detected
this bug.

Reviewed by: rillig
 1.1 03-Oct-2020  rillig make(1): add tests for the various supported shells
 1.5 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.4 07-Dec-2020  rillig branches: 1.4.8;
make(1): fix exit status in -k mode if a dependency fails

Whether in -k mode or not, the exit status tells whether all requested
targets were made or not. If a dependency could not be made, the main
target was not made as well, therefore the exit status must be nonzero
in such a case.

This part of the code lacked proper unit tests until today. The unit
test deptgt-end-fail.mk is compatible with make>=2003 at least, allowing
to compare the output over time.

In 2003, in the ok-ok-ok-ok case, "Making all from all-dep." was printed
twice in a row, for whatever reason ... (40 minutes later) ... If I had
just made the two commands for 'all' and '.END' more distinguishable.
Back in 2003, the local variables for .END had not been initialized,
instead the .END node was run with the local variables of the last
preceding node. In this case, that node was 'all', therefore ${.TARGET}
had obviously expanded to 'all'.

Somewhere in 2004, the shell commands were no longer run with the -e
flag, which resulted in the "exit status $?" line to be printed in cases
that had stopped early before.

Somewhere in 2005, the local variables for the .END node had been fixed.
The variable ${.TARGET} now had the value '.END', just as expected. In
addition, the dependencies for the .END node were made, although without
getting their proper local variables. This resulted in the output
"Making out of nothing" instead of the expected "Making end-dep out of
nothing".

Still in 2005, in the test case "all=ok all-dep=ok end=ok end-dep=ERR",
the error code of the failed 'end-dep' was first reported as "*** Error
code 1 (continuing)". To compensate for this improvement, a new bug had
been introduced. The test case "all=ok all-dep=ok end=ERR end-dep=ERR"
had properly exited with status 1 on 2005-01-01, but on 2006-01-01 it
exited with status 0, thereby ignoring errors in the .END node.

Somewhere in 2008, some of the error messages (but not all) were
directed to stderr instead of stdout. The actual output stayed the same
though.

Somewhere in 2011, the dependency of the .END node got its own local
variables, and ${.TARGET} now expanded to 'end-dep', as expected.

Somewhere in 2016, the two empty lines between the "*** Error code 1
(continuing)" and the "Stop." got compressed into a single empty line.

On 2020-12-07 (that is, today), the exit status 1 has been restored in
the error cases, after it had been wrong for at least 14 years.
 1.3 21-Nov-2020  rillig make(1): add debug logging when adding a suffix to the global list
 1.2 21-Oct-2020  rillig make(1): enable suffix log for test suff-add-later.mk

The log shows that only some of the transformations are actually
defined.
 1.1 20-Oct-2020  rillig make(1): split test suffixes.mk into simpler, isolated tests

The code in suff.c is already hard to understand, and so were the tests
in suffixes.mk since several independent topics were merged into a
single test.

Splitting this test into a separate test per issue allows to document
the expected and actual behavior in more detail. That's complicated
enough already.

PR bin/49086
 1.4.8.1 02-Aug-2025  perseant Sync with HEAD
 1.2 21-Oct-2020  rillig make(1): enable suffix log for test suff-add-later.mk

The log shows that only some of the transformations are actually
defined.
 1.1 20-Oct-2020  rillig make(1): split test suffixes.mk into simpler, isolated tests

The code in suff.c is already hard to understand, and so were the tests
in suffixes.mk since several independent topics were merged into a
single test.

Splitting this test into a separate test per issue allows to document
the expected and actual behavior in more detail. That's complicated
enough already.

PR bin/49086
 1.3 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.2 07-Dec-2020  rillig branches: 1.2.8;
make(1): fix exit status in -k mode if a dependency fails

Whether in -k mode or not, the exit status tells whether all requested
targets were made or not. If a dependency could not be made, the main
target was not made as well, therefore the exit status must be nonzero
in such a case.

This part of the code lacked proper unit tests until today. The unit
test deptgt-end-fail.mk is compatible with make>=2003 at least, allowing
to compare the output over time.

In 2003, in the ok-ok-ok-ok case, "Making all from all-dep." was printed
twice in a row, for whatever reason ... (40 minutes later) ... If I had
just made the two commands for 'all' and '.END' more distinguishable.
Back in 2003, the local variables for .END had not been initialized,
instead the .END node was run with the local variables of the last
preceding node. In this case, that node was 'all', therefore ${.TARGET}
had obviously expanded to 'all'.

Somewhere in 2004, the shell commands were no longer run with the -e
flag, which resulted in the "exit status $?" line to be printed in cases
that had stopped early before.

Somewhere in 2005, the local variables for the .END node had been fixed.
The variable ${.TARGET} now had the value '.END', just as expected. In
addition, the dependencies for the .END node were made, although without
getting their proper local variables. This resulted in the output
"Making out of nothing" instead of the expected "Making end-dep out of
nothing".

Still in 2005, in the test case "all=ok all-dep=ok end=ok end-dep=ERR",
the error code of the failed 'end-dep' was first reported as "*** Error
code 1 (continuing)". To compensate for this improvement, a new bug had
been introduced. The test case "all=ok all-dep=ok end=ERR end-dep=ERR"
had properly exited with status 1 on 2005-01-01, but on 2006-01-01 it
exited with status 0, thereby ignoring errors in the .END node.

Somewhere in 2008, some of the error messages (but not all) were
directed to stderr instead of stdout. The actual output stayed the same
though.

Somewhere in 2011, the dependency of the .END node got its own local
variables, and ${.TARGET} now expanded to 'end-dep', as expected.

Somewhere in 2016, the two empty lines between the "*** Error code 1
(continuing)" and the "Stop." got compressed into a single empty line.

On 2020-12-07 (that is, today), the exit status 1 has been restored in
the error cases, after it had been wrong for at least 14 years.
 1.1 20-Oct-2020  rillig make(1): split test suffixes.mk into simpler, isolated tests

The code in suff.c is already hard to understand, and so were the tests
in suffixes.mk since several independent topics were merged into a
single test.

Splitting this test into a separate test per issue allows to document
the expected and actual behavior in more detail. That's complicated
enough already.

PR bin/49086
 1.2.8.1 02-Aug-2025  perseant Sync with HEAD
 1.2 07-Dec-2020  rillig make(1): fix exit status in -k mode if a dependency fails

Whether in -k mode or not, the exit status tells whether all requested
targets were made or not. If a dependency could not be made, the main
target was not made as well, therefore the exit status must be nonzero
in such a case.

This part of the code lacked proper unit tests until today. The unit
test deptgt-end-fail.mk is compatible with make>=2003 at least, allowing
to compare the output over time.

In 2003, in the ok-ok-ok-ok case, "Making all from all-dep." was printed
twice in a row, for whatever reason ... (40 minutes later) ... If I had
just made the two commands for 'all' and '.END' more distinguishable.
Back in 2003, the local variables for .END had not been initialized,
instead the .END node was run with the local variables of the last
preceding node. In this case, that node was 'all', therefore ${.TARGET}
had obviously expanded to 'all'.

Somewhere in 2004, the shell commands were no longer run with the -e
flag, which resulted in the "exit status $?" line to be printed in cases
that had stopped early before.

Somewhere in 2005, the local variables for the .END node had been fixed.
The variable ${.TARGET} now had the value '.END', just as expected. In
addition, the dependencies for the .END node were made, although without
getting their proper local variables. This resulted in the output
"Making out of nothing" instead of the expected "Making end-dep out of
nothing".

Still in 2005, in the test case "all=ok all-dep=ok end=ok end-dep=ERR",
the error code of the failed 'end-dep' was first reported as "*** Error
code 1 (continuing)". To compensate for this improvement, a new bug had
been introduced. The test case "all=ok all-dep=ok end=ERR end-dep=ERR"
had properly exited with status 1 on 2005-01-01, but on 2006-01-01 it
exited with status 0, thereby ignoring errors in the .END node.

Somewhere in 2008, some of the error messages (but not all) were
directed to stderr instead of stdout. The actual output stayed the same
though.

Somewhere in 2011, the dependency of the .END node got its own local
variables, and ${.TARGET} now expanded to 'end-dep', as expected.

Somewhere in 2016, the two empty lines between the "*** Error code 1
(continuing)" and the "Stop." got compressed into a single empty line.

On 2020-12-07 (that is, today), the exit status 1 has been restored in
the error cases, after it had been wrong for at least 14 years.
 1.1 20-Oct-2020  rillig make(1): split test suffixes.mk into simpler, isolated tests

The code in suff.c is already hard to understand, and so were the tests
in suffixes.mk since several independent topics were merged into a
single test.

Splitting this test into a separate test per issue allows to document
the expected and actual behavior in more detail. That's complicated
enough already.

PR bin/49086
 1.3 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.2 07-Dec-2020  rillig branches: 1.2.8;
make(1): fix exit status in -k mode if a dependency fails

Whether in -k mode or not, the exit status tells whether all requested
targets were made or not. If a dependency could not be made, the main
target was not made as well, therefore the exit status must be nonzero
in such a case.

This part of the code lacked proper unit tests until today. The unit
test deptgt-end-fail.mk is compatible with make>=2003 at least, allowing
to compare the output over time.

In 2003, in the ok-ok-ok-ok case, "Making all from all-dep." was printed
twice in a row, for whatever reason ... (40 minutes later) ... If I had
just made the two commands for 'all' and '.END' more distinguishable.
Back in 2003, the local variables for .END had not been initialized,
instead the .END node was run with the local variables of the last
preceding node. In this case, that node was 'all', therefore ${.TARGET}
had obviously expanded to 'all'.

Somewhere in 2004, the shell commands were no longer run with the -e
flag, which resulted in the "exit status $?" line to be printed in cases
that had stopped early before.

Somewhere in 2005, the local variables for the .END node had been fixed.
The variable ${.TARGET} now had the value '.END', just as expected. In
addition, the dependencies for the .END node were made, although without
getting their proper local variables. This resulted in the output
"Making out of nothing" instead of the expected "Making end-dep out of
nothing".

Still in 2005, in the test case "all=ok all-dep=ok end=ok end-dep=ERR",
the error code of the failed 'end-dep' was first reported as "*** Error
code 1 (continuing)". To compensate for this improvement, a new bug had
been introduced. The test case "all=ok all-dep=ok end=ERR end-dep=ERR"
had properly exited with status 1 on 2005-01-01, but on 2006-01-01 it
exited with status 0, thereby ignoring errors in the .END node.

Somewhere in 2008, some of the error messages (but not all) were
directed to stderr instead of stdout. The actual output stayed the same
though.

Somewhere in 2011, the dependency of the .END node got its own local
variables, and ${.TARGET} now expanded to 'end-dep', as expected.

Somewhere in 2016, the two empty lines between the "*** Error code 1
(continuing)" and the "Stop." got compressed into a single empty line.

On 2020-12-07 (that is, today), the exit status 1 has been restored in
the error cases, after it had been wrong for at least 14 years.
 1.1 20-Oct-2020  rillig make(1): split test suffixes.mk into simpler, isolated tests

The code in suff.c is already hard to understand, and so were the tests
in suffixes.mk since several independent topics were merged into a
single test.

Splitting this test into a separate test per issue allows to document
the expected and actual behavior in more detail. That's complicated
enough already.

PR bin/49086
 1.2.8.1 02-Aug-2025  perseant Sync with HEAD
 1.1 20-Oct-2020  rillig make(1): split test suffixes.mk into simpler, isolated tests

The code in suff.c is already hard to understand, and so were the tests
in suffixes.mk since several independent topics were merged into a
single test.

Splitting this test into a separate test per issue allows to document
the expected and actual behavior in more detail. That's complicated
enough already.

PR bin/49086
 1.8 31-Oct-2024  rillig make: in the debug log, always qualify line number with filename

Previously, to find out the filename corresponding to a line number from
a 'Parsing' line, it was necessary to find the preceding
'SetFilenameVars' line, which was unnecessarily time-consuming and
distracting.

The 'filename:line' format matches the one used in PrintStackTrace, and
it differs from the one used in PrintLocation, as the former format is
more common in other tools.

Most of the affected unit tests only use the 'Parsing' lines to give
additional context to their debug log, so no structural changes there.
 1.7 25-May-2024  rillig branches: 1.7.2;
make: use fewer technical terms in debug message for dependency
 1.6 28-Dec-2021  rillig make: make debug logging a bit more human-friendly

The previous log format "ParseReadLine (%d): '%s'" focused on the
implementation, it was not immediately obvious to a casual reader that
the number in parentheses was the line number. Additionally, having
both a colon and quotes in a log message is uncommon. The quotes have
been added in parse.c 1.127 from 2007-01-01.

The new log format "Parsing line %d: %s" is meant to be easier readable
by humans. The quotes are not needed since ParseReadLine always strips
trailing whitespace, leaving no room for ambiguities. The other log
messages follow common punctuation rules, which makes the beginning of
the line equally unambiguous. Before var.c 1.911 from 2021-04-05,
variable assignments were logged with the format "%s:%s = %s", without a
space after the colon.
 1.5 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.4 02-Feb-2021  rillig make: remove overengineered Enum_ValueToString

For printing the status of a GNode, there was already made_name (now
renamed to GNodeMade_Name), which prints user-friendly text instead of
the bare enum constant names.

To do this change confidently, I first had to demonstrate that the
output really affects something other than just the word "UNMADE". There
had not been a test for that case before, and the test immediately
discovered a bug in the -dg2 and -dg3 options. This bug is one of the
oldest in make, dating back to at least 1993.
 1.3 22-Nov-2020  rillig make(1): add more debugging for searching transformation rules
 1.2 21-Nov-2020  rillig make(1): add more debug logging for suffixes

The "Removing suffix" is not covered by the current tests. It would be
best if that code were unreachable at all, since a reference count of -1
doesn't make sense.
 1.1 21-Nov-2020  rillig make(1): add test for incomplete transformation rule
 1.7.2.1 02-Aug-2025  perseant Sync with HEAD
 1.2 22-Nov-2020  rillig make(1): document the type of the .DEFAULT node

It is marked intentionally as a transformation node, even though this
seems counterintuitive at first.
 1.1 21-Nov-2020  rillig make(1): add test for incomplete transformation rule
 1.6 22-Nov-2020  rillig make(1): add more debugging for searching transformation rules
 1.5 21-Nov-2020  rillig make(1): add more debug logging for suffixes

The "Removing suffix" is not covered by the current tests. It would be
best if that code were unreachable at all, since a reference count of -1
doesn't make sense.
 1.4 21-Nov-2020  rillig make(1): add debug logging when adding a suffix to the global list
 1.3 25-Oct-2020  rillig make(1): properly terminate debug output with newline

Without this, NetBSD's sed adds the missing newline at the end of the
file, while other sed implementations don't do that.
 1.2 24-Oct-2020  rillig make(1): extend test suff-lookup.mk

This test ensures that FindSuffByName behaves correctly.

In order to convert some char pointers to const char pointers, there
needs to be FindSuffByNameLen, and to make sure that this function
actually uses the given length, this test has the suffixes ".sho" and
".short". Without the proper string comparison in FindSuffByNameLen,
the suffix ".short" might be found when searching for ".sho".
 1.1 24-Oct-2020  rillig make(1): add test for looking up suffixes
 1.2 24-Oct-2020  rillig make(1): extend test suff-lookup.mk

This test ensures that FindSuffByName behaves correctly.

In order to convert some char pointers to const char pointers, there
needs to be FindSuffByNameLen, and to make sure that this function
actually uses the given length, this test has the suffixes ".sho" and
".short". Without the proper string comparison in FindSuffByNameLen,
the suffix ".short" might be found when searching for ".sho".
 1.1 24-Oct-2020  rillig make(1): add test for looking up suffixes
 1.15 07-May-2025  rillig make: add end marker for -dg1, -dg2 and -dg3 debug log

The marker helps distinguish the output from sub-makes from the output
of the primary make.
 1.14 31-Oct-2024  rillig make: in the debug log, always qualify line number with filename

Previously, to find out the filename corresponding to a line number from
a 'Parsing' line, it was necessary to find the preceding
'SetFilenameVars' line, which was unnecessarily time-consuming and
distracting.

The 'filename:line' format matches the one used in PrintStackTrace, and
it differs from the one used in PrintLocation, as the former format is
more common in other tools.

Most of the affected unit tests only use the 'Parsing' lines to give
additional context to their debug log, so no structural changes there.
 1.13 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.12 25-May-2024  rillig branches: 1.12.2;
make: use fewer technical terms in debug message for dependency
 1.11 07-May-2024  sjg make: all command line overrides go in .MAKEOVERRIDES

Not all variables that start with '.' are internals,
and unless they are explicitly flagged as internal should go
into .MAKEOVERRIDES

Update varname-dot-makeoverrides to check this.

Also avoid using SCOPE_CMDLINE when ReadOnly will do.
 1.10 09-Sep-2023  sjg Add .MAKE.JOBS.C to indicate wether -jC is supported
 1.9 24-Jan-2023  sjg make: .SYSPATH: to add dirs to sysIncPath

.SYSPATH: with no sources will clear sysIncPath
otherwise sources are added

Reviewed by: rillig
 1.8 26-Mar-2022  rillig make: avoid trailing whitespace in debug log for variables

Since trailing whitespace is invisible, describe the variable value in
words to make it visible.
 1.7 28-Dec-2021  rillig make: make debug logging a bit more human-friendly

The previous log format "ParseReadLine (%d): '%s'" focused on the
implementation, it was not immediately obvious to a casual reader that
the number in parentheses was the line number. Additionally, having
both a colon and quotes in a log message is uncommon. The quotes have
been added in parse.c 1.127 from 2007-01-01.

The new log format "Parsing line %d: %s" is meant to be easier readable
by humans. The quotes are not needed since ParseReadLine always strips
trailing whitespace, leaving no room for ambiguities. The other log
messages follow common punctuation rules, which makes the beginning of
the line equally unambiguous. Before var.c 1.911 from 2021-04-05,
variable assignments were logged with the format "%s:%s = %s", without a
space after the colon.
 1.6 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.5 02-Feb-2021  rillig make: remove overengineered Enum_ValueToString

For printing the status of a GNode, there was already made_name (now
renamed to GNodeMade_Name), which prints user-friendly text instead of
the bare enum constant names.

To do this change confidently, I first had to demonstrate that the
output really affects something other than just the word "UNMADE". There
had not been a test for that case before, and the test immediately
discovered a bug in the -dg2 and -dg3 options. This bug is one of the
oldest in make, dating back to at least 1993.
 1.4 07-Dec-2020  rillig make(1): fix exit status in -k mode if a dependency fails

Whether in -k mode or not, the exit status tells whether all requested
targets were made or not. If a dependency could not be made, the main
target was not made as well, therefore the exit status must be nonzero
in such a case.

This part of the code lacked proper unit tests until today. The unit
test deptgt-end-fail.mk is compatible with make>=2003 at least, allowing
to compare the output over time.

In 2003, in the ok-ok-ok-ok case, "Making all from all-dep." was printed
twice in a row, for whatever reason ... (40 minutes later) ... If I had
just made the two commands for 'all' and '.END' more distinguishable.
Back in 2003, the local variables for .END had not been initialized,
instead the .END node was run with the local variables of the last
preceding node. In this case, that node was 'all', therefore ${.TARGET}
had obviously expanded to 'all'.

Somewhere in 2004, the shell commands were no longer run with the -e
flag, which resulted in the "exit status $?" line to be printed in cases
that had stopped early before.

Somewhere in 2005, the local variables for the .END node had been fixed.
The variable ${.TARGET} now had the value '.END', just as expected. In
addition, the dependencies for the .END node were made, although without
getting their proper local variables. This resulted in the output
"Making out of nothing" instead of the expected "Making end-dep out of
nothing".

Still in 2005, in the test case "all=ok all-dep=ok end=ok end-dep=ERR",
the error code of the failed 'end-dep' was first reported as "*** Error
code 1 (continuing)". To compensate for this improvement, a new bug had
been introduced. The test case "all=ok all-dep=ok end=ERR end-dep=ERR"
had properly exited with status 1 on 2005-01-01, but on 2006-01-01 it
exited with status 0, thereby ignoring errors in the .END node.

Somewhere in 2008, some of the error messages (but not all) were
directed to stderr instead of stdout. The actual output stayed the same
though.

Somewhere in 2011, the dependency of the .END node got its own local
variables, and ${.TARGET} now expanded to 'end-dep', as expected.

Somewhere in 2016, the two empty lines between the "*** Error code 1
(continuing)" and the "Stop." got compressed into a single empty line.

On 2020-12-07 (that is, today), the exit status 1 has been restored in
the error cases, after it had been wrong for at least 14 years.
 1.3 04-Dec-2020  rillig make(1): use fixed format for debug output of the directory cache

The previous output format had a %-20s conversion specifier. This
produced different output depending on the length of the pathname, which
was too difficult to normalize. By moving the directory name to the
end, it is no longer necessary to fill up any space, and the numbers are
always aligned properly.

As a result, 3 of the unit tests no longer need any special
postprocessing of their output.
 1.2 25-Nov-2020  sjg Add .MAKE.UID and .MAKE.GID
 1.1 22-Nov-2020  rillig make(1): add another unit test for suffix handling
 1.12.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 22-Nov-2020  rillig make(1): add another unit test for suffix handling
 1.1 18-Oct-2020  rillig make(1): add test for turning a target into a transformation
 1.1 18-Oct-2020  rillig make(1): add test for turning a target into a transformation
 1.1 23-Nov-2020  rillig make(1): test that .PHONY targets are not resolved using suffix rules
 1.1 23-Nov-2020  rillig make(1): test that .PHONY targets are not resolved using suffix rules
 1.9 31-Oct-2024  rillig make: in the debug log, always qualify line number with filename

Previously, to find out the filename corresponding to a line number from
a 'Parsing' line, it was necessary to find the preceding
'SetFilenameVars' line, which was unnecessarily time-consuming and
distracting.

The 'filename:line' format matches the one used in PrintStackTrace, and
it differs from the one used in PrintLocation, as the former format is
more common in other tools.

Most of the affected unit tests only use the 'Parsing' lines to give
additional context to their debug log, so no structural changes there.
 1.8 28-Dec-2021  rillig branches: 1.8.4;
make: make debug logging a bit more human-friendly

The previous log format "ParseReadLine (%d): '%s'" focused on the
implementation, it was not immediately obvious to a casual reader that
the number in parentheses was the line number. Additionally, having
both a colon and quotes in a log message is uncommon. The quotes have
been added in parse.c 1.127 from 2007-01-01.

The new log format "Parsing line %d: %s" is meant to be easier readable
by humans. The quotes are not needed since ParseReadLine always strips
trailing whitespace, leaving no room for ambiguities. The other log
messages follow common punctuation rules, which makes the beginning of
the line equally unambiguous. Before var.c 1.911 from 2021-04-05,
variable assignments were logged with the format "%s:%s = %s", without a
space after the colon.
 1.7 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.6 22-Nov-2020  rillig make(1): add more debugging for searching transformation rules
 1.5 21-Nov-2020  rillig make(1): add explanation for test suff-rebuild
 1.4 21-Nov-2020  rillig make(1): add more debug logging for suffix handling

One notable thing is that there is no debug output when adding a
transformation rule like ".c.o", which means that these rules don't end
up in the global allTargets variable.

This may or may not be intentional. It seems not intentional since this
is one of the causes for the suff-rebuild test to behave unexpectedly.
 1.3 21-Nov-2020  rillig make(1): enable debug logging for test suff-rebuild

As long as it is not clear why this test fails, it's better to have the
debug log available, both for reading it and for getting notified if
any behavior in this area changes.
 1.2 21-Nov-2020  rillig make(1): make output of test suff-rebuild more verbose
 1.1 25-Sep-2020  rillig make(1): add test for deleting the suffixes during parsing
 1.8.4.1 02-Aug-2025  perseant Sync with HEAD
 1.6 21-Nov-2020  rillig make(1): add explanation for test suff-rebuild
 1.5 21-Nov-2020  rillig make(1): enable debug logging for test suff-rebuild

As long as it is not clear why this test fails, it's better to have the
debug log available, both for reading it and for getting notified if
any behavior in this area changes.
 1.4 21-Nov-2020  rillig make(1): make output of test suff-rebuild more verbose
 1.3 21-Nov-2020  rillig make(1): rename SuffScanTargets to SuffUpdateTarget

The word "scan" no longer applies to this function since that is done by
SuffUpdateTargets instead.
 1.2 18-Oct-2020  rillig make(1): fix typo in test suff-rebuild.mk
 1.1 25-Sep-2020  rillig make(1): add test for deleting the suffixes during parsing
 1.3 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.2 07-Dec-2020  rillig branches: 1.2.8;
make(1): fix exit status in -k mode if a dependency fails

Whether in -k mode or not, the exit status tells whether all requested
targets were made or not. If a dependency could not be made, the main
target was not made as well, therefore the exit status must be nonzero
in such a case.

This part of the code lacked proper unit tests until today. The unit
test deptgt-end-fail.mk is compatible with make>=2003 at least, allowing
to compare the output over time.

In 2003, in the ok-ok-ok-ok case, "Making all from all-dep." was printed
twice in a row, for whatever reason ... (40 minutes later) ... If I had
just made the two commands for 'all' and '.END' more distinguishable.
Back in 2003, the local variables for .END had not been initialized,
instead the .END node was run with the local variables of the last
preceding node. In this case, that node was 'all', therefore ${.TARGET}
had obviously expanded to 'all'.

Somewhere in 2004, the shell commands were no longer run with the -e
flag, which resulted in the "exit status $?" line to be printed in cases
that had stopped early before.

Somewhere in 2005, the local variables for the .END node had been fixed.
The variable ${.TARGET} now had the value '.END', just as expected. In
addition, the dependencies for the .END node were made, although without
getting their proper local variables. This resulted in the output
"Making out of nothing" instead of the expected "Making end-dep out of
nothing".

Still in 2005, in the test case "all=ok all-dep=ok end=ok end-dep=ERR",
the error code of the failed 'end-dep' was first reported as "*** Error
code 1 (continuing)". To compensate for this improvement, a new bug had
been introduced. The test case "all=ok all-dep=ok end=ERR end-dep=ERR"
had properly exited with status 1 on 2005-01-01, but on 2006-01-01 it
exited with status 0, thereby ignoring errors in the .END node.

Somewhere in 2008, some of the error messages (but not all) were
directed to stderr instead of stdout. The actual output stayed the same
though.

Somewhere in 2011, the dependency of the .END node got its own local
variables, and ${.TARGET} now expanded to 'end-dep', as expected.

Somewhere in 2016, the two empty lines between the "*** Error code 1
(continuing)" and the "Stop." got compressed into a single empty line.

On 2020-12-07 (that is, today), the exit status 1 has been restored in
the error cases, after it had been wrong for at least 14 years.
 1.1 16-Nov-2020  rillig make(1): add test for self-referencing suffix rule

Just to ensure that make doesn't run into an endless loop.
 1.2.8.1 02-Aug-2025  perseant Sync with HEAD
 1.1 16-Nov-2020  rillig make(1): add test for self-referencing suffix rule

Just to ensure that make doesn't run into an endless loop.
 1.9 07-May-2025  rillig make: add end marker for -dg1, -dg2 and -dg3 debug log

The marker helps distinguish the output from sub-makes from the output
of the primary make.
 1.8 07-May-2024  sjg branches: 1.8.2;
make: all command line overrides go in .MAKEOVERRIDES

Not all variables that start with '.' are internals,
and unless they are explicitly flagged as internal should go
into .MAKEOVERRIDES

Update varname-dot-makeoverrides to check this.

Also avoid using SCOPE_CMDLINE when ReadOnly will do.
 1.7 09-Sep-2023  sjg Add .MAKE.JOBS.C to indicate wether -jC is supported
 1.6 24-Jan-2023  sjg make: .SYSPATH: to add dirs to sysIncPath

.SYSPATH: with no sources will clear sysIncPath
otherwise sources are added

Reviewed by: rillig
 1.5 26-Mar-2022  rillig make: avoid trailing whitespace in debug log for variables

Since trailing whitespace is invisible, describe the variable value in
words to make it visible.
 1.4 02-Feb-2021  rillig make: remove overengineered Enum_ValueToString

For printing the status of a GNode, there was already made_name (now
renamed to GNodeMade_Name), which prints user-friendly text instead of
the bare enum constant names.

To do this change confidently, I first had to demonstrate that the
output really affects something other than just the word "UNMADE". There
had not been a test for that case before, and the test immediately
discovered a bug in the -dg2 and -dg3 options. This bug is one of the
oldest in make, dating back to at least 1993.
 1.3 04-Dec-2020  rillig make(1): use fixed format for debug output of the directory cache

The previous output format had a %-20s conversion specifier. This
produced different output depending on the length of the pathname, which
was too difficult to normalize. By moving the directory name to the
end, it is no longer necessary to fill up any space, and the numbers are
always aligned properly.

As a result, 3 of the unit tests no longer need any special
postprocessing of their output.
 1.2 25-Nov-2020  sjg Add .MAKE.UID and .MAKE.GID
 1.1 22-Nov-2020  rillig make(1): add test for debug output from transformation rules
 1.8.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 22-Nov-2020  rillig make(1): add test for debug output from transformation rules
 1.5 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.4 07-Dec-2020  rillig branches: 1.4.8;
make(1): fix exit status in -k mode if a dependency fails

Whether in -k mode or not, the exit status tells whether all requested
targets were made or not. If a dependency could not be made, the main
target was not made as well, therefore the exit status must be nonzero
in such a case.

This part of the code lacked proper unit tests until today. The unit
test deptgt-end-fail.mk is compatible with make>=2003 at least, allowing
to compare the output over time.

In 2003, in the ok-ok-ok-ok case, "Making all from all-dep." was printed
twice in a row, for whatever reason ... (40 minutes later) ... If I had
just made the two commands for 'all' and '.END' more distinguishable.
Back in 2003, the local variables for .END had not been initialized,
instead the .END node was run with the local variables of the last
preceding node. In this case, that node was 'all', therefore ${.TARGET}
had obviously expanded to 'all'.

Somewhere in 2004, the shell commands were no longer run with the -e
flag, which resulted in the "exit status $?" line to be printed in cases
that had stopped early before.

Somewhere in 2005, the local variables for the .END node had been fixed.
The variable ${.TARGET} now had the value '.END', just as expected. In
addition, the dependencies for the .END node were made, although without
getting their proper local variables. This resulted in the output
"Making out of nothing" instead of the expected "Making end-dep out of
nothing".

Still in 2005, in the test case "all=ok all-dep=ok end=ok end-dep=ERR",
the error code of the failed 'end-dep' was first reported as "*** Error
code 1 (continuing)". To compensate for this improvement, a new bug had
been introduced. The test case "all=ok all-dep=ok end=ERR end-dep=ERR"
had properly exited with status 1 on 2005-01-01, but on 2006-01-01 it
exited with status 0, thereby ignoring errors in the .END node.

Somewhere in 2008, some of the error messages (but not all) were
directed to stderr instead of stdout. The actual output stayed the same
though.

Somewhere in 2011, the dependency of the .END node got its own local
variables, and ${.TARGET} now expanded to 'end-dep', as expected.

Somewhere in 2016, the two empty lines between the "*** Error code 1
(continuing)" and the "Stop." got compressed into a single empty line.

On 2020-12-07 (that is, today), the exit status 1 has been restored in
the error cases, after it had been wrong for at least 14 years.
 1.3 23-Nov-2020  rillig make(1): fix endless loop when resolving circular suffix rules
 1.2 23-Nov-2020  rillig make(1): add debug logging for suffix tests
 1.1 20-Oct-2020  rillig make(1): split test suffixes.mk into simpler, isolated tests

The code in suff.c is already hard to understand, and so were the tests
in suffixes.mk since several independent topics were merged into a
single test.

Splitting this test into a separate test per issue allows to document
the expected and actual behavior in more detail. That's complicated
enough already.

PR bin/49086
 1.4.8.1 02-Aug-2025  perseant Sync with HEAD
 1.4 23-Nov-2020  rillig make(1): fix endless loop when resolving circular suffix rules
 1.3 23-Nov-2020  rillig make(1): add debug logging for suffix tests
 1.2 22-Nov-2020  rillig make(1): fix confusing command output in test suff-transform-endless
 1.1 20-Oct-2020  rillig make(1): split test suffixes.mk into simpler, isolated tests

The code in suff.c is already hard to understand, and so were the tests
in suffixes.mk since several independent topics were merged into a
single test.

Splitting this test into a separate test per issue allows to document
the expected and actual behavior in more detail. That's complicated
enough already.

PR bin/49086
 1.3 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.2 07-Dec-2020  rillig branches: 1.2.8;
make(1): fix exit status in -k mode if a dependency fails

Whether in -k mode or not, the exit status tells whether all requested
targets were made or not. If a dependency could not be made, the main
target was not made as well, therefore the exit status must be nonzero
in such a case.

This part of the code lacked proper unit tests until today. The unit
test deptgt-end-fail.mk is compatible with make>=2003 at least, allowing
to compare the output over time.

In 2003, in the ok-ok-ok-ok case, "Making all from all-dep." was printed
twice in a row, for whatever reason ... (40 minutes later) ... If I had
just made the two commands for 'all' and '.END' more distinguishable.
Back in 2003, the local variables for .END had not been initialized,
instead the .END node was run with the local variables of the last
preceding node. In this case, that node was 'all', therefore ${.TARGET}
had obviously expanded to 'all'.

Somewhere in 2004, the shell commands were no longer run with the -e
flag, which resulted in the "exit status $?" line to be printed in cases
that had stopped early before.

Somewhere in 2005, the local variables for the .END node had been fixed.
The variable ${.TARGET} now had the value '.END', just as expected. In
addition, the dependencies for the .END node were made, although without
getting their proper local variables. This resulted in the output
"Making out of nothing" instead of the expected "Making end-dep out of
nothing".

Still in 2005, in the test case "all=ok all-dep=ok end=ok end-dep=ERR",
the error code of the failed 'end-dep' was first reported as "*** Error
code 1 (continuing)". To compensate for this improvement, a new bug had
been introduced. The test case "all=ok all-dep=ok end=ERR end-dep=ERR"
had properly exited with status 1 on 2005-01-01, but on 2006-01-01 it
exited with status 0, thereby ignoring errors in the .END node.

Somewhere in 2008, some of the error messages (but not all) were
directed to stderr instead of stdout. The actual output stayed the same
though.

Somewhere in 2011, the dependency of the .END node got its own local
variables, and ${.TARGET} now expanded to 'end-dep', as expected.

Somewhere in 2016, the two empty lines between the "*** Error code 1
(continuing)" and the "Stop." got compressed into a single empty line.

On 2020-12-07 (that is, today), the exit status 1 has been restored in
the error cases, after it had been wrong for at least 14 years.
 1.1 20-Oct-2020  rillig make(1): split test suffixes.mk into simpler, isolated tests

The code in suff.c is already hard to understand, and so were the tests
in suffixes.mk since several independent topics were merged into a
single test.

Splitting this test into a separate test per issue allows to document
the expected and actual behavior in more detail. That's complicated
enough already.

PR bin/49086
 1.2.8.1 02-Aug-2025  perseant Sync with HEAD
 1.1 20-Oct-2020  rillig make(1): split test suffixes.mk into simpler, isolated tests

The code in suff.c is already hard to understand, and so were the tests
in suffixes.mk since several independent topics were merged into a
single test.

Splitting this test into a separate test per issue allows to document
the expected and actual behavior in more detail. That's complicated
enough already.

PR bin/49086
 1.5 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.4 07-Dec-2020  rillig branches: 1.4.8;
make(1): fix exit status in -k mode if a dependency fails

Whether in -k mode or not, the exit status tells whether all requested
targets were made or not. If a dependency could not be made, the main
target was not made as well, therefore the exit status must be nonzero
in such a case.

This part of the code lacked proper unit tests until today. The unit
test deptgt-end-fail.mk is compatible with make>=2003 at least, allowing
to compare the output over time.

In 2003, in the ok-ok-ok-ok case, "Making all from all-dep." was printed
twice in a row, for whatever reason ... (40 minutes later) ... If I had
just made the two commands for 'all' and '.END' more distinguishable.
Back in 2003, the local variables for .END had not been initialized,
instead the .END node was run with the local variables of the last
preceding node. In this case, that node was 'all', therefore ${.TARGET}
had obviously expanded to 'all'.

Somewhere in 2004, the shell commands were no longer run with the -e
flag, which resulted in the "exit status $?" line to be printed in cases
that had stopped early before.

Somewhere in 2005, the local variables for the .END node had been fixed.
The variable ${.TARGET} now had the value '.END', just as expected. In
addition, the dependencies for the .END node were made, although without
getting their proper local variables. This resulted in the output
"Making out of nothing" instead of the expected "Making end-dep out of
nothing".

Still in 2005, in the test case "all=ok all-dep=ok end=ok end-dep=ERR",
the error code of the failed 'end-dep' was first reported as "*** Error
code 1 (continuing)". To compensate for this improvement, a new bug had
been introduced. The test case "all=ok all-dep=ok end=ERR end-dep=ERR"
had properly exited with status 1 on 2005-01-01, but on 2006-01-01 it
exited with status 0, thereby ignoring errors in the .END node.

Somewhere in 2008, some of the error messages (but not all) were
directed to stderr instead of stdout. The actual output stayed the same
though.

Somewhere in 2011, the dependency of the .END node got its own local
variables, and ${.TARGET} now expanded to 'end-dep', as expected.

Somewhere in 2016, the two empty lines between the "*** Error code 1
(continuing)" and the "Stop." got compressed into a single empty line.

On 2020-12-07 (that is, today), the exit status 1 has been restored in
the error cases, after it had been wrong for at least 14 years.
 1.3 23-Nov-2020  rillig make(1): fix endless loop when resolving circular suffix rules
 1.2 23-Nov-2020  rillig make(1): add debug logging for suffix tests
 1.1 20-Oct-2020  rillig make(1): split test suffixes.mk into simpler, isolated tests

The code in suff.c is already hard to understand, and so were the tests
in suffixes.mk since several independent topics were merged into a
single test.

Splitting this test into a separate test per issue allows to document
the expected and actual behavior in more detail. That's complicated
enough already.

PR bin/49086
 1.4.8.1 02-Aug-2025  perseant Sync with HEAD
 1.3 23-Nov-2020  rillig make(1): fix endless loop when resolving circular suffix rules
 1.2 23-Nov-2020  rillig make(1): add debug logging for suffix tests
 1.1 20-Oct-2020  rillig make(1): split test suffixes.mk into simpler, isolated tests

The code in suff.c is already hard to understand, and so were the tests
in suffixes.mk since several independent topics were merged into a
single test.

Splitting this test into a separate test per issue allows to document
the expected and actual behavior in more detail. That's complicated
enough already.

PR bin/49086
 1.2 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.1 07-Feb-2022  rillig branches: 1.1.4;
tests/make: demonstrate combination of .USE with transformation rule

Reported in 2003 in PR toolchain/20993. Linking a transformation rule
with .USE or .USEBEFORE node makes the transformation rule fail.
 1.1.4.1 02-Aug-2025  perseant Sync with HEAD
 1.2 09-Feb-2022  rillig make: fix mistakes, spelling and typos in comments and manual page

No binary change for -DNDEBUG.
 1.1 07-Feb-2022  rillig tests/make: demonstrate combination of .USE with transformation rule

Reported in 2003 in PR toolchain/20993. Linking a transformation rule
with .USE or .USEBEFORE node makes the transformation rule fail.
 1.4 14-Jan-2025  rillig branches: 1.4.4;
make: clarify that undefined expressions are allowed in dependencies
 1.3 14-Jan-2025  rillig make: simplify parsing of dependency lines

The evaluation modes that allow or deny undefined variables have the same
effect in this case, as Var_Subst does not return an error marker.
 1.2 12-Jan-2025  rillig tests/make: fix suffix rule test in ATF mode
 1.1 10-Jan-2025  rillig tests/make: test expressions based on undefined variables

When an undefined variable is used in a conditional, make complains about
"Malformed conditional", which is wrong since the conditional is
well-formed but errors out during evaluation.

In order to fix this wrong error message and preserve the remaining
behavior, cover the places in which an expression is evaluated with
undefined expressions being an error (VARE_EVAL_DEFINED), but with
neither producing an error message nor handling errors. This combination
results in the same behavior as evaluating the expressions in the mode
that allows undefined variables to be used in expressions.
 1.4.4.2 02-Aug-2025  perseant Sync with HEAD
 1.4.4.1 14-Jan-2025  perseant file suff.exp was added on branch perseant-exfatfs on 2025-08-02 05:58:37 +0000
 1.3 14-Jan-2025  rillig branches: 1.3.4;
make: clarify that undefined expressions are allowed in dependencies
 1.2 12-Jan-2025  rillig tests/make: fix suffix rule test in ATF mode
 1.1 10-Jan-2025  rillig tests/make: test expressions based on undefined variables

When an undefined variable is used in a conditional, make complains about
"Malformed conditional", which is wrong since the conditional is
well-formed but errors out during evaluation.

In order to fix this wrong error message and preserve the remaining
behavior, cover the places in which an expression is evaluated with
undefined expressions being an error (VARE_EVAL_DEFINED), but with
neither producing an error message nor handling errors. This combination
results in the same behavior as evaluating the expressions in the mode
that allows undefined variables to be used in expressions.
 1.3.4.2 02-Aug-2025  perseant Sync with HEAD
 1.3.4.1 14-Jan-2025  perseant file suff.mk was added on branch perseant-exfatfs on 2025-08-02 05:58:37 +0000
 1.2 20-Oct-2020  rillig make(1): split test suffixes.mk into simpler, isolated tests

The code in suff.c is already hard to understand, and so were the tests
in suffixes.mk since several independent topics were merged into a
single test.

Splitting this test into a separate test per issue allows to document
the expected and actual behavior in more detail. That's complicated
enough already.

PR bin/49086
 1.1 23-Aug-2014  christos PR/46096: Jarmo Jaakkola: fix many problems with dependencies (PR 49086)

Quite extensive rewrite of the Suff module. Some ripple effects into
Parse and Targ modules too.

Dependency searches in general were made to honor explicit rules so
implicit and explicit sources are no longer applied on targets that
do not invoke a transformation rule.

Archive member dependency search was rewritten. Explicit rules now
work properly and $(.TARGET) is set correctly. POSIX semantics for
lib(member.o) and .s1.a rules are supported.

.SUFFIXES list maintenance was rewritten so that scanning of existing
rules works when suffixes are added and that clearing the suffix list
removes single suffix rules too. Transformation rule nodes are now
mixed with regular nodes so they are available as regular targets too
if needed (especially after the known suffixes are cleared).

The .NULL target was documented in the manual page, especially to
warn against using it when a single suffix rule would work.
A deprecation warning was also added to the manual and make also
warns the user if it encounters .NULL.

Search for suffix rules no longer allows the explicit dependencies
to override the selected transformation rule. A check is made in
the search that the transformation that would be tried does not
already exist in the chain. This prevents getting stuck in an infinite
loop under specific circumstances. Local variables are now set
before node's children are expanded so dynamic sources work in
multi-stage transformations. Make_HandleUse() no longer expands
the added children for transformation nodes, preventing triple
expansion and allowing the Suff module to properly postpone their
expansion until proper values are set for the local variables.

Directory prefix is no longer removed from $(.PREFIX) if the target
is found via directory search.

The last rule defined is now used instead of the first one (POSIX
requirement) in case a rule is defined multiple times. Everything
defined in the first instance is undone, but things added "globally"
are honored. To implement this, each node tracks attribute bits
which have been set by special targets (global) instead of special
sources (local). They also track dependencies that were added by
a rule with commands (local) instead of rule with no commands (global).

New attribute, OP_FROM_SYS_MK is introduced. It is set on all targets
found in system makefiles so that they are not eligible to become
the main target. We cannot just set OP_NOTMAIN because it is one of
the attributes inherited from transformation and .USE rules and would
make any eligible target that uses a built-in inference rule ineligible.

The $(.IMPSRC) local variable now works like in gmake: it is set to
the first prerequisite for explicit rules. For implicit rules it
is still the implied source.

The manual page is improved regarding the fixed features. Test cases
for the fixed problems are added.

Other improvements in the Suff module include:
- better debug messages for transformation rule search (length of
the chain is now visualized by indentation)
- Suff structures are created, destroyed and moved around by a set
of maintenance functions so their reference counts are easier
to track (this also gets rid of a lot of code duplication)
- some unreasonably long functions were split into smaller ones
- many local variables had their names changed to describe their
purpose instead of their type
 1.4 20-Oct-2020  rillig make(1): split test suffixes.mk into simpler, isolated tests

The code in suff.c is already hard to understand, and so were the tests
in suffixes.mk since several independent topics were merged into a
single test.

Splitting this test into a separate test per issue allows to document
the expected and actual behavior in more detail. That's complicated
enough already.

PR bin/49086
 1.3 30-Aug-2014  sjg Replace use of $() with ${}
$() means something special to the shell, so ${} reduces confusion
and is used almost exclusively in the rest of the makefiles.

Discussed with: christos
 1.2 29-Aug-2014  sjg posix1.mk and suffixes.mk need to cleanup in order to achieve
repeatable results.
posix1.mk's lib.a target still looks dubious.
 1.1 23-Aug-2014  christos PR/46096: Jarmo Jaakkola: fix many problems with dependencies (PR 49086)

Quite extensive rewrite of the Suff module. Some ripple effects into
Parse and Targ modules too.

Dependency searches in general were made to honor explicit rules so
implicit and explicit sources are no longer applied on targets that
do not invoke a transformation rule.

Archive member dependency search was rewritten. Explicit rules now
work properly and $(.TARGET) is set correctly. POSIX semantics for
lib(member.o) and .s1.a rules are supported.

.SUFFIXES list maintenance was rewritten so that scanning of existing
rules works when suffixes are added and that clearing the suffix list
removes single suffix rules too. Transformation rule nodes are now
mixed with regular nodes so they are available as regular targets too
if needed (especially after the known suffixes are cleared).

The .NULL target was documented in the manual page, especially to
warn against using it when a single suffix rule would work.
A deprecation warning was also added to the manual and make also
warns the user if it encounters .NULL.

Search for suffix rules no longer allows the explicit dependencies
to override the selected transformation rule. A check is made in
the search that the transformation that would be tried does not
already exist in the chain. This prevents getting stuck in an infinite
loop under specific circumstances. Local variables are now set
before node's children are expanded so dynamic sources work in
multi-stage transformations. Make_HandleUse() no longer expands
the added children for transformation nodes, preventing triple
expansion and allowing the Suff module to properly postpone their
expansion until proper values are set for the local variables.

Directory prefix is no longer removed from $(.PREFIX) if the target
is found via directory search.

The last rule defined is now used instead of the first one (POSIX
requirement) in case a rule is defined multiple times. Everything
defined in the first instance is undone, but things added "globally"
are honored. To implement this, each node tracks attribute bits
which have been set by special targets (global) instead of special
sources (local). They also track dependencies that were added by
a rule with commands (local) instead of rule with no commands (global).

New attribute, OP_FROM_SYS_MK is introduced. It is set on all targets
found in system makefiles so that they are not eligible to become
the main target. We cannot just set OP_NOTMAIN because it is one of
the attributes inherited from transformation and .USE rules and would
make any eligible target that uses a built-in inference rule ineligible.

The $(.IMPSRC) local variable now works like in gmake: it is set to
the first prerequisite for explicit rules. For implicit rules it
is still the implied source.

The manual page is improved regarding the fixed features. Test cases
for the fixed problems are added.

Other improvements in the Suff module include:
- better debug messages for transformation rule search (length of
the chain is now visualized by indentation)
- Suff structures are created, destroyed and moved around by a set
of maintenance functions so their reference counts are easier
to track (this also gets rid of a lot of code duplication)
- some unreasonably long functions were split into smaller ones
- many local variables had their names changed to describe their
purpose instead of their type
 1.2 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.1 28-Aug-2013  sjg branches: 1.1.4; 1.1.8;
Fix parsing of SUNSHCMD style :sh = assigments.

Submitted by: Will Andrews at freebsd.org
 1.1.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.8.1 28-Aug-2013  tls file sunshcmd was added on branch tls-maxphys on 2014-08-20 00:05:00 +0000
 1.1.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.4.1 28-Aug-2013  yamt file sunshcmd was added on branch yamt-pagecache on 2014-05-22 11:42:46 +0000
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.3 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.2 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.3 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2 03-Jun-2011  sjg ApplyModifiers: if we parse a variable in the modifier list,
do not consider it a nested modifier set, unless it is followed by
endc, a ':' or end of string.
 1.1 06-Mar-2011  sjg branches: 1.1.2;
Add unit tests to check that exists(some/dir/) works

Also fix handling of sysV substitutions when lhs and variable are empty.

Also that modifiers do not cause errors during conditional tests
when undefined variables should otherwise be ok.
Ie. .if defined(nosuch) && ${nosuch:Mx} != ""
 1.1.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.11 31-Oct-2020  rillig make(1): merge the SysV modifier tests into varmod-sysv
 1.10 23-Aug-2020  rillig make(1): move some of the SysV modifier tests into another file
 1.9 26-Jul-2020  rillig make(1): add test for prefix mismatch in SysV substitution
 1.8 20-Jul-2020  rillig make(1): fix obscure edge case for ${VAR:e$=x}

The characters "$=" do not occur in either src or pkgsrc, therefore this
case is unlikely to occur in practice.
 1.7 20-Jul-2020  rillig make(1): demonstrate obscure edge case in SysV modifier
 1.6 19-Jul-2020  rillig make(1): make ampersand in ${VAR:from=to&} an ordinary character

In SysV substitutions, wildcards are expressed with % instead of &. The
& is not mentioned in the manual page, and having another wildcard for
the whole word would be such an obscure feature that not even pkgsrc uses
it. The easiest way to discover this feature had been to read the source
code of make(1) or to use a fuzzer and accidentally stumble upon this
edge case.
 1.5 19-Jul-2020  rillig make(1): add test for ampersand in SysV substitution modifier
 1.4 03-Jul-2020  rillig make(1): add another test for the SysV :%=% modifier
 1.3 06-May-2020  christos Behave like gmake: empty string does not match % pattern
 1.2 25-Apr-2020  christos - Percent on the rhs is special only if the lhs has one too.
- If the rhs does not have percent, but the lhs has, the result is the rhs
This behavior matches gmake
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.16 31-Oct-2020  rillig make(1): merge the SysV modifier tests into varmod-sysv
 1.15 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.14 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.13 23-Aug-2020  rillig make(1): move some of the SysV modifier tests into another file
 1.12 01-Aug-2020  rillig make(1): reduce the number of string comparisons in ${VAR:%.c=%.o}

There is only a single position in the word where the tail ".c" can
match, since it is implicitly anchored at the end. Therefore there's no
need to do several string comparisons.
 1.11 01-Aug-2020  rillig make(1): fix typo in newly added SysV modifier test case

I should have been more suspicious when all my test cases succeeded at
the first try.
 1.10 01-Aug-2020  rillig make(1): add more tests for the SysV modifier
 1.9 26-Jul-2020  rillig make(1): add test for prefix mismatch in SysV substitution
 1.8 20-Jul-2020  rillig make(1): demonstrate obscure edge case in SysV modifier
 1.7 19-Jul-2020  rillig make(1): make ampersand in ${VAR:from=to&} an ordinary character

In SysV substitutions, wildcards are expressed with % instead of &. The
& is not mentioned in the manual page, and having another wildcard for
the whole word would be such an obscure feature that not even pkgsrc uses
it. The easiest way to discover this feature had been to read the source
code of make(1) or to use a fuzzer and accidentally stumble upon this
edge case.
 1.6 19-Jul-2020  rillig make(1): add test for ampersand in SysV substitution modifier
 1.5 03-Jul-2020  rillig make(1): add another test for the SysV :%=% modifier
 1.4 06-May-2020  christos Behave like gmake: empty string does not match % pattern
 1.3 25-Apr-2020  christos - Percent on the rhs is special only if the lhs has one too.
- If the rhs does not have percent, but the lhs has, the result is the rhs
This behavior matches gmake
 1.2 30-Aug-2014  sjg Replace use of $() with ${}
$() means something special to the shell, so ${} reduces confusion
and is used almost exclusively in the rest of the makefiles.

Discussed with: christos
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.3 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2 20-Feb-2004  sjg Fix :M so that modifiers in nested variables don't terminate parsing
early. Add a unit-test to verify it works and keeps working.
Re-jig the unit-tests so that all are sub makefiles.
 1.1 09-Jan-2004  sjg Add unit test for ternary modifier
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.2 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.45 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.44 20-Aug-2014  apb Add tests for VAR != command.
 1.43 28-Aug-2013  sjg Fix parsing of SUNSHCMD style :sh = assigments.

Submitted by: Will Andrews at freebsd.org
 1.42 22-Mar-2013  sjg Add unit-test for export-env and gmake export
 1.41 09-Nov-2012  sjg Add a unit-test for .ORDER
 1.40 19-Jun-2012  sjg branches: 1.40.2;
Add unit-tests for .for
 1.39 29-Sep-2011  sjg branches: 1.39.2;
Make sure .PHONY targets get .TARGET set.
This wasn't happening when a dependency of .END.
Set .PREFIX too and add a unit-test.

PR: 43534
 1.38 03-Jun-2011  sjg ApplyModifiers: if we parse a variable in the modifier list,
do not consider it a nested modifier set, unless it is followed by
endc, a ':' or end of string.
 1.37 11-Apr-2011  sjg branches: 1.37.2;
Add a test case for sysV modifier subst
 1.36 07-Apr-2011  joerg Add the :hash modifier to compute a 32bit hash of an variable.
This uses MurmurHash3 to get a reasonable collission-free hash with
small code. The result is endian neutral.
 1.35 06-Mar-2011  sjg Add unit tests to check that exists(some/dir/) works

Also fix handling of sysV substitutions when lhs and variable are empty.

Also that modifiers do not cause errors during conditional tests
when undefined variables should otherwise be ok.
Ie. .if defined(nosuch) && ${nosuch:Mx} != ""
 1.34 23-Apr-2010  sjg PR: 42850
Reviewed by:

Reduced the "expected to exist" dirs in path to just
/ /bin and /tmp
and change the "not expected to exist" dir to something
even less likely.
Add a comment to suggest why.
 1.33 22-Apr-2010  sjg PR: 42850
Reviewed by:

modmisc: since we apply an exists() test to $paths, be conservative
in what we expect.

Run the unit tests with -r -m / so that we do not fail if there
is no sys.mk present.
 1.32 21-Apr-2010  sjg If we do .export (all) and have any variables that involve :sh
we will hit an error (var is recursive) while trying to evaluate that.
Fix, and add a unit test for this.
 1.31 08-Apr-2010  sjg Process .ERROR the same as .BEGIN, .END etc
so that it cannot be the default target.
Add unit-tests for .info - .error, and .ERROR.
 1.30 19-Nov-2009  sjg PR: make.unexport
Reviewed by:
 1.29 07-Oct-2009  sjg The parser used to break dependency lines at ';' without regard
for substitution patterns. This (perhaps coupled with the
new handling of .for variables in ${:U<value>...) caused interesting
results for lines like:

.for file in ${LIST}
for-subst: ${file:S;^;${here}/;g}

add a unit-test to keep an eye on this.
 1.28 07-Sep-2009  sjg PR: 41998

:Ufu\:goo

should expand to fu:goo even when it appears in :M${:Ufu\:goo}
When scanning for :M do not compress \: if we know we have
to call Var_Subst.
 1.27 03-Feb-2009  sjg Update expected results to match recent changes!
 1.26 29-Oct-2008  sjg If Parse_Error is called after curFile is invalid, set it to a dummy
to avoid seg-fault. Also the NULL filename will cause ParseVErrorInternal
to skip trying to report file and line number info.

If CondToken is called outside the context of a .if etc, variables in
the expression being parsed will already be expanded, so allow for
an unqouted number to jump us back into the compare logic.
This allows ${${SomeNumber:U42} > 0:?True:False} to work anywhere.

Job_Finish should process postCommands if it has commands or children.
 1.25 15-May-2008  sjg VAR_CMD context is used by conditionals and other purposes, so
actually set VAR_FROM_CMD when appropriate and only skip setting in
VAR_GLOBAL when that flag is set.
 1.24 15-May-2008  sjg Disable this for now, VAR_CMD is abused for other purposes...
 1.23 14-May-2008  sjg Do not set vars in VAR_GLOBAL context, if they have been set on the
command line.
Add a suitable unit-test.
 1.22 31-Mar-2008  sjg branches: 1.22.2; 1.22.4;
If the name passed to Var_Exists contains '$' run it through Var_Subst.
 1.21 09-Oct-2007  sjg Fix an off-by-one error in handing mal-formed modifiers.
The issue seems to have been present for some time, only showed up
when running unit-tests on SunOS.
Make sure we get an error message, but otherwise behave as before.
 1.20 05-Oct-2007  sjg Add the ability to .export variables to the environment.
 1.19 11-May-2006  sjg branches: 1.19.12;
Remove the modterm case from moderrs, the syntax errors
generated by /bin/sh on other systems are not consistent.
 1.18 11-May-2006  sjg Extract the variable modifier logic to a separate function.
This cuts Var_Parse in half! and allows the modifier logic to
be used recursively - when getting modifiers via variables.

Add new unit-test, to check that certain error cases are handled
correctly.
 1.17 26-Feb-2006  apb Make ".WAIT" apply recursively to all children of nodes on the right
hand side of the .WAIT, except when the recursive interpretation would
cause a cycle in the dependency graph.

Discussed in tech-toolchain. Reviewed by christos, sjg.
 1.16 26-Feb-2006  sjg Using ./bin in the test case, causes problems when 'make test' is
run from 'unit-tests' rather than the parent dir.
 1.15 26-Feb-2006  sjg Update man page and add test case for specifying modifiers via variable.
Also allow said variable to appear anywhere in the modifier list.
 1.14 11-Jul-2005  sjg Expected results were not updated for comment testing.
 1.13 01-Jun-2005  sjg Add :Ox for random ordering, based on patch from
Mike M. Volokhov <mishka@apk.od.ua>
 1.12 07-May-2004  sjg branches: 1.12.2;
Remove use of sh -e when running in compat mode.
Its not posix compliant and serves very little purpose.
With this change compat and jobs modes are consistent wrt how
they treat each line of a script.

Add support for the '+' command line prefix as required by posix.
Lines prefixed with '+' are executed even when -n is given.
[Actually posix says they should also be done for -q and -t]

PR:
Reviewed by: jmc
 1.11 13-Apr-2004  sjg Allow "string" and "${varspec}" on lhs of conditionals.
This makes it possible to use expressions like
${("${LIST:Msomething"}):?present:absent}
it also makes treatment of lhs and rhs more consistent, and
makes CondToken easier to read.

Update unit-test/cond1 to test new features.
 1.10 08-Apr-2004  sjg Revised patch for catching extraneous .else's
We actually need to tack condTop and skipIfLevel.
Bump MAXIF while here.
Enhance the unit-test for conditionals to exercise more code.

PR: 24420
 1.9 08-Apr-2004  sjg Add check for extraneous .else's - based on patch from Arne H. Juul
in PR/24420.
Add a unit-test for conditionals.
Also in the unit-test makefile strip any .CURDIR in output.

PR: 24420
 1.8 20-Feb-2004  sjg branches: 1.8.2;
Fix :M so that modifiers in nested variables don't terminate parsing
early. Add a unit-test to verify it works and keeps working.
Re-jig the unit-tests so that all are sub makefiles.
 1.7 09-Jan-2004  sjg Add unit test for ternary modifier
 1.6 27-Sep-2003  sjg Implement :[] modifier to allow picking a range of words out of a variable.
Also :tW and a W flag to :C and :S to allow treating value as a single word.
Add unit tests for the above, and fix some corner cases.
Based on patches supplied by Alan Barrett <apb@cequrux.com>
 1.5 01-Aug-2003  sjg Avoid \a as a test of invalid separator, since if we make ksh the default
shell, we get different results. \x seems safe.
 1.4 31-Jul-2003  sjg Test behavior of commandline variable assignments.
 1.3 29-Jul-2003  sjg First bug picked up by the unit tests - delim wasn't always initialized.
Avoid putting '\' in test case script lines since shell's like that on
SunOS insist on interpreting them.
 1.2 29-Jul-2003  sjg Use single quotes to protect everything from shell's that might
alter the results.
 1.1 28-Jul-2003  sjg Fix parsing bug for :ts - patch from Alan Barrett <apb@cequrux.com>
Also add simple unit-test jig (regress/usr.bin/make will use it too)
but having it local here makes inclusion in bmake simpler.
 1.8.2.4 10-May-2004  tron Pull up revision 1.12 (requested by sjg in ticket #282):
Remove use of sh -e when running in compat mode.
Its not posix compliant and serves very little purpose.
With this change compat and jobs modes are consistent wrt how
they treat each line of a script.
Add support for the '+' command line prefix as required by posix.
Lines prefixed with '+' are executed even when -n is given.
[Actually posix says they should also be done for -q and -t]
PR:
Reviewed by: jmc
 1.8.2.3 10-May-2004  tron Pull up revision 1.11 (requested by sjg in ticket #282):
Allow "string" and "${varspec}" on lhs of conditionals.
This makes it possible to use expressions like
${("${LIST:Msomething"}):?present:absent}
it also makes treatment of lhs and rhs more consistent, and
makes CondToken easier to read.
Update unit-test/cond1 to test new features.
 1.8.2.2 10-May-2004  tron Pull up revision 1.10 (requested by sjg in ticket #282):
Revised patch for catching extraneous .else's
We actually need to tack condTop and skipIfLevel.
Bump MAXIF while here.
Enhance the unit-test for conditionals to exercise more code.
PR: 24420
 1.8.2.1 10-May-2004  tron Pull up revision 1.9 (requested by sjg in ticket #282):
Add check for extraneous .else's - based on patch from Arne H. Juul
in PR/24420.
Add a unit-test for conditionals.
Also in the unit-test makefile strip any .CURDIR in output.
PR: 24420
 1.12.2.1 24-Jul-2005  tron Pull up revision 1.14 (requested by rpaulo in ticket #608):
Expected results were not updated for comment testing.
 1.19.12.1 06-Nov-2007  matt sync with HEAD
 1.22.4.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.22.2.1 18-May-2008  yamt sync with head.
 1.37.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.39.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.39.2.2 16-Jan-2013  yamt sync with (a bit old) head
 1.39.2.1 30-Oct-2012  yamt sync with head
 1.40.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.40.2.2 23-Jun-2013  tls resync from head
 1.40.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.2 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.1 19-Nov-2009  sjg Add .unexport - the exact opposite of .export
and .unexport-env which unexport's all previously .export'd globals
as well as clearing environ[].
Allow's sys.mk near total controll.

Reviewed by: apb
 1.2 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.1 19-Nov-2009  sjg Add .unexport - the exact opposite of .export
and .unexport-env which unexport's all previously .export'd globals
as well as clearing environ[].
Allow's sys.mk near total controll.

Reviewed by: apb
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.4 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.3 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.2 27-Jul-2020  rillig make(1): prepare test for .export to show all exported variables

Currently the unit tests don't cover exporting of local variables like
.TARGET or @. To see the effects, all exported variables must be listed
by the tests.
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.6 19-Oct-2023  rillig tests/make: clean up, explain and reorganize several tests
 1.5 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.4 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.3 08-Aug-2020  rillig make(1): clean up Var_UnExport

Mark the parameter as constant since it is not modified.

Remove tests for '\n' since these can never succeed.

newenv can never be NULL since neither of bmake_malloc or bmake_realloc
returns NULL.

Improve variable names: vlist was too unexpressive.

Add debug logging since unexporting variables is an uncommon operation
that directly affects the observable environment of the child processes.

Fix CRLF line endings in a few unit tests.
 1.2 27-Jul-2020  rillig make(1): prepare test for .export to show all exported variables

Currently the unit tests don't cover exporting of local variables like
.TARGET or @. To see the effects, all exported variables must be listed
by the tests.
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.3 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.2 07-Dec-2020  rillig branches: 1.2.8;
make(1): fix exit status in -k mode if a dependency fails

Whether in -k mode or not, the exit status tells whether all requested
targets were made or not. If a dependency could not be made, the main
target was not made as well, therefore the exit status must be nonzero
in such a case.

This part of the code lacked proper unit tests until today. The unit
test deptgt-end-fail.mk is compatible with make>=2003 at least, allowing
to compare the output over time.

In 2003, in the ok-ok-ok-ok case, "Making all from all-dep." was printed
twice in a row, for whatever reason ... (40 minutes later) ... If I had
just made the two commands for 'all' and '.END' more distinguishable.
Back in 2003, the local variables for .END had not been initialized,
instead the .END node was run with the local variables of the last
preceding node. In this case, that node was 'all', therefore ${.TARGET}
had obviously expanded to 'all'.

Somewhere in 2004, the shell commands were no longer run with the -e
flag, which resulted in the "exit status $?" line to be printed in cases
that had stopped early before.

Somewhere in 2005, the local variables for the .END node had been fixed.
The variable ${.TARGET} now had the value '.END', just as expected. In
addition, the dependencies for the .END node were made, although without
getting their proper local variables. This resulted in the output
"Making out of nothing" instead of the expected "Making end-dep out of
nothing".

Still in 2005, in the test case "all=ok all-dep=ok end=ok end-dep=ERR",
the error code of the failed 'end-dep' was first reported as "*** Error
code 1 (continuing)". To compensate for this improvement, a new bug had
been introduced. The test case "all=ok all-dep=ok end=ERR end-dep=ERR"
had properly exited with status 1 on 2005-01-01, but on 2006-01-01 it
exited with status 0, thereby ignoring errors in the .END node.

Somewhere in 2008, some of the error messages (but not all) were
directed to stderr instead of stdout. The actual output stayed the same
though.

Somewhere in 2011, the dependency of the .END node got its own local
variables, and ${.TARGET} now expanded to 'end-dep', as expected.

Somewhere in 2016, the two empty lines between the "*** Error code 1
(continuing)" and the "Stop." got compressed into a single empty line.

On 2020-12-07 (that is, today), the exit status 1 has been restored in
the error cases, after it had been wrong for at least 14 years.
 1.1 09-Aug-2020  rillig make(1): add test for .USE combined with inference rule without commands

Discovered by christos.
 1.2.8.1 02-Aug-2025  perseant Sync with HEAD
 1.3 07-Dec-2020  rillig make(1): fix exit status in -k mode if a dependency fails

Whether in -k mode or not, the exit status tells whether all requested
targets were made or not. If a dependency could not be made, the main
target was not made as well, therefore the exit status must be nonzero
in such a case.

This part of the code lacked proper unit tests until today. The unit
test deptgt-end-fail.mk is compatible with make>=2003 at least, allowing
to compare the output over time.

In 2003, in the ok-ok-ok-ok case, "Making all from all-dep." was printed
twice in a row, for whatever reason ... (40 minutes later) ... If I had
just made the two commands for 'all' and '.END' more distinguishable.
Back in 2003, the local variables for .END had not been initialized,
instead the .END node was run with the local variables of the last
preceding node. In this case, that node was 'all', therefore ${.TARGET}
had obviously expanded to 'all'.

Somewhere in 2004, the shell commands were no longer run with the -e
flag, which resulted in the "exit status $?" line to be printed in cases
that had stopped early before.

Somewhere in 2005, the local variables for the .END node had been fixed.
The variable ${.TARGET} now had the value '.END', just as expected. In
addition, the dependencies for the .END node were made, although without
getting their proper local variables. This resulted in the output
"Making out of nothing" instead of the expected "Making end-dep out of
nothing".

Still in 2005, in the test case "all=ok all-dep=ok end=ok end-dep=ERR",
the error code of the failed 'end-dep' was first reported as "*** Error
code 1 (continuing)". To compensate for this improvement, a new bug had
been introduced. The test case "all=ok all-dep=ok end=ERR end-dep=ERR"
had properly exited with status 1 on 2005-01-01, but on 2006-01-01 it
exited with status 0, thereby ignoring errors in the .END node.

Somewhere in 2008, some of the error messages (but not all) were
directed to stderr instead of stdout. The actual output stayed the same
though.

Somewhere in 2011, the dependency of the .END node got its own local
variables, and ${.TARGET} now expanded to 'end-dep', as expected.

Somewhere in 2016, the two empty lines between the "*** Error code 1
(continuing)" and the "Stop." got compressed into a single empty line.

On 2020-12-07 (that is, today), the exit status 1 has been restored in
the error cases, after it had been wrong for at least 14 years.
 1.2 05-Nov-2020  rillig make(1): add remark for exit status 0 despite error
 1.1 09-Aug-2020  rillig make(1): add test for .USE combined with inference rule without commands

Discovered by christos.
 1.5 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.4 23-Feb-2021  rillig make: document the history of bugs in "cmdline overrides global"

For performance reasons, the implementation of the simple rule "cmdline
overrides global" grew into code that is much more complicated than a
straight-forward implementation. This added complexity made it easy for
bugs to sneak in.
 1.3 23-Feb-2021  rillig make: demonstrate how to undefine variables during evaluation

For a very long time now, I had thought that it would be impossible to
undefine global variables during the evaluation of variable expressions.
This is something that the memory management in Var_Parse relies upon,
see the comment 'the value of the variable must not change'.

After several unsuccessful attempts at referring to an already freed
previous value of a variable, today I discovered how to unset a global
variable while evaluating an expression, which has the same effect. To
demonstrate that this use-after-free can reliably crash make, it would
need a memory allocator with a debug mode that never re-allocates the
same memory block after it has been used once. This is something that
jemalloc cannot do at the moment. Valgrind would be another idea, but
that has not been ported to NetBSD.

Undefining a global variable while evaluating an expression is made
possible by an implementation detail of the modifier ':@'. That
modifier undefines the loop variable, without restoring its previous
value, see ApplyModifier_Loop.

By the very old conventions of ODE Make, these loop variables are named
'.V.' and thus do not conflict with variables from other naming
conventions. In NetBSD and pkgsrc, these loop variables are typically
called 'var', sometimes '_var' with a leading underscore, which also
doesn't conflict with the typical form 'VAR' of variables in the global
namespace. Therefore, in practice these loop variables don't interfere
with other variables.

One case that can practically arise is when an outer variable has a
modifier ':@word@${VAR.${word}}@' and one of the referenced variables
uses the same variable name in the modifier, see varmod-loop.mk 1.10
line 91 for a detailed explanation.

By using the ${:@VAR@@} modifier in a place that is evaluated with
cmdline scope, it is not only possible to undefine global variables, it
is possible to undefine cmdline variables as well. When evaluated in a
specific make target, the expression ${:@\@@@} can even be used to
undefine the variable '.TARGET', which will probably crash make with an
assertion failure.
 1.2 22-Feb-2021  rillig make: add test for cmdline variables overriding global variables
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.6 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.5 23-Feb-2021  rillig make: document the history of bugs in "cmdline overrides global"

For performance reasons, the implementation of the simple rule "cmdline
overrides global" grew into code that is much more complicated than a
straight-forward implementation. This added complexity made it easy for
bugs to sneak in.
 1.4 23-Feb-2021  rillig make: demonstrate how to undefine variables during evaluation

For a very long time now, I had thought that it would be impossible to
undefine global variables during the evaluation of variable expressions.
This is something that the memory management in Var_Parse relies upon,
see the comment 'the value of the variable must not change'.

After several unsuccessful attempts at referring to an already freed
previous value of a variable, today I discovered how to unset a global
variable while evaluating an expression, which has the same effect. To
demonstrate that this use-after-free can reliably crash make, it would
need a memory allocator with a debug mode that never re-allocates the
same memory block after it has been used once. This is something that
jemalloc cannot do at the moment. Valgrind would be another idea, but
that has not been ported to NetBSD.

Undefining a global variable while evaluating an expression is made
possible by an implementation detail of the modifier ':@'. That
modifier undefines the loop variable, without restoring its previous
value, see ApplyModifier_Loop.

By the very old conventions of ODE Make, these loop variables are named
'.V.' and thus do not conflict with variables from other naming
conventions. In NetBSD and pkgsrc, these loop variables are typically
called 'var', sometimes '_var' with a leading underscore, which also
doesn't conflict with the typical form 'VAR' of variables in the global
namespace. Therefore, in practice these loop variables don't interfere
with other variables.

One case that can practically arise is when an outer variable has a
modifier ':@word@${VAR.${word}}@' and one of the referenced variables
uses the same variable name in the modifier, see varmod-loop.mk 1.10
line 91 for a detailed explanation.

By using the ${:@VAR@@} modifier in a place that is evaluated with
cmdline scope, it is not only possible to undefine global variables, it
is possible to undefine cmdline variables as well. When evaluated in a
specific make target, the expression ${:@\@@@} can even be used to
undefine the variable '.TARGET', which will probably crash make with an
assertion failure.
 1.3 22-Feb-2021  rillig make: add test for cmdline variables overriding global variables
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.3 23-Jan-2022  rillig tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.3 05-Nov-2020  rillig make(1): add test for legacy local variables @F, @D
 1.2 25-Oct-2020  rillig make(1): add test for setting a variable in a GNode context

This edge case is probably not used widely. The local variables of a
GNode should only ever be the predefined variables.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.6 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.5 05-Nov-2020  rillig make(1): add test for legacy local variables @F, @D
 1.4 25-Oct-2020  rillig make(1): add test for setting a variable in a GNode context

This edge case is probably not used widely. The local variables of a
GNode should only ever be the predefined variables.
 1.3 23-Oct-2020  rillig make(1): add test for variable name aliasing
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.34 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.33 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.32 31-Oct-2024  rillig make: in the debug log, always qualify line number with filename

Previously, to find out the filename corresponding to a line number from
a 'Parsing' line, it was necessary to find the preceding
'SetFilenameVars' line, which was unnecessarily time-consuming and
distracting.

The 'filename:line' format matches the one used in PrintStackTrace, and
it differs from the one used in PrintLocation, as the former format is
more common in other tools.

Most of the affected unit tests only use the 'Parsing' lines to give
additional context to their debug log, so no structural changes there.
 1.31 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.30 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.29 05-Jul-2024  rillig make: in error messages, distinguish parsing from evaluating
 1.28 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.27 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.26 02-Jun-2024  rillig branches: 1.26.2;
make: sync VarEvalMode constant names with their debug log names
 1.25 20-Apr-2024  rillig make: provide more context information for parse/evaluate errors
 1.24 14-Apr-2024  rillig make: add debug logging for .if and .for lines in -dp mode

This helps track down in which line a condition is evaluated.
 1.23 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.22 09-May-2023  rillig make: allow ':gmtime' and ':localtime' with dynamic argument

This allows ${%Y:L:gmtime=${mtime}} instead of the indirect
${%Y:L:${:Ugmtime=${mtime}}}.

The direct form also prevents any ':' from the nested expression to be
interpreted as a separator, which doesn't matter for the ':gmtime' and
':localtime' modifiers but will prove useful for other modifiers that
follow the same pattern.
 1.21 18-Feb-2023  rillig make: fix parsing of unevaluated subexpressions with unbalanced '{}'

Since var.c 1.323 from 2020-07-26, modifiers containing unbalanced
braces or parentheses were parsed differently, depending on whether they
were relevant or not.

For example, the expression '${VAR:...}' is enclosed with braces. When
this expression has a modifier ':S,},}},g' that would double each '}' in
that expression, the parser got confused:

If the expression was relevant, the modifier was parsed as usual, taking
into account that the 3 '}' in the modifier are ordinary characters.

If the expression was irrelevant, the parser only counted the '{' and
the '}', without taking into account that a '}' might be escaped by a
'\' or be an ordinary character. Parsing therefore stopped at the first
'}', assuming it would finish the expression '${VAR:S,}'.

This parsing mode of only counting balanced '{' and '}' makes sense for
the modifier ':@var@...@', which expands each word of the expression
using the template from the '...'. These templates tend to be simple
enough that counting the '{' and '}' suffices.
 1.20 23-Aug-2022  rillig make: revert parsing of modifier parts (since 2022-08-08)

The modifier ':@var@body@' parses the body in parse-only mode and later
uses Var_Subst on it, in which each literal '$' must be written as '$$'.

Trying to parse the loop body using Var_Parse treated the text
'$${var:-0}' as a single '$' followed by the expression '${var:-0}',
wrongly complaining about the 'Unknown modifier "-0"'.

Found by sjg.
 1.19 08-Aug-2022  rillig make: fix parsing of modifiers containing unbalanced subexpressions
 1.18 28-Dec-2021  rillig make: make debug logging a bit more human-friendly

The previous log format "ParseReadLine (%d): '%s'" focused on the
implementation, it was not immediately obvious to a casual reader that
the number in parentheses was the line number. Additionally, having
both a colon and quotes in a log message is uncommon. The quotes have
been added in parse.c 1.127 from 2007-01-01.

The new log format "Parsing line %d: %s" is meant to be easier readable
by humans. The quotes are not needed since ParseReadLine always strips
trailing whitespace, leaving no room for ambiguities. The other log
messages follow common punctuation rules, which makes the beginning of
the line equally unambiguous. Before var.c 1.911 from 2021-04-05,
variable assignments were logged with the format "%s:%s = %s", without a
space after the colon.
 1.17 27-Dec-2021  rillig make: clean up comments
 1.16 09-Dec-2021  rillig make: in parse errors, mark whitespace more clearly

This prevents any trailing whitespace from going unnoticed. It also
marks leading whitespace more clearly, as in the examples with the time
value " 1".
 1.15 09-Dec-2021  rillig make: remove period from end of error messages and warnings

The majority of the existing error messages and warnings does not
include a period at the end. Follow this style consistently.
 1.14 07-Sep-2021  rillig tests/make: expand on the history of unnecessary evaluation
 1.13 05-Apr-2021  rillig make: in debug log, add space between scope and variable name

Without this space, the debug log looked more like line noise, even
though the only punctuation was a single innocent ':'. From a make
user's perspective, the variable name is a word of its own and should
not be visually glued to its namespace.
 1.12 05-Apr-2021  rillig make: be more verbose in -dv debug logging

The previous log output was too brief to be understandable. Give more
hints by describing each part of the expression when evaluating a
modifier. Distinguish between parse-only mode and eval mode since in
parse-only mode most of the details are irrelevant.
 1.11 04-Apr-2021  rillig make: disallow '$' in the variable name of the modifier ':@'

If this restriction should break any existing makefile, the author of
that makefile was probably heading for the IOMCC.
 1.10 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.9 03-Apr-2021  rillig make: remove VarFlags from debug logging

Before the introduction of ExprDefined, VarFlags contained whether the
expression was defined or not, which was useful to know since the final
value of the expression depends on this information. The other VarFlags
do not influence the evaluation, so there is no point logging them.
 1.8 15-Mar-2021  rillig make: change debug log for variable evaluation flags to lowercase

This makes them easier distinguishable from variable names since the
latter are usually uppercase.

No functional change outside debug mode.
 1.7 14-Mar-2021  rillig tests/make: document today's bug fixes in the test
 1.6 14-Mar-2021  rillig make: do not evaluate modifier ':[...]' in parse-only mode

In parse-only mode, variable expressions in the argument to that
modifier are not resolved. This led to the error message about the 'Bad
modifier' in var-eval-short.mk.
 1.5 14-Mar-2021  rillig make: do not return unevaluated 'else' part from the ':?' modifier

No functional change outside debug mode.
 1.4 14-Mar-2021  rillig tests/make: add test for the ':?' modifier in parse-only mode

The debug output for this scenario will change a bit in an upcoming
commit, but that will not affect anything outside the debug log.
 1.3 14-Mar-2021  rillig make: only evaluate the ':@' modifier if the result is actually used

The test 'var-eval-short' had produced the output 'unexpected' before,
on stderr. It had been generated by '${:Uword:@${FAIL}@expr@}' by
combining the following obscure "features" of make:

1. the ':@' modifier loops over the words of the variable. This
modifier is not really obscure, it still takes some time to get used
to it.

2. the ':@' modifier allows a '$' sign in the variable name, which is
useless in practice.

3. the ':@' modifier creates a temporary loop variable in the global
namespace. Luckily there are only few collisions with other
variable names since their naming conventions differ.

4. after looping over the words of the expression, the temporary global
loop variable is deleted, and at that point the '$' is expanded,
being interpreted as the start of a variable expression.

5. The ':@' modifier deleted the global variable even when it was
called in parse-only mode (without VARE_WANTRES).

When the modifier ':@' was initially added to make in var.c 1.40 from
2000-04-29, Var_Delete didn't expand the variable name. That feature
was added in var.c 1.174 from 2013-05-18, probably without thinking of
this very edge-casey combination of features.

This commit fixes item 5 from the above list. The other obscurities
remain for now.
 1.2 14-Mar-2021  rillig make: only evaluate the ':_' modifier if the expression is needed

See var-eval-short.mk:46 for the test demonstrating this change.
Previously, the expression ${:Uword:_=VAR} was evaluated including all
its side effects even though it was in an irrelevant branch of the
condition.
 1.1 14-Mar-2021  rillig tests/make: add test for short-circuit evaluation of modifiers
 1.26.2.1 02-Aug-2025  perseant Sync with HEAD
 1.17 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.16 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.15 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.14 05-Jul-2024  rillig make: in error messages, distinguish parsing from evaluating
 1.13 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.12 20-Apr-2024  rillig branches: 1.12.2;
make: provide more context information for parse/evaluate errors
 1.11 19-Oct-2023  rillig tests/make: clean up, explain and reorganize several tests
 1.10 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.9 09-May-2023  rillig make: allow ':gmtime' and ':localtime' with dynamic argument

This allows ${%Y:L:gmtime=${mtime}} instead of the indirect
${%Y:L:${:Ugmtime=${mtime}}}.

The direct form also prevents any ':' from the nested expression to be
interpreted as a separator, which doesn't matter for the ':gmtime' and
':localtime' modifiers but will prove useful for other modifiers that
follow the same pattern.
 1.8 27-Dec-2021  rillig make: clean up comments
 1.7 07-Sep-2021  rillig tests/make: expand on the history of unnecessary evaluation
 1.6 06-Sep-2021  rillig make: fix typos in comments
 1.5 04-Apr-2021  rillig make: disallow '$' in the variable name of the modifier ':@'

If this restriction should break any existing makefile, the author of
that makefile was probably heading for the IOMCC.
 1.4 14-Mar-2021  rillig tests/make: document today's bug fixes in the test
 1.3 14-Mar-2021  rillig make: do not return unevaluated 'else' part from the ':?' modifier

No functional change outside debug mode.
 1.2 14-Mar-2021  rillig tests/make: add test for the ':?' modifier in parse-only mode

The debug output for this scenario will change a bit in an upcoming
commit, but that will not affect anything outside the debug log.
 1.1 14-Mar-2021  rillig tests/make: add test for short-circuit evaluation of modifiers
 1.12.2.1 02-Aug-2025  perseant Sync with HEAD
 1.9 05-Apr-2021  rillig make: in debug log, add space between scope and variable name

Without this space, the debug log looked more like line noise, even
though the only punctuation was a single innocent ':'. From a make
user's perspective, the variable name is a word of its own and should
not be visually glued to its namespace.
 1.8 05-Apr-2021  rillig make: be more verbose in -dv debug logging

The previous log output was too brief to be understandable. Give more
hints by describing each part of the expression when evaluating a
modifier. Distinguish between parse-only mode and eval mode since in
parse-only mode most of the details are irrelevant.
 1.7 03-Apr-2021  rillig make: remove VarFlags from debug logging

Before the introduction of ExprDefined, VarFlags contained whether the
expression was defined or not, which was useful to know since the final
value of the expression depends on this information. The other VarFlags
do not influence the evaluation, so there is no point logging them.
 1.6 15-Mar-2021  rillig make: change debug log for variable evaluation flags to lowercase

This makes them easier distinguishable from variable names since the
latter are usually uppercase.

No functional change outside debug mode.
 1.5 15-Feb-2021  rillig make: rename ExprDefined constants for debug logging
 1.4 03-Feb-2021  rillig make: fix double expansion when appending to a new variable
 1.3 02-Feb-2021  rillig make: replace VarExprFlags with VarExprStatus

The combination of !VEF_UNDEF && VEF_DEF was not possible, which made it
rather strange to model this state as a bit set.

The only functional change is the renamed constants in the debug output.

Using ENUM_VALUE_RTTI_2 felt like overengineering since it's harder to
understand than a simple array of names.
 1.2 30-Oct-2020  rillig make(1): demonstrate double expansion when appending to a variable
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.12 02-Nov-2023  rillig tests/make: test appending to an environment variable
 1.11 02-Nov-2023  rillig make: sync comments with the extracted ParseModifier_Match

No functional change.
 1.10 21-Jun-2023  rillig tests/make: document a few tests
 1.9 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.8 03-Feb-2021  rillig make: fix double expansion when appending to a new variable
 1.7 30-Oct-2020  rillig make(1): demonstrate double expansion when appending to a variable
 1.6 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.5 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.4 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.3 04-Oct-2020  rillig make(1): add basic tests for the += assignment operator
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.10 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.9 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.8 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.7 19-Aug-2023  rillig branches: 1.7.2;
make: add more details to error message about invalid lines
 1.6 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.5 01-Feb-2021  rillig make: replace parse error "Need an operator" with better message

The previous error message is not easily understandable since it is
missing a crucial detail, the column where the operator is needed.
Without this information, the author of the makefile gets no useful
hint. Furthermore, there are several types of operators in makefiles:

the dependency operators ':', '!', '::',
the variable assignment operators '=', '!=', '+=', '?=', ':=',
the conditional operators '&&', '||', '!',
the comparison operators '==', '!=', '>', '>=', '<', '<='.

This leaves too much ambiguity.

Replace this error message with "Invalid line type", which is more
generic, more accurate and thus less misleading.
 1.4 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.3 25-Aug-2020  rillig make(1): demonstrate how the parser handles spaces in variable names

Not that anyone would need this feature, or that it was ever intended to
be used at all. But it is there, and if someone ever wants to fix this
part of the parser, they should at least know about this behavior.
 1.2 25-Aug-2020  rillig make(1): add test for variable assignment using the '=' operator
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7.2.1 02-Aug-2025  perseant Sync with HEAD
 1.12 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.11 19-Nov-2023  rillig branches: 1.11.2;
tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.10 19-Aug-2023  rillig make: add more details to error message about invalid lines
 1.9 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.8 15-Mar-2021  rillig make: improve documentation of ApplyModifiersState

No functional change.
 1.7 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.6 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.5 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.4 25-Aug-2020  rillig make(1): demonstrate how the parser handles spaces in variable names

Not that anyone would need this feature, or that it was ever intended to
be used at all. But it is there, and if someone ever wants to fix this
part of the parser, they should at least know about this behavior.
 1.3 25-Aug-2020  rillig make(1): add test for variable assignment using the '=' operator
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.11.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 19-Nov-2023  rillig tests/make: replace 'variable expressions' with 'expressions'
 1.4 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.3 07-Dec-2020  rillig make(1): add tests and tutorial for the ?= assignment operator
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.16 29-Jun-2025  rillig make: if a condition is erroneous, skip the whole .if/.endif
 1.15 30-Apr-2025  rillig make: fix order of error messages in the ":?" modifier

While here: In Var_Parse, EvalStack_Pop needs to be called before
freeing the short-lived variable, as its name is part of the evaluation
stack.
 1.14 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.13 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.12 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.11 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.10 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.9 20-Apr-2024  rillig branches: 1.9.2;
make: provide more context information for parse/evaluate errors
 1.8 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.7 08-Sep-2022  rillig tests/make: extend tests for the ':=' assignment operator
 1.6 30-Nov-2021  rillig tests/make: test and document .MAKE.SAVE_DOLLARS and ':='
 1.5 20-Nov-2021  rillig tests/make: finish a previously unfinished sentence in a comment
 1.4 13-Nov-2021  rillig tests/make: test double indirection in ':=' with undefined variable

Reported by Simon J Gerraty via private mail.

This edge case has been handled in essentially the same way since at
least 2000-05-30, probably several years earlier as well. The test file
is:

---- snip ----
.undef LATER
.undef later
INDIRECT:= ${LATER:S,value,replaced,}
indirect:= ${INDIRECT:C,S,s,}
# expect+1: Unknown modifier "s,value,replaced,"
.if ${indirect} != ""
. error
.else
. warning XXX Neither branch should be taken.
.endif
LATER= uppercase-value
later= lowercase-value
# expect+1: Unknown modifier "s,value,replaced,"
.if ${indirect} != "uppercase-replaced"
. warning XXX Neither branch should be taken.
.else
. error
.endif

all:
@:;
---- snap ----

The output from 'make -r -f later.mk' is:

make-2000.05.30.02.32.21
| make: Unknown modifier 's'
|
| "later.mk", line 9: Need an operator
| make: Unknown modifier 's'
|
| "later.mk", line 15: Need an operator
| Fatal errors encountered -- cannot continue
| exit status 1
make-2000.12.30.16.38.22

The pathnames in the error message gets absolute:

make-2001.01.23.02.48.05
| make: Unknown modifier 's'
|
| ".../later.mk", line 9: Need an operator
| make: Unknown modifier 's'
|
| ".../later.mk", line 15: Need an operator
| Fatal errors encountered -- cannot continue
| exit status 1
make-2001.01.23.02.48.05

All error messages get 'make:' as a common prefix:

make-2001.02.23.21.11.38
| make: Unknown modifier 's'
|
| make: ".../later.mk" line 9: Need an operator
| make: Unknown modifier 's'
|
| make: ".../later.mk" line 15: Need an operator
| make: Fatal errors encountered -- cannot continue
| exit status 1
make-2001.05.29.17.37.52

The 'stopped in' gets added:

make-2001.06.12.23.36.18
| make: Unknown modifier 's'
|
| make: ".../later.mk" line 9: Need an operator
| make: Unknown modifier 's'
|
| make: ".../later.mk" line 15: Need an operator
| make: Fatal errors encountered -- cannot continue
|
| make: stopped in ...
| exit status 1
make-2002.02.21.22.21.34

The empty lines between the error messages get removed.

make-2002.03.21.11.42.21
| make: Unknown modifier 's'
| make: ".../later.mk" line 9: Need an operator
| make: Unknown modifier 's'
| make: ".../later.mk" line 15: Need an operator
| make: Fatal errors encountered -- cannot continue
|
| make: stopped in ...
| exit status 1
make-2009.10.15.02.27.44

The error message for unknown directives gets more helpful:

make-2009.11.19.06.48.37
| make: Unknown modifier 's'
| make: ".../later.mk" line 9: Unknown directive
| make: Unknown modifier 's'
| make: ".../later.mk" line 15: Unknown directive
| make: Fatal errors encountered -- cannot continue
|
| make: stopped in ...
| exit status 1
make-2010.02.22.19.20.33

The directives '.error', '.warning' and '.info' get added:

make-2010.04.29.23.12.21
| make: Unknown modifier 's'
| make: ".../later.mk" line 9: warning: XXX Neither branch should be taken.
| make: Unknown modifier 's'
| make: ".../later.mk" line 15: warning: XXX Neither branch should be taken.
| exit status 0
make-2020.12.20.19.37.23

The error message about an unknown variable modifier gets line number
information:

make-2020.12.20.19.47.34
| make: ".../later.mk" line 6: Unknown modifier 's'
| make: ".../later.mk" line 9: warning: XXX Neither branch should be taken.
| make: ".../later.mk" line 14: Unknown modifier 's'
| make: ".../later.mk" line 15: warning: XXX Neither branch should be taken.
| make: Fatal errors encountered -- cannot continue
| make: stopped in ...
| exit status 1
make-2021.02.23.15.07.58

The error message about an unknown variable modifier gets more context
than only a single letter:

make-2021.02.23.15.19.41
| make: ".../later.mk" line 6: Unknown modifier "s,value,replaced,"
| make: ".../later.mk" line 9: warning: XXX Neither branch should be taken.
| make: ".../later.mk" line 14: Unknown modifier "s,value,replaced,"
| make: ".../later.mk" line 15: warning: XXX Neither branch should be taken.
| make: Fatal errors encountered -- cannot continue
| make: stopped in ...
| exit status 1
 1.3 27-Dec-2020  rillig make(1): move test result of var-op-expand.mk from exp to mk

This makes it easier to run this test in older versions of make. Empty
output means success.
 1.2 08-Nov-2020  rillig make(1): add test for edge case in resolving undefined variables
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.9.2.1 02-Aug-2025  perseant Sync with HEAD
 1.25 29-Jun-2025  rillig make: if a condition is erroneous, skip the whole .if/.endif
 1.24 30-Apr-2025  rillig make: fix order of error messages in the ":?" modifier

While here: In Var_Parse, EvalStack_Pop needs to be called before
freeing the short-lived variable, as its name is part of the evaluation
stack.
 1.23 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.22 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.21 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.20 20-Apr-2024  rillig branches: 1.20.2;
make: provide more context information for parse/evaluate errors
 1.19 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.18 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.17 08-Sep-2022  rillig tests/make: extend tests for the ':=' assignment operator
 1.16 28-Dec-2021  rillig tests/make: use tabs instead of spaces for indentation
 1.15 30-Nov-2021  rillig tests/make: test and document .MAKE.SAVE_DOLLARS and ':='
 1.14 20-Nov-2021  rillig tests/make: finish a previously unfinished sentence in a comment
 1.13 13-Nov-2021  rillig tests/make: extend test for undefined variable in doubly indirect ':='

Just to prevent a half-baked fix to the current behavior that would
concatenate the modifiers of the two expressions, leading to
${LATER:value=sysv:tl} in this case. That expression would be
interpreted as having only a single modifier that would replace the
suffix 'value' with 'sysv:tl'. This is because the SysV modifier
':from=to' spans until the end of the expression.
 1.12 13-Nov-2021  rillig tests/make: test double indirection in ':=' with undefined variable

Reported by Simon J Gerraty via private mail.

This edge case has been handled in essentially the same way since at
least 2000-05-30, probably several years earlier as well. The test file
is:

---- snip ----
.undef LATER
.undef later
INDIRECT:= ${LATER:S,value,replaced,}
indirect:= ${INDIRECT:C,S,s,}
# expect+1: Unknown modifier "s,value,replaced,"
.if ${indirect} != ""
. error
.else
. warning XXX Neither branch should be taken.
.endif
LATER= uppercase-value
later= lowercase-value
# expect+1: Unknown modifier "s,value,replaced,"
.if ${indirect} != "uppercase-replaced"
. warning XXX Neither branch should be taken.
.else
. error
.endif

all:
@:;
---- snap ----

The output from 'make -r -f later.mk' is:

make-2000.05.30.02.32.21
| make: Unknown modifier 's'
|
| "later.mk", line 9: Need an operator
| make: Unknown modifier 's'
|
| "later.mk", line 15: Need an operator
| Fatal errors encountered -- cannot continue
| exit status 1
make-2000.12.30.16.38.22

The pathnames in the error message gets absolute:

make-2001.01.23.02.48.05
| make: Unknown modifier 's'
|
| ".../later.mk", line 9: Need an operator
| make: Unknown modifier 's'
|
| ".../later.mk", line 15: Need an operator
| Fatal errors encountered -- cannot continue
| exit status 1
make-2001.01.23.02.48.05

All error messages get 'make:' as a common prefix:

make-2001.02.23.21.11.38
| make: Unknown modifier 's'
|
| make: ".../later.mk" line 9: Need an operator
| make: Unknown modifier 's'
|
| make: ".../later.mk" line 15: Need an operator
| make: Fatal errors encountered -- cannot continue
| exit status 1
make-2001.05.29.17.37.52

The 'stopped in' gets added:

make-2001.06.12.23.36.18
| make: Unknown modifier 's'
|
| make: ".../later.mk" line 9: Need an operator
| make: Unknown modifier 's'
|
| make: ".../later.mk" line 15: Need an operator
| make: Fatal errors encountered -- cannot continue
|
| make: stopped in ...
| exit status 1
make-2002.02.21.22.21.34

The empty lines between the error messages get removed.

make-2002.03.21.11.42.21
| make: Unknown modifier 's'
| make: ".../later.mk" line 9: Need an operator
| make: Unknown modifier 's'
| make: ".../later.mk" line 15: Need an operator
| make: Fatal errors encountered -- cannot continue
|
| make: stopped in ...
| exit status 1
make-2009.10.15.02.27.44

The error message for unknown directives gets more helpful:

make-2009.11.19.06.48.37
| make: Unknown modifier 's'
| make: ".../later.mk" line 9: Unknown directive
| make: Unknown modifier 's'
| make: ".../later.mk" line 15: Unknown directive
| make: Fatal errors encountered -- cannot continue
|
| make: stopped in ...
| exit status 1
make-2010.02.22.19.20.33

The directives '.error', '.warning' and '.info' get added:

make-2010.04.29.23.12.21
| make: Unknown modifier 's'
| make: ".../later.mk" line 9: warning: XXX Neither branch should be taken.
| make: Unknown modifier 's'
| make: ".../later.mk" line 15: warning: XXX Neither branch should be taken.
| exit status 0
make-2020.12.20.19.37.23

The error message about an unknown variable modifier gets line number
information:

make-2020.12.20.19.47.34
| make: ".../later.mk" line 6: Unknown modifier 's'
| make: ".../later.mk" line 9: warning: XXX Neither branch should be taken.
| make: ".../later.mk" line 14: Unknown modifier 's'
| make: ".../later.mk" line 15: warning: XXX Neither branch should be taken.
| make: Fatal errors encountered -- cannot continue
| make: stopped in ...
| exit status 1
make-2021.02.23.15.07.58

The error message about an unknown variable modifier gets more context
than only a single letter:

make-2021.02.23.15.19.41
| make: ".../later.mk" line 6: Unknown modifier "s,value,replaced,"
| make: ".../later.mk" line 9: warning: XXX Neither branch should be taken.
| make: ".../later.mk" line 14: Unknown modifier "s,value,replaced,"
| make: ".../later.mk" line 15: warning: XXX Neither branch should be taken.
| make: Fatal errors encountered -- cannot continue
| make: stopped in ...
| exit status 1
 1.11 01-Jan-2021  sjg var-op-expand needs MAKE.SAVE_DOLLARS=yes
 1.10 28-Dec-2020  rillig make(1): extend test for modifier parts in ':=' assignments
 1.9 27-Dec-2020  rillig make(1): add test for modifier parts in ':=' assignments
 1.8 27-Dec-2020  rillig make(1): fix edge case in := with undefined in variable name

Previously, the assignment "VAR${UNDEF} := value" actually assigned to 2
variables. See var-op-expand.mk for details.
 1.7 27-Dec-2020  rillig make(1): move test result of var-op-expand.mk from exp to mk

This makes it easier to run this test in older versions of make. Empty
output means success.
 1.6 27-Dec-2020  rillig make(1): add more tests for ':=' assignments
 1.5 27-Dec-2020  rillig make(1): add tests for variable assignments using the ':=' operator
 1.4 08-Nov-2020  rillig make(1): fix bug description of using := with undefined variable

In 1993, the variable names could not refer to other variables yet.
This has been made possible on 2000-05-11, when the "cool magic" was
added that allows assigning to VAR.${param}.
 1.3 08-Nov-2020  rillig make(1): add test for edge case in resolving undefined variables
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.20.2.1 02-Aug-2025  perseant Sync with HEAD
 1.10 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.9 14-Jan-2025  rillig make: simplify code for evaluating the '!=' variable assignment

An undefined variable evaluates to an empty string, without an error
message.
 1.8 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.7 30-Jun-2024  rillig make: add detailed exit status to message for failed sub-commands

Several commands communicate via the exit status and not only
distinguish between zero and non-zero, so make this information
available to ease investigations.

The command "false" is not guaranteed to exit with a consistent status,
so use "(exit 13)" instead in the tests, to keep these tests portable
across different operating systems. The exit status 127 is required for
a shell that cannot find a command, so keep that one.
 1.6 01-Jun-2023  rillig branches: 1.6.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.5 10-Jan-2022  rillig make: add debug logging for capturing the output of external commands

This applies to all 4 situations in which the output of an external
command is used for modifying a variable or an expression:

* the assignment operator '!='
* the assignment modifier '::!='
* the SUN shell modifier ':sh'
* the other shell modifier ':!cmd!'

Previously, only the shell modifier ':!cmd!' had debug logging.

Suggested by Christoph Badura.
 1.4 09-Jan-2022  rillig tests/make: demonstrate inconsistencies in Cmd_Exec callers

The assignment 'VAR != cmd' generates a warning, the others generate an
error message. That error message is ignored for backwards
compatibility though.

The assignment via the expression ${VAR::!=cmd} only uses the output of
the command if there was no error, the other places use the output
nevertheless.
 1.3 06-Feb-2021  sjg Use plain kill to test signaled child

Recent update to Darwin18 make the test using kill -14
stop working.

Reviewed by: rillig
 1.2 09-Nov-2020  rillig make(1): move test for != assignments to var-op-shell
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.6.2.2 02-Aug-2025  perseant Sync with HEAD
 1.6.2.1 01-Jul-2024  perseant Sync with HEAD.
 1.11 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.10 11-Jul-2024  sjg Compat_RunCommand use tempfile if cmd too big

Extract the logic recently added to Cmd_Exec to handle
long commands via temp file to Cmd_Argv,
so it can also be leveraged by Compat_RunCommand

Reviewed by: christos
 1.9 30-Jun-2024  rillig make: add detailed exit status to message for failed sub-commands

Several commands communicate via the exit status and not only
distinguish between zero and non-zero, so make this information
available to ease investigations.

The command "false" is not guaranteed to exit with a consistent status,
so use "(exit 13)" instead in the tests, to keep these tests portable
across different operating systems. The exit status 127 is required for
a shell that cannot find a command, so keep that one.
 1.8 05-Jan-2024  rillig branches: 1.8.2;
tests/make: test long shell commands via Cmd_Exec
 1.7 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.6 10-Jan-2022  rillig make: add debug logging for capturing the output of external commands

This applies to all 4 situations in which the output of an external
command is used for modifying a variable or an expression:

* the assignment operator '!='
* the assignment modifier '::!='
* the SUN shell modifier ':sh'
* the other shell modifier ':!cmd!'

Previously, only the shell modifier ':!cmd!' had debug logging.

Suggested by Christoph Badura.
 1.5 09-Jan-2022  rillig tests/make: demonstrate inconsistencies in Cmd_Exec callers

The assignment 'VAR != cmd' generates a warning, the others generate an
error message. That error message is ignored for backwards
compatibility though.

The assignment via the expression ${VAR::!=cmd} only uses the output of
the command if there was no error, the other places use the output
nevertheless.
 1.4 06-Feb-2021  sjg Use plain kill to test signaled child

Recent update to Darwin18 make the test using kill -14
stop working.

Reviewed by: rillig
 1.3 09-Nov-2020  rillig make(1): move test for != assignments to var-op-shell
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.8.2.2 02-Aug-2025  perseant Sync with HEAD
 1.8.2.1 01-Jul-2024  perseant Sync with HEAD.
 1.2 04-Oct-2020  rillig make(1): fix parsing of the :sh assignment operator modifier
 1.1 04-Oct-2020  rillig make(1): add tests for parsing assignments, especially :sh

Luckily nobody uses the :sh variable assignment modifier since its
syntactical variant != is simpler.
 1.10 09-Feb-2022  rillig make: fix mistakes, spelling and typos in comments and manual page

No binary change for -DNDEBUG.
 1.9 16-Jan-2022  rillig tests/make: document more edge cases for the assignment modifier ':sh'
 1.8 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.7 07-Feb-2021  rillig make: fix typo in comment in test
 1.6 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.5 04-Oct-2020  rillig make(1): add test for combining :sh with +=
 1.4 04-Oct-2020  rillig make(1): add another test for parsing :sh assignments
 1.3 04-Oct-2020  rillig make(1): test another edge case for the :sh assignment
 1.2 04-Oct-2020  rillig make(1): fix parsing of the :sh assignment operator modifier
 1.1 04-Oct-2020  rillig make(1): add tests for parsing assignments, especially :sh

Luckily nobody uses the :sh variable assignment modifier since its
syntactical variant != is simpler.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 20-Dec-2023  rillig make: fix confusing debug logging when deleting a variable

Be clear when deleting a variable is ignored and state the reason,
instead of only providing a keyword as a hint for insiders.
 1.2 20-Dec-2023  rillig tests/make: demonstrate confusing debug log for read-only variables

The message 'delete %s' that occurs above the 'readOnly' looks as if the
variable would indeed be deleted. The wording in the 'readOnly' line is
unclear.
 1.1 24-Jan-2023  sjg Add the unit tests
 1.4 20-Dec-2023  rillig tests/make: demonstrate confusing debug log for read-only variables

The message 'delete %s' that occurs above the 'readOnly' looks as if the
variable would indeed be deleted. The wording in the 'readOnly' line is
unclear.
 1.3 19-Jun-2023  sjg Test that .undef of readOnly variable fails
 1.2 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.1 24-Jan-2023  sjg Add the unit tests
 1.18 13-Jun-2025  rillig make: add on-demand inter-process stack traces

When debugging a build that heavily uses nested calls to sub-makes, the
chain of calls is useful to quickly assess the situation. If explicitly
requested, include the actions from any parent processes in the stack
traces.

Reviewed by: sjg
 1.17 12-Jun-2025  rillig make: add program name to stack traces from sub-makes
 1.16 12-Jun-2025  rillig make: add quotes to "in directory" line in stack traces

The other lines in stack traces use quotes as well.
 1.15 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.14 29-Mar-2025  rillig make: in stack traces from target commands, add the command level

A target can contain several commands, and these commands are likely to
contain the same expressions. To distinguish them, add one more line to
the stack trace, to narrow down the source of the error.
 1.13 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.12 27-Aug-2024  rillig tests/make: add stricter checks to test for recursive variables
 1.11 27-Aug-2024  rillig make: treat recursive variables non-fatally

A recursive variable is no worse than an unknown modifier, so treat them
in the same way by continuing parsing until the end of the makefile.
 1.10 25-Aug-2024  rillig make: add more context to error message about recursive variables
 1.9 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.8 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.7 07-Jan-2024  sjg branches: 1.7.2;
make: more consistent error messages

Move %s: progname from Job_CheckCommands to Fatal
to avoid is being repeated when Job_CheckCommands is passed Error.

This means some errors from var also report progname (and level)
which is useful.

Reviewed by: rillig
 1.6 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.5 29-Jan-2022  rillig make: for recursive variables in commands, print location

Print the approximate location based on the last command that has been
defined for the target. It would be possible to get more detailed
location information by counting the number of commands of the target,
but that would get messy due to .USEBEFORE, .USE and .DEFAULT, and
still, this is an edge case, so don't waste too much code for it now.
Having this hint about the location is more helpful than just a plain
"Variable X is recursive" without any further details.
 1.4 29-Jan-2022  rillig tests/make: demonstrate recursive variable in target
 1.3 29-Jan-2022  rillig make: print stack trace on fatal errors

The only fatal error that occurs while the makefiles are read in is the
one about recursive variables, which didn't give any hint about the
location before.

If a recursive variable is detected while evaluating the commands of a
target to be made, there is no location information, as before.
 1.2 31-Oct-2020  rillig make(1): add test for recursion detection with short variable names
 1.1 31-Oct-2020  rillig make(1): add test for recursive variable expressions
 1.7.2.1 02-Aug-2025  perseant Sync with HEAD
 1.12 13-Apr-2025  rillig tests/make: add tests for POSIX mode
 1.11 29-Mar-2025  rillig make: in stack traces from target commands, add the command level

A target can contain several commands, and these commands are likely to
contain the same expressions. To distinguish them, add one more line to
the stack trace, to narrow down the source of the error.
 1.10 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.9 27-Aug-2024  rillig tests/make: add stricter checks to test for recursive variables
 1.8 27-Aug-2024  rillig make: treat recursive variables non-fatally

A recursive variable is no worse than an unknown modifier, so treat them
in the same way by continuing parsing until the end of the makefile.
 1.7 25-Aug-2024  rillig make: add more context to error message about recursive variables
 1.6 19-Nov-2023  rillig branches: 1.6.2;
tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.5 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.4 29-Jan-2022  rillig tests/make: sync comment in test for recursive variable
 1.3 29-Jan-2022  rillig tests/make: demonstrate recursive variable in target
 1.2 31-Oct-2020  rillig make(1): add test for recursion detection with short variable names
 1.1 31-Oct-2020  rillig make(1): add test for recursive variable expressions
 1.6.2.1 02-Aug-2025  perseant Sync with HEAD
 1.4 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.3 01-Jun-2023  rillig branches: 1.3.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.2 07-Apr-2023  rillig tests/make: add cross references to command line tests
 1.1 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.4 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.3 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.2 07-Apr-2023  rillig tests/make: add cross references to command line tests
 1.1 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.1 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.1 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.1 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.1 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.3 17-Dec-2023  rillig tests/make: extend tests for include guards and empty expressions
 1.2 27-Sep-2022  rillig tests/make: add tests for legacy local variables and sorting
 1.1 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.3 17-Dec-2023  rillig tests/make: extend tests for include guards and empty expressions
 1.2 27-Sep-2022  rillig tests/make: add tests for legacy local variables and sorting
 1.1 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.9 05-Mar-2024  rillig tests/make: clean up test for local scope variables

Use the same style of quotes for both kinds of variables. To make the
variable values more easily comparable, write them to a single line.
Add the output to the 'expect' lines.
 1.8 01-Mar-2024  sjg make: update var-scope-local test

Show what VAR value is in environment of target script.
 1.7 20-Dec-2023  rillig make: use consistent debug messages style when ignoring variables

When a variable is not modified or not deleted, clearly say so and state
the reason. Use the same style of debug messages everywhere, putting
the word 'ignoring' at the front. Previously, that word sticked out to
the right, but only in some cases.
 1.6 29-Apr-2023  rillig tests/make: extend test for target-local variables
 1.5 28-Apr-2023  rillig tests/make: add tests for target-local variables

While here, move a test from var-scope-local.mk to parse.mk since that
test is not related to variables.
 1.4 26-Mar-2022  rillig make: avoid trailing whitespace in debug log for variables

Since trailing whitespace is invisible, describe the variable value in
words to make it visible.
 1.3 29-Jan-2022  rillig tests/make: extend and isolate tests for target-local variables

Reusing the target var-scope-local.o for several tests made the test
more difficult to understand than necessary. The test names '2' and '3'
didn't convey any meaning.

Instead, add more test targets that are named after what they test. Add
tests for each of the 5 variable assignment operators, to demonstrate an
inconsistency between '+=' and '?='.

Add tests for the built-in target-local variables as well and explain
the general concepts, in particular the exact point where target-local
expressions are expanded.

The lines in the expected output file are not generated in the same
order as they appear in the makefile, so allow the 'expect' lines in
non-linear order, in check-expect.lua.
 1.2 27-Jan-2022  sjg Unit test for local variables
 1.1 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.11 05-Mar-2024  rillig tests/make: clean up test for local scope variables

Use the same style of quotes for both kinds of variables. To make the
variable values more easily comparable, write them to a single line.
Add the output to the 'expect' lines.
 1.10 01-Mar-2024  sjg make: update var-scope-local test

Show what VAR value is in environment of target script.
 1.9 20-Dec-2023  rillig make: use consistent debug messages style when ignoring variables

When a variable is not modified or not deleted, clearly say so and state
the reason. Use the same style of debug messages everywhere, putting
the word 'ignoring' at the front. Previously, that word sticked out to
the right, but only in some cases.
 1.8 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.7 29-Apr-2023  rillig tests/make: extend test for target-local variables
 1.6 28-Apr-2023  rillig tests/make: add tests for target-local variables

While here, move a test from var-scope-local.mk to parse.mk since that
test is not related to variables.
 1.5 09-Feb-2022  rillig make: fix mistakes, spelling and typos in comments and manual page

No binary change for -DNDEBUG.
 1.4 05-Feb-2022  rillig tests/make: document and try to reproduce the crash in Parse_IsVar

Fixed in parse.c 1.662 from today. To actually crash make, the end of
the expanded dependency line must be at the end of a mapped region.
There is no guaranteed crash, as this depends on the memory allocator.
NetBSD's jemalloc allocates large contiguous regions, making it less
likely for an allocation to end up at the end of a mapped region. The
memory allocators used by FreeBSD and OpenBSD are better at detecting
such bugs.
 1.3 29-Jan-2022  rillig tests/make: extend and isolate tests for target-local variables

Reusing the target var-scope-local.o for several tests made the test
more difficult to understand than necessary. The test names '2' and '3'
didn't convey any meaning.

Instead, add more test targets that are named after what they test. Add
tests for each of the 5 variable assignment operators, to demonstrate an
inconsistency between '+=' and '?='.

Add tests for the built-in target-local variables as well and explain
the general concepts, in particular the exact point where target-local
expressions are expanded.

The lines in the expected output file are not generated in the same
order as they appear in the makefile, so allow the 'expect' lines in
non-linear order, in check-expect.lua.
 1.2 27-Jan-2022  sjg Unit test for local variables
 1.1 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.1 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.1 23-Jan-2022  rillig tests/make: rename var-class to var-scope

There is no such concept as a "variable class" in make, these tests
focus on the variable scope instead.
 1.4 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.3 14-May-2008  sjg Do not set vars in VAR_GLOBAL context, if they have been set on the
command line.
Add a suitable unit-test.
 1.2 01-Jun-2005  sjg branches: 1.2.20; 1.2.22;
Add :Ox for random ordering, based on patch from
Mike M. Volokhov <mishka@apk.od.ua>
 1.1 31-Jul-2003  sjg Test behavior of commandline variable assignments.
 1.2.22.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.2.20.1 18-May-2008  yamt sync with head.
 1.3 08-Dec-2017  sjg Ensure VAR+=val on command line is handled correctly

If VAR is not previously set, call Var_Set to deal with
the special case of VAR_CMD.

If VAR is previously set, and ctxt is VAR_CMD we should do the update
even if VAR_FROM_CMD is set.
 1.2 18-Nov-2017  sjg Do not append to variable set on command line

POSIX requires that variables set on the command line
be immutable.
Var_Append needs to pass FIND_CMD and skip append
if found variable has VAR_FROM_CMD flag set.
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.7 07-Apr-2023  rillig tests/make: add cross references to command line tests
 1.6 16-Feb-2021  rillig make: document the bad state in which the test varcmd.mk is
 1.5 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.4 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.3 08-Dec-2017  sjg Ensure VAR+=val on command line is handled correctly

If VAR is not previously set, call Var_Set to deal with
the special case of VAR_CMD.

If VAR is previously set, and ctxt is VAR_CMD we should do the update
even if VAR_FROM_CMD is set.
 1.2 18-Nov-2017  sjg Do not append to variable set on command line

POSIX requires that variables set on the command line
be immutable.
Var_Append needs to pass FIND_CMD and skip append
if found variable has VAR_FROM_CMD flag set.
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.43 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.42 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.41 29-Mar-2025  rillig make: stop parsing after seeing an unknown modifier in an expression

Previously, after an expression such as ${VAR:Z::::}, make detected the
unknown modifier ":Z" and then continued parsing, which produced
unnecessary follow-up error messages. It was also necessary to
distinguish the error cases when logging the result of an applied
modifier in -dv mode.

Unify the error handling cases of a syntax error, an evaluation error
and an unknown modifier, to avoid the unnecessary follow-up error
messages.

The test in varmod-edge.mk now produces ":}" from the erroneous
expression, which may be misleading and thus will be looked at in a
follow-up commit.

The general idea of this patch was reviewed by sjg, I made a few
nonsubstantial changes after the review.
 1.40 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.39 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.38 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.37 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.36 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.35 20-Apr-2024  rillig branches: 1.35.2;
make: provide more context information for parse/evaluate errors
 1.34 20-Dec-2023  rillig tests/make: add the expected output to the test for variable debugging
 1.33 20-Dec-2023  rillig make: use consistent debug messages style when ignoring variables

When a variable is not modified or not deleted, clearly say so and state
the reason. Use the same style of debug messages everywhere, putting
the word 'ignoring' at the front. Previously, that word sticked out to
the right, but only in some cases.
 1.32 20-Dec-2023  rillig make: fix confusing debug logging when deleting a variable

Be clear when deleting a variable is ignored and state the reason,
instead of only providing a keyword as a hint for insiders.
 1.31 10-Dec-2023  rillig make: explain in the debug log why a variable assignment is ignored
 1.30 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.29 26-Mar-2022  rillig make: avoid trailing whitespace in debug log for variables

Since trailing whitespace is invisible, describe the variable value in
words to make it visible.
 1.28 26-Mar-2022  rillig make: add space after colon in debug logging for variables

These log messages are intended for human interpretation, so don't make
them unnecessarily hard to read.
 1.27 20-Nov-2021  rillig make: use correct plural form in debug message
 1.26 10-Apr-2021  rillig make: reword debug log message for empty variable name

The function names did not match anymore, after one of the many
refactorings in the last few months.
 1.25 10-Apr-2021  rillig make: reduce debug logging and memory allocation for ${:U...}

Expressions of the form ${:U...} are often generated by .for loops.
Since these expressions are not generated knowingly by the make user, do
not fill the debug log with them since that would interrupt the normal
reading flow of the -dv log for nested expressions.
 1.24 06-Apr-2021  rillig make: reduce verbosity of the -dv debug logging for standard cases

The verbosity was already removed from LogBeforeApply, now it is
consistent between LogBeforeApply and LogAfterApply.
 1.23 05-Apr-2021  rillig make: in debug log, add space between scope and variable name

Without this space, the debug log looked more like line noise, even
though the only punctuation was a single innocent ':'. From a make
user's perspective, the variable name is a word of its own and should
not be visually glued to its namespace.
 1.22 05-Apr-2021  rillig make: omit unnecessary details from -dv debug log

When an expression is based on a defined variable, it does not matter
whether the evaluation mode is "eval" or "eval-defined", therefore omit
these details to reduce confusion.
 1.21 05-Apr-2021  rillig make: be more verbose in -dv debug logging

The previous log output was too brief to be understandable. Give more
hints by describing each part of the expression when evaluating a
modifier. Distinguish between parse-only mode and eval mode since in
parse-only mode most of the details are irrelevant.
 1.20 05-Apr-2021  rillig make: clean up debug logging for ':M' and ':N'

Using square brackets as quotes was confusing since patterns can contain
square brackets themselves.

The debug logging for VarMatch was a bit too detailed. Having the
"before" and "after" states is enough for all practically relevant
cases.
 1.19 03-Apr-2021  rillig make: remove VarFlags from debug logging

Before the introduction of ExprDefined, VarFlags contained whether the
expression was defined or not, which was useful to know since the final
value of the expression depends on this information. The other VarFlags
do not influence the evaluation, so there is no point logging them.
 1.18 15-Mar-2021  rillig make: change debug log for variable evaluation flags to lowercase

This makes them easier distinguishable from variable names since the
latter are usually uppercase.

No functional change outside debug mode.
 1.17 23-Feb-2021  rillig make: improve error message for unknown modifier

Back in 1995, the modifiers were all single-character, and it made sense
to print only the first character. Nowadays, with ':S', ':@var@...@',
'::=' and several others, a little more context is useful to see where
the exact error is. The actual modifier is still guessed, and the guess
may be wrong as soon as backslashes get involved, but it is still better
than before.
 1.16 15-Feb-2021  rillig make: rename ExprDefined constants for debug logging
 1.15 02-Feb-2021  rillig make: replace VarExprFlags with VarExprStatus

The combination of !VEF_UNDEF && VEF_DEF was not possible, which made it
rather strange to model this state as a bit set.

The only functional change is the renamed constants in the debug output.

Using ENUM_VALUE_RTTI_2 felt like overengineering since it's harder to
understand than a simple array of names.
 1.14 20-Dec-2020  rillig make(1): error out on unknown variable modifiers at parse time

Before, make printed an "error message" that did not include the word
error and thus was not easily identified as such. This "error message"
also did not influence the exit status in the default mode but only in
-dL mode. The error message also didn't include any line number
information and was thus rude.
 1.13 17-Nov-2020  rillig make(1): make test vardebug independent from the shell
 1.12 31-Oct-2020  rillig make(1): remove debug logging for the :Q variable modifier

The same information is already logged in LogAfterApply.
 1.11 29-Oct-2020  rillig make(1): add test for ignoring assignment to read-only variable
 1.10 29-Oct-2020  rillig make(1): move MAKEFLAGS handling in vardebug test to the test itself
 1.9 30-Sep-2020  rillig make(1): fix bug in evaluation of indirect variable modifiers

Since 2020-09-22, when indirect variable modifiers were applied to a
variable expression based on an undefined variable, these modifiers did
not change the state of a variable expression from undefined to defined.
The modifiers that do this are :D, :U, :L, :P. Minimal example:

${VARNAME:${:UL}}

The :L modifier from the inner expression sets the value of the outer
expression to its variable name, in this case "VARNAME". The outer
expression was not marked as being defined though, which resulted in a
"Malformed conditional" error.

In the commit from 2020-09-22, vardebug.exp had changed a lot, and I had
not inspected the change closely. The important detail was in lines 56
and 60, where VAR_JUNK|VAR_KEEP changed into VEF_UNDEF, thereby losing
the VEF_DEF bit.
 1.8 22-Sep-2020  rillig make(1): move VAR_JUNK and VAR_KEEP away from VarFlags

These two flags have nothing to do with a variable. They are only used
while evaluating a variable expression.

While here, rename the flags and make their documentation more precise.
 1.7 13-Sep-2020  rillig make(1): shorten debug output of ApplyModifiers

Having the words "eflags" and "vflags" in the debug output was too
repetitive. That they are flags is made obvious by the '|' separator,
and the flags have clearly distinguishable names (VARE_* vs. VAR_*),
which lowers the chance for confusion.
 1.6 08-Aug-2020  rillig make(1): add debug logging for Var_Parse

This will hopefully help with tracking down why the "Undefined variable"
error message is not triggered.

There is some other non-obvious behavior nearby. In Parse_DoVar, the !=
assignment operator evaluates the variable using VARE_UNDEFERR, but
there is not even a warning for the following line:

!= echo err ${UNDEFINED} 1>&2
 1.5 08-Aug-2020  rillig make(1): extend debug logging to error values

The error marker var_Error is just an empty string. In the debug log
this empty string was not distinguishable from an otherwise empty
string.

Having this distinction helps in understanding the exact data flow.
 1.4 08-Aug-2020  rillig make(1): add more detailed debug logging for variable modifiers

Before a modifier is applied to a variable, it is not yet parsed,
therefore it is only possible to log a rough estimate of the modifier.
But after applying it, the parsing position has advanced, and the full
modifier can be logged.

In addition, to fully understand how the modifiers work, it's not enough
to just know the variable names and values, there are also some flags
that influence how the modifiers behave. The most influential is
VARE_WANTRES.

Thanks to sjg for the extensive review and valuable feedback on the
first drafts.
 1.3 08-Aug-2020  rillig make(1): fix debug output for indirect modifiers

The trailing part after the modifier was confusing at best. It does
make sense to log the string from p to p+rlen, but not from p+len to
p+len+len.

Consistently use double quotes for strings.
 1.2 08-Aug-2020  rillig make(1): add test for debugging message for indirect modifiers

The current output format stops in the middle of the next modifier,
which was probably not intended.
 1.1 25-Jul-2020  rillig make(1): add tests for previously uncovered code
 1.35.2.1 02-Aug-2025  perseant Sync with HEAD
 1.18 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.17 29-Mar-2025  rillig make: stop parsing after seeing an unknown modifier in an expression

Previously, after an expression such as ${VAR:Z::::}, make detected the
unknown modifier ":Z" and then continued parsing, which produced
unnecessary follow-up error messages. It was also necessary to
distinguish the error cases when logging the result of an applied
modifier in -dv mode.

Unify the error handling cases of a syntax error, an evaluation error
and an unknown modifier, to avoid the unnecessary follow-up error
messages.

The test in varmod-edge.mk now produces ":}" from the erroneous
expression, which may be misleading and thus will be looked at in a
follow-up commit.

The general idea of this patch was reviewed by sjg, I made a few
nonsubstantial changes after the review.
 1.16 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.15 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.14 11-Jan-2025  rillig tests/make: force correct order of expected messages
 1.13 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.12 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.11 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.10 20-Apr-2024  rillig branches: 1.10.2;
make: provide more context information for parse/evaluate errors
 1.9 20-Dec-2023  rillig tests/make: add the expected output to the test for variable debugging
 1.8 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.7 04-Feb-2021  rillig make: rename context and ctxt to scope

This continues the previous commit, in which VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE were renamed.

Renaming the variable 'ctxt' was trivial since that word is used nowhere
else. In the comments though, each occurrence of the word 'context' had
to be checked individually since the word 'context' was not only used
for referring to a variable scope. It is also used to distinguish
different situations where characters are escaped in a certain way
('parsing context') and in a few other expressions.
 1.6 31-Oct-2020  rillig make(1): fix function names in test for variable debugging
 1.5 29-Oct-2020  rillig make(1): add test for ignoring assignment to read-only variable
 1.4 29-Oct-2020  rillig make(1): move MAKEFLAGS handling in vardebug test to the test itself
 1.3 08-Aug-2020  rillig make(1): extend debug logging to error values

The error marker var_Error is just an empty string. In the debug log
this empty string was not distinguishable from an otherwise empty
string.

Having this distinction helps in understanding the exact data flow.
 1.2 08-Aug-2020  rillig make(1): add test for debugging message for indirect modifiers

The current output format stops in the middle of the next modifier,
which was probably not intended.
 1.1 25-Jul-2020  rillig make(1): add tests for previously uncovered code
 1.10.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 25-Jul-2020  rillig make(1): add tests for previously uncovered code
 1.1 25-Jul-2020  rillig make(1): add tests for previously uncovered code
 1.27 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.26 29-Mar-2025  rillig make: in stack traces from target commands, add the command level

A target can contain several commands, and these commands are likely to
contain the same expressions. To distinguish them, add one more line to
the stack trace, to narrow down the source of the error.
 1.25 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.24 20-Jul-2024  rillig make: don't run erroneous commands in compat mode

When there is a parse or evaluation error in an expression that becomes
part of the command, don't run that command, as the result of the failed
evaluation typically contains garbage characters. Skip the remaining
commands from that target as well, as they may depend on the erroneous
command.
 1.23 09-Jul-2024  rillig make: error out on parse/evaluation errors in shell commands

The expression ${VAR:X} has an unknown modifier ':X'. Previously, this
expression errored out when the expression was evaluated at parse time,
but not when the expression was evaluated when generating the commands
to bring a target up to date. The errors were previously reported, they
didn't affect the exit status, though.

Now, errors in expressions are handled in the same way, regardless of
the time at which they are evaluated.
 1.22 05-Jul-2024  rillig make: error out on unclosed expressions during parse time

In exchange, this adds location information.

For unnamed expressions, the value is no longer printed. This will be
added back in a follow-up commit.
 1.21 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.20 20-Apr-2024  rillig branches: 1.20.2;
make: provide more context information for parse/evaluate errors
 1.19 19-Nov-2023  rillig make: replace 'variable expression' with 'expression' in diagnostics
 1.18 19-Oct-2023  rillig tests/make: clean up, explain and reorganize several tests
 1.17 23-Feb-2021  rillig make: improve error message for unclosed modifier

Replace "variable specification" with the more modern "variable
expression", reduce the number of parentheses, output more than a single
character for modifiers, make it obvious that in expressions such as
${:Serror}, the "" means a variable name.
 1.16 31-Aug-2020  sjg Add test case for FLAGS dependent on .TARGET
 1.15 30-Jul-2020  rillig make(1): add test for indirect unclosed variable

The error message mentions only the original variable name right now.
It's left to the Makefile author to see where the actual unclosed
variable value comes from. From a usability standpoint that's not
optimal, but everything else would need additional cycles even in the
good cases, or it might have side-effects when evaluating a variable
twice (once to detect the error, and a second time to find out the
details of the error).
 1.14 28-Jul-2020  rillig make(1): issue a parse error on unclosed variables

These errors had not been detected before by make.
In pkgsrc, this task as been done by pkglint since 2019-04-07.
 1.13 26-Jul-2020  rillig make(1): add coverage test for dynamic = TRUE in Var_Parse
 1.12 26-Jul-2020  rillig make(1): add test for unclosed variables
 1.11 26-Jul-2020  rillig make(1): add test for expanding dynamic variables
 1.10 26-Jul-2020  rillig make(1): add test for appending and exporting a variable
 1.9 26-Jul-2020  rillig make(1): add test for .MAKE.SAVE_DOLLARS
 1.8 01-Jul-2020  sjg Fix parsing of nested variables during .for loop

Recent change to cond.c to avoid eval of unnecessary
terms had side effect on constructs like:

.for s in 1 2
.if defined(MAN$s) && !empty(MAN$s)
MAN+= ${MAN$s}
.endif
.endfor

resulting in MAN being flagged as recursive.

When Var_Parse encounters a variable within a variable name
we want to force it to be expanded.
But given the way get_mpt_arg calls Var_Parse we need to check
whether we actually started parsing a variable yet.
 1.7 31-Jan-2017  sjg Add check to cmpv test to ensure that target specific vars with
modifiers work as expected.
 1.6 30-Jan-2017  sjg Add :range and :_

:range replaces var value with an integer sequence one per word
in the current var value.

:_ stores the current var value in $_ so that it can be referred to
later in the modifier series.

Reviewed by: christos
 1.5 14-Jan-2017  sjg branches: 1.5.2;
Allow providing a utc value to :{gm,local}time

Reviewed by: christos
 1.4 12-Oct-2015  sjg branches: 1.4.2;
Add unit-test for discarded :?
 1.3 11-Oct-2015  sjg Avoid echo -n in unit-tests
 1.2 11-Oct-2015  sjg Add Boolean wantit to Var_Parse and Var_Subst

wantit will be FALSE when we are just consuming to discard
in which case we skip "expensive" things like Cmd_Exec.

Reviewed by: christos
 1.1 21-Aug-2014  apb Add varmisc.mk, for miscellaneous variable tests.

For now, the only test is copied from
src/tests/usr.bin/make/d_unmatchedvarparen.mk. This was
the only test in src/tests/usr.bin/make that was not also in
src/usr.bin/make/unit-tests.

XXX: src/tests/usr.bin/mk should be changed to reach over to
src/usr.bin/make/unit-tests, instead of keeping out of date copies
of the tests.
 1.4.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.5.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.20.2.1 02-Aug-2025  perseant Sync with HEAD
 1.38 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.37 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.36 20-Jul-2024  rillig make: don't run erroneous commands in compat mode

When there is a parse or evaluation error in an expression that becomes
part of the command, don't run that command, as the result of the failed
evaluation typically contains garbage characters. Skip the remaining
commands from that target as well, as they may depend on the erroneous
command.
 1.35 05-Jul-2024  rillig make: error out on unclosed expressions during parse time

In exchange, this adds location information.

For unnamed expressions, the value is no longer printed. This will be
added back in a follow-up commit.
 1.34 05-Jul-2024  rillig tests/make: add expected messages for "Unclosed expression"
 1.33 19-Oct-2023  rillig branches: 1.33.2;
tests/make: clean up, explain and reorganize several tests
 1.32 05-Dec-2021  rillig tests/make: fix documentation of .MAKE.SAVE_DOLLARS
 1.31 30-Nov-2021  rillig tests/make: test and document .MAKE.SAVE_DOLLARS and ':='
 1.30 04-Feb-2021  rillig make: rename context and ctxt to scope

This continues the previous commit, in which VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE were renamed.

Renaming the variable 'ctxt' was trivial since that word is used nowhere
else. In the comments though, each occurrence of the word 'context' had
to be checked individually since the word 'context' was not only used
for referring to a variable scope. It is also used to distinguish
different situations where characters are escaped in a certain way
('parsing context') and in a few other expressions.
 1.29 28-Nov-2020  rillig make(1): move test for recursive variable to cond-func-empty

Previously, the documentation of that test was much too short to explain
all the effects that happened in the bug situation from 2020-06-28 until
2020-07-02.
 1.28 07-Nov-2020  rillig make(1): fix references to Var_SetWithFlags in tests
 1.27 06-Nov-2020  rillig make(1): rename getBoolean and s2Boolean
 1.26 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.25 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.24 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.23 31-Aug-2020  sjg Add test case for FLAGS dependent on .TARGET
 1.22 23-Aug-2020  rillig make(1): move test for .undef into separate file
 1.21 08-Aug-2020  rillig make(1): fix typo in test
 1.20 30-Jul-2020  rillig make(1): add test for indirect unclosed variable

The error message mentions only the original variable name right now.
It's left to the Makefile author to see where the actual unclosed
variable value comes from. From a usability standpoint that's not
optimal, but everything else would need additional cycles even in the
good cases, or it might have side-effects when evaluating a variable
twice (once to detect the error, and a second time to find out the
details of the error).
 1.19 28-Jul-2020  rillig make(1): add test for missing argument validation in .undef
 1.18 28-Jul-2020  rillig make(1): issue a parse error on unclosed variables

These errors had not been detected before by make.
In pkgsrc, this task as been done by pkglint since 2019-04-07.
 1.17 26-Jul-2020  rillig make(1): add coverage test for dynamic = TRUE in Var_Parse
 1.16 26-Jul-2020  rillig make(1): add test for unclosed variables
 1.15 26-Jul-2020  rillig make(1): add test for expanding dynamic variables
 1.14 26-Jul-2020  rillig make(1): add test for appending and exporting a variable
 1.13 26-Jul-2020  rillig make(1): add tests for appending to a variable
 1.12 26-Jul-2020  rillig make(1): add test for .MAKE.SAVE_DOLLARS
 1.11 19-Jul-2020  rillig make(1): fix date in comment in unit test
 1.10 02-Jul-2020  rillig make(1): document the actual cause for "recursive variable"

That wrong error message had nothing to do with the .for loop, it was
only caused because the .for loop uses the :U modifier internally.
 1.9 01-Jul-2020  sjg Fix parsing of nested variables during .for loop

Recent change to cond.c to avoid eval of unnecessary
terms had side effect on constructs like:

.for s in 1 2
.if defined(MAN$s) && !empty(MAN$s)
MAN+= ${MAN$s}
.endif
.endfor

resulting in MAN being flagged as recursive.

When Var_Parse encounters a variable within a variable name
we want to force it to be expanded.
But given the way get_mpt_arg calls Var_Parse we need to check
whether we actually started parsing a variable yet.
 1.8 31-Jan-2017  sjg Add check to cmpv test to ensure that target specific vars with
modifiers work as expected.
 1.7 30-Jan-2017  sjg Add :range and :_

:range replaces var value with an integer sequence one per word
in the current var value.

:_ stores the current var value in $_ so that it can be referred to
later in the modifier series.

Reviewed by: christos
 1.6 14-Jan-2017  sjg branches: 1.6.2;
Allow providing a utc value to :{gm,local}time

Reviewed by: christos
 1.5 12-Oct-2015  sjg branches: 1.5.2;
Add unit-test for discarded :?
 1.4 11-Oct-2015  sjg Avoid echo -n in unit-tests
 1.3 11-Oct-2015  sjg Add Boolean wantit to Var_Parse and Var_Subst

wantit will be FALSE when we are just consuming to discard
in which case we skip "expensive" things like Cmd_Exec.

Reviewed by: christos
 1.2 30-Aug-2014  sjg Replace use of $() with ${}
$() means something special to the shell, so ${} reduces confusion
and is used almost exclusively in the rest of the makefiles.

Discussed with: christos
 1.1 21-Aug-2014  apb Add varmisc.mk, for miscellaneous variable tests.

For now, the only test is copied from
src/tests/usr.bin/make/d_unmatchedvarparen.mk. This was
the only test in src/tests/usr.bin/make that was not also in
src/usr.bin/make/unit-tests.

XXX: src/tests/usr.bin/mk should be changed to reach over to
src/usr.bin/make/unit-tests, instead of keeping out of date copies
of the tests.
 1.5.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.6.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.33.2.1 02-Aug-2025  perseant Sync with HEAD
 1.12 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.11 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.10 10-Jan-2025  rillig tests/make: test expressions based on undefined variables

When an undefined variable is used in a conditional, make complains about
"Malformed conditional", which is wrong since the conditional is
well-formed but errors out during evaluation.

In order to fix this wrong error message and preserve the remaining
behavior, cover the places in which an expression is evaluated with
undefined expressions being an error (VARE_EVAL_DEFINED), but with
neither producing an error message nor handling errors. This combination
results in the same behavior as evaluating the expressions in the mode
that allows undefined variables to be used in expressions.
 1.9 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.8 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.7 30-Jun-2024  rillig make: sync error handling between '!=' assignment and '::!=' modifier
 1.6 30-Jun-2024  rillig make: add detailed exit status to message for failed sub-commands

Several commands communicate via the exit status and not only
distinguish between zero and non-zero, so make this information
available to ease investigations.

The command "false" is not guaranteed to exit with a consistent status,
so use "(exit 13)" instead in the tests, to keep these tests portable
across different operating systems. The exit status 127 is required for
a shell that cannot find a command, so keep that one.
 1.5 01-Jun-2023  rillig branches: 1.5.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.4 26-Mar-2022  rillig make: avoid trailing whitespace in debug log for variables

Since trailing whitespace is invisible, describe the variable value in
words to make it visible.
 1.3 10-Jan-2022  rillig make: add debug logging for capturing the output of external commands

This applies to all 4 situations in which the output of an external
command is used for modifying a variable or an expression:

* the assignment operator '!='
* the assignment modifier '::!='
* the SUN shell modifier ':sh'
* the other shell modifier ':!cmd!'

Previously, only the shell modifier ':!cmd!' had debug logging.

Suggested by Christoph Badura.
 1.2 09-Jan-2022  rillig tests/make: demonstrate inconsistencies in Cmd_Exec callers

The assignment 'VAR != cmd' generates a warning, the others generate an
error message. That error message is ignored for backwards
compatibility though.

The assignment via the expression ${VAR::!=cmd} only uses the output of
the command if there was no error, the other places use the output
nevertheless.
 1.1 28-Dec-2021  rillig tests/make: document inconsistencies between '!=' and '::!='

Found while trying to make the error messages from Cmd_Exec more
detailed.
 1.5.2.2 02-Aug-2025  perseant Sync with HEAD
 1.5.2.1 01-Jul-2024  perseant Sync with HEAD.
 1.11 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.10 10-Jan-2025  rillig tests/make: test expressions based on undefined variables

When an undefined variable is used in a conditional, make complains about
"Malformed conditional", which is wrong since the conditional is
well-formed but errors out during evaluation.

In order to fix this wrong error message and preserve the remaining
behavior, cover the places in which an expression is evaluated with
undefined expressions being an error (VARE_EVAL_DEFINED), but with
neither producing an error message nor handling errors. This combination
results in the same behavior as evaluating the expressions in the mode
that allows undefined variables to be used in expressions.
 1.9 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.8 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.7 30-Jun-2024  rillig make: sync error handling between '!=' assignment and '::!=' modifier
 1.6 30-Jun-2024  rillig make: add detailed exit status to message for failed sub-commands

Several commands communicate via the exit status and not only
distinguish between zero and non-zero, so make this information
available to ease investigations.

The command "false" is not guaranteed to exit with a consistent status,
so use "(exit 13)" instead in the tests, to keep these tests portable
across different operating systems. The exit status 127 is required for
a shell that cannot find a command, so keep that one.
 1.5 01-Jun-2023  rillig branches: 1.5.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.4 10-Jan-2022  rillig make: add debug logging for capturing the output of external commands

This applies to all 4 situations in which the output of an external
command is used for modifying a variable or an expression:

* the assignment operator '!='
* the assignment modifier '::!='
* the SUN shell modifier ':sh'
* the other shell modifier ':!cmd!'

Previously, only the shell modifier ':!cmd!' had debug logging.

Suggested by Christoph Badura.
 1.3 09-Jan-2022  rillig tests/make: demonstrate inconsistencies in Cmd_Exec callers

The assignment 'VAR != cmd' generates a warning, the others generate an
error message. That error message is ignored for backwards
compatibility though.

The assignment via the expression ${VAR::!=cmd} only uses the output of
the command if there was no error, the other places use the output
nevertheless.
 1.2 28-Dec-2021  rillig tests/make: use tabs instead of spaces for indentation
 1.1 28-Dec-2021  rillig tests/make: document inconsistencies between '!=' and '::!='

Found while trying to make the error messages from Cmd_Exec more
detailed.
 1.5.2.2 02-Aug-2025  perseant Sync with HEAD
 1.5.2.1 01-Jul-2024  perseant Sync with HEAD.
 1.35 16-Jun-2025  rillig make: in a warning without location information, print the stack trace

Without further context, a warning like the following is hard to track
back:

> nbmake[4]: warning: Invalid character " " in variable name
> "if ,"LSAN_OPTIONS=""
 1.34 30-Mar-2025  rillig make: add details to error message for the "::=" modifier

The previous error message about a bad modifier ":" was not helpful, as
the strcspn call stopped immediately due to the modifier starting with
the separater character ":". The previous error message also didn't
reveal that the "parse error" was due to the expression name being
empty.
 1.33 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.32 29-Mar-2025  rillig make: add more details to error message about unfinished modifier

These details allow to quickly see the place where the syntax error is,
based on the surrounding lines from the stack trace.
 1.31 29-Mar-2025  rillig make: in stack traces from target commands, add the command level

A target can contain several commands, and these commands are likely to
contain the same expressions. To distinguish them, add one more line to
the stack trace, to narrow down the source of the error.
 1.30 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.29 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.28 20-Jul-2024  rillig make: don't run erroneous commands in compat mode

When there is a parse or evaluation error in an expression that becomes
part of the command, don't run that command, as the result of the failed
evaluation typically contains garbage characters. Skip the remaining
commands from that target as well, as they may depend on the erroneous
command.
 1.27 09-Jul-2024  rillig make: error out on parse/evaluation errors in shell commands

The expression ${VAR:X} has an unknown modifier ':X'. Previously, this
expression errored out when the expression was evaluated at parse time,
but not when the expression was evaluated when generating the commands
to bring a target up to date. The errors were previously reported, they
didn't affect the exit status, though.

Now, errors in expressions are handled in the same way, regardless of
the time at which they are evaluated.
 1.26 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.25 04-Jul-2024  rillig make: error out on the "Bad modifier" error message

Previously, the "Bad modifier" error message did not affect make's exit
status. As a side effect, this kind of error now gets more context
information.
 1.24 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.23 30-Jun-2024  rillig make: error out on some more syntax errors

Previously, these errors only produced a message on stderr. They only
affected make's exit status when they were evaluated at parse time, but
not when evaluating the commands for a specific target right before
executing them.

The affected syntax errors are:
* invalid regular expressions in the ':C' modifier
* out-of-range references to regex groups in the ':C' modifier
* unfinished modifiers
 1.22 30-Jun-2024  rillig make: sync error handling between '!=' assignment and '::!=' modifier
 1.21 30-Jun-2024  rillig make: add detailed exit status to message for failed sub-commands

Several commands communicate via the exit status and not only
distinguish between zero and non-zero, so make this information
available to ease investigations.

The command "false" is not guaranteed to exit with a consistent status,
so use "(exit 13)" instead in the tests, to keep these tests portable
across different operating systems. The exit status 127 is required for
a shell that cannot find a command, so keep that one.
 1.20 20-Apr-2024  rillig branches: 1.20.2;
make: provide more context information for parse/evaluate errors
 1.19 07-Jan-2024  rillig tests/make: test the '::=' modifier in target scope
 1.18 29-Dec-2023  rillig tests/make: test the '::=' assignment modifier
 1.17 30-Nov-2021  rillig tests/make: convert tests for modifier '::=' to parse time

This puts the expected result of the expressions closer to the
expressions, making the tests self-contained.

The error messages that used to produce trailing spaces have been fixed
in var.c 1.853 from 2021-02-23. The error message now encloses the
variable name in quotes.
 1.16 06-Apr-2021  rillig make: reduce verbosity of the -dv debug logging for standard cases

The verbosity was already removed from LogBeforeApply, now it is
consistent between LogBeforeApply and LogAfterApply.
 1.15 05-Apr-2021  rillig make: in debug log, add space between scope and variable name

Without this space, the debug log looked more like line noise, even
though the only punctuation was a single innocent ':'. From a make
user's perspective, the variable name is a word of its own and should
not be visually glued to its namespace.
 1.14 05-Apr-2021  rillig make: omit unnecessary details from -dv debug log

When an expression is based on a defined variable, it does not matter
whether the evaluation mode is "eval" or "eval-defined", therefore omit
these details to reduce confusion.
 1.13 05-Apr-2021  rillig make: be more verbose in -dv debug logging

The previous log output was too brief to be understandable. Give more
hints by describing each part of the expression when evaluating a
modifier. Distinguish between parse-only mode and eval mode since in
parse-only mode most of the details are irrelevant.
 1.12 03-Apr-2021  rillig make: remove VarFlags from debug logging

Before the introduction of ExprDefined, VarFlags contained whether the
expression was defined or not, which was useful to know since the final
value of the expression depends on this information. The other VarFlags
do not influence the evaluation, so there is no point logging them.
 1.11 15-Mar-2021  rillig make: fix double varname expansion in the variable modifier '::='

This is an edge case that doesn't occur in practice since pretty much
nobody dares to use variable names that contain an actual '$' in their
name. This is not about the fairly common VAR.${param} (as written in
the makefile), but instead about the variable whose name is literally
'VAR.${param}'.

The test demonstrates that after the fix, the variable name is taken
exactly as-is for the simple assignment modifier '::='. There are no
such tests for the modifiers '::+=', '::!=' and '::?=', but that's ok.
The code in ApplyModifier_Assign would look assymetrical and suspicious
enough if one of these modifiers would expand its variable name and the
others wouldn't.
 1.10 15-Mar-2021  rillig tests/make: demonstrate that the modifier '::=' expands the varname
 1.9 23-Feb-2021  rillig make: improve error message for bad modifier in variable expression

The improvement is especially noteable for variable expressions based on
the empty variable, see moderrs.exp:103.
 1.8 23-Feb-2021  rillig make: improve error message for unknown modifier

Back in 1995, the modifiers were all single-character, and it made sense
to print only the first character. Nowadays, with ':S', ':@var@...@',
'::=' and several others, a little more context is useful to see where
the exact error is. The actual modifier is still guessed, and the guess
may be wrong as soon as backslashes get involved, but it is still better
than before.
 1.7 23-Feb-2021  rillig make: add quotes around variable name in an error message
 1.6 18-Oct-2020  rillig make(1): explain existing tests for the ::= assignment modifiers
 1.5 25-Aug-2020  rillig make(1): fix error message for ::!= modifier with shell error

It's just too easy to confuse st->val and val.
 1.4 25-Aug-2020  rillig make(1): add test for ::!= modifier with shell error
 1.3 25-Aug-2020  rillig make(1): move test for the ::= modifier to varmod-assign
 1.2 16-Aug-2020  rillig make(1): move tests for the :gmtime and ::= modifiers to separate files
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.20.2.2 02-Aug-2025  perseant Sync with HEAD
 1.20.2.1 01-Jul-2024  perseant Sync with HEAD.
 1.28 30-Mar-2025  rillig make: add details to error message for the "::=" modifier

The previous error message about a bad modifier ":" was not helpful, as
the strcspn call stopped immediately due to the modifier starting with
the separater character ":". The previous error message also didn't
reveal that the "parse error" was due to the expression name being
empty.
 1.27 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.26 29-Mar-2025  rillig make: add more details to error message about unfinished modifier

These details allow to quickly see the place where the syntax error is,
based on the surrounding lines from the stack trace.
 1.25 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.24 20-Jul-2024  rillig make: don't run erroneous commands in compat mode

When there is a parse or evaluation error in an expression that becomes
part of the command, don't run that command, as the result of the failed
evaluation typically contains garbage characters. Skip the remaining
commands from that target as well, as they may depend on the erroneous
command.
 1.23 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.22 30-Jun-2024  rillig make: error out on some more syntax errors

Previously, these errors only produced a message on stderr. They only
affected make's exit status when they were evaluated at parse time, but
not when evaluating the commands for a specific target right before
executing them.

The affected syntax errors are:
* invalid regular expressions in the ':C' modifier
* out-of-range references to regex groups in the ':C' modifier
* unfinished modifiers
 1.21 30-Jun-2024  rillig make: add detailed exit status to message for failed sub-commands

Several commands communicate via the exit status and not only
distinguish between zero and non-zero, so make this information
available to ease investigations.

The command "false" is not guaranteed to exit with a consistent status,
so use "(exit 13)" instead in the tests, to keep these tests portable
across different operating systems. The exit status 127 is required for
a shell that cannot find a command, so keep that one.
 1.20 20-Apr-2024  rillig branches: 1.20.2;
make: provide more context information for parse/evaluate errors
 1.19 07-Jan-2024  rillig tests/make: test the '::=' modifier in target scope
 1.18 31-Dec-2023  rillig tests/make: finish incomplete sentence in test for assignment modifiers
 1.17 29-Dec-2023  rillig tests/make: test the '::=' assignment modifier
 1.16 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.15 09-Feb-2022  rillig make: fix mistakes, spelling and typos in comments and manual page

No binary change for -DNDEBUG.
 1.14 05-Dec-2021  rillig tests/make: make test for '::=' easier to read, fix comments
 1.13 30-Nov-2021  rillig tests/make: convert tests for modifier '::=' to parse time

This puts the expected result of the expressions closer to the
expressions, making the tests self-contained.

The error messages that used to produce trailing spaces have been fixed
in var.c 1.853 from 2021-02-23. The error message now encloses the
variable name in quotes.
 1.12 15-Mar-2021  rillig make: fix double varname expansion in the variable modifier '::='

This is an edge case that doesn't occur in practice since pretty much
nobody dares to use variable names that contain an actual '$' in their
name. This is not about the fairly common VAR.${param} (as written in
the makefile), but instead about the variable whose name is literally
'VAR.${param}'.

The test demonstrates that after the fix, the variable name is taken
exactly as-is for the simple assignment modifier '::='. There are no
such tests for the modifiers '::+=', '::!=' and '::?=', but that's ok.
The code in ApplyModifier_Assign would look assymetrical and suspicious
enough if one of these modifiers would expand its variable name and the
others wouldn't.
 1.11 15-Mar-2021  rillig tests/make: demonstrate that the modifier '::=' expands the varname
 1.10 14-Feb-2021  rillig make: add test for ::= modifier enclosed in parentheses
 1.9 22-Jan-2021  rillig make(1): remove outdated comment from test

It was fixed in var.c 1.472 from 2020-08-25.
 1.8 18-Oct-2020  rillig make(1): add test for the ::+= modifier expanding its right-hand side
 1.7 18-Oct-2020  rillig make(1): explain existing tests for the ::= assignment modifiers
 1.6 25-Aug-2020  rillig make(1): fix error message for ::!= modifier with shell error

It's just too easy to confuse st->val and val.
 1.5 25-Aug-2020  rillig make(1): add test for ::!= modifier with shell error
 1.4 25-Aug-2020  rillig make(1): move test for the ::= modifier to varmod-assign
 1.3 25-Aug-2020  rillig make(1): explain the varmod-assign test

I have no idea why I added the mod-assign-nested test. It is completely
boring and doesn't provide any insight.
 1.2 16-Aug-2020  rillig make(1): move tests for the :gmtime and ::= modifiers to separate files
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.20.2.2 02-Aug-2025  perseant Sync with HEAD
 1.20.2.1 01-Jul-2024  perseant Sync with HEAD.
 1.14 29-Dec-2023  rillig make: simplify debug message for the ':@var@...@' modifier

The previous variant was hard to understand.
 1.13 23-Aug-2022  rillig make: revert parsing of modifier parts (since 2022-08-08)

The modifier ':@var@body@' parses the body in parse-only mode and later
uses Var_Subst on it, in which each literal '$' must be written as '$$'.

Trying to parse the loop body using Var_Parse treated the text
'$${var:-0}' as a single '$' followed by the expression '${var:-0}',
wrongly complaining about the 'Unknown modifier "-0"'.

Found by sjg.
 1.12 08-Aug-2022  rillig make: fix parsing of modifiers containing unbalanced subexpressions
 1.11 26-Mar-2022  rillig make: avoid trailing whitespace in debug log for variables

Since trailing whitespace is invisible, describe the variable value in
words to make it visible.
 1.10 26-Mar-2022  rillig make: add space after colon in debug logging for variables

These log messages are intended for human interpretation, so don't make
them unnecessarily hard to read.
 1.9 20-Nov-2021  rillig make: use correct plural form in debug message
 1.8 05-Apr-2021  rillig make: in debug log, add space between scope and variable name

Without this space, the debug log looked more like line noise, even
though the only punctuation was a single innocent ':'. From a make
user's perspective, the variable name is a word of its own and should
not be visually glued to its namespace.
 1.7 05-Apr-2021  rillig make: be more verbose in -dv debug logging

The previous log output was too brief to be understandable. Give more
hints by describing each part of the expression when evaluating a
modifier. Distinguish between parse-only mode and eval mode since in
parse-only mode most of the details are irrelevant.
 1.6 03-Apr-2021  rillig make: remove VarFlags from debug logging

Before the introduction of ExprDefined, VarFlags contained whether the
expression was defined or not, which was useful to know since the final
value of the expression depends on this information. The other VarFlags
do not influence the evaluation, so there is no point logging them.
 1.5 15-Mar-2021  rillig make: change debug log for variable evaluation flags to lowercase

This makes them easier distinguishable from variable names since the
latter are usually uppercase.

No functional change outside debug mode.
 1.4 15-Feb-2021  rillig make: rename ExprDefined constants for debug logging
 1.3 28-Dec-2020  rillig make(1): replace global preserveUndefined with VARE_KEEP_UNDEF

Controlling the expansion of variable expressions using a global
variable and a VARE flag was inconsistent.

Converting the global variable into a flag had to prerequisites:

1. The unintended duplicate variable assignment had to be fixed, as
done in parse.c 1.520 from 2020-12-27. Without this fix, it would have
been necessary to add more flags to Var_Exists and Var_SetWithFlags, and
this would have become too complex.

2. There had to be a unit test demonstrating that VARE_KEEP_DOLLAR only
applies to the top-level expression and is not passed to the
subexpressions, while VARE_KEEP_UNDEF applies to all subexpressions as
well. This test is in var-op-expand.mk 1.10 from 2020-12-28, at least
for the ':@word@' modifier. In ParseModifierPartSubst, VARE_KEEP_UNDEF
is not passed down either, in the same way.
 1.2 08-Nov-2020  rillig make(1): add test demonstrating the :D modifier with := assignments
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.16 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.15 02-Nov-2023  rillig make: clean up comments

No functional change.
 1.14 02-Nov-2023  rillig make: sync comments with the extracted ParseModifier_Match

No functional change.
 1.13 24-Aug-2022  rillig make: fix out-of-bounds read when parsing the ':D' modifier

Since 2000-04-29, when the ':D' and ':U' modifiers were added.
 1.12 30-Nov-2021  rillig tests/make: test and document .MAKE.SAVE_DOLLARS and ':='
 1.11 11-Apr-2021  rillig make: clean up remaining references to VarEvalFlags

VarEvalFlags has been replaced with VarEvalMode. There were some
comments and tests that still referred to the old names.

No functional change.
 1.10 15-Mar-2021  rillig make: replace enum bit-field with struct bit-field for VarEvalFlags

This makes the code easier to read, especially in var.c. It also makes
debugging sessions easier since some debuggers don't show enum
bit-fields symbolically as soon as more than one bit is set.

The code outside var.c is basically unchanged, except that instead of
passing the individual flags, there are 4 predefined evaluation modes.
These suffice for all practical use cases. Only in the implementation
deep inside var.c, the value of the flags keepDollar and keepUndef
differs.

There is no way of passing the struct to EnumFlags_ToString, which means
the ToString function has to be spelled out explicitly. This allows for
fine-tuning the representation in the debug log, to reduce the amount of
uppercae letters.

No functional change.
 1.9 12-Nov-2020  rillig make(1): fix tests varmod-defined and varmod-loop regarding dollars

Some derived versions of NetBSD's make set .MAKE.SAVE_DOLLARS to no. In
these versions, running the tests would fail. Therefore better set
.MAKE.SAVE_DOLLARS to yes explicitly as far as necessary.

Suggested by sjg.
 1.8 08-Nov-2020  rillig make(1): add test demonstrating the :D modifier with := assignments
 1.7 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.6 29-Sep-2020  rillig make(1): add test for using the :D variable modifier as comment
 1.5 12-Sep-2020  rillig make(1): add tests for combining the :D and :U variable modifiers
 1.4 03-Sep-2020  rillig make(1): add tests for the :D and :U modifiers

This prepares a refactoring for ApplyModifier_Defined.
 1.3 25-Aug-2020  rillig make(1): add test for the :D modifier
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.34 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.33 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.32 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.31 29-Mar-2025  rillig make: stop parsing after seeing an unknown modifier in an expression

Previously, after an expression such as ${VAR:Z::::}, make detected the
unknown modifier ":Z" and then continued parsing, which produced
unnecessary follow-up error messages. It was also necessary to
distinguish the error cases when logging the result of an applied
modifier in -dv mode.

Unify the error handling cases of a syntax error, an evaluation error
and an unknown modifier, to avoid the unnecessary follow-up error
messages.

The test in varmod-edge.mk now produces ":}" from the erroneous
expression, which may be misleading and thus will be looked at in a
follow-up commit.

The general idea of this patch was reviewed by sjg, I made a few
nonsubstantial changes after the review.
 1.30 29-Mar-2025  rillig make: add more details to error message about unfinished modifier

These details allow to quickly see the place where the syntax error is,
based on the surrounding lines from the stack trace.
 1.29 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.28 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.27 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.26 09-Jul-2024  rillig make: error out on syntax errors in ':M' and ':N' modifiers

More than a year ago, the warning has been added. Now it has been
promoted to an error.
 1.25 06-Jul-2024  rillig make: error out on a matching malformed matching pattern '[['
 1.24 06-Jul-2024  rillig tests/make: clean up tests

Prefer "expect+X" directives to be above the code generating them,
instead of "expect-X" directives below the code.

In varmod-edge.mk, separate the tests, as the common loop does not pull
its weight.
 1.23 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.22 05-Jul-2024  rillig make: error out on unclosed expressions during parse time

In exchange, this adds location information.

For unnamed expressions, the value is no longer printed. This will be
added back in a follow-up commit.
 1.21 05-Jul-2024  rillig tests/make: add expected messages for "Unclosed expression"
 1.20 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.19 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.18 30-Jun-2024  rillig make: error out on some more syntax errors

Previously, these errors only produced a message on stderr. They only
affected make's exit status when they were evaluated at parse time, but
not when evaluating the commands for a specific target right before
executing them.

The affected syntax errors are:
* invalid regular expressions in the ':C' modifier
* out-of-range references to regex groups in the ':C' modifier
* unfinished modifiers
 1.17 20-Apr-2024  rillig branches: 1.17.2;
make: provide more context information for parse/evaluate errors
 1.16 19-Nov-2023  rillig make: replace 'variable expression' with 'expression' in diagnostics
 1.15 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.14 23-Feb-2021  rillig make: improve error message for unclosed modifier

Replace "variable specification" with the more modern "variable
expression", reduce the number of parentheses, output more than a single
character for modifiers, make it obvious that in expressions such as
${:Serror}, the "" means a variable name.
 1.13 23-Feb-2021  rillig make: improve error message for unknown modifier

Back in 1995, the modifiers were all single-character, and it made sense
to print only the first character. Nowadays, with ':S', ':@var@...@',
'::=' and several others, a little more context is useful to see where
the exact error is. The actual modifier is still guessed, and the guess
may be wrong as soon as backslashes get involved, but it is still better
than before.
 1.12 23-Feb-2021  rillig make: add quotes around variable name in an error message
 1.11 22-Feb-2021  rillig make: add test for confusing double space in error message
 1.10 20-Dec-2020  rillig make(1): error out on unknown variable modifiers at parse time

Before, make printed an "error message" that did not include the word
error and thus was not easily identified as such. This "error message"
also did not influence the exit status in the default mode but only in
-dL mode. The error message also didn't include any line number
information and was thus rude.
 1.9 20-Dec-2020  rillig make(1): include line numbers in output of test varmod-edge.mk

Suppressing the line numbers does not provide much benefit, given that
the test file doesn't change often.
 1.8 08-Aug-2020  rillig make(1): improve error message in case of unfinished modifiers

The previous error message "Unclosed substitution" was wrong for several
reasons.

It is not about "unclosed", but about "unfinished" since in the
:@var@...@ modifier the missing '@' does not really close anything.

The word "substitution" may have originated in a time where :S and
:from=to were the only modifiers, and these were indeed substitutions,
but several other modifiers aren't.

The :S and :C modifiers allow an arbitrary delimiter, therefore it is
helpful to enclose the delimiter in quotes, just in case someone chooses
')' or '{' or even ' ' as delimiter.
 1.7 01-Aug-2020  rillig make(1): improve output grouping in varmod-edge test

The generated error messages are now closer to the test cases that
produce them. To keep the expected output stable, the line numbers are
omitted from the .info directives.
 1.6 01-Aug-2020  rillig make(1): add test for ${VAR::::}

It's a bit unrealistic, but at least there are good diagnostics.
 1.5 01-Aug-2020  rillig make(1): add test for empty modifier list after colon

This is a good candidate for becoming an error in strict mode.
Either write ${VAR} or write ${VAR:modifiers}, but not half-baked.
 1.4 02-Dec-2019  rillig branches: 1.4.4;
Add more tests for variable modifiers in make.
 1.3 30-Nov-2019  rillig Demonstrate some more edge cases for the :M modifier
 1.2 30-Nov-2019  rillig Add another unit test for the :M modifier
 1.1 30-Nov-2019  rillig Add unit tests for variable modifiers like :M and :N
 1.4.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.4.4.1 02-Dec-2019  martin file varmod-edge.exp was added on branch phil-wifi on 2020-04-08 14:09:17 +0000
 1.17.2.2 02-Aug-2025  perseant Sync with HEAD
 1.17.2.1 01-Jul-2024  perseant Sync with HEAD.
 1.37 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.36 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.35 29-Mar-2025  rillig make: stop parsing after seeing an unknown modifier in an expression

Previously, after an expression such as ${VAR:Z::::}, make detected the
unknown modifier ":Z" and then continued parsing, which produced
unnecessary follow-up error messages. It was also necessary to
distinguish the error cases when logging the result of an applied
modifier in -dv mode.

Unify the error handling cases of a syntax error, an evaluation error
and an unknown modifier, to avoid the unnecessary follow-up error
messages.

The test in varmod-edge.mk now produces ":}" from the erroneous
expression, which may be misleading and thus will be looked at in a
follow-up commit.

The general idea of this patch was reviewed by sjg, I made a few
nonsubstantial changes after the review.
 1.34 29-Mar-2025  rillig make: add more details to error message about unfinished modifier

These details allow to quickly see the place where the syntax error is,
based on the surrounding lines from the stack trace.
 1.33 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.32 11-Jan-2025  rillig tests/make: force correct order of expected messages
 1.31 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.30 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.29 09-Jul-2024  rillig make: error out on syntax errors in ':M' and ':N' modifiers

More than a year ago, the warning has been added. Now it has been
promoted to an error.
 1.28 06-Jul-2024  rillig tests/make: sync a comment with reality
 1.27 06-Jul-2024  rillig make: error out on a matching malformed matching pattern '[['
 1.26 06-Jul-2024  rillig tests/make: clean up tests

Prefer "expect+X" directives to be above the code generating them,
instead of "expect-X" directives below the code.

In varmod-edge.mk, separate the tests, as the common loop does not pull
its weight.
 1.25 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.24 05-Jul-2024  rillig make: error out on unclosed expressions during parse time

In exchange, this adds location information.

For unnamed expressions, the value is no longer printed. This will be
added back in a follow-up commit.
 1.23 05-Jul-2024  rillig tests/make: add expected messages for "Unclosed expression"
 1.22 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.21 30-Jun-2024  rillig make: error out on some more syntax errors

Previously, these errors only produced a message on stderr. They only
affected make's exit status when they were evaluated at parse time, but
not when evaluating the commands for a specific target right before
executing them.

The affected syntax errors are:
* invalid regular expressions in the ':C' modifier
* out-of-range references to regex groups in the ':C' modifier
* unfinished modifiers
 1.20 20-Apr-2024  rillig branches: 1.20.2;
make: provide more context information for parse/evaluate errors
 1.19 19-Nov-2023  rillig make: replace 'variable expression' with 'expression' in diagnostics
 1.18 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.17 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.16 23-Feb-2021  rillig make: improve error message for unclosed modifier

Replace "variable specification" with the more modern "variable
expression", reduce the number of parentheses, output more than a single
character for modifiers, make it obvious that in expressions such as
${:Serror}, the "" means a variable name.
 1.15 23-Feb-2021  rillig make: add quotes around variable name in an error message
 1.14 22-Feb-2021  rillig make: add test for confusing double space in error message
 1.13 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.12 08-Aug-2020  rillig make(1): fixup for "Unfinished modifier"
 1.11 01-Aug-2020  rillig make(1): improve output grouping in varmod-edge test

The generated error messages are now closer to the test cases that
produce them. To keep the expected output stable, the line numbers are
omitted from the .info directives.
 1.10 01-Aug-2020  rillig make(1): add test for ${VAR::::}

It's a bit unrealistic, but at least there are good diagnostics.
 1.9 01-Aug-2020  rillig make(1): add test for empty modifier list after colon

This is a good candidate for becoming an error in strict mode.
Either write ${VAR} or write ${VAR:modifiers}, but not half-baked.
 1.8 19-Jul-2020  rillig make(1): rename VarGetPattern to ParseModifierPart
 1.7 27-Apr-2020  christos Adjust test for the new behavior: % on hls and no % on the rhs does not
prepend the lhs to the rhs.
 1.6 02-Dec-2019  rillig branches: 1.6.4;
Add more tests for variable modifiers in make.
 1.5 01-Dec-2019  rillig Fix out-of-bounds read in Str_Match.
 1.4 30-Nov-2019  rillig Demonstrate some more edge cases for the :M modifier
 1.3 30-Nov-2019  rillig Fix unit test for edge case in :M modifier
 1.2 30-Nov-2019  rillig Add another unit test for the :M modifier
 1.1 30-Nov-2019  rillig Add unit tests for variable modifiers like :M and :N
 1.6.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.6.4.1 02-Dec-2019  martin file varmod-edge.mk was added on branch phil-wifi on 2020-04-08 14:09:17 +0000
 1.20.2.2 02-Aug-2025  perseant Sync with HEAD
 1.20.2.1 01-Jul-2024  perseant Sync with HEAD.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 03-Nov-2020  rillig make(1): clean up unit tests
 1.3 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.2 16-Aug-2020  rillig make(1): move tests for the :gmtime and ::= modifiers to separate files
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 20-Dec-2020  rillig make(1): add tests for variable modifiers on trailing slashes
 1.2 23-Aug-2020  rillig make(1): move tests for :H :E :R :T into separate files
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 20-Dec-2020  rillig make(1): add tests for variable modifiers on trailing slashes
 1.3 23-Aug-2020  rillig make(1): move tests for :H :E :R :T into separate files
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.24 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.23 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.22 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.21 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.20 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.19 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.18 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.17 20-Apr-2024  rillig branches: 1.17.2;
make: provide more context information for parse/evaluate errors
 1.16 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.15 09-May-2023  rillig tests/make: clean up tests for ':gmtime' and ':localtime'
 1.14 09-May-2023  rillig make: allow ':gmtime' and ':localtime' with dynamic argument

This allows ${%Y:L:gmtime=${mtime}} instead of the indirect
${%Y:L:${:Ugmtime=${mtime}}}.

The direct form also prevents any ':' from the nested expression to be
interpreted as a separator, which doesn't matter for the ':gmtime' and
':localtime' modifiers but will prove useful for other modifiers that
follow the same pattern.
 1.13 09-May-2023  rillig tests/make: demonstrate parse bug in :gmtime and :localtime modifiers
 1.12 09-Dec-2021  rillig make: in parse errors, mark whitespace more clearly

This prevents any trailing whitespace from going unnoticed. It also
marks leading whitespace more clearly, as in the examples with the time
value " 1".
 1.11 19-Jan-2021  rillig make(1): fix tests for :gmtime and :localtime for 32-bit time_t

The comparison operator had accidentally been '!=' instead of '=='.

While here, proofread the documentation and add references for where the
32-bit time_t is defined on Linux and FreeBSD.
 1.10 21-Dec-2020  rillig make(1): remove excess newline from parse errors (since 2020-11-01)

For the modifiers :gmtime and :localtime, the excess newline had been
added in var.c 1.631 from 2020-10-31 21:40:20.

For the modifiers :range and :ts, the excess newline had been added in
var.c 1.635 from 2020-11-01 14:36:25.
 1.9 21-Dec-2020  rillig make(1): align tests for :localtime with those for :gmtime

These tests had been almost the same before, now they are as similar as
possible again.
 1.8 21-Dec-2020  rillig make(1): move tests for :gmtime to parse time

It's easier to have both the expressions and the expected values in a
single file. This also allows for flexible handling of multiple
acceptable outputs, in this case for 32-bit time_t.
 1.7 30-Nov-2020  rillig make(1): fix tests for :gmtime and :localtime for 32-bit time_t

https://bugs.freebsd.org/251465
 1.6 31-Oct-2020  rillig make(1): make parsing of the :gmtime and :localtime modifiers stricter

These variable modifiers accept an optional timestamp in seconds, to
select which date to print. This feature is only used very rarely. The
NetBSD build doesn't use it at all, and the FreeBSD build mainly uses
the plain modifiers :gmtime and :localtime, but not their optional
argument :gmtime=1500000000.

Therefore, this change is not going to affect many builds. Those that
are indeed affected had been wrong all the time anyway.

At parse time, these errors stop the build, as intended. After that,
when the actual shell commands of the targets are expanded and run,
these errors don't stop anything, the build just continues as if nothing
had happened. This is a general problem with Var_Parse, see the many
"handle errors" markers in the code. Another problem is that on parse
errors, parsing continues and spits out spurious strings of the form
"mtime" and "ocaltime". This as well is a general problem with error
handling in make.

ok sjg
 1.5 31-Oct-2020  rillig make(1): add more tests for the variable modifier :localtime
 1.4 31-Oct-2020  rillig make(1): add test for :gmtime with space before the number of seconds
 1.3 31-Oct-2020  rillig make(1): add tests for error handling in the :gmtime variable modifier
 1.2 16-Aug-2020  rillig make(1): move tests for the :gmtime and ::= modifiers to separate files
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.17.2.1 02-Aug-2025  perseant Sync with HEAD
 1.27 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.26 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.25 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.24 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.23 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.22 20-Apr-2024  rillig branches: 1.22.2;
make: provide more context information for parse/evaluate errors
 1.21 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.20 19-Oct-2023  rillig tests/make: clean up, explain and reorganize several tests
 1.19 19-Aug-2023  rillig make: clean up comments regarding gmtime/strftime

These two functions are not supposed to be used together, thus it is not
a bug if combining them produces unexpected results.
 1.18 19-Aug-2023  rillig make: work around bugs in gmtime on several platforms
 1.17 19-Aug-2023  rillig tests/make: provide instructions for reproducing bug in gmtime

The test is not enabled because its results differ too much between the
platforms.
 1.16 19-Aug-2023  rillig tests/make: document bug in ':gmtime' with '%s'
 1.15 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.14 10-May-2023  rillig tests/make: clean up comments in tests
 1.13 09-May-2023  rillig tests/make: clean up tests for ':gmtime' and ':localtime'
 1.12 09-May-2023  rillig make: allow ':gmtime' and ':localtime' with dynamic argument

This allows ${%Y:L:gmtime=${mtime}} instead of the indirect
${%Y:L:${:Ugmtime=${mtime}}}.

The direct form also prevents any ':' from the nested expression to be
interpreted as a separator, which doesn't matter for the ':gmtime' and
':localtime' modifiers but will prove useful for other modifiers that
follow the same pattern.
 1.11 09-May-2023  rillig tests/make: demonstrate parse bug in :gmtime and :localtime modifiers
 1.10 19-Jan-2021  rillig make(1): fix tests for :gmtime and :localtime for 32-bit time_t

The comparison operator had accidentally been '!=' instead of '=='.

While here, proofread the documentation and add references for where the
32-bit time_t is defined on Linux and FreeBSD.
 1.9 22-Dec-2020  rillig make(1): fix commit number in tests for :gmtime and :localtime
 1.8 21-Dec-2020  rillig make(1): align tests for :localtime with those for :gmtime

These tests had been almost the same before, now they are as similar as
possible again.
 1.7 21-Dec-2020  rillig make(1): move tests for :gmtime to parse time

It's easier to have both the expressions and the expected values in a
single file. This also allows for flexible handling of multiple
acceptable outputs, in this case for 32-bit time_t.
 1.6 31-Oct-2020  rillig make(1): add more tests for the variable modifier :localtime
 1.5 31-Oct-2020  rillig make(1): add test for :gmtime with space before the number of seconds
 1.4 31-Oct-2020  rillig make(1): add tests for error handling in the :gmtime variable modifier
 1.3 29-Oct-2020  rillig make(1): add test for default time format of the :gmtime modifier
 1.2 16-Aug-2020  rillig make(1): move tests for the :gmtime and ::= modifiers to separate files
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.22.2.1 02-Aug-2025  perseant Sync with HEAD
 1.10 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.9 29-Mar-2025  rillig make: in stack traces from target commands, add the command level

A target can contain several commands, and these commands are likely to
contain the same expressions. To distinguish them, add one more line to
the stack trace, to narrow down the source of the error.
 1.8 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.7 20-Jul-2024  rillig make: don't run erroneous commands in compat mode

When there is a parse or evaluation error in an expression that becomes
part of the command, don't run that command, as the result of the failed
evaluation typically contains garbage characters. Skip the remaining
commands from that target as well, as they may depend on the erroneous
command.
 1.6 09-Jul-2024  rillig make: error out on parse/evaluation errors in shell commands

The expression ${VAR:X} has an unknown modifier ':X'. Previously, this
expression errored out when the expression was evaluated at parse time,
but not when the expression was evaluated when generating the commands
to bring a target up to date. The errors were previously reported, they
didn't affect the exit status, though.

Now, errors in expressions are handled in the same way, regardless of
the time at which they are evaluated.
 1.5 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.4 20-Apr-2024  rillig branches: 1.4.2;
make: provide more context information for parse/evaluate errors
 1.3 23-Feb-2021  rillig make: improve error message for unknown modifier

Back in 1995, the modifiers were all single-character, and it made sense
to print only the first character. Nowadays, with ':S', ':@var@...@',
'::=' and several others, a little more context is useful to see where
the exact error is. The actual modifier is still guessed, and the guess
may be wrong as soon as backslashes get involved, but it is still better
than before.
 1.2 23-Aug-2020  rillig make(1): move tests for :hash :range :localtime into separate files
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4.2.1 02-Aug-2025  perseant Sync with HEAD
 1.6 20-Jul-2024  rillig make: don't run erroneous commands in compat mode

When there is a parse or evaluation error in an expression that becomes
part of the command, don't run that command, as the result of the failed
evaluation typically contains garbage characters. Skip the remaining
commands from that target as well, as they may depend on the erroneous
command.
 1.5 04-Sep-2020  rillig branches: 1.5.8;
make(1): add test for :hash returning ffffffff

In the previous brute force search, it seemed there was no string with
that hash code. That was probably an oversight or a little programming
mistake. Anyway, it's possible to get that hash value, so keep the
example.
 1.4 04-Sep-2020  rillig make(1): extend tests for the :hash variable modifier

The previous test vectors didn't contain any hash with a leading zero.
This could have been a simple programming mistake by using %8x instead
of the intended %08x. Using snprintf wouldn't have been possible anyway
since the hex digits are printed in little-endian order, but without
reversing the bits of each digit. Kind of unusual, but doesn't affect
the distribution of the hashes.
 1.3 23-Aug-2020  rillig make(1): move tests for :hash :range :localtime into separate files
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5.8.1 02-Aug-2025  perseant Sync with HEAD
 1.4 10-Jul-2022  rillig tests/make: extend tests for modifier ':H'
 1.3 20-Dec-2020  rillig make(1): add tests for variable modifiers on trailing slashes
 1.2 23-Aug-2020  rillig make(1): move tests for :H :E :R :T into separate files
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.6 01-Jun-2024  rillig tests/make: test more modifiers and special variables
 1.5 10-Jul-2022  rillig tests/make: extend tests for modifier ':H'
 1.4 20-Dec-2020  rillig make(1): add tests for variable modifiers on trailing slashes
 1.3 23-Aug-2020  rillig make(1): move tests for :H :E :R :T into separate files
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.32 29-Jun-2025  rillig make: if a condition is erroneous, skip the whole .if/.endif
 1.31 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.30 30-Apr-2025  rillig make: fix order of error messages in the ":?" modifier

While here: In Var_Parse, EvalStack_Pop needs to be called before
freeing the short-lived variable, as its name is part of the evaluation
stack.
 1.29 30-Apr-2025  rillig tests/make: demonstrate wrong order of error messages
 1.28 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.27 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.26 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.25 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.24 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.23 05-Jul-2024  rillig make: in error messages, distinguish parsing from evaluating
 1.22 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.21 30-Jun-2024  rillig make: error out on syntax error in conditions in ':?then:else' modifier

The 'Error' function only reports errors but does not affect the exit
status, the 'Parse_Error' function does, while providing more details to
find the cause of the syntax error.
 1.20 20-Apr-2024  rillig branches: 1.20.2;
make: provide more context information for parse/evaluate errors
 1.19 10-Dec-2023  rillig make: remove redundant text from diagnostic about bad '?:' modifier
 1.18 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.17 01-Jul-2023  rillig tests/make: show how to use indirect conditions in the '?:' modifier
 1.16 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.15 18-Feb-2023  rillig tests/make: document why ':?' cannot parse its operands in balanced mode
 1.14 25-Sep-2022  rillig tests/make: reduce trailing whitespace
 1.13 04-Sep-2022  rillig make: add more details to error message for numeric comparison

Before:
String comparison operator must be either == or !=

After:
Comparison with '>=' requires both operands 'no' and '10' to be numeric

Noticed by martin@ in pkgsrc/textproc/py-pygments.
 1.12 03-Mar-2022  rillig make: make debug logging for comparisons less technical
 1.11 11-Jun-2021  rillig tests/make: demonstrate handling of '+' and '*' in modifier ':?'

It doesn't make sense that these two characters are handled differently,
but that's what the current code has been doing for years.
 1.10 19-Apr-2021  rillig make: do not complain when skipping the condition 'no >= 10'

Seen in external/bsd/tmux when building with Clang. See
varmod-ifelse.mk for the detailed story.
 1.9 19-Apr-2021  rillig tests/make: add another example for parsing of the modifier ':?'
 1.8 19-Apr-2021  rillig tests/make: add detailed explanation for error message in conditional
 1.7 19-Apr-2021  rillig make: use straight quotes for error 'Bad conditional expression'

This diagnostic was supposed to be an error, see ApplyModifier_IfElse.

When such an error occurs while the makefiles are read, make stops with
an error, as can be expected. But when such an error occurs later,
after all makefiles have been read, the message is printed but make does
not stop.

In lint mode (-dL), make stops in such a case. I didn't dare to make
this the default behavior, out of fear of breaking existing build
infrastructure, not only in NetBSD or pkgsrc, but also FreeBSD and other
operating systems that use the bmake distribution, generated from the
same source code.
 1.6 19-Apr-2021  rillig tests/make: demonstrate unexpected behavior of the modifier ':?'
 1.5 10-Dec-2020  rillig make(1): add test demonstrating how to defer evaluation in :? modifier
 1.4 12-Nov-2020  rillig make(1): add test for unhandled parse error in :? variable modifier
 1.3 23-Oct-2020  rillig make(1): move tests from cond2.mk to varmod-ifelse.mk (fixup)
 1.2 23-Oct-2020  rillig make(1): move tests from cond2.mk to varmod-ifelse.mk
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.20.2.2 02-Aug-2025  perseant Sync with HEAD
 1.20.2.1 01-Jul-2024  perseant Sync with HEAD.
 1.41 29-Jun-2025  rillig make: if a condition is erroneous, skip the whole .if/.endif
 1.40 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.39 30-Apr-2025  rillig make: fix order of error messages in the ":?" modifier

While here: In Var_Parse, EvalStack_Pop needs to be called before
freeing the short-lived variable, as its name is part of the evaluation
stack.
 1.38 30-Apr-2025  rillig tests/make: demonstrate wrong order of error messages
 1.37 04-Apr-2025  rillig make: fix error message for undefined variable in conditional

Previously, only ${UNDEF} had the proper error message, while
${UNDEF:M*} still produced the wrong "Malformed conditional".
 1.36 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.35 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.34 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.33 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.32 05-Jul-2024  rillig make: in error messages, distinguish parsing from evaluating
 1.31 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.30 30-Jun-2024  rillig make: error out on syntax error in conditions in ':?then:else' modifier

The 'Error' function only reports errors but does not affect the exit
status, the 'Parse_Error' function does, while providing more details to
find the cause of the syntax error.
 1.29 02-Jun-2024  rillig branches: 1.29.2;
make: sync VarEvalMode constant names with their debug log names
 1.28 23-Apr-2024  rillig make: clean up comments, code and tests
 1.27 20-Apr-2024  rillig make: provide more context information for parse/evaluate errors
 1.26 10-Dec-2023  rillig make: remove redundant text from diagnostic about bad '?:' modifier
 1.25 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.24 18-Nov-2023  rillig tests/make: test parsing of the ':?' modifier
 1.23 01-Jul-2023  rillig tests/make: show how to use indirect conditions in the '?:' modifier
 1.22 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.21 18-Feb-2023  rillig tests/make: document why ':?' cannot parse its operands in balanced mode
 1.20 25-Sep-2022  rillig tests/make: reduce trailing whitespace
 1.19 08-May-2022  rillig tests/make: migrate cond1 test to other, more specific tests

The tests in cond1 were a mixture of "everything related to conditions",
and the test cases were heavily dependent on each other, which made them
hard to understand. Move each test case to its corresponding
special-purpose test.
 1.18 15-Jan-2022  rillig tests/make: fix comment in test
 1.17 11-Jun-2021  rillig tests/make: demonstrate handling of '+' and '*' in modifier ':?'

It doesn't make sense that these two characters are handled differently,
but that's what the current code has been doing for years.
 1.16 19-Apr-2021  rillig make: do not complain when skipping the condition 'no >= 10'

Seen in external/bsd/tmux when building with Clang. See
varmod-ifelse.mk for the detailed story.
 1.15 19-Apr-2021  rillig tests/make: add another example for parsing of the modifier ':?'
 1.14 19-Apr-2021  rillig tests/make: add detailed explanation for error message in conditional
 1.13 19-Apr-2021  rillig make: use straight quotes for error 'Bad conditional expression'

This diagnostic was supposed to be an error, see ApplyModifier_IfElse.

When such an error occurs while the makefiles are read, make stops with
an error, as can be expected. But when such an error occurs later,
after all makefiles have been read, the message is printed but make does
not stop.

In lint mode (-dL), make stops in such a case. I didn't dare to make
this the default behavior, out of fear of breaking existing build
infrastructure, not only in NetBSD or pkgsrc, but also FreeBSD and other
operating systems that use the bmake distribution, generated from the
same source code.
 1.12 19-Apr-2021  rillig tests/make: demonstrate unexpected behavior of the modifier ':?'
 1.11 11-Apr-2021  rillig make: clean up remaining references to VarEvalFlags

VarEvalFlags has been replaced with VarEvalMode. There were some
comments and tests that still referred to the old names.

No functional change.
 1.10 15-Mar-2021  rillig make: replace enum bit-field with struct bit-field for VarEvalFlags

This makes the code easier to read, especially in var.c. It also makes
debugging sessions easier since some debuggers don't show enum
bit-fields symbolically as soon as more than one bit is set.

The code outside var.c is basically unchanged, except that instead of
passing the individual flags, there are 4 predefined evaluation modes.
These suffice for all practical use cases. Only in the implementation
deep inside var.c, the value of the flags keepDollar and keepUndef
differs.

There is no way of passing the struct to EnumFlags_ToString, which means
the ToString function has to be spelled out explicitly. This allows for
fine-tuning the representation in the debug log, to reduce the amount of
uppercae letters.

No functional change.
 1.9 25-Jan-2021  rillig make(1): rename struct For to struct ForLoop

This removes the ambiguity whether For_Free is meant to be a
module-exported function or a local function associate with that struct.
Rename the affected functions as well.
 1.8 10-Dec-2020  rillig make(1): document limitations of deferred '$' in ':?' modifier
 1.7 10-Dec-2020  rillig make(1): add test demonstrating how to defer evaluation in :? modifier
 1.6 12-Nov-2020  rillig make(1): add test for unhandled parse error in :? variable modifier
 1.5 23-Oct-2020  rillig make(1): move tests from cond2.mk to varmod-ifelse.mk
 1.4 09-Oct-2020  rillig make(1): add test for parsing the :? variable modifier
 1.3 02-Oct-2020  rillig make(1): add tests for parsing and exporting variables

Once again, there are a few surprises deeply hidden inside the edge
cases.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.29.2.2 02-Aug-2025  perseant Sync with HEAD
 1.29.2.1 01-Jul-2024  perseant Sync with HEAD.
 1.36 30-Mar-2025  rillig make: if there is an error in the items of a .for loop, don't iterate
 1.35 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.34 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.33 29-Mar-2025  rillig make: stop parsing after seeing an unknown modifier in an expression

Previously, after an expression such as ${VAR:Z::::}, make detected the
unknown modifier ":Z" and then continued parsing, which produced
unnecessary follow-up error messages. It was also necessary to
distinguish the error cases when logging the result of an applied
modifier in -dv mode.

Unify the error handling cases of a syntax error, an evaluation error
and an unknown modifier, to avoid the unnecessary follow-up error
messages.

The test in varmod-edge.mk now produces ":}" from the erroneous
expression, which may be misleading and thus will be looked at in a
follow-up commit.

The general idea of this patch was reviewed by sjg, I made a few
nonsubstantial changes after the review.
 1.32 29-Mar-2025  rillig make: add details about indirect modifiers to the stack traces

Previously, the error message "Unfinished modifier (',' missing)" from
moderrs.mk didn't provide enough context to understand where and why the
comma was missing.
 1.31 31-Oct-2024  rillig make: in the debug log, always qualify line number with filename

Previously, to find out the filename corresponding to a line number from
a 'Parsing' line, it was necessary to find the preceding
'SetFilenameVars' line, which was unnecessarily time-consuming and
distracting.

The 'filename:line' format matches the one used in PrintStackTrace, and
it differs from the one used in PrintLocation, as the former format is
more common in other tools.

Most of the affected unit tests only use the 'Parsing' lines to give
additional context to their debug log, so no structural changes there.
 1.30 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.29 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.28 20-Apr-2024  rillig branches: 1.28.2;
make: provide more context information for parse/evaluate errors
 1.27 04-Feb-2024  rillig make: do not evaluate indirect modifiers in parse-only mode

Discovered by sjg.
 1.26 04-Feb-2024  rillig make: in parse-only mode, don't evaluate modifiers

Previously, the ':S', ':ts', ':tA' and ':from=to' modifiers were
evaluated in parse-only mode, unnecessarily. This is only noticeable
when an indirect modifier is evaluated in parse-only mode, which is
another bug that will be fixed in a follow-up commit.
 1.25 04-Feb-2024  rillig tests/make: extend test for wrong evaluation in parse-only mode
 1.24 04-Feb-2024  rillig tests/make: indirect modifiers are evaluated in parse-only mode

Found by sjg@.
 1.23 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.22 26-Mar-2022  rillig make: avoid trailing whitespace in debug log for variables

Since trailing whitespace is invisible, describe the variable value in
words to make it visible.
 1.21 08-Jan-2022  rillig make: fix reported line numbers of continuation lines (since 2002)

Previously, multi-line directives like '.info' or '.error' reported the
line number of their last line instead of their first line, which is
more usual. This also affected the debug log from '-dp'.
 1.20 28-Dec-2021  rillig make: make debug logging a bit more human-friendly

The previous log format "ParseReadLine (%d): '%s'" focused on the
implementation, it was not immediately obvious to a casual reader that
the number in parentheses was the line number. Additionally, having
both a colon and quotes in a log message is uncommon. The quotes have
been added in parse.c 1.127 from 2007-01-01.

The new log format "Parsing line %d: %s" is meant to be easier readable
by humans. The quotes are not needed since ParseReadLine always strips
trailing whitespace, leaving no room for ambiguities. The other log
messages follow common punctuation rules, which makes the beginning of
the line equally unambiguous. Before var.c 1.911 from 2021-04-05,
variable assignments were logged with the format "%s:%s = %s", without a
space after the colon.
 1.19 20-Nov-2021  rillig make: use correct plural form in debug message
 1.18 10-Apr-2021  rillig make: reduce debug logging and memory allocation for ${:U...}

Expressions of the form ${:U...} are often generated by .for loops.
Since these expressions are not generated knowingly by the make user, do
not fill the debug log with them since that would interrupt the normal
reading flow of the -dv log for nested expressions.
 1.17 05-Apr-2021  rillig make: in debug log, add space between scope and variable name

Without this space, the debug log looked more like line noise, even
though the only punctuation was a single innocent ':'. From a make
user's perspective, the variable name is a word of its own and should
not be visually glued to its namespace.
 1.16 05-Apr-2021  rillig make: be more verbose in -dv debug logging

The previous log output was too brief to be understandable. Give more
hints by describing each part of the expression when evaluating a
modifier. Distinguish between parse-only mode and eval mode since in
parse-only mode most of the details are irrelevant.
 1.15 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.14 03-Apr-2021  rillig make: remove VarFlags from debug logging

Before the introduction of ExprDefined, VarFlags contained whether the
expression was defined or not, which was useful to know since the final
value of the expression depends on this information. The other VarFlags
do not influence the evaluation, so there is no point logging them.
 1.13 15-Mar-2021  rillig make: change debug log for variable evaluation flags to lowercase

This makes them easier distinguishable from variable names since the
latter are usually uppercase.

No functional change outside debug mode.
 1.12 23-Feb-2021  rillig make: improve error message for unknown modifier

Back in 1995, the modifiers were all single-character, and it made sense
to print only the first character. Nowadays, with ':S', ':@var@...@',
'::=' and several others, a little more context is useful to see where
the exact error is. The actual modifier is still guessed, and the guess
may be wrong as soon as backslashes get involved, but it is still better
than before.
 1.11 15-Feb-2021  rillig make: rename ExprDefined constants for debug logging
 1.10 14-Feb-2021  rillig make: update line numbers in expected test output

The documentation from the previous commit added a few lines.
 1.9 14-Feb-2021  rillig make: add more tests for edge cases in evaluating variable expressions

As a preparation for refactoring the code around variable expressions,
there need to be a few tests for indirect variable modifiers since these
were not covered before.

Indirect modifiers may include ':ts' and ':tW', which change the
interpretation of the variable expression in small details. The scope
of these changes is limited to the indirect modifier, any evaluations
outside this indirect modifier are unaffected.

The changes to the .exp file are mostly line number changes, plus a
demonstration of a newly found bug, where an expression is evaluated
successfully despite producing a parse error.
 1.8 02-Feb-2021  rillig make: replace VarExprFlags with VarExprStatus

The combination of !VEF_UNDEF && VEF_DEF was not possible, which made it
rather strange to model this state as a bit set.

The only functional change is the renamed constants in the debug output.

Using ENUM_VALUE_RTTI_2 felt like overengineering since it's harder to
understand than a simple array of names.
 1.7 28-Dec-2020  rillig make(1): replace global preserveUndefined with VARE_KEEP_UNDEF

Controlling the expansion of variable expressions using a global
variable and a VARE flag was inconsistent.

Converting the global variable into a flag had to prerequisites:

1. The unintended duplicate variable assignment had to be fixed, as
done in parse.c 1.520 from 2020-12-27. Without this fix, it would have
been necessary to add more flags to Var_Exists and Var_SetWithFlags, and
this would have become too complex.

2. There had to be a unit test demonstrating that VARE_KEEP_DOLLAR only
applies to the top-level expression and is not passed to the
subexpressions, while VARE_KEEP_UNDEF applies to all subexpressions as
well. This test is in var-op-expand.mk 1.10 from 2020-12-28, at least
for the ':@word@' modifier. In ParseModifierPartSubst, VARE_KEEP_UNDEF
is not passed down either, in the same way.
 1.6 27-Dec-2020  rillig make(1): split test for indirect modifiers into paragraphs
 1.5 27-Dec-2020  rillig make(1): add tests for parsing indirect modifiers in nested expressions
 1.4 27-Dec-2020  rillig make(1): remove dead code from ApplyModifiersIndirect

At that point, the expression can never be varUndefined. At the
beginning of ParseVarnameLong, the expression is initialized to a simple
empty string, and that string is only ever converted to varUndefined at
the very end of Var_Parse.
 1.3 20-Dec-2020  rillig make(1): error out on unknown variable modifiers at parse time

Before, make printed an "error message" that did not include the word
error and thus was not easily identified as such. This "error message"
also did not influence the exit status in the default mode but only in
-dL mode. The error message also didn't include any line number
information and was thus rude.
 1.2 20-Dec-2020  rillig make(1): move tests for indirect modifiers around

The next commit will error out on unknown modifiers and influence the
exit status. The test modmisc.mk contains both parse time tests and run
time tests. To prevent the latter from being run, the parse error is
moved to varmod-indirect.mk, which only contains parse time tests.
 1.1 01-Dec-2020  rillig make(1): add test and tutorial for indirect modifiers
 1.28.2.1 02-Aug-2025  perseant Sync with HEAD
 1.24 30-Mar-2025  rillig make: if there is an error in the items of a .for loop, don't iterate
 1.23 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.22 29-Mar-2025  rillig make: stop parsing after seeing an unknown modifier in an expression

Previously, after an expression such as ${VAR:Z::::}, make detected the
unknown modifier ":Z" and then continued parsing, which produced
unnecessary follow-up error messages. It was also necessary to
distinguish the error cases when logging the result of an applied
modifier in -dv mode.

Unify the error handling cases of a syntax error, an evaluation error
and an unknown modifier, to avoid the unnecessary follow-up error
messages.

The test in varmod-edge.mk now produces ":}" from the erroneous
expression, which may be misleading and thus will be looked at in a
follow-up commit.

The general idea of this patch was reviewed by sjg, I made a few
nonsubstantial changes after the review.
 1.21 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.20 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.19 20-Apr-2024  rillig branches: 1.19.2;
make: provide more context information for parse/evaluate errors
 1.18 04-Feb-2024  rillig make: do not evaluate indirect modifiers in parse-only mode

Discovered by sjg.
 1.17 04-Feb-2024  rillig make: in parse-only mode, don't evaluate modifiers

Previously, the ':S', ':ts', ':tA' and ':from=to' modifiers were
evaluated in parse-only mode, unnecessarily. This is only noticeable
when an indirect modifier is evaluated in parse-only mode, which is
another bug that will be fixed in a follow-up commit.
 1.16 04-Feb-2024  rillig tests/make: extend test for wrong evaluation in parse-only mode
 1.15 04-Feb-2024  rillig tests/make: indirect modifiers are evaluated in parse-only mode

Found by sjg@.
 1.14 19-Nov-2023  rillig tests/make: replace 'variable expressions' with 'expressions'
 1.13 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.12 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.11 15-Jan-2022  rillig tests/make: ensure that the 'expect' comments in tests are correct

Based on tests/usr.bin/xlint/check-expect.lua.

For now, this extra check needs to be run manually.
 1.10 08-Jan-2022  rillig make: fix reported line numbers of continuation lines (since 2002)

Previously, multi-line directives like '.info' or '.error' reported the
line number of their last line instead of their first line, which is
more usual. This also affected the debug log from '-dp'.
 1.9 15-Mar-2021  rillig make: rename ApplyModifiersState to ModChain

The new name accurately describes the structural element that holds such
properties as the separator character and whether the expression value
is considered a single word. The old name ApplyModifiersState was too
long and was meant as a placeholder anyway, when I introduced it in
var.c 1.236 from 2020-07-03.
 1.8 14-Feb-2021  rillig make: add test for indirect ':U' modifier

Unlike ':ts' and ':tW', the effects of ':U' are visible even after the
modifiers from the nested expression have been applied. These subtle
details, like many others, are not documented in the manual page.
 1.7 14-Feb-2021  rillig make: document since when indirect modifiers are supported
 1.6 14-Feb-2021  rillig make: add more tests for edge cases in evaluating variable expressions

As a preparation for refactoring the code around variable expressions,
there need to be a few tests for indirect variable modifiers since these
were not covered before.

Indirect modifiers may include ':ts' and ':tW', which change the
interpretation of the variable expression in small details. The scope
of these changes is limited to the indirect modifier, any evaluations
outside this indirect modifier are unaffected.

The changes to the .exp file are mostly line number changes, plus a
demonstration of a newly found bug, where an expression is evaluated
successfully despite producing a parse error.
 1.5 27-Dec-2020  rillig make(1): split test for indirect modifiers into paragraphs
 1.4 27-Dec-2020  rillig make(1): add tests for parsing indirect modifiers in nested expressions
 1.3 27-Dec-2020  rillig make(1): remove dead code from ApplyModifiersIndirect

At that point, the expression can never be varUndefined. At the
beginning of ParseVarnameLong, the expression is initialized to a simple
empty string, and that string is only ever converted to varUndefined at
the very end of Var_Parse.
 1.2 20-Dec-2020  rillig make(1): move tests for indirect modifiers around

The next commit will error out on unknown modifiers and influence the
exit status. The test modmisc.mk contains both parse time tests and run
time tests. To prevent the latter from being run, the parse error is
moved to varmod-indirect.mk, which only contains parse time tests.
 1.1 01-Dec-2020  rillig make(1): add test and tutorial for indirect modifiers
 1.19.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 30-Sep-2020  rillig make(1): fix bug in evaluation of indirect variable modifiers

Since 2020-09-22, when indirect variable modifiers were applied to a
variable expression based on an undefined variable, these modifiers did
not change the state of a variable expression from undefined to defined.
The modifiers that do this are :D, :U, :L, :P. Minimal example:

${VARNAME:${:UL}}

The :L modifier from the inner expression sets the value of the outer
expression to its variable name, in this case "VARNAME". The outer
expression was not marked as being defined though, which resulted in a
"Malformed conditional" error.

In the commit from 2020-09-22, vardebug.exp had changed a lot, and I had
not inspected the change closely. The important detail was in lines 56
and 60, where VAR_JUNK|VAR_KEEP changed into VEF_UNDEF, thereby losing
the VEF_DEF bit.
 1.2 30-Sep-2020  rillig make(1): demonstrate bug in evaluation of indirect variable modifiers

Reported by sjg.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.8 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.7 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.6 02-Oct-2020  rillig make(1): add test for repeating the :L variable modifier
 1.5 30-Sep-2020  rillig make(1): fix typos in test for the :L variable modifier
 1.4 30-Sep-2020  rillig make(1): demonstrate bug in evaluation of indirect variable modifiers

Reported by sjg.
 1.3 25-Aug-2020  rillig make(1): add test for the :L modifier
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.21 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.20 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.19 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.18 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.17 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.16 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.15 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.14 20-Apr-2024  rillig branches: 1.14.2;
make: provide more context information for parse/evaluate errors
 1.13 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.12 09-May-2023  rillig tests/make: clean up tests for ':gmtime' and ':localtime'
 1.11 09-May-2023  rillig make: allow ':gmtime' and ':localtime' with dynamic argument

This allows ${%Y:L:gmtime=${mtime}} instead of the indirect
${%Y:L:${:Ugmtime=${mtime}}}.

The direct form also prevents any ':' from the nested expression to be
interpreted as a separator, which doesn't matter for the ':gmtime' and
':localtime' modifiers but will prove useful for other modifiers that
follow the same pattern.
 1.10 09-May-2023  rillig tests/make: demonstrate parse bug in :gmtime and :localtime modifiers
 1.9 09-Dec-2021  rillig make: in parse errors, mark whitespace more clearly

This prevents any trailing whitespace from going unnoticed. It also
marks leading whitespace more clearly, as in the examples with the time
value " 1".
 1.8 19-Jan-2021  rillig make(1): fix tests for :gmtime and :localtime for 32-bit time_t

The comparison operator had accidentally been '!=' instead of '=='.

While here, proofread the documentation and add references for where the
32-bit time_t is defined on Linux and FreeBSD.
 1.7 21-Dec-2020  rillig make(1): remove excess newline from parse errors (since 2020-11-01)

For the modifiers :gmtime and :localtime, the excess newline had been
added in var.c 1.631 from 2020-10-31 21:40:20.

For the modifiers :range and :ts, the excess newline had been added in
var.c 1.635 from 2020-11-01 14:36:25.
 1.6 21-Dec-2020  rillig make(1): align tests for :localtime with those for :gmtime

These tests had been almost the same before, now they are as similar as
possible again.
 1.5 30-Nov-2020  rillig make(1): fix tests for :gmtime and :localtime for 32-bit time_t

https://bugs.freebsd.org/251465
 1.4 31-Oct-2020  rillig make(1): make parsing of the :gmtime and :localtime modifiers stricter

These variable modifiers accept an optional timestamp in seconds, to
select which date to print. This feature is only used very rarely. The
NetBSD build doesn't use it at all, and the FreeBSD build mainly uses
the plain modifiers :gmtime and :localtime, but not their optional
argument :gmtime=1500000000.

Therefore, this change is not going to affect many builds. Those that
are indeed affected had been wrong all the time anyway.

At parse time, these errors stop the build, as intended. After that,
when the actual shell commands of the targets are expanded and run,
these errors don't stop anything, the build just continues as if nothing
had happened. This is a general problem with Var_Parse, see the many
"handle errors" markers in the code. Another problem is that on parse
errors, parsing continues and spits out spurious strings of the form
"mtime" and "ocaltime". This as well is a general problem with error
handling in make.

ok sjg
 1.3 31-Oct-2020  rillig make(1): add more tests for the variable modifier :localtime
 1.2 23-Aug-2020  rillig make(1): move tests for :hash :range :localtime into separate files
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.14.2.1 02-Aug-2025  perseant Sync with HEAD
 1.20 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.19 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.18 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.17 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.16 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.15 20-Apr-2024  rillig branches: 1.15.2;
make: provide more context information for parse/evaluate errors
 1.14 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.13 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.12 10-May-2023  rillig tests/make: clean up comments in tests
 1.11 09-May-2023  rillig tests/make: clean up tests for ':gmtime' and ':localtime'
 1.10 09-May-2023  rillig make: allow ':gmtime' and ':localtime' with dynamic argument

This allows ${%Y:L:gmtime=${mtime}} instead of the indirect
${%Y:L:${:Ugmtime=${mtime}}}.

The direct form also prevents any ':' from the nested expression to be
interpreted as a separator, which doesn't matter for the ':gmtime' and
':localtime' modifiers but will prove useful for other modifiers that
follow the same pattern.
 1.9 09-May-2023  rillig tests/make: demonstrate parse bug in :gmtime and :localtime modifiers
 1.8 19-Jan-2021  rillig make(1): fix tests for :gmtime and :localtime for 32-bit time_t

The comparison operator had accidentally been '!=' instead of '=='.

While here, proofread the documentation and add references for where the
32-bit time_t is defined on Linux and FreeBSD.
 1.7 22-Dec-2020  rillig make(1): fix commit number in tests for :gmtime and :localtime
 1.6 21-Dec-2020  rillig make(1): align tests for :localtime with those for :gmtime

These tests had been almost the same before, now they are as similar as
possible again.
 1.5 31-Oct-2020  rillig make(1): add more tests for the variable modifier :localtime
 1.4 29-Oct-2020  rillig make(1): add test for default format of the :localtime modifier
 1.3 23-Aug-2020  rillig make(1): move tests for :hash :range :localtime into separate files
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.15.2.1 02-Aug-2025  perseant Sync with HEAD
 1.9 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.8 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.7 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.6 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.5 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.4 20-Apr-2024  rillig branches: 1.4.2;
make: provide more context information for parse/evaluate errors
 1.3 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.2 09-Dec-2021  rillig make: remove period from end of error messages and warnings

The majority of the existing error messages and warnings does not
include a period at the end. Follow this style consistently.
 1.1 05-Dec-2021  rillig make: fix use-after-free in modifier ':@'

Without memory allocator debugging, the newly added test doesn't show
any obvious failure.

With memory allocator debugging enabled, all make versions since
2016.02.27.16.20.06 crash with a segmentation fault.
 1.4.2.1 02-Aug-2025  perseant Sync with HEAD
 1.7 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.6 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.5 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.4 20-Apr-2024  rillig branches: 1.4.2;
make: provide more context information for parse/evaluate errors
 1.3 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.2 05-Dec-2021  rillig tests/make: document use-after-free in ':@' more precisely

The commit message from the previous commit was misleading. This bug
had not been introduced in 2016.02.27.16.20.06 (which was entirely
unrelated) but rather in 2016.02.18.23.33.25.

The commit 2016.02.27.16.20.06 just happened to be the first one from my
make-archive that triggered the bug. That's because I had only checked
out the last commit from each month, to save some disk space.
 1.1 05-Dec-2021  rillig make: fix use-after-free in modifier ':@'

Without memory allocator debugging, the newly added test doesn't show
any obvious failure.

With memory allocator debugging enabled, all make versions since
2016.02.27.16.20.06 crash with a segmentation fault.
 1.4.2.1 02-Aug-2025  perseant Sync with HEAD
 1.14 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.13 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.12 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.11 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.10 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.9 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.8 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.7 20-Apr-2024  rillig branches: 1.7.2;
make: provide more context information for parse/evaluate errors
 1.6 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.5 09-Dec-2021  rillig make: remove period from end of error messages and warnings

The majority of the existing error messages and warnings does not
include a period at the end. Follow this style consistently.
 1.4 05-Dec-2021  rillig tests/make: demonstrate use-after-free in modifier ':@'
 1.3 30-Nov-2021  rillig tests/make: test and document .MAKE.SAVE_DOLLARS and ':='
 1.2 04-Apr-2021  rillig make: disallow '$' in the variable name of the modifier ':@'

If this restriction should break any existing makefile, the author of
that makefile was probably heading for the IOMCC.
 1.1 04-Apr-2021  rillig tests/make: split test for modifier ':@' into separate files

The file varmod-loop.mk has grown too large to be single-purpose, plus
it combined parse-time and run-time tests. This has the downside that
as soon as a parse-time test results in an error, the run-time tests are
not run anymore.
 1.7.2.1 02-Aug-2025  perseant Sync with HEAD
 1.12 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.11 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.10 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.9 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.8 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.7 20-Apr-2024  rillig branches: 1.7.2;
make: provide more context information for parse/evaluate errors
 1.6 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.5 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.4 05-Dec-2021  rillig tests/make: demonstrate use-after-free in modifier ':@'
 1.3 30-Nov-2021  rillig tests/make: test and document .MAKE.SAVE_DOLLARS and ':='
 1.2 04-Apr-2021  rillig make: disallow '$' in the variable name of the modifier ':@'

If this restriction should break any existing makefile, the author of
that makefile was probably heading for the IOMCC.
 1.1 04-Apr-2021  rillig tests/make: split test for modifier ':@' into separate files

The file varmod-loop.mk has grown too large to be single-purpose, plus
it combined parse-time and run-time tests. This has the downside that
as soon as a parse-time test results in an error, the run-time tests are
not run anymore.
 1.7.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 04-Apr-2021  rillig tests/make: remove accidentally added intermediate files
 1.2 04-Apr-2021  rillig make: disallow '$' in the variable name of the modifier ':@'

If this restriction should break any existing makefile, the author of
that makefile was probably heading for the IOMCC.
 1.1 04-Apr-2021  rillig tests/make: split test for modifier ':@' into separate files

The file varmod-loop.mk has grown too large to be single-purpose, plus
it combined parse-time and run-time tests. This has the downside that
as soon as a parse-time test results in an error, the run-time tests are
not run anymore.
 1.3 04-Apr-2021  rillig tests/make: remove accidentally added intermediate files
 1.2 04-Apr-2021  rillig make: disallow '$' in the variable name of the modifier ':@'

If this restriction should break any existing makefile, the author of
that makefile was probably heading for the IOMCC.
 1.1 04-Apr-2021  rillig tests/make: split test for modifier ':@' into separate files

The file varmod-loop.mk has grown too large to be single-purpose, plus
it combined parse-time and run-time tests. This has the downside that
as soon as a parse-time test results in an error, the run-time tests are
not run anymore.
 1.3 04-Apr-2021  rillig tests/make: remove accidentally added intermediate files
 1.2 04-Apr-2021  rillig make: disallow '$' in the variable name of the modifier ':@'

If this restriction should break any existing makefile, the author of
that makefile was probably heading for the IOMCC.
 1.1 04-Apr-2021  rillig tests/make: split test for modifier ':@' into separate files

The file varmod-loop.mk has grown too large to be single-purpose, plus
it combined parse-time and run-time tests. This has the downside that
as soon as a parse-time test results in an error, the run-time tests are
not run anymore.
 1.22 31-Oct-2024  rillig make: in the debug log, always qualify line number with filename

Previously, to find out the filename corresponding to a line number from
a 'Parsing' line, it was necessary to find the preceding
'SetFilenameVars' line, which was unnecessarily time-consuming and
distracting.

The 'filename:line' format matches the one used in PrintStackTrace, and
it differs from the one used in PrintLocation, as the former format is
more common in other tools.

Most of the affected unit tests only use the 'Parsing' lines to give
additional context to their debug log, so no structural changes there.
 1.21 01-Jun-2024  rillig branches: 1.21.2;
make: remove unused VARE_EVAL_KEEP_DOLLAR
 1.20 14-Apr-2024  rillig make: add debug logging for .if and .for lines in -dp mode

This helps track down in which line a condition is evaluated.
 1.19 18-Feb-2023  rillig tests/make: document the modifier ':@var@body@'
 1.18 23-Aug-2022  rillig tests/make: document how the modifier ':@' works
 1.17 23-Aug-2022  rillig make: revert parsing of modifier parts (since 2022-08-08)

The modifier ':@var@body@' parses the body in parse-only mode and later
uses Var_Subst on it, in which each literal '$' must be written as '$$'.

Trying to parse the loop body using Var_Parse treated the text
'$${var:-0}' as a single '$' followed by the expression '${var:-0}',
wrongly complaining about the 'Unknown modifier "-0"'.

Found by sjg.
 1.16 23-Aug-2022  rillig tests/make: demonstrate parse error in ':@' modifier (since 2022-08-08)

Reported by sjg via private mail.
 1.15 03-Mar-2022  rillig make: make debug logging for comparisons less technical
 1.14 28-Dec-2021  rillig make: make debug logging a bit more human-friendly

The previous log format "ParseReadLine (%d): '%s'" focused on the
implementation, it was not immediately obvious to a casual reader that
the number in parentheses was the line number. Additionally, having
both a colon and quotes in a log message is uncommon. The quotes have
been added in parse.c 1.127 from 2007-01-01.

The new log format "Parsing line %d: %s" is meant to be easier readable
by humans. The quotes are not needed since ParseReadLine always strips
trailing whitespace, leaving no room for ambiguities. The other log
messages follow common punctuation rules, which makes the beginning of
the line equally unambiguous. Before var.c 1.911 from 2021-04-05,
variable assignments were logged with the format "%s:%s = %s", without a
space after the colon.
 1.13 05-Dec-2021  rillig make: fix use-after-free in modifier ':@'

Without memory allocator debugging, the newly added test doesn't show
any obvious failure.

With memory allocator debugging enabled, all make versions since
2016.02.27.16.20.06 crash with a segmentation fault.
 1.12 05-Dec-2021  rillig tests/make: demonstrate use-after-free in modifier ':@'
 1.11 30-Nov-2021  rillig tests/make: test and document .MAKE.SAVE_DOLLARS and ':='
 1.10 04-Apr-2021  rillig tests/make: split test for modifier ':@' into separate files

The file varmod-loop.mk has grown too large to be single-purpose, plus
it combined parse-time and run-time tests. This has the downside that
as soon as a parse-time test results in an error, the run-time tests are
not run anymore.
 1.9 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.8 15-Mar-2021  rillig tests/make: convert varmod-loop to parse-time

In case of unexpected failures, this provides the line number of the
'.error' directive.
 1.7 15-Mar-2021  rillig tests/make: add position marker in test 'varmod-loop'
 1.6 23-Feb-2021  rillig make: demonstrate how to undefine variables during evaluation

For a very long time now, I had thought that it would be impossible to
undefine global variables during the evaluation of variable expressions.
This is something that the memory management in Var_Parse relies upon,
see the comment 'the value of the variable must not change'.

After several unsuccessful attempts at referring to an already freed
previous value of a variable, today I discovered how to unset a global
variable while evaluating an expression, which has the same effect. To
demonstrate that this use-after-free can reliably crash make, it would
need a memory allocator with a debug mode that never re-allocates the
same memory block after it has been used once. This is something that
jemalloc cannot do at the moment. Valgrind would be another idea, but
that has not been ported to NetBSD.

Undefining a global variable while evaluating an expression is made
possible by an implementation detail of the modifier ':@'. That
modifier undefines the loop variable, without restoring its previous
value, see ApplyModifier_Loop.

By the very old conventions of ODE Make, these loop variables are named
'.V.' and thus do not conflict with variables from other naming
conventions. In NetBSD and pkgsrc, these loop variables are typically
called 'var', sometimes '_var' with a leading underscore, which also
doesn't conflict with the typical form 'VAR' of variables in the global
namespace. Therefore, in practice these loop variables don't interfere
with other variables.

One case that can practically arise is when an outer variable has a
modifier ':@word@${VAR.${word}}@' and one of the referenced variables
uses the same variable name in the modifier, see varmod-loop.mk 1.10
line 91 for a detailed explanation.

By using the ${:@VAR@@} modifier in a place that is evaluated with
cmdline scope, it is not only possible to undefine global variables, it
is possible to undefine cmdline variables as well. When evaluated in a
specific make target, the expression ${:@\@@@} can even be used to
undefine the variable '.TARGET', which will probably crash make with an
assertion failure.
 1.5 12-Nov-2020  rillig make(1): fix tests varmod-defined and varmod-loop regarding dollars

Some derived versions of NetBSD's make set .MAKE.SAVE_DOLLARS to no. In
these versions, running the tests would fail. Therefore better set
.MAKE.SAVE_DOLLARS to yes explicitly as far as necessary.

Suggested by sjg.
 1.4 08-Nov-2020  rillig make(1): add test demonstrating how ':=' and ':@var@' interact
 1.3 13-Sep-2020  rillig make(1): add test for empty variable name in :@var@...@ modifier
 1.2 16-Aug-2020  rillig make(1): move tests for :S, :C, :@ from modmisc to their separate tests
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.21.2.1 02-Aug-2025  perseant Sync with HEAD
 1.26 02-Jun-2024  rillig make: sync VarEvalMode constant names with their debug log names
 1.25 01-Jun-2024  rillig make: remove unused VARE_EVAL_KEEP_DOLLAR
 1.24 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.23 18-Feb-2023  rillig tests/make: document the modifier ':@var@body@'
 1.22 18-Feb-2023  rillig make: fix parsing of unevaluated subexpressions with unbalanced '{}'

Since var.c 1.323 from 2020-07-26, modifiers containing unbalanced
braces or parentheses were parsed differently, depending on whether they
were relevant or not.

For example, the expression '${VAR:...}' is enclosed with braces. When
this expression has a modifier ':S,},}},g' that would double each '}' in
that expression, the parser got confused:

If the expression was relevant, the modifier was parsed as usual, taking
into account that the 3 '}' in the modifier are ordinary characters.

If the expression was irrelevant, the parser only counted the '{' and
the '}', without taking into account that a '}' might be escaped by a
'\' or be an ordinary character. Parsing therefore stopped at the first
'}', assuming it would finish the expression '${VAR:S,}'.

This parsing mode of only counting balanced '{' and '}' makes sense for
the modifier ':@var@...@', which expands each word of the expression
using the template from the '...'. These templates tend to be simple
enough that counting the '{' and '}' suffices.
 1.21 23-Aug-2022  rillig tests/make: document how the modifier ':@' works
 1.20 23-Aug-2022  rillig make: revert parsing of modifier parts (since 2022-08-08)

The modifier ':@var@body@' parses the body in parse-only mode and later
uses Var_Subst on it, in which each literal '$' must be written as '$$'.

Trying to parse the loop body using Var_Parse treated the text
'$${var:-0}' as a single '$' followed by the expression '${var:-0}',
wrongly complaining about the 'Unknown modifier "-0"'.

Found by sjg.
 1.19 23-Aug-2022  rillig tests/make: demonstrate parse error in ':@' modifier (since 2022-08-08)

Reported by sjg via private mail.
 1.18 05-Dec-2021  rillig make: fix use-after-free in modifier ':@'

Without memory allocator debugging, the newly added test doesn't show
any obvious failure.

With memory allocator debugging enabled, all make versions since
2016.02.27.16.20.06 crash with a segmentation fault.
 1.17 05-Dec-2021  rillig tests/make: demonstrate use-after-free in modifier ':@'
 1.16 30-Nov-2021  rillig tests/make: test and document .MAKE.SAVE_DOLLARS and ':='
 1.15 11-Apr-2021  rillig make: clean up remaining references to VarEvalFlags

VarEvalFlags has been replaced with VarEvalMode. There were some
comments and tests that still referred to the old names.

No functional change.
 1.14 04-Apr-2021  rillig tests/make: split test for modifier ':@' into separate files

The file varmod-loop.mk has grown too large to be single-purpose, plus
it combined parse-time and run-time tests. This has the downside that
as soon as a parse-time test results in an error, the run-time tests are
not run anymore.
 1.13 15-Mar-2021  rillig tests/make: convert varmod-loop to parse-time

In case of unexpected failures, this provides the line number of the
'.error' directive.
 1.12 15-Mar-2021  rillig tests/make: add position marker in test 'varmod-loop'
 1.11 15-Mar-2021  rillig make: replace enum bit-field with struct bit-field for VarEvalFlags

This makes the code easier to read, especially in var.c. It also makes
debugging sessions easier since some debuggers don't show enum
bit-fields symbolically as soon as more than one bit is set.

The code outside var.c is basically unchanged, except that instead of
passing the individual flags, there are 4 predefined evaluation modes.
These suffice for all practical use cases. Only in the implementation
deep inside var.c, the value of the flags keepDollar and keepUndef
differs.

There is no way of passing the struct to EnumFlags_ToString, which means
the ToString function has to be spelled out explicitly. This allows for
fine-tuning the representation in the debug log, to reduce the amount of
uppercae letters.

No functional change.
 1.10 23-Feb-2021  rillig make: demonstrate how to undefine variables during evaluation

For a very long time now, I had thought that it would be impossible to
undefine global variables during the evaluation of variable expressions.
This is something that the memory management in Var_Parse relies upon,
see the comment 'the value of the variable must not change'.

After several unsuccessful attempts at referring to an already freed
previous value of a variable, today I discovered how to unset a global
variable while evaluating an expression, which has the same effect. To
demonstrate that this use-after-free can reliably crash make, it would
need a memory allocator with a debug mode that never re-allocates the
same memory block after it has been used once. This is something that
jemalloc cannot do at the moment. Valgrind would be another idea, but
that has not been ported to NetBSD.

Undefining a global variable while evaluating an expression is made
possible by an implementation detail of the modifier ':@'. That
modifier undefines the loop variable, without restoring its previous
value, see ApplyModifier_Loop.

By the very old conventions of ODE Make, these loop variables are named
'.V.' and thus do not conflict with variables from other naming
conventions. In NetBSD and pkgsrc, these loop variables are typically
called 'var', sometimes '_var' with a leading underscore, which also
doesn't conflict with the typical form 'VAR' of variables in the global
namespace. Therefore, in practice these loop variables don't interfere
with other variables.

One case that can practically arise is when an outer variable has a
modifier ':@word@${VAR.${word}}@' and one of the referenced variables
uses the same variable name in the modifier, see varmod-loop.mk 1.10
line 91 for a detailed explanation.

By using the ${:@VAR@@} modifier in a place that is evaluated with
cmdline scope, it is not only possible to undefine global variables, it
is possible to undefine cmdline variables as well. When evaluated in a
specific make target, the expression ${:@\@@@} can even be used to
undefine the variable '.TARGET', which will probably crash make with an
assertion failure.
 1.9 04-Feb-2021  rillig make: rename context and ctxt to scope

This continues the previous commit, in which VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE were renamed.

Renaming the variable 'ctxt' was trivial since that word is used nowhere
else. In the comments though, each occurrence of the word 'context' had
to be checked individually since the word 'context' was not only used
for referring to a variable scope. It is also used to distinguish
different situations where characters are escaped in a certain way
('parsing context') and in a few other expressions.
 1.8 12-Nov-2020  rillig make(1): fix tests varmod-defined and varmod-loop regarding dollars

Some derived versions of NetBSD's make set .MAKE.SAVE_DOLLARS to no. In
these versions, running the tests would fail. Therefore better set
.MAKE.SAVE_DOLLARS to yes explicitly as far as necessary.

Suggested by sjg.
 1.7 08-Nov-2020  rillig make(1): add test demonstrating how ':=' and ':@var@' interact
 1.6 03-Nov-2020  rillig make(1): in tests, replace "dollar character" with "dollar sign"
 1.5 31-Oct-2020  rillig make(1): add test for combining the :@ and :? variable modifiers
 1.4 18-Oct-2020  rillig make(1): add test for nested :@ modifiers using the same variable name
 1.3 13-Sep-2020  rillig make(1): add test for empty variable name in :@var@...@ modifier
 1.2 16-Aug-2020  rillig make(1): move tests for :S, :C, :@ from modmisc to their separate tests
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.29 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.28 28-Jun-2025  rillig make: error out on an ":M" modifier whose pattern ends with backslash

This edge case is not expected to occur intentionally in practice.
 1.27 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.26 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.25 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.24 09-Jul-2024  rillig make: error out on syntax errors in ':M' and ':N' modifiers

More than a year ago, the warning has been added. Now it has been
promoted to an error.
 1.23 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.22 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.21 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.20 15-Jun-2024  rillig branches: 1.20.2;
make: in warnings, move the word "warning" to the front
 1.19 20-Apr-2024  rillig make: provide more context information for parse/evaluate errors
 1.18 23-Jun-2023  rillig make: warn about malformed patterns in ':M', ':N' and '.if make(...)'

These patterns shouldn't occur in practice, as their results are tricky
to predict. Generate a warning for now, and maybe an error later.

Reviewed by sjg@.
 1.17 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.16 03-Mar-2022  rillig make: make debug logging for comparisons less technical
 1.15 10-Apr-2021  rillig make: reduce debug logging and memory allocation for ${:U...}

Expressions of the form ${:U...} are often generated by .for loops.
Since these expressions are not generated knowingly by the make user, do
not fill the debug log with them since that would interrupt the normal
reading flow of the -dv log for nested expressions.
 1.14 06-Apr-2021  rillig make: reduce verbosity of the -dv debug logging for standard cases

The verbosity was already removed from LogBeforeApply, now it is
consistent between LogBeforeApply and LogAfterApply.
 1.13 05-Apr-2021  rillig make: in debug log, add space between scope and variable name

Without this space, the debug log looked more like line noise, even
though the only punctuation was a single innocent ':'. From a make
user's perspective, the variable name is a word of its own and should
not be visually glued to its namespace.
 1.12 05-Apr-2021  rillig make: omit unnecessary details from -dv debug log

When an expression is based on a defined variable, it does not matter
whether the evaluation mode is "eval" or "eval-defined", therefore omit
these details to reduce confusion.
 1.11 05-Apr-2021  rillig make: be more verbose in -dv debug logging

The previous log output was too brief to be understandable. Give more
hints by describing each part of the expression when evaluating a
modifier. Distinguish between parse-only mode and eval mode since in
parse-only mode most of the details are irrelevant.
 1.10 05-Apr-2021  rillig make: clean up debug logging for ':M' and ':N'

Using square brackets as quotes was confusing since patterns can contain
square brackets themselves.

The debug logging for VarMatch was a bit too detailed. Having the
"before" and "after" states is enough for all practically relevant
cases.
 1.9 03-Apr-2021  rillig make: remove VarFlags from debug logging

Before the introduction of ExprDefined, VarFlags contained whether the
expression was defined or not, which was useful to know since the final
value of the expression depends on this information. The other VarFlags
do not influence the evaluation, so there is no point logging them.
 1.8 15-Mar-2021  rillig make: change debug log for variable evaluation flags to lowercase

This makes them easier distinguishable from variable names since the
latter are usually uppercase.

No functional change outside debug mode.
 1.7 15-Feb-2021  rillig make: rename ExprDefined constants for debug logging
 1.6 02-Feb-2021  rillig make: replace VarExprFlags with VarExprStatus

The combination of !VEF_UNDEF && VEF_DEF was not possible, which made it
rather strange to model this state as a bit set.

The only functional change is the renamed constants in the debug output.

Using ENUM_VALUE_RTTI_2 felt like overengineering since it's harder to
understand than a simple array of names.
 1.5 01-Nov-2020  rillig make(1): add more tests for the variable modifier :M

Despite its popularity and usefulness, the variable modifier :M is
implemented so weirdly that it's not surprising people get confused
about make's parsing and escaping rules.
 1.4 01-Nov-2020  rillig make(1): add test for surprising parsing result of the :M modifier
 1.3 01-Nov-2020  rillig make(1): move test flags to test varmod-match-escape.mk
 1.2 25-Oct-2020  sjg Skip reading .MAKE.DEPENDFILE if set to
"/dev/null" or anything starting with "no".

Ref: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=223564
 1.1 16-Aug-2020  rillig make(1): move tests for the :M modifier into separate files

The test for the different escaping has been adjusted to actually show
the different parsing results in the test output. To do this, it had to
get its own file since it needs the -dv debug flag and specialized
post-processing.
 1.20.2.1 02-Aug-2025  perseant Sync with HEAD
 1.20 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.19 28-Jun-2025  rillig make: error out on an ":M" modifier whose pattern ends with backslash

This edge case is not expected to occur intentionally in practice.
 1.18 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.17 09-Jul-2024  rillig make: error out on syntax errors in ':M' and ':N' modifiers

More than a year ago, the warning has been added. Now it has been
promoted to an error.
 1.16 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.15 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.14 15-Jun-2024  rillig branches: 1.14.2;
make: in warnings, move the word "warning" to the front
 1.13 20-Apr-2024  rillig make: provide more context information for parse/evaluate errors
 1.12 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.11 02-Nov-2023  rillig make: sync comments with the extracted ParseModifier_Match

No functional change.
 1.10 23-Jun-2023  rillig make: warn about malformed patterns in ':M', ':N' and '.if make(...)'

These patterns shouldn't occur in practice, as their results are tricky
to predict. Generate a warning for now, and maybe an error later.

Reviewed by sjg@.
 1.9 22-Jun-2023  rillig tests/make: demonstrate inconsistency in pattern matching with ranges
 1.8 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.7 03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.6 01-Feb-2021  rillig make: document necessary tests for Str_Match
 1.5 01-Nov-2020  rillig make(1): add more tests for the variable modifier :M

Despite its popularity and usefulness, the variable modifier :M is
implemented so weirdly that it's not surprising people get confused
about make's parsing and escaping rules.
 1.4 01-Nov-2020  rillig make(1): add test for surprising parsing result of the :M modifier
 1.3 01-Nov-2020  rillig make(1): move test flags to test varmod-match-escape.mk
 1.2 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.1 16-Aug-2020  rillig make(1): move tests for the :M modifier into separate files

The test for the different escaping has been adjusted to actually show
the different parsing results in the test output. To do this, it had to
get its own file since it needs the -dv debug flag and specialized
post-processing.
 1.14.2.1 02-Aug-2025  perseant Sync with HEAD
 1.27 29-Jun-2025  rillig tests/make: test backslash at the end of a line and in the :M modifier

As described in PR bin/46139 by David A. Holland.
 1.26 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.25 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.24 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.23 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.22 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.21 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.20 09-Jul-2024  rillig make: error out on syntax errors in ':M' and ':N' modifiers

More than a year ago, the warning has been added. Now it has been
promoted to an error.
 1.19 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.18 15-Jun-2024  rillig branches: 1.18.2;
make: in warnings, move the word "warning" to the front
 1.17 05-Jun-2024  rillig make: sync comments with reality
 1.16 23-Apr-2024  rillig make: clean up comments, code and tests
 1.15 20-Apr-2024  rillig make: provide more context information for parse/evaluate errors
 1.14 17-Dec-2023  rillig tests/make: test the fast code path for ':M' patterns like '*.c'
 1.13 17-Dec-2023  rillig tests/make: add basic tests for the ':M' modifier
 1.12 16-Dec-2023  rillig tests/make: fix line numbers in expected test output for ':M'
 1.11 16-Dec-2023  rillig tests/make: reorganize tests for the ':M' modifier

Add a table of contents. Group the existing tests into sections. Fix
the pattern of the test for the malformed ':M[\' modifier, now in line
283.

Note that the tests for the pattern characters '*?\' are missing.
 1.10 23-Jun-2023  rillig make: warn about malformed patterns in ':M', ':N' and '.if make(...)'

These patterns shouldn't occur in practice, as their results are tricky
to predict. Generate a warning for now, and maybe an error later.

Reviewed by sjg@.
 1.9 22-Jun-2023  rillig tests/make: fix line numbers in test result, since the previous commit
 1.8 22-Jun-2023  rillig make: clean up comments related to pattern matching
 1.7 11-Jun-2022  rillig tests/make: test edge cases in pattern matching
 1.6 11-Jun-2022  rillig tests/make: demonstrate another pathological pattern match
 1.5 03-Mar-2022  rillig tests/make: add more comprehensive tests for ':M' and ':N'
 1.4 03-Mar-2022  rillig make: make debug logging for comparisons less technical
 1.3 12-Sep-2020  rillig make(1): add test for escaping dollars in the :M variable modifier
 1.2 16-Aug-2020  rillig make(1): move tests for the :M modifier into separate files

The test for the different escaping has been adjusted to actually show
the different parsing results in the test output. To do this, it had to
get its own file since it needs the -dv debug flag and specialized
post-processing.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.18.2.1 02-Aug-2025  perseant Sync with HEAD
 1.32 29-Jun-2025  rillig tests/make: test backslash at the end of a line and in the :M modifier

As described in PR bin/46139 by David A. Holland.
 1.31 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.30 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.29 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.28 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.27 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.26 09-Jul-2024  rillig make: error out on syntax errors in ':M' and ':N' modifiers

More than a year ago, the warning has been added. Now it has been
promoted to an error.
 1.25 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.24 15-Jun-2024  rillig branches: 1.24.2;
make: in warnings, move the word "warning" to the front
 1.23 05-Jun-2024  rillig make: sync comments with reality
 1.22 23-Apr-2024  rillig make: clean up comments, code and tests
 1.21 20-Apr-2024  rillig make: provide more context information for parse/evaluate errors
 1.20 17-Dec-2023  rillig tests/make: test the fast code path for ':M' patterns like '*.c'
 1.19 17-Dec-2023  rillig tests/make: add basic tests for the ':M' modifier
 1.18 16-Dec-2023  rillig tests/make: reorganize tests for the ':M' modifier

Add a table of contents. Group the existing tests into sections. Fix
the pattern of the test for the malformed ':M[\' modifier, now in line
283.

Note that the tests for the pattern characters '*?\' are missing.
 1.17 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.16 02-Nov-2023  rillig make: sync comments with the extracted ParseModifier_Match

No functional change.
 1.15 23-Jun-2023  rillig make: warn about malformed patterns in ':M', ':N' and '.if make(...)'

These patterns shouldn't occur in practice, as their results are tricky
to predict. Generate a warning for now, and maybe an error later.

Reviewed by sjg@.
 1.14 22-Jun-2023  rillig make: speed up pattern matching in the ':M' and ':N' modifiers

In the code coverage report, the highest count for Str_Match goes from
5,298,924 down to 79,646.
 1.13 22-Jun-2023  rillig make: clean up comments related to pattern matching
 1.12 24-Aug-2022  rillig make: fix out-of-bounds read when parsing the ':M' modifier

Since at least 2009-01-17, probably already since 2006-02-18, when
modifiers were allowed to be nested expressions.
 1.11 11-Jun-2022  rillig tests/make: test edge cases in pattern matching
 1.10 11-Jun-2022  rillig tests/make: demonstrate another pathological pattern match
 1.9 08-May-2022  rillig tests/make: migrate cond1 test to other, more specific tests

The tests in cond1 were a mixture of "everything related to conditions",
and the test cases were heavily dependent on each other, which made them
hard to understand. Move each test case to its corresponding
special-purpose test.
 1.8 27-Mar-2022  rillig make: fix spacing, and a typo in a test
 1.7 03-Mar-2022  rillig tests/make: add more comprehensive tests for ':M' and ':N'
 1.6 15-Nov-2020  rillig make(1): add remarks to var.c and the test varmod-match
 1.5 13-Sep-2020  rillig make(1): fix comments in test for the :M variable modifier

One mistake per sentence is pretty much, I must have been quite
unconcentrated.

The other commits from around that time are fine though.
 1.4 12-Sep-2020  rillig make(1): add test for escaping dollars in the :M variable modifier
 1.3 16-Aug-2020  rillig make(1): move tests for the :M modifier into separate files

The test for the different escaping has been adjusted to actually show
the different parsing results in the test output. To do this, it had to
get its own file since it needs the -dv debug flag and specialized
post-processing.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.24.2.1 02-Aug-2025  perseant Sync with HEAD
 1.16 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.15 12-Jun-2025  rillig make: use a common style for unexpected error messages

In enomem, report the actual error instead of a fixed ENOMEM.
 1.14 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.13 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.12 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.11 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.10 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.9 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.8 20-Apr-2024  rillig branches: 1.8.2;
make: provide more context information for parse/evaluate errors
 1.7 19-Nov-2023  rillig tests/make: cover all code paths for the ':mtime' modifier
 1.6 19-Nov-2023  rillig make: produce more accurate error message for invalid ':mtime' argument
 1.5 19-Nov-2023  rillig tests/make: test non-integer fallback in ':mtime' modifier
 1.4 19-Aug-2023  sjg varmod-mtime.mk: use :localtime for %s

Add a comment to explain why ${%s:L:localtime} should be used to get
a value that matches time(3).
 1.3 17-Aug-2023  rillig make: be strict when parsing the argument of the ':mtime' modifier
 1.2 17-Aug-2023  rillig tests/make: extend tests for the ':mtime' modifier
 1.1 09-May-2023  sjg make: add :mtime to provide mtime of file

The value of the variable is passed to stat(2)
and st_mtime is new value.
An optional arg can be used if stat(2) fails, otherwise
the current time is used.

See varmod-mtime.mk for usage examples.
 1.8.2.1 02-Aug-2025  perseant Sync with HEAD
 1.17 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.16 12-Jun-2025  rillig make: use a common style for unexpected error messages

In enomem, report the actual error instead of a fixed ENOMEM.
 1.15 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.14 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.13 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.12 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.11 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.10 20-Apr-2024  rillig branches: 1.10.2;
make: provide more context information for parse/evaluate errors
 1.9 17-Dec-2023  rillig tests/make: extend tests for include guards and empty expressions
 1.8 19-Nov-2023  rillig tests/make: cover all code paths for the ':mtime' modifier
 1.7 19-Nov-2023  rillig make: produce more accurate error message for invalid ':mtime' argument
 1.6 19-Nov-2023  rillig tests/make: test non-integer fallback in ':mtime' modifier
 1.5 19-Aug-2023  rillig tests/make: document bug in ':gmtime' with '%s'
 1.4 19-Aug-2023  sjg varmod-mtime.mk: use :localtime for %s

Add a comment to explain why ${%s:L:localtime} should be used to get
a value that matches time(3).
 1.3 17-Aug-2023  rillig make: be strict when parsing the argument of the ':mtime' modifier
 1.2 17-Aug-2023  rillig tests/make: extend tests for the ':mtime' modifier
 1.1 09-May-2023  sjg make: add :mtime to provide mtime of file

The value of the variable is passed to stat(2)
and st_mtime is new value.
An optional arg can be used if stat(2) fails, otherwise
the current time is used.

See varmod-mtime.mk for usage examples.
 1.10.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 26-Feb-2023  rillig tests/make: extend tests for expression modifiers, especially ':N'
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 31-Jul-2021  rillig tests/make: split tests for the variable modifier ':O'

The tests for parse errors are now in varmod-order, which lets the other
tests focus on the desired behavior of the modifiers.
 1.3 30-Jul-2021  rillig make: handle parse errors in ':O' uniformly

Previously, the error handling for the variable modifier ':O' differed
depending on the exact variant and in some cases led to misleading
or missing diagnostics.
 1.2 30-Jul-2021  rillig make: fix typo in manual page, add more tests for the new ':On'
 1.1 30-Jul-2021  sjg Add :On for numeric sort

Reviewed by: christos rillig
 1.8 27-Sep-2022  rillig tests/make: add tests for legacy local variables and sorting
 1.7 09-Feb-2022  rillig make: fix mistakes, spelling and typos in comments and manual page

No binary change for -DNDEBUG.
 1.6 04-Feb-2022  rillig make: use fixed type for comparing numbers using the modifier ':On'

When the modifier ':On' was added on 2021-07-30, there were concerns
that pre-C99 environments would not have the type 'long long', therefore
the type was made configurable, but parsing such numbers was hard-coded
to using strtoll.

To improve compatibility with C90 environments, use 'long' and 'strtol'
in these environments. In C99 environments, use 'long long' and
'strtoll', to account for larger file sizes.

If the flexibility of choosing yet another type for these numbers should
ever arise, it can still be implemented. Until then, reduce the number
of possible build configurations.
 1.5 03-Aug-2021  rillig tests/make: fix test for the variable modifier ':On'

The variable modifier ':On' sorts words numerically. If these words are
not numeric at all, they get assigned the numeric value 0. Internally,
':On' uses qsort for sorting the words. Since qsort is not specified to
use a stable sorting algorithm, the test data must only use words that
either are written in the same way or that are numerically different.

The test varmod-order failed this requirement by trying to numerically
sort a list of non-numeric words. This led to different results on BSD
and Ubuntu, as could be expected.

To fix the tests, distinguish between words and numbers in the tests.
While here, clean up the tests for all variants of the variable modifier
':O'.

Found by sjg on Ubuntu.
 1.4 31-Jul-2021  rillig tests/make: split tests for the variable modifier ':O'

The tests for parse errors are now in varmod-order, which lets the other
tests focus on the desired behavior of the modifiers.
 1.3 30-Jul-2021  rillig make: handle parse errors in ':O' uniformly

Previously, the error handling for the variable modifier ':O' differed
depending on the exact variant and in some cases led to misleading
or missing diagnostics.
 1.2 30-Jul-2021  rillig make: fix typo in manual page, add more tests for the new ':On'
 1.1 30-Jul-2021  sjg Add :On for numeric sort

Reviewed by: christos rillig
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 03-Aug-2021  rillig tests/make: fix test for the variable modifier ':On'

The variable modifier ':On' sorts words numerically. If these words are
not numeric at all, they get assigned the numeric value 0. Internally,
':On' uses qsort for sorting the words. Since qsort is not specified to
use a stable sorting algorithm, the test data must only use words that
either are written in the same way or that are numerically different.

The test varmod-order failed this requirement by trying to numerically
sort a list of non-numeric words. This led to different results on BSD
and Ubuntu, as could be expected.

To fix the tests, distinguish between words and numbers in the tests.
While here, clean up the tests for all variants of the variable modifier
':O'.

Found by sjg on Ubuntu.
 1.4 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.3 16-Aug-2020  rillig make(1): move tests for the :O and :Or modifiers into separate files
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.8 26-Feb-2023  rillig tests/make: extend tests for expression modifiers, especially ':N'
 1.7 03-Aug-2021  rillig tests/make: fix test for the variable modifier ':On'

The variable modifier ':On' sorts words numerically. If these words are
not numeric at all, they get assigned the numeric value 0. Internally,
':On' uses qsort for sorting the words. Since qsort is not specified to
use a stable sorting algorithm, the test data must only use words that
either are written in the same way or that are numerically different.

The test varmod-order failed this requirement by trying to numerically
sort a list of non-numeric words. This led to different results on BSD
and Ubuntu, as could be expected.

To fix the tests, distinguish between words and numbers in the tests.
While here, clean up the tests for all variants of the variable modifier
':O'.

Found by sjg on Ubuntu.
 1.6 09-Nov-2020  rillig make(1): document since when the :Ox modifier is available
 1.5 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.4 27-Sep-2020  rillig make(1): mark test for the :Ox variable modifier as probabilistic

It fails very seldom, but it can.
 1.3 16-Aug-2020  rillig make(1): move tests for the :Ox modifier into separate file

The test has been extended by ensuring that the shuffled words are still
the same. Comparing two shuffled lists is probabilistic, but comparing
their sorted results is not, therefore that's completely sensible to do.

When writing this test, by coincidence I discovered how to generate the
"Undefined variable" error message. Unfortunately, the error message is
wrong since the variable NUMBERS is defined at that point. In summary,
that error message is shown when it shouldn't, and when it should it is
not shown. Still, I'm glad that I finally found it.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 31-Jul-2021  rillig tests/make: split tests for the variable modifier ':O'

The tests for parse errors are now in varmod-order, which lets the other
tests focus on the desired behavior of the modifiers.
 1.2 03-Aug-2021  rillig tests/make: fix test for the variable modifier ':On'

The variable modifier ':On' sorts words numerically. If these words are
not numeric at all, they get assigned the numeric value 0. Internally,
':On' uses qsort for sorting the words. Since qsort is not specified to
use a stable sorting algorithm, the test data must only use words that
either are written in the same way or that are numerically different.

The test varmod-order failed this requirement by trying to numerically
sort a list of non-numeric words. This led to different results on BSD
and Ubuntu, as could be expected.

To fix the tests, distinguish between words and numbers in the tests.
While here, clean up the tests for all variants of the variable modifier
':O'.

Found by sjg on Ubuntu.
 1.1 31-Jul-2021  rillig tests/make: split tests for the variable modifier ':O'

The tests for parse errors are now in varmod-order, which lets the other
tests focus on the desired behavior of the modifiers.
 1.20 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.19 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.18 29-Mar-2025  rillig make: let unknown ":O" modifiers fall back to the ":from=to" modifier

Inspired by https://bugs.freebsd.org/285726, which concerns the ":t"
modifier instead.

This means that future extensions to the ":O" modifier must not contain
a "=" anywhere, otherwise they may break existing code.
 1.17 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.16 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.15 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.14 20-Jul-2024  rillig make: remove wrong error message about an undefined variable
 1.13 05-Jul-2024  rillig make: error out on unclosed expressions during parse time

In exchange, this adds location information.

For unnamed expressions, the value is no longer printed. This will be
added back in a follow-up commit.
 1.12 05-Jul-2024  rillig tests/make: add expected messages for "Unclosed expression"
 1.11 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.10 04-Jul-2024  rillig make: error out on the "Bad modifier" error message

Previously, the "Bad modifier" error message did not affect make's exit
status. As a side effect, this kind of error now gets more context
information.
 1.9 19-Nov-2023  rillig branches: 1.9.2;
make: replace 'variable expression' with 'expression' in diagnostics
 1.8 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.7 27-Feb-2023  rillig tests/make: describe the absent fallback for ':O' modifiers more clearly
 1.6 26-Feb-2023  rillig tests/make: extend tests for expression modifiers, especially ':N'
 1.5 03-Aug-2021  rillig tests/make: fix test for the variable modifier ':On'

The variable modifier ':On' sorts words numerically. If these words are
not numeric at all, they get assigned the numeric value 0. Internally,
':On' uses qsort for sorting the words. Since qsort is not specified to
use a stable sorting algorithm, the test data must only use words that
either are written in the same way or that are numerically different.

The test varmod-order failed this requirement by trying to numerically
sort a list of non-numeric words. This led to different results on BSD
and Ubuntu, as could be expected.

To fix the tests, distinguish between words and numbers in the tests.
While here, clean up the tests for all variants of the variable modifier
':O'.

Found by sjg on Ubuntu.
 1.4 31-Jul-2021  rillig tests/make: split tests for the variable modifier ':O'

The tests for parse errors are now in varmod-order, which lets the other
tests focus on the desired behavior of the modifiers.
 1.3 23-Feb-2021  rillig make: improve error message for bad modifier in variable expression

The improvement is especially noteable for variable expressions based on
the empty variable, see moderrs.exp:103.
 1.2 16-Aug-2020  rillig make(1): move tests for the :Ox modifier into separate file

The test has been extended by ensuring that the shuffled words are still
the same. Comparing two shuffled lists is probabilistic, but comparing
their sorted results is not, therefore that's completely sensible to do.

When writing this test, by coincidence I discovered how to generate the
"Undefined variable" error message. Unfortunately, the error message is
wrong since the variable NUMBERS is defined at that point. In summary,
that error message is shown when it shouldn't, and when it should it is
not shown. Still, I'm glad that I finally found it.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.9.2.1 02-Aug-2025  perseant Sync with HEAD
 1.20 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.19 29-Mar-2025  rillig make: let unknown ":O" modifiers fall back to the ":from=to" modifier

Inspired by https://bugs.freebsd.org/285726, which concerns the ":t"
modifier instead.

This means that future extensions to the ":O" modifier must not contain
a "=" anywhere, otherwise they may break existing code.
 1.18 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.17 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.16 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.15 20-Jul-2024  rillig make: remove wrong error message about an undefined variable
 1.14 05-Jul-2024  rillig make: error out on unclosed expressions during parse time

In exchange, this adds location information.

For unnamed expressions, the value is no longer printed. This will be
added back in a follow-up commit.
 1.13 05-Jul-2024  rillig tests/make: add expected messages for "Unclosed expression"
 1.12 04-Jul-2024  rillig make: error out on the "Bad modifier" error message

Previously, the "Bad modifier" error message did not affect make's exit
status. As a side effect, this kind of error now gets more context
information.
 1.11 01-Jun-2023  rillig branches: 1.11.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.10 27-Feb-2023  rillig tests/make: describe the absent fallback for ':O' modifiers more clearly
 1.9 26-Feb-2023  rillig tests/make: extend tests for expression modifiers, especially ':N'
 1.8 15-Jan-2022  rillig tests/make: ensure that the 'expect' comments in tests are correct

Based on tests/usr.bin/xlint/check-expect.lua.

For now, this extra check needs to be run manually.
 1.7 03-Aug-2021  rillig tests/make: fix test for the variable modifier ':On'

The variable modifier ':On' sorts words numerically. If these words are
not numeric at all, they get assigned the numeric value 0. Internally,
':On' uses qsort for sorting the words. Since qsort is not specified to
use a stable sorting algorithm, the test data must only use words that
either are written in the same way or that are numerically different.

The test varmod-order failed this requirement by trying to numerically
sort a list of non-numeric words. This led to different results on BSD
and Ubuntu, as could be expected.

To fix the tests, distinguish between words and numbers in the tests.
While here, clean up the tests for all variants of the variable modifier
':O'.

Found by sjg on Ubuntu.
 1.6 31-Jul-2021  rillig tests/make: split tests for the variable modifier ':O'

The tests for parse errors are now in varmod-order, which lets the other
tests focus on the desired behavior of the modifiers.
 1.5 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.4 16-Aug-2020  rillig make(1): move tests for the :Ox modifier into separate file

The test has been extended by ensuring that the shuffled words are still
the same. Comparing two shuffled lists is probabilistic, but comparing
their sorted results is not, therefore that's completely sensible to do.

When writing this test, by coincidence I discovered how to generate the
"Undefined variable" error message. Unfortunately, the error message is
wrong since the variable NUMBERS is defined at that point. In summary,
that error message is shown when it shouldn't, and when it should it is
not shown. Still, I'm glad that I finally found it.
 1.3 16-Aug-2020  rillig make(1): move tests for the :O and :Or modifiers into separate files
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.11.2.1 02-Aug-2025  perseant Sync with HEAD
 1.2 23-Aug-2020  rillig make(1): add test for the :P variable modifier
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 10-May-2023  rillig tests/make: clean up comments in tests
 1.3 23-Aug-2020  rillig make(1): add test for the :P variable modifier
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 08-May-2022  rillig tests/make: explain that assignments ignore leading spaces
 1.2 22-Jan-2022  rillig tests/make: add a few more tests
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 08-May-2022  rillig tests/make: explain that assignments ignore leading spaces
 1.3 22-Jan-2022  rillig tests/make: add a few more tests
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 29-Oct-2020  rillig make(1): add test for the :Q modifier
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.22 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.21 04-Apr-2025  rillig make: fix error message for undefined variable in conditional

Previously, only ${UNDEF} had the proper error message, while
${UNDEF:M*} still produced the wrong "Malformed conditional".
 1.20 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.19 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.18 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.17 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.16 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.15 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.14 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.13 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.12 20-Apr-2024  rillig branches: 1.12.2;
make: provide more context information for parse/evaluate errors
 1.11 17-Dec-2023  rillig tests/make: extend tests for include guards and empty expressions
 1.10 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.9 23-Feb-2021  rillig make: improve error message for unknown modifier

Back in 1995, the modifiers were all single-character, and it made sense
to print only the first character. Nowadays, with ':S', ':@var@...@',
'::=' and several others, a little more context is useful to see where
the exact error is. The actual modifier is still guessed, and the guess
may be wrong as soon as backslashes get involved, but it is still better
than before.
 1.8 23-Feb-2021  rillig make: add context information to error message about ':range' modifier
 1.7 21-Dec-2020  rillig make(1): remove excess newline from parse errors (since 2020-11-01)

For the modifiers :gmtime and :localtime, the excess newline had been
added in var.c 1.631 from 2020-10-31 21:40:20.

For the modifiers :range and :ts, the excess newline had been added in
var.c 1.635 from 2020-11-01 14:36:25.
 1.6 20-Dec-2020  rillig make(1): error out on unknown variable modifiers at parse time

Before, make printed an "error message" that did not include the word
error and thus was not easily identified as such. This "error message"
also did not influence the exit status in the default mode but only in
-dL mode. The error message also didn't include any line number
information and was thus rude.
 1.5 01-Nov-2020  rillig make(1): treat malformed :range, :ts and :[...] as errors

Before, integer overflow in the :[1..2] modifier had not been detected,
and the actual behavior varied between ILP64 and LP64I32 machines.

Before, the :ts modifier accepted character literals like \012345 and
\x1F600, which don't fit in a single character and were thus truncated.

Before, the :range modifier issued an "Unknown modifier" error message
for :range=x, which was not quite correct. The error message in this
case is now "Invalid number".
 1.4 01-Nov-2020  rillig make(1): add tests for the variable modifiers :[words] and :range
 1.3 01-Nov-2020  rillig make(1): add more tests for the variable modifier :range, edge cases
 1.2 23-Aug-2020  rillig make(1): move tests for :hash :range :localtime into separate files
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.12.2.1 02-Aug-2025  perseant Sync with HEAD
 1.19 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.18 04-Apr-2025  rillig make: fix error message for undefined variable in conditional

Previously, only ${UNDEF} had the proper error message, while
${UNDEF:M*} still produced the wrong "Malformed conditional".
 1.17 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.16 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.15 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.14 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.13 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.12 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.11 20-Apr-2024  rillig branches: 1.11.2;
make: provide more context information for parse/evaluate errors
 1.10 17-Dec-2023  rillig tests/make: extend tests for include guards and empty expressions
 1.9 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.8 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.7 01-Nov-2020  rillig make(1): treat malformed :range, :ts and :[...] as errors

Before, integer overflow in the :[1..2] modifier had not been detected,
and the actual behavior varied between ILP64 and LP64I32 machines.

Before, the :ts modifier accepted character literals like \012345 and
\x1F600, which don't fit in a single character and were thus truncated.

Before, the :range modifier issued an "Unknown modifier" error message
for :range=x, which was not quite correct. The error message in this
case is now "Invalid number".
 1.6 01-Nov-2020  rillig make(1): add tests for the variable modifiers :[words] and :range
 1.5 01-Nov-2020  rillig make(1): add more tests for the variable modifier :range, edge cases
 1.4 27-Sep-2020  rillig make(1): add test cases for the :range variable modifier
 1.3 23-Aug-2020  rillig make(1): move tests for :hash :range :localtime into separate files
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.11.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 14-Mar-2021  rillig tests/make: convert test for ':_' modifier to parse time
 1.2 23-Aug-2020  rillig make(1): move tests for the :tu and :_ modifiers into separate files
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.9 09-Feb-2023  rillig tests/make: remove debugging directive from test for ':_'
 1.8 09-Feb-2023  rillig tests/make: extend and explain test for the ':_' modifier
 1.7 09-Feb-2023  sjg make: ApplyModifier_Remember always use SCOPE_GLOBAL

Conditionals evaluate vars with SCOPE_CMDLINE, if :_
is used within a conditional expression and is thus
set in SCOPE_CMDLINE, it breaks any use of :_ in SCOPE_GLOBAL.

The simplest solution is for :_ to always use SCOPE_GLOBAL

Reviewed by: rillig
 1.6 14-Mar-2021  rillig make: do not expand the variable name in the ':_' modifier

This edge case had been so obscure that even discovering this takes
quite some time and requires reading the source code of make.

The manual page doesn't document whether the variable name is expanded
or not, it doesn't even give an example. When this obscure modifier was
initially added in var.c 1.210 from 2017-01-30, Var_Set always expanded
the variable name once, and there was no way around it. Therefore this
expansion has probably been unintentional.
 1.5 14-Mar-2021  rillig tests/make: demonstrate unintended edge case for the ':_' modifier
 1.4 14-Mar-2021  rillig tests/make: convert test for ':_' modifier to parse time
 1.3 23-Aug-2020  rillig make(1): move tests for the :tu and :_ modifiers into separate files
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 05-Dec-2021  rillig tests/make: split test cases for ':R' into separate tests

This allows to comment or explain individual test cases.

Remove duplicates.
 1.3 20-Dec-2020  rillig make(1): add tests for variable modifiers on trailing slashes
 1.2 23-Aug-2020  rillig make(1): move tests for :H :E :R :T into separate files
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 05-Dec-2021  rillig tests/make: split test cases for ':R' into separate tests

This allows to comment or explain individual test cases.

Remove duplicates.
 1.4 20-Dec-2020  rillig make(1): add tests for variable modifiers on trailing slashes
 1.3 23-Aug-2020  rillig make(1): move tests for :H :E :R :T into separate files
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.8 30-Mar-2025  rillig make: fix error message for invalid ":[...]" modifier

The unparsed value of the modifier argument can already be seen in the
stack trace, but the modifier argument may contain expressions and the
expanded value of these expressions was hidden up to now. See the EMPTY
test at the bottom of varmod-select-words.mk for details.
 1.7 29-Mar-2025  rillig make: in stack traces from target commands, add the command level

A target can contain several commands, and these commands are likely to
contain the same expressions. To distinguish them, add one more line to
the stack trace, to narrow down the source of the error.
 1.6 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.5 20-Jul-2024  rillig make: don't run erroneous commands in compat mode

When there is a parse or evaluation error in an expression that becomes
part of the command, don't run that command, as the result of the failed
evaluation typically contains garbage characters. Skip the remaining
commands from that target as well, as they may depend on the erroneous
command.
 1.4 09-Jul-2024  rillig make: error out on parse/evaluation errors in shell commands

The expression ${VAR:X} has an unknown modifier ':X'. Previously, this
expression errored out when the expression was evaluated at parse time,
but not when the expression was evaluated when generating the commands
to bring a target up to date. The errors were previously reported, they
didn't affect the exit status, though.

Now, errors in expressions are handled in the same way, regardless of
the time at which they are evaluated.
 1.3 04-Jul-2024  rillig make: error out on the "Bad modifier" error message

Previously, the "Bad modifier" error message did not affect make's exit
status. As a side effect, this kind of error now gets more context
information.
 1.2 23-Jan-2022  rillig branches: 1.2.4;
tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2.4.1 02-Aug-2025  perseant Sync with HEAD
 1.7 30-Mar-2025  rillig make: fix error message for invalid ":[...]" modifier

The unparsed value of the modifier argument can already be seen in the
stack trace, but the modifier argument may contain expressions and the
expanded value of these expressions was hidden up to now. See the EMPTY
test at the bottom of varmod-select-words.mk for details.
 1.6 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.5 20-Jul-2024  rillig make: don't run erroneous commands in compat mode

When there is a parse or evaluation error in an expression that becomes
part of the command, don't run that command, as the result of the failed
evaluation typically contains garbage characters. Skip the remaining
commands from that target as well, as they may depend on the erroneous
command.
 1.4 23-Jan-2022  rillig branches: 1.4.4;
tests/make: extend test suite, move old tests to 2020 scheme

The tests from envfirst.mk are now in opt-env.mk.
The tests from modword.mk are now in varmod-select-words.mk.
 1.3 05-Dec-2021  rillig make: save a memory allocation in the modifier ':[...]'

No functional change.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4.4.1 02-Aug-2025  perseant Sync with HEAD
 1.10 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.9 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.8 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.7 30-Jun-2024  rillig make: add detailed exit status to message for failed sub-commands

Several commands communicate via the exit status and not only
distinguish between zero and non-zero, so make this information
available to ease investigations.

The command "false" is not guaranteed to exit with a consistent status,
so use "(exit 13)" instead in the tests, to keep these tests portable
across different operating systems. The exit status 127 is required for
a shell that cannot find a command, so keep that one.
 1.6 30-Jun-2024  rillig make: add more context to "returned non-zero status" message

Previously, this message was an "error" but had no influence on the exit
status, so make it a warning instead. In the seldom used -W mode that
treats warnings as errors, this change influences the exit status.
 1.5 26-Mar-2022  rillig branches: 1.5.4;
make: avoid trailing whitespace in debug log for variables

Since trailing whitespace is invisible, describe the variable value in
words to make it visible.
 1.4 10-Jan-2022  rillig make: add debug logging for capturing the output of external commands

This applies to all 4 situations in which the output of an external
command is used for modifying a variable or an expression:

* the assignment operator '!='
* the assignment modifier '::!='
* the SUN shell modifier ':sh'
* the other shell modifier ':!cmd!'

Previously, only the shell modifier ':!cmd!' had debug logging.

Suggested by Christoph Badura.
 1.3 17-Nov-2020  rillig make(1): fix error message of failed :!cmd! modifier (since 2000-04-29)
 1.2 17-Nov-2020  rillig make(1): document 20-year-old bug in the :!cmd! modifier
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5.4.2 02-Aug-2025  perseant Sync with HEAD
 1.5.4.1 01-Jul-2024  perseant Sync with HEAD.
 1.11 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.10 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.9 30-Jun-2024  rillig make: add detailed exit status to message for failed sub-commands

Several commands communicate via the exit status and not only
distinguish between zero and non-zero, so make this information
available to ease investigations.

The command "false" is not guaranteed to exit with a consistent status,
so use "(exit 13)" instead in the tests, to keep these tests portable
across different operating systems. The exit status 127 is required for
a shell that cannot find a command, so keep that one.
 1.8 30-Jun-2024  rillig make: add more context to "returned non-zero status" message

Previously, this message was an "error" but had no influence on the exit
status, so make it a warning instead. In the seldom used -W mode that
treats warnings as errors, this change influences the exit status.
 1.7 10-Jan-2022  rillig branches: 1.7.4;
make: add debug logging for capturing the output of external commands

This applies to all 4 situations in which the output of an external
command is used for modifying a variable or an expression:

* the assignment operator '!='
* the assignment modifier '::!='
* the SUN shell modifier ':sh'
* the other shell modifier ':!cmd!'

Previously, only the shell modifier ':!cmd!' had debug logging.

Suggested by Christoph Badura.
 1.6 14-Feb-2021  rillig make: add test for the variable modifier ':sh'
 1.5 17-Nov-2020  rillig make(1): fix error message of failed :!cmd! modifier (since 2000-04-29)
 1.4 17-Nov-2020  rillig make(1): document 20-year-old bug in the :!cmd! modifier
 1.3 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7.4.2 02-Aug-2025  perseant Sync with HEAD
 1.7.4.1 01-Jul-2024  perseant Sync with HEAD.
 1.14 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.13 29-Mar-2025  rillig make: in stack traces from target commands, add the command level

A target can contain several commands, and these commands are likely to
contain the same expressions. To distinguish them, add one more line to
the stack trace, to narrow down the source of the error.
 1.12 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.11 20-Jul-2024  rillig make: don't run erroneous commands in compat mode

When there is a parse or evaluation error in an expression that becomes
part of the command, don't run that command, as the result of the failed
evaluation typically contains garbage characters. Skip the remaining
commands from that target as well, as they may depend on the erroneous
command.
 1.10 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.9 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.8 30-Jun-2024  rillig make: error out on some more syntax errors

Previously, these errors only produced a message on stderr. They only
affected make's exit status when they were evaluated at parse time, but
not when evaluating the commands for a specific target right before
executing them.

The affected syntax errors are:
* invalid regular expressions in the ':C' modifier
* out-of-range references to regex groups in the ':C' modifier
* unfinished modifiers
 1.7 20-Apr-2024  rillig branches: 1.7.2;
make: provide more context information for parse/evaluate errors
 1.6 21-Jun-2021  rillig tests/make: move and extend test for unmatched '\1' in ':C'

This test lived together with a few unrelated tests in moderrs.mk, it is
better placed in varmod-subst-regex.mk though.

While here, extend, document and explain the test since its purpose was
not obvious from reading the code alone.
 1.5 23-Feb-2021  rillig make: improve error message for unknown modifier

Back in 1995, the modifiers were all single-character, and it made sense
to print only the first character. Nowadays, with ':S', ':@var@...@',
'::=' and several others, a little more context is useful to see where
the exact error is. The actual modifier is still guessed, and the guess
may be wrong as soon as backslashes get involved, but it is still better
than before.
 1.4 05-Dec-2020  rillig make(1): add test for unknown modifier in :C modifier replacement
 1.3 28-Aug-2020  rillig make(1): fix manual page about the modifiers of the :C modifier
 1.2 16-Aug-2020  rillig make(1): move tests for :S, :C, :@ from modmisc to their separate tests
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7.2.2 02-Aug-2025  perseant Sync with HEAD
 1.7.2.1 01-Jul-2024  perseant Sync with HEAD.
 1.12 20-Jul-2024  rillig make: don't run erroneous commands in compat mode

When there is a parse or evaluation error in an expression that becomes
part of the command, don't run that command, as the result of the failed
evaluation typically contains garbage characters. Skip the remaining
commands from that target as well, as they may depend on the erroneous
command.
 1.11 18-Dec-2023  rillig branches: 1.11.2;
tests/make: fix typo in test for ':C' modifier

The expression ${U:...} was always undefined, as there was no variable
named 'U'; the intended form was ${:U:...}. Due to this typo, the
comments in the tests for the ':S' and the ':C' modifier contradicted
each other.
 1.10 17-Dec-2023  rillig tests/make: extend tests for include guards and empty expressions
 1.9 10-Dec-2023  rillig make: fix crash in ':C' modifier on an empty expression

Since var.c 1.982 from 2021-12-13.
 1.8 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.7 21-Jun-2021  rillig tests/make: move and extend test for unmatched '\1' in ':C'

This test lived together with a few unrelated tests in moderrs.mk, it is
better placed in varmod-subst-regex.mk though.

While here, extend, document and explain the test since its purpose was
not obvious from reading the code alone.
 1.6 05-Dec-2020  rillig make(1): add test for unknown modifier in :C modifier replacement
 1.5 31-Oct-2020  rillig make(1): add tests for edge cases in the :C variable modifier
 1.4 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.3 28-Aug-2020  rillig make(1): fix manual page about the modifiers of the :C modifier
 1.2 16-Aug-2020  rillig make(1): move tests for :S, :C, :@ from modmisc to their separate tests
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.11.2.1 02-Aug-2025  perseant Sync with HEAD
 1.11 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.10 29-Mar-2025  rillig make: in stack traces from target commands, add the command level

A target can contain several commands, and these commands are likely to
contain the same expressions. To distinguish them, add one more line to
the stack trace, to narrow down the source of the error.
 1.9 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.8 20-Jul-2024  rillig make: don't run erroneous commands in compat mode

When there is a parse or evaluation error in an expression that becomes
part of the command, don't run that command, as the result of the failed
evaluation typically contains garbage characters. Skip the remaining
commands from that target as well, as they may depend on the erroneous
command.
 1.7 09-Jul-2024  rillig make: error out on parse/evaluation errors in shell commands

The expression ${VAR:X} has an unknown modifier ':X'. Previously, this
expression errored out when the expression was evaluated at parse time,
but not when the expression was evaluated when generating the commands
to bring a target up to date. The errors were previously reported, they
didn't affect the exit status, though.

Now, errors in expressions are handled in the same way, regardless of
the time at which they are evaluated.
 1.6 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.5 20-Apr-2024  rillig branches: 1.5.2;
make: provide more context information for parse/evaluate errors
 1.4 23-Feb-2021  rillig make: improve error message for unknown modifier

Back in 1995, the modifiers were all single-character, and it made sense
to print only the first character. Nowadays, with ':S', ':@var@...@',
'::=' and several others, a little more context is useful to see where
the exact error is. The actual modifier is still guessed, and the guess
may be wrong as soon as backslashes get involved, but it is still better
than before.
 1.3 03-Nov-2020  rillig make(1): add all printable ASCII characters to the varmod-subst test

I must have missed some of them when I originally wrote the test. Not
sure how that happened. While here, use the official Unicode names.
 1.2 16-Aug-2020  rillig make(1): move tests for :S, :C, :@ from modmisc to their separate tests
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5.2.1 02-Aug-2025  perseant Sync with HEAD
 1.17 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.16 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.15 20-Jul-2024  rillig make: don't run erroneous commands in compat mode

When there is a parse or evaluation error in an expression that becomes
part of the command, don't run that command, as the result of the failed
evaluation typically contains garbage characters. Skip the remaining
commands from that target as well, as they may depend on the erroneous
command.
 1.14 18-Dec-2023  rillig branches: 1.14.2;
tests/make: fix typo in test for ':C' modifier

The expression ${U:...} was always undefined, as there was no variable
named 'U'; the intended form was ${:U:...}. Due to this typo, the
comments in the tests for the ':S' and the ':C' modifier contradicted
each other.
 1.13 17-Dec-2023  rillig tests/make: extend tests for include guards and empty expressions
 1.12 16-Jun-2023  rillig tests/make: clean up tests for the ':M' and ':S' modifiers
 1.11 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.10 01-Jun-2023  rillig tests/make: clean up comments, extend a few tests
 1.9 06-Sep-2021  rillig tests/make: test modifier ':S' with replacement '&'

Before 2020-08-30, OpenBSD make incorrectly copied the anchors '^' and
'$' to the replacement string. Just guard against this possible bug.
 1.8 14-May-2021  rillig tests/make: show that in ':S', '.' and '*' are ordinary characters
 1.7 15-Nov-2020  rillig branches: 1.7.2;
make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.6 03-Nov-2020  rillig make(1): in tests, replace "dollar character" with "dollar sign"
 1.5 03-Nov-2020  rillig make(1): add all printable ASCII characters to the varmod-subst test

I must have missed some of them when I originally wrote the test. Not
sure how that happened. While here, use the official Unicode names.
 1.4 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.3 19-Aug-2020  rillig make(1): fix a few inconsistencies in the manual page
 1.2 16-Aug-2020  rillig make(1): move tests for :S, :C, :@ from modmisc to their separate tests
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7.2.1 31-May-2021  cjep sync with head
 1.14.2.1 02-Aug-2025  perseant Sync with HEAD
 1.8 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.7 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.6 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.5 30-Jun-2024  rillig make: add detailed exit status to message for failed sub-commands

Several commands communicate via the exit status and not only
distinguish between zero and non-zero, so make this information
available to ease investigations.

The command "false" is not guaranteed to exit with a consistent status,
so use "(exit 13)" instead in the tests, to keep these tests portable
across different operating systems. The exit status 127 is required for
a shell that cannot find a command, so keep that one.
 1.4 30-Jun-2024  rillig make: add more context to "returned non-zero status" message

Previously, this message was an "error" but had no influence on the exit
status, so make it a warning instead. In the seldom used -W mode that
treats warnings as errors, this change influences the exit status.
 1.3 26-Mar-2022  rillig branches: 1.3.4;
make: avoid trailing whitespace in debug log for variables

Since trailing whitespace is invisible, describe the variable value in
words to make it visible.
 1.2 10-Jan-2022  rillig make: add debug logging for capturing the output of external commands

This applies to all 4 situations in which the output of an external
command is used for modifying a variable or an expression:

* the assignment operator '!='
* the assignment modifier '::!='
* the SUN shell modifier ':sh'
* the other shell modifier ':!cmd!'

Previously, only the shell modifier ':!cmd!' had debug logging.

Suggested by Christoph Badura.
 1.1 14-Feb-2021  rillig make: add test for the variable modifier ':sh'
 1.3.4.2 02-Aug-2025  perseant Sync with HEAD
 1.3.4.1 01-Jul-2024  perseant Sync with HEAD.
 1.6 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.5 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.4 30-Jun-2024  rillig make: add detailed exit status to message for failed sub-commands

Several commands communicate via the exit status and not only
distinguish between zero and non-zero, so make this information
available to ease investigations.

The command "false" is not guaranteed to exit with a consistent status,
so use "(exit 13)" instead in the tests, to keep these tests portable
across different operating systems. The exit status 127 is required for
a shell that cannot find a command, so keep that one.
 1.3 30-Jun-2024  rillig make: add more context to "returned non-zero status" message

Previously, this message was an "error" but had no influence on the exit
status, so make it a warning instead. In the seldom used -W mode that
treats warnings as errors, this change influences the exit status.
 1.2 10-Jan-2022  rillig branches: 1.2.4;
make: add debug logging for capturing the output of external commands

This applies to all 4 situations in which the output of an external
command is used for modifying a variable or an expression:

* the assignment operator '!='
* the assignment modifier '::!='
* the SUN shell modifier ':sh'
* the other shell modifier ':!cmd!'

Previously, only the shell modifier ':!cmd!' had debug logging.

Suggested by Christoph Badura.
 1.1 14-Feb-2021  rillig make: add test for the variable modifier ':sh'
 1.2.4.2 02-Aug-2025  perseant Sync with HEAD
 1.2.4.1 01-Jul-2024  perseant Sync with HEAD.
 1.19 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.18 29-Mar-2025  rillig make: add more details to error message about unfinished modifier

These details allow to quickly see the place where the syntax error is,
based on the surrounding lines from the stack trace.
 1.17 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.16 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.15 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.14 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.13 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.12 30-Jun-2024  rillig make: error out on some more syntax errors

Previously, these errors only produced a message on stderr. They only
affected make's exit status when they were evaluated at parse time, but
not when evaluating the commands for a specific target right before
executing them.

The affected syntax errors are:
* invalid regular expressions in the ':C' modifier
* out-of-range references to regex groups in the ':C' modifier
* unfinished modifiers
 1.11 01-Jun-2024  rillig branches: 1.11.2;
tests/make: test more modifiers and special variables
 1.10 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.9 12-Apr-2021  rillig tests/make: fix test for modifier ':from=to'

I had forgotten to remove the single quotes, to produce a really empty
word. Plus I had forgotten the modifier ':Q' for the result, which
meant that the single quotes did not show up in the output.
 1.8 12-Apr-2021  rillig tests/make: add table test for the modifier ':from=to'

Just to prevent any accidental change in the upcoming refactoring to
reduce memory allocation in ApplyModifier_SysV.
 1.7 23-Feb-2021  rillig make: add quotes around variable name in an error message
 1.6 05-Dec-2020  rillig make(1): improve explanation of tests for the SysV modifier
 1.5 01-Nov-2020  rillig make(1): add another test case for the SysV modifier

The "special case" in ApplyModifier_SysV looks redundant since in
SysVMatch, the empty word does not match anything.
 1.4 01-Nov-2020  rillig make(1): add tests for parsing the SysV variable modifier
 1.3 06-Oct-2020  rillig make(1): migrate SysV modifier test to use the preprocessor

When both the expected and the actual expression are written in the same
line of the same file, it is easier to compare them and to document
anything interesting. The exp file doesn't provide any space for
comments or explanations.
 1.2 23-Aug-2020  rillig make(1): move some of the SysV modifier tests into another file
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.11.2.2 02-Aug-2025  perseant Sync with HEAD
 1.11.2.1 01-Jul-2024  perseant Sync with HEAD.
 1.24 30-Mar-2025  rillig make: let the ":t" modifiers fall back to the ":from=to" modifier

Suggested by https://bugs.freebsd.org/285726.

This means that the ":t" modifiers cannot have future extensions that
include a "=", as that may break existing code.
 1.23 29-Mar-2025  rillig make: add more details to error message about unfinished modifier

These details allow to quickly see the place where the syntax error is,
based on the surrounding lines from the stack trace.
 1.22 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.21 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.20 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.19 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.18 30-Jun-2024  rillig make: error out on some more syntax errors

Previously, these errors only produced a message on stderr. They only
affected make's exit status when they were evaluated at parse time, but
not when evaluating the commands for a specific target right before
executing them.

The affected syntax errors are:
* invalid regular expressions in the ':C' modifier
* out-of-range references to regex groups in the ':C' modifier
* unfinished modifiers
 1.17 01-Jun-2024  rillig branches: 1.17.2;
tests/make: test more modifiers and special variables
 1.16 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.15 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.14 12-Apr-2021  rillig tests/make: fix test for modifier ':from=to'

I had forgotten to remove the single quotes, to produce a really empty
word. Plus I had forgotten the modifier ':Q' for the result, which
meant that the single quotes did not show up in the output.
 1.13 12-Apr-2021  rillig tests/make: add table test for the modifier ':from=to'

Just to prevent any accidental change in the upcoming refactoring to
reduce memory allocation in ApplyModifier_SysV.
 1.12 05-Dec-2020  rillig make(1): improve explanation of tests for the SysV modifier
 1.11 01-Nov-2020  rillig make(1): add another test case for the SysV modifier

The "special case" in ApplyModifier_SysV looks redundant since in
SysVMatch, the empty word does not match anything.
 1.10 01-Nov-2020  rillig make(1): add tests for parsing the SysV variable modifier
 1.9 31-Oct-2020  rillig make(1): merge the SysV modifier tests into varmod-sysv
 1.8 31-Oct-2020  rillig make(1): add tutorial for the :from=to variable modifier
 1.7 31-Oct-2020  rillig make(1): remove redundant code branch in SysVMatch

The general code path of parsing :from=to achieves the same effect.
 1.6 31-Oct-2020  rillig make(1): explain tests for the SysV variable modifier
 1.5 06-Oct-2020  rillig make(1): add test for double expansion in SySV modifier
 1.4 06-Oct-2020  rillig make(1): migrate SysV modifier test to use the preprocessor

When both the expected and the actual expression are written in the same
line of the same file, it is easier to compare them and to document
anything interesting. The exp file doesn't provide any space for
comments or explanations.
 1.3 23-Aug-2020  rillig make(1): move some of the SysV modifier tests into another file
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.17.2.2 02-Aug-2025  perseant Sync with HEAD
 1.17.2.1 01-Jul-2024  perseant Sync with HEAD.
 1.3 20-Dec-2020  rillig make(1): add tests for variable modifiers on trailing slashes
 1.2 23-Aug-2020  rillig make(1): move tests for :H :E :R :T into separate files
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 01-Jun-2024  rillig tests/make: test more modifiers and special variables
 1.4 20-Dec-2020  rillig make(1): add tests for variable modifiers on trailing slashes
 1.3 23-Aug-2020  rillig make(1): move tests for :H :E :R :T into separate files
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.6 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.5 01-Jun-2023  rillig branches: 1.5.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.4 15-Nov-2020  rillig make(1): fix test varmod-to-abs with USE_ABSOLUTE_TESTNAMES=yes

When running the tests with specifying absolute filenames, it doesn't
make sense to prefix the MAKEFILE with "./", which made the tests fail on
FreeBSD.
 1.3 14-Nov-2020  rillig make(1): switch cache for realpath from GNode to HashTable

An unintended side effect from the GNode implementation was that the
variable modifier :tA and the other places where cached_realpath are
used could be affected by setting a variable in the global scope,
thereby "redirecting" absolute paths to completely unrelated but
existing paths.

Another unintended side effect was that filenames containing a dollar
sign would not be resolved correctly since the dollar sign would be
expanded as a variable expression by Var_Set.

While here, the debugging output for the realpath cache has been
adjusted to the standard behavior. Previously, when a new entry was
added to the cache, this was logged for the module VAR, as a side effect
of calling Var_Set, but only if the preprocessor macro
DEBUG_REALPATH_CACHE was defined at compilation time. When relative
paths were purged from the cache because the current directory changed
and logging for the DIR module was active, the log output went directly
to stderr instead of the usual opts.debug_file. This deviation from the
standard behavior was probably not intended as well.

All logging concerning the realpath cache now goes into the standard
debug log file and is controlled by the -dd option, not -dv.
 1.2 14-Nov-2020  rillig make(1): add test for undocumented path-to-abspath mapping for :tA
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5.2.1 02-Aug-2025  perseant Sync with HEAD
 1.6 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.5 15-Nov-2020  rillig make(1): fix test varmod-to-abs with USE_ABSOLUTE_TESTNAMES=yes

When running the tests with specifying absolute filenames, it doesn't
make sense to prefix the MAKEFILE with "./", which made the tests fail on
FreeBSD.
 1.4 14-Nov-2020  rillig make(1): switch cache for realpath from GNode to HashTable

An unintended side effect from the GNode implementation was that the
variable modifier :tA and the other places where cached_realpath are
used could be affected by setting a variable in the global scope,
thereby "redirecting" absolute paths to completely unrelated but
existing paths.

Another unintended side effect was that filenames containing a dollar
sign would not be resolved correctly since the dollar sign would be
expanded as a variable expression by Var_Set.

While here, the debugging output for the realpath cache has been
adjusted to the standard behavior. Previously, when a new entry was
added to the cache, this was logged for the module VAR, as a side effect
of calling Var_Set, but only if the preprocessor macro
DEBUG_REALPATH_CACHE was defined at compilation time. When relative
paths were purged from the cache because the current directory changed
and logging for the DIR module was active, the log output went directly
to stderr instead of the usual opts.debug_file. This deviation from the
standard behavior was probably not intended as well.

All logging concerning the realpath cache now goes into the standard
debug log file and is controlled by the -dd option, not -dv.
 1.3 14-Nov-2020  rillig make(1): add test for undocumented path-to-abspath mapping for :tA
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.6 29-Nov-2022  rillig tests/make: document that the ':tl' modifier does not split words
 1.5 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.4 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.3 28-Aug-2020  rillig make(1): add tests for :tl and :tu modifiers
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 20-Dec-2020  rillig make(1): add tests for :tW and :tw modifiers
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 20-Dec-2020  rillig make(1): add tests for :tW and :tw modifiers
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.21 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.20 30-Mar-2025  rillig make: let the ":t" modifiers fall back to the ":from=to" modifier

Suggested by https://bugs.freebsd.org/285726.

This means that the ":t" modifiers cannot have future extensions that
include a "=", as that may break existing code.
 1.19 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.18 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.17 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.16 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.15 04-Jul-2024  rillig make: error out on the "Bad modifier" error message

Previously, the "Bad modifier" error message did not affect make's exit
status. As a side effect, this kind of error now gets more context
information.
 1.14 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.13 01-Jun-2024  rillig branches: 1.13.2;
tests/make: test more modifiers and special variables
 1.12 20-Apr-2024  rillig make: provide more context information for parse/evaluate errors
 1.11 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.10 23-Jan-2022  rillig tests/make: add more tests for the modifier ':ts'
 1.9 23-Jan-2022  rillig tests/make: migrate modts to varmod-to-separator and explain
 1.8 09-Dec-2021  rillig make: in parse errors, mark whitespace more clearly

This prevents any trailing whitespace from going unnoticed. It also
marks leading whitespace more clearly, as in the examples with the time
value " 1".
 1.7 23-Feb-2021  rillig make: improve error message for bad modifier in variable expression

The improvement is especially noteable for variable expressions based on
the empty variable, see moderrs.exp:103.
 1.6 21-Dec-2020  rillig make(1): remove excess newline from parse errors (since 2020-11-01)

For the modifiers :gmtime and :localtime, the excess newline had been
added in var.c 1.631 from 2020-10-31 21:40:20.

For the modifiers :range and :ts, the excess newline had been added in
var.c 1.635 from 2020-11-01 14:36:25.
 1.5 01-Nov-2020  rillig make(1): treat malformed :range, :ts and :[...] as errors

Before, integer overflow in the :[1..2] modifier had not been detected,
and the actual behavior varied between ILP64 and LP64I32 machines.

Before, the :ts modifier accepted character literals like \012345 and
\x1F600, which don't fit in a single character and were thus truncated.

Before, the :range modifier issued an "Unknown modifier" error message
for :range=x, which was not quite correct. The error message in this
case is now "Invalid number".
 1.4 01-Nov-2020  rillig make(1): add tests for parsing errors in the :ts variable modifier
 1.3 01-Nov-2020  rillig make(1): add test for out-of-bounds separator in variable modifier :ts
 1.2 31-Aug-2020  rillig make(1): move some of the :ts tests into a separate file

The successful cases can be easily tested in the .if conditions. Around
these conditions, there is enough space for explaining the test cases
and their purpose.

The failure cases have been left in the file for now since they still
produce unwanted characters in the output. These characters are not
produced when the parse error occurs in a conditional.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.13.2.1 02-Aug-2025  perseant Sync with HEAD
 1.23 30-Mar-2025  rillig make: let the ":t" modifiers fall back to the ":from=to" modifier

Suggested by https://bugs.freebsd.org/285726.

This means that the ":t" modifiers cannot have future extensions that
include a "=", as that may break existing code.
 1.22 29-Mar-2025  rillig tests/make: remove copy-and-paste errors from warning messages

Several of the warnings didn't match what they actually tested, so
remove them all to prevent further disagreements.
 1.21 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.20 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.19 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.18 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.17 04-Jul-2024  rillig make: error out on the "Bad modifier" error message

Previously, the "Bad modifier" error message did not affect make's exit
status. As a side effect, this kind of error now gets more context
information.
 1.16 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.15 01-Jun-2024  rillig branches: 1.15.2;
tests/make: test more modifiers and special variables
 1.14 20-Apr-2024  rillig make: provide more context information for parse/evaluate errors
 1.13 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.12 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.11 09-Feb-2022  rillig make: fix mistakes, spelling and typos in comments and manual page

No binary change for -DNDEBUG.
 1.10 23-Jan-2022  rillig tests/make: add a few more tests
 1.9 23-Jan-2022  rillig tests/make: add more tests for the modifier ':ts'
 1.8 23-Jan-2022  rillig tests/make: migrate modts to varmod-to-separator and explain
 1.7 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.6 01-Nov-2020  rillig make(1): treat malformed :range, :ts and :[...] as errors

Before, integer overflow in the :[1..2] modifier had not been detected,
and the actual behavior varied between ILP64 and LP64I32 machines.

Before, the :ts modifier accepted character literals like \012345 and
\x1F600, which don't fit in a single character and were thus truncated.

Before, the :range modifier issued an "Unknown modifier" error message
for :range=x, which was not quite correct. The error message in this
case is now "Invalid number".
 1.5 01-Nov-2020  rillig make(1): add tests for parsing errors in the :ts variable modifier
 1.4 01-Nov-2020  rillig make(1): add test for out-of-bounds separator in variable modifier :ts
 1.3 31-Aug-2020  rillig make(1): move some of the :ts tests into a separate file

The successful cases can be easily tested in the .if conditions. Around
these conditions, there is enough space for explaining the test cases
and their purpose.

The failure cases have been left in the file for now since they still
produce unwanted characters in the output. These characters are not
produced when the parse error occurs in a conditional.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.15.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 01-Jul-2024  sjg branches: 1.1.4;
make: add :tc to capitalize first letter of each word

This is very hard to do without :tc

Reviewed by: rillig
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 01-Jul-2024  perseant file varmod-to-title.exp was added on branch perseant-exfatfs on 2025-08-02 05:58:39 +0000
 1.1 01-Jul-2024  sjg branches: 1.1.4;
make: add :tc to capitalize first letter of each word

This is very hard to do without :tc

Reviewed by: rillig
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 01-Jul-2024  perseant file varmod-to-title.mk was added on branch perseant-exfatfs on 2025-08-02 05:58:40 +0000
 1.2 23-Aug-2020  rillig make(1): move tests for the :tu and :_ modifiers into separate files
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.4 28-Aug-2020  rillig make(1): add tests for :tl and :tu modifiers
 1.3 23-Aug-2020  rillig make(1): move tests for the :tu and :_ modifiers into separate files
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.11 03-Jun-2024  sjg Note that varmod-undefined depends on .MAKE.SAVE_DOLLARS=yes
 1.10 02-Jun-2024  rillig tests/make: test more details of the :U and :D modifiers
 1.9 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.8 06-Aug-2022  rillig tests/make: demonstrate bug in parsing of modifier parts

In the modifier ':S,from,to,', parsing the two parts 'from' and 'to' of
the modifier differs depending on whether the expression is actually
evaluated or merely parsed. This not only applies to the ':S' modifier,
but also to ':C', ':@var@body@', ':!cmd!', ':[...]', ':?:', '::=' and
':from=to'.
 1.7 15-Nov-2020  rillig make(1): update and add comments in tests

As a result of the new comments, some line numbers have changed in the
output of the tests. No other changes.
 1.6 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.5 12-Sep-2020  rillig make(1): add tests for combining the :D and :U variable modifiers
 1.4 03-Sep-2020  rillig make(1): add tests for the :D and :U modifiers

This prepares a refactoring for ApplyModifier_Defined.
 1.3 23-Aug-2020  rillig make(1): add test for :U modifier
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 31-Aug-2020  rillig make(1): fix the :u modifier, which was broken for almost a day

Big thanks go to sjg, who discovered the bug and did the main work to
track it down.

In the unit tests for the :u modifier from the previous commit, I had
forgotten to actually add the :u modifier at the end. I added it now
and also added a few other tests. It's better to have a few more tests
than too few.
 1.2 31-Aug-2020  rillig make(1): add test for the currently broken :u variable modifier

The :u modifier had been broken in var.c 1.479 from 2020.08.30.19.56.02.
The code that implements the :u modifier was well-covered in the unit
tests, except for the single line that actually deals with adjacent
duplicate words.

The "refactoring" commit that replaced brk_string with Str_Words had not
taken into account that the number of words (in ac) had to be passed to
WordList_JoinFree. Instead, the number of words was always preserved,
and the words at the end were therefore duplicated in the result.

The fix for this bug will be in the follow-up commit.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.6 05-Dec-2021  rillig tests/make: replace ':U' with ':L' in test for ':u'

In expressions using ':L', the value of the variable is delimited by
'{', which makes it easier to recognize it visually, as opposed to being
delimited by 'U'.
 1.5 30-May-2021  rillig tests/make: test whitespace normalization for modifier ':u'
 1.4 31-Aug-2020  rillig branches: 1.4.2;
make(1): fix the :u modifier, which was broken for almost a day

Big thanks go to sjg, who discovered the bug and did the main work to
track it down.

In the unit tests for the :u modifier from the previous commit, I had
forgotten to actually add the :u modifier at the end. I added it now
and also added a few other tests. It's better to have a few more tests
than too few.
 1.3 31-Aug-2020  rillig make(1): add test for the currently broken :u variable modifier

The :u modifier had been broken in var.c 1.479 from 2020.08.30.19.56.02.
The code that implements the :u modifier was well-covered in the unit
tests, except for the single line that actually deals with adjacent
duplicate words.

The "refactoring" commit that replaced brk_string with Str_Words had not
taken into account that the number of words (in ac) had to be passed to
WordList_JoinFree. Instead, the number of words was always preserved,
and the words at the end were therefore duplicated in the result.

The fix for this bug will be in the follow-up commit.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4.2.1 31-May-2021  cjep sync with head
 1.26 29-Jun-2025  rillig make: if a condition is erroneous, skip the whole .if/.endif
 1.25 29-Jun-2025  rillig make: fix parsing of modifier parts for :gmtime and :localtime

There's no practical use for escaping the ":" or "}" in these two
modifiers, but the same scheme may prove useful for the :M and :N
modifiers, which are currently parsed in a completely different manner,
thus adding needless complexity.

Parsing of the :M and :N modifiers is discussed in PR bin/46139.
 1.24 29-Jun-2025  rillig tests/make: demonstrate bug in parsing :gmtime and :localtime

When the parsing of modifiers was unified a bit in May 2024, the :gmtime
and :localtime modifiers were the only ones that had two different
delimiters. Of these delimiters, only the second one can be escaped, but
the intention was that both of them can be escaped.

Since it doesn't make sense to have either ":" or "}" or ")" in a
second-based timestamp, this bug has survived more than a year.
 1.23 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.22 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.21 30-Mar-2025  rillig make: fix error message for invalid ":[...]" modifier

The unparsed value of the modifier argument can already be seen in the
stack trace, but the modifier argument may contain expressions and the
expanded value of these expressions was hidden up to now. See the EMPTY
test at the bottom of varmod-select-words.mk for details.
 1.20 29-Mar-2025  rillig tests/make: fix the documented modifier table

The SysV column was largely incorrect or too unspecific, stating N/A
when "no" was actually correct.

The modifiers differ in whether they fall back to the ":from=to"
modifier. The suggestion in https://bugs.freebsd.org/285726 to make more
of the modifiers fall back to the ":from=to" modifier thus becomes
nonobvious to decide.
 1.19 29-Mar-2025  rillig make: add details about indirect modifiers to the stack traces

Previously, the error message "Unfinished modifier (',' missing)" from
moderrs.mk didn't provide enough context to understand where and why the
comma was missing.
 1.18 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.17 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.16 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.15 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.14 04-Jul-2024  rillig make: error out on the "Bad modifier" error message

Previously, the "Bad modifier" error message did not affect make's exit
status. As a side effect, this kind of error now gets more context
information.
 1.13 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.12 06-Jun-2024  rillig branches: 1.12.2;
tests/make: test unescaped '$' at the end of a modifier part

In ParseModifierPart, an unescaped '$' that occurs right before a
delimiter is handled differently from a '$' that occurs in the middle of
the modifier part.

In practice, this edge case is only used by the first part of the
':C,from,to,' modifier. Using it in most other modifier parts produces
an error message.
 1.11 02-Jun-2024  rillig make: fix out-of-bounds read when parsing indirect modifiers
 1.10 01-Jun-2024  rillig tests/make: test more modifiers and special variables
 1.9 20-Apr-2024  rillig make: provide more context information for parse/evaluate errors
 1.8 03-Feb-2024  sjg make: state of save_dollars affects what is a parse error

When save_dollars is false it is not a parse error to
encounter $$ rather than \$.
 1.7 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.6 24-Aug-2022  rillig tests/make: test misleading error messages on unclosed expressions

The error messages say 'Unknown modifier' or 'Bad modifier', which is
not entirely correct. The modifier in itself is valid, it's just that
make doesn't expect the end of the string after the modifier.
 1.5 06-Aug-2022  rillig tests/make: document parsing behavior of modifiers

The table was created by manually inspecting the code of the various
ApplyModifier functions in var.c.

The modifiers are listed in alphabetical order, except for the SysV
modifier, which is listed at the end since it is used as a fallback
modifier for many other modifiers and because it does not have a fixed
prefix.
 1.4 19-Dec-2020  rillig make(1): fix error message for .info/.warning/.error without argument

Previously, the error message was "Unknown directive", which was
obviously wrong. The new error message is "Missing argument".
 1.3 02-Nov-2020  rillig make(1): add test for the :P modifier, which does not fall back
 1.2 13-Sep-2020  rillig make(1): in lint mode, complain about erroneous $$

Since 2008-12-21, make has silently ignored strange variable names in
constructs like '$$', '$}', '$' followed by nothing. Ignoring these
bugs in makefiles instead of reporting them is not a good idea.

To improve the situation, make complains about these errors now, but
only in lint mode (-dL). This preserves existing behavior while still
allowing to validate existing makefiles that they don't depend on this
bug.

If the test phase goes well, these error messages may be enabled
unconditionally.

https://mail-index.netbsd.org/pkgsrc-users/2020/09/12/msg032229.html
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.12.2.1 02-Aug-2025  perseant Sync with HEAD
 1.30 29-Jun-2025  rillig make: if a condition is erroneous, skip the whole .if/.endif
 1.29 29-Jun-2025  rillig make: fix parsing of modifier parts for :gmtime and :localtime

There's no practical use for escaping the ":" or "}" in these two
modifiers, but the same scheme may prove useful for the :M and :N
modifiers, which are currently parsed in a completely different manner,
thus adding needless complexity.

Parsing of the :M and :N modifiers is discussed in PR bin/46139.
 1.28 29-Jun-2025  rillig tests/make: demonstrate bug in parsing :gmtime and :localtime

When the parsing of modifiers was unified a bit in May 2024, the :gmtime
and :localtime modifiers were the only ones that had two different
delimiters. Of these delimiters, only the second one can be escaped, but
the intention was that both of them can be escaped.

Since it doesn't make sense to have either ":" or "}" or ")" in a
second-based timestamp, this bug has survived more than a year.
 1.27 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.26 30-Mar-2025  rillig make: fix error message for invalid ":[...]" modifier

The unparsed value of the modifier argument can already be seen in the
stack trace, but the modifier argument may contain expressions and the
expanded value of these expressions was hidden up to now. See the EMPTY
test at the bottom of varmod-select-words.mk for details.
 1.25 30-Mar-2025  rillig make: let the ":t" modifiers fall back to the ":from=to" modifier

Suggested by https://bugs.freebsd.org/285726.

This means that the ":t" modifiers cannot have future extensions that
include a "=", as that may break existing code.
 1.24 29-Mar-2025  rillig make: let unknown ":O" modifiers fall back to the ":from=to" modifier

Inspired by https://bugs.freebsd.org/285726, which concerns the ":t"
modifier instead.

This means that future extensions to the ":O" modifier must not contain
a "=" anywhere, otherwise they may break existing code.
 1.23 29-Mar-2025  rillig tests/make: fix the documented modifier table

The SysV column was largely incorrect or too unspecific, stating N/A
when "no" was actually correct.

The modifiers differ in whether they fall back to the ":from=to"
modifier. The suggestion in https://bugs.freebsd.org/285726 to make more
of the modifiers fall back to the ":from=to" modifier thus becomes
nonobvious to decide.
 1.22 11-Jan-2025  rillig make: omit redundant follow-up message "Malformed conditional"

If there is a parse error or an evaluation error during the conditional,
the conditional is already mentioned in the "while evaluating condition"
line, so there's no reason to repeat it once again.

Same for the "Bad condition" message from the '?:' modifier.
 1.21 11-Jan-2025  rillig tests/make: force correct order of expected messages
 1.20 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.19 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.18 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.17 04-Jul-2024  rillig make: error out on the "Bad modifier" error message

Previously, the "Bad modifier" error message did not affect make's exit
status. As a side effect, this kind of error now gets more context
information.
 1.16 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.15 06-Jun-2024  rillig branches: 1.15.2;
tests/make: test unescaped '$' at the end of a modifier part

In ParseModifierPart, an unescaped '$' that occurs right before a
delimiter is handled differently from a '$' that occurs in the middle of
the modifier part.

In practice, this edge case is only used by the first part of the
':C,from,to,' modifier. Using it in most other modifier parts produces
an error message.
 1.14 05-Jun-2024  rillig make: sync comments with reality
 1.13 02-Jun-2024  rillig make: fix out-of-bounds read when parsing indirect modifiers
 1.12 01-Jun-2024  rillig tests/make: test more modifiers and special variables
 1.11 20-Apr-2024  rillig make: provide more context information for parse/evaluate errors
 1.10 03-Feb-2024  sjg make: state of save_dollars affects what is a parse error

When save_dollars is false it is not a parse error to
encounter $$ rather than \$.
 1.9 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.8 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.7 24-Aug-2022  rillig tests/make: test misleading error messages on unclosed expressions

The error messages say 'Unknown modifier' or 'Bad modifier', which is
not entirely correct. The modifier in itself is valid, it's just that
make doesn't expect the end of the string after the modifier.
 1.6 06-Aug-2022  rillig tests/make: document parsing behavior of modifiers

The table was created by manually inspecting the code of the various
ApplyModifier functions in var.c.

The modifiers are listed in alphabetical order, except for the SysV
modifier, which is listed at the end since it is used as a fallback
modifier for many other modifiers and because it does not have a fixed
prefix.
 1.5 19-Dec-2020  rillig make(1): fix error message for .info/.warning/.error without argument

Previously, the error message was "Unknown directive", which was
obviously wrong. The new error message is "Missing argument".
 1.4 02-Nov-2020  rillig make(1): add test for the :P modifier, which does not fall back
 1.3 13-Sep-2020  rillig make(1): in lint mode, complain about erroneous $$

Since 2008-12-21, make has silently ignored strange variable names in
constructs like '$$', '$}', '$' followed by nothing. Ignoring these
bugs in makefiles instead of reporting them is not a good idea.

To improve the situation, make complains about these errors now, but
only in lint mode (-dL). This preserves existing behavior while still
allowing to validate existing makefiles that they don't depend on this
bug.

If the test phase goes well, these error messages may be enabled
unconditionally.

https://mail-index.netbsd.org/pkgsrc-users/2020/09/12/msg032229.html
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.15.2.1 02-Aug-2025  perseant Sync with HEAD
 1.2 28-Jun-2025  rillig branches: 1.2.4;
make: add POSIX $^ support

POSIX 2024 [1] introduced the $^ internal macro. Implement it as an
alias for $> (.ALLSRC), following the suggestion from defect 1520 [2].

[1]: https://pubs.opengroup.org/onlinepubs/9799919799/utilities/make.html
[2]: https://www.austingroupbugs.net/view.php?id=1520

Patch provided by Diogo Santos in PR bin/59018.
 1.1 27-Jun-2025  rillig tests/make: test missing support for $^

Test provided by Diogo Santos via PR bin/59018; extended by me for .WAIT
and implicit rules.
 1.2.4.2 02-Aug-2025  perseant Sync with HEAD
 1.2.4.1 28-Jun-2025  perseant file varname-circumflex.exp was added on branch perseant-exfatfs on 2025-08-02 05:58:40 +0000
 1.2 09-Aug-2025  rillig make: clean up
 1.1 27-Jun-2025  rillig branches: 1.1.4;
tests/make: test missing support for $^

Test provided by Diogo Santos via PR bin/59018; extended by me for .WAIT
and implicit rules.
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 27-Jun-2025  perseant file varname-circumflex.mk was added on branch perseant-exfatfs on 2025-08-02 05:58:40 +0000
 1.4 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.3 01-Jun-2023  rillig branches: 1.3.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.2 19-Aug-2020  rillig make(1): add test for the $$ expression
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.4 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.3 19-Aug-2020  rillig make(1): add test for the $$ expression
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 25-Aug-2020  rillig make(1): add test for the .ALLTARGETS special variable
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 25-Aug-2020  rillig make(1): add test for the .ALLTARGETS special variable
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7 08-Oct-2020  rillig make(1): move test for .CURDIR from misc.mk to varname-dot-curname.mk
 1.6 05-Oct-2020  rillig make(1): revert previous commit

It had accidentally reverted all the work from the past few days.
 1.5 05-Oct-2020  rillig make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)

The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.

Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.

With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.4 04-Oct-2020  rillig make(1): fix assignment to .CURDIR via the shell assignment operator

This is probably an edge case that nobody will ever stumble upon, since
.CURDIR is usually regarded as a read-only variable.

The other variable that is affected by this code path is .MAKE.EXPORTED,
and for this variable as well, it would be unusual to assign it a value
from a shell command.
 1.3 04-Oct-2020  rillig make(1): add test for assigning to .CURDIR
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 28-Aug-2020  rillig make(1): add tests for the special .INCLUDES and .LIBS variables
 1.2 13-Sep-2020  rillig make(1): fix tests for .INCLUDES and .LIBS

Found by an early draft of a refactoring of Var_Parse to properly report
errors.
 1.1 28-Aug-2020  rillig make(1): add tests for the special .INCLUDES and .LIBS variables
 1.1 28-Aug-2020  rillig make(1): add tests for the special .INCLUDES and .LIBS variables
 1.2 13-Sep-2020  rillig make(1): fix tests for .INCLUDES and .LIBS

Found by an early draft of a refactoring of Var_Parse to properly report
errors.
 1.1 28-Aug-2020  rillig make(1): add tests for the special .INCLUDES and .LIBS variables
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 09-Sep-2023  sjg make: allow -j to compute a multiple of ncpu

If _SC_NPROCESSORS_ONLN is supported; and -j arg is a floating point
number or ends in 'C' compute .MAKE.JOBS as a multiple of _SC_NPROCESSORS_ONLN

Based on a suggestion from des at freebsd.org
Discussed with: rillig, christos
 1.2 26-Jan-2022  rillig tests/make: test meta mode in jobs mode
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5 10-Sep-2023  sjg make: skip -jC tests unless .MAKE.JOBS.C is yes
 1.4 09-Sep-2023  sjg make: allow -j to compute a multiple of ncpu

If _SC_NPROCESSORS_ONLN is supported; and -j arg is a floating point
number or ends in 'C' compute .MAKE.JOBS as a multiple of _SC_NPROCESSORS_ONLN

Based on a suggestion from des at freebsd.org
Discussed with: rillig, christos
 1.3 26-Jan-2022  rillig tests/make: test meta mode in jobs mode
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.6 13-Jun-2025  rillig make: add on-demand inter-process stack traces

When debugging a build that heavily uses nested calls to sub-makes, the
chain of calls is useful to quickly assess the situation. If explicitly
requested, include the actions from any parent processes in the stack
traces.

Reviewed by: sjg
 1.5 22-Mar-2025  rillig make: ignore attempts to override a read-only global with the same value

Up to NetBSD 9, make passed around the internal variable .MAKE.LEVEL.ENV
via MAKEFLAGS. Allow these old versions of make to coexist with newer
versions of make. See unit-tests/varname-dot-make-level.mk for details.

Fixes PR pkg/59184.
 1.4 23-Nov-2024  rillig make: fix confusing error message when overriding a read-only variable
 1.3 23-Nov-2024  rillig tests/make: demonstrate confusing error message for .MAKE.LEVEL.ENV
 1.2 01-Jun-2024  rillig branches: 1.2.2;
tests/make: test more modifiers and special variables
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2.2.1 02-Aug-2025  perseant Sync with HEAD
 1.6 22-Mar-2025  rillig make: ignore attempts to override a read-only global with the same value

Up to NetBSD 9, make passed around the internal variable .MAKE.LEVEL.ENV
via MAKEFLAGS. Allow these old versions of make to coexist with newer
versions of make. See unit-tests/varname-dot-make-level.mk for details.

Fixes PR pkg/59184.
 1.5 23-Nov-2024  rillig make: fix confusing error message when overriding a read-only variable
 1.4 23-Nov-2024  rillig tests/make: demonstrate confusing error message for .MAKE.LEVEL.ENV
 1.3 01-Jun-2024  rillig branches: 1.3.2;
tests/make: test more modifiers and special variables
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 12-Apr-2025  sjg make/unit-tests: Fix expected results for meta-ignore tests
 1.3 25-Feb-2023  sjg branches: 1.3.2;
make: meta-ignore tests will not work if TMPDIR is /tmp

Since /tmp and /var/tmp are always part of .MAKE.META.IGNORE_PATHS
the varname-dot-make-meta-ignore_* tests will not work
if TMPDIR is either (or subdir) of those.
 1.2 23-Feb-2023  sjg Add unit-tests for .MAKE.META.IGNORE_*

These unit-tests should only be run if TEST_MAKE
has a valid .MAKE.PATH_FILEMON to indicate that filemon is
supported.

All three tests use the same meta-ignore.inc
which runs three sub-makes

one to initialize the target .meta file
two to ignore a file using .MAKE.META.IGNORE_{PATHS,PATTERNS,FILTER}
three to verify that without .MAKE.META.IGNORE_* the target is out of date.

Fix the order of _SED_CMDS to avoid errors when ${MAKE:T} appears in
.OBJDIR
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 23-Feb-2023  sjg Add unit-tests for .MAKE.META.IGNORE_*

These unit-tests should only be run if TEST_MAKE
has a valid .MAKE.PATH_FILEMON to indicate that filemon is
supported.

All three tests use the same meta-ignore.inc
which runs three sub-makes

one to initialize the target .meta file
two to ignore a file using .MAKE.META.IGNORE_{PATHS,PATTERNS,FILTER}
three to verify that without .MAKE.META.IGNORE_* the target is out of date.

Fix the order of _SED_CMDS to avoid errors when ${MAKE:T} appears in
.OBJDIR
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 12-Apr-2025  sjg make/unit-tests: Fix expected results for meta-ignore tests
 1.3 25-Feb-2023  sjg branches: 1.3.2;
make: meta-ignore tests will not work if TMPDIR is /tmp

Since /tmp and /var/tmp are always part of .MAKE.META.IGNORE_PATHS
the varname-dot-make-meta-ignore_* tests will not work
if TMPDIR is either (or subdir) of those.
 1.2 23-Feb-2023  sjg Add unit-tests for .MAKE.META.IGNORE_*

These unit-tests should only be run if TEST_MAKE
has a valid .MAKE.PATH_FILEMON to indicate that filemon is
supported.

All three tests use the same meta-ignore.inc
which runs three sub-makes

one to initialize the target .meta file
two to ignore a file using .MAKE.META.IGNORE_{PATHS,PATTERNS,FILTER}
three to verify that without .MAKE.META.IGNORE_* the target is out of date.

Fix the order of _SED_CMDS to avoid errors when ${MAKE:T} appears in
.OBJDIR
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 23-Feb-2023  sjg Add unit-tests for .MAKE.META.IGNORE_*

These unit-tests should only be run if TEST_MAKE
has a valid .MAKE.PATH_FILEMON to indicate that filemon is
supported.

All three tests use the same meta-ignore.inc
which runs three sub-makes

one to initialize the target .meta file
two to ignore a file using .MAKE.META.IGNORE_{PATHS,PATTERNS,FILTER}
three to verify that without .MAKE.META.IGNORE_* the target is out of date.

Fix the order of _SED_CMDS to avoid errors when ${MAKE:T} appears in
.OBJDIR
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.4 12-Apr-2025  sjg make/unit-tests: Fix expected results for meta-ignore tests
 1.3 25-Feb-2023  sjg branches: 1.3.2;
make: meta-ignore tests will not work if TMPDIR is /tmp

Since /tmp and /var/tmp are always part of .MAKE.META.IGNORE_PATHS
the varname-dot-make-meta-ignore_* tests will not work
if TMPDIR is either (or subdir) of those.
 1.2 23-Feb-2023  sjg Add unit-tests for .MAKE.META.IGNORE_*

These unit-tests should only be run if TEST_MAKE
has a valid .MAKE.PATH_FILEMON to indicate that filemon is
supported.

All three tests use the same meta-ignore.inc
which runs three sub-makes

one to initialize the target .meta file
two to ignore a file using .MAKE.META.IGNORE_{PATHS,PATTERNS,FILTER}
three to verify that without .MAKE.META.IGNORE_* the target is out of date.

Fix the order of _SED_CMDS to avoid errors when ${MAKE:T} appears in
.OBJDIR
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 23-Feb-2023  sjg Add unit-tests for .MAKE.META.IGNORE_*

These unit-tests should only be run if TEST_MAKE
has a valid .MAKE.PATH_FILEMON to indicate that filemon is
supported.

All three tests use the same meta-ignore.inc
which runs three sub-makes

one to initialize the target .meta file
two to ignore a file using .MAKE.META.IGNORE_{PATHS,PATTERNS,FILTER}
three to verify that without .MAKE.META.IGNORE_* the target is out of date.

Fix the order of _SED_CMDS to avoid errors when ${MAKE:T} appears in
.OBJDIR
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 07-May-2022  rillig make: allow to randomize build order of targets

In complex dependency structures, when a build fails, a probable cause
is a missing dependency declaration between some files. In compat mode,
the build order is deterministic, in jobs mode, it is somewhat
deterministic. To explore more edge cases, add the line ".MAKE.MODE +=
randomize-targets" somewhere in the makefile.

Fixes PR bin/45226 by riastradh. Reviewed by christos.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 07-May-2022  rillig make: allow to randomize build order of targets

In complex dependency structures, when a build fails, a probable cause
is a missing dependency declaration between some files. In compat mode,
the build order is deterministic, in jobs mode, it is somewhat
deterministic. To explore more edge cases, add the line ".MAKE.MODE +=
randomize-targets" somewhere in the makefile.

Fixes PR bin/45226 by riastradh. Reviewed by christos.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 23-Jan-2022  rillig tests/make: add a few more tests
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 23-Jan-2022  rillig tests/make: add a few more tests
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7 03-Dec-2021  rillig tests/make: document .MAKE.SAVE_DOLLARS in modifier ':@'
 1.6 02-Dec-2021  rillig tests/make: fix test for .MAKE.SAVE_DOLLARS

The previous assumption was wrong that only literal '$$' that occur
directly in the right-hand side of a variable assignment would be
affected. Indirect variable definitions are affected as well when they
are evaluated nestedly, as long as the '$$' appears in the text of the
variable that is actually parsed. Whether the '$$' ends up in the
expanded value of the expression doesn't matter though.
 1.5 01-Dec-2021  rillig tests/make: clean up test for .MAKE.SAVE_DOLLARS
 1.4 30-Nov-2021  rillig tests/make: document that undefining .MAKE.SAVE_DOLLARS has no effect
 1.3 30-Nov-2021  rillig tests/make: test and document .MAKE.SAVE_DOLLARS and ':='
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.8 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.7 01-Jun-2023  rillig branches: 1.7.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.6 25-Feb-2023  rillig tests/make: clean up tests for MAKEFLAGS and related variables
 1.5 25-Feb-2023  rillig tests/make: move tests for MAKRFLAGS to the correct file

I had accidentally added these tests to the file for the special
variable '.MAKEFLAGS' instead of the file for the environment variable
'MAKEFLAGS'. While here, add a basic test that shows how 'MAKEFLAGS' is
built from '.MAKEFLAGS' and '.MAKEOVERRIDES'.
 1.4 25-Feb-2023  rillig tests/make: test that MAKEFLAGS is an environment variable
 1.3 25-Feb-2023  rillig tests/make: activate all tests for MAKEFLAGS
 1.2 25-Feb-2023  rillig tests/make: reproduce and explain '$' in MAKEFLAGS

https://mail-index.netbsd.org/current-users/2023/02/24/msg043633.html
 1.1 01-Dec-2020  rillig make(1): add test for the special .MAKEFLAGS variable
 1.7.2.1 02-Aug-2025  perseant Sync with HEAD
 1.11 20-May-2025  sjg Revert export of MAKEFLAGS from Cmd_Exec

Until we work out what the issue is.
Revert related unit-test changes as well
 1.10 18-May-2025  rillig tests/make: test exporting of MAKEFLAGS in compat and parallel mode
 1.9 18-May-2025  sjg make: Cmd_Exec call Main_ExportMAKEFLAGS

export MAKEFLAGS the fist time Cmd_Exec is called.
This allows ${.MAKE} run via x!= to see them.

Remove test case from varname-dot-makeflags that checked
this does not happen.

Reviewed by: christos
 1.8 01-Jun-2023  rillig branches: 1.8.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.7 25-Feb-2023  rillig tests/make: clean up tests for MAKEFLAGS and related variables
 1.6 25-Feb-2023  rillig tests/make: move tests for MAKRFLAGS to the correct file

I had accidentally added these tests to the file for the special
variable '.MAKEFLAGS' instead of the file for the environment variable
'MAKEFLAGS'. While here, add a basic test that shows how 'MAKEFLAGS' is
built from '.MAKEFLAGS' and '.MAKEOVERRIDES'.
 1.5 25-Feb-2023  rillig tests/make: test that MAKEFLAGS is an environment variable
 1.4 25-Feb-2023  rillig tests/make: fix explanation for '$' in MAKEFLAGS

My previous interpretation was completely wrong.
 1.3 25-Feb-2023  rillig tests/make: activate all tests for MAKEFLAGS
 1.2 25-Feb-2023  rillig tests/make: reproduce and explain '$' in MAKEFLAGS

https://mail-index.netbsd.org/current-users/2023/02/24/msg043633.html
 1.1 01-Dec-2020  rillig make(1): add test for the special .MAKEFLAGS variable
 1.8.2.1 02-Aug-2025  perseant Sync with HEAD
 1.4 07-May-2024  sjg make: all command line overrides go in .MAKEOVERRIDES

Not all variables that start with '.' are internals,
and unless they are explicitly flagged as internal should go
into .MAKEOVERRIDES

Update varname-dot-makeoverrides to check this.

Also avoid using SCOPE_CMDLINE when ReadOnly will do.
 1.3 25-Feb-2023  rillig tests/make: reproduce and explain '$' in MAKEFLAGS

https://mail-index.netbsd.org/current-users/2023/02/24/msg043633.html
 1.2 25-Feb-2023  rillig tests/make: test how '$' behaves in .MAKEOVERRIDES and MAKEFLAGS
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.6 07-May-2024  sjg make: all command line overrides go in .MAKEOVERRIDES

Not all variables that start with '.' are internals,
and unless they are explicitly flagged as internal should go
into .MAKEOVERRIDES

Update varname-dot-makeoverrides to check this.

Also avoid using SCOPE_CMDLINE when ReadOnly will do.
 1.5 25-Feb-2023  rillig tests/make: reproduce and explain '$' in MAKEFLAGS

https://mail-index.netbsd.org/current-users/2023/02/24/msg043633.html
 1.4 25-Feb-2023  rillig tests/make: test how '$' behaves in .MAKEOVERRIDES and MAKEFLAGS
 1.3 15-Feb-2023  rillig make: inline macros for variable names

The variable name '.MAKEOVERRIDES' was already used in the non-macro
form.

No binary change.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.10 12-Jun-2025  rillig make: add program name to stack traces from sub-makes
 1.9 12-Jun-2025  rillig make: add quotes to "in directory" line in stack traces

The other lines in stack traces use quotes as well.
 1.8 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.7 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.6 04-Jul-2024  rillig make: add more context information to error messages

In case of a parse error or evaluation error, print the variable value
in addition to the variable name, to see the effects of previous
expression modifiers.

In nested make calls, print the current directory at the bottom of a
stack trace, as that information is otherwise hard to get in a parallel
build spanning multiple directories.
 1.5 15-Jun-2024  rillig branches: 1.5.2;
make: error out if an internal read-only variable is overwritten

The affected variables are:
* .newline
* .MAKE.OS
* .MAKE.JOBS.C
* .MAKE.LEVEL.ENV
* .MAKE.PID
* .MAKE.PPID
* .MAKE.UID
* .MAKE.GID

This change does not affect the .SHELL and .SUFFIXES variables, as well
as variables that are manually turned read-only by the special .READONLY
target.
 1.4 26-Jan-2023  sjg make: some variables should be read-only

Make variables like .newline and .MAKE.{GID,PID,PPID,UID} read-only.

Reviewed by: rillig
 1.3 17-Jan-2023  rillig tests/make: test backslash-newline after macro expansion in command
 1.2 19-Aug-2020  rillig make(1): add test for the .newline variable
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5.2.1 02-Aug-2025  perseant Sync with HEAD
 1.7 15-Jun-2024  rillig make: error out if an internal read-only variable is overwritten

The affected variables are:
* .newline
* .MAKE.OS
* .MAKE.JOBS.C
* .MAKE.LEVEL.ENV
* .MAKE.PID
* .MAKE.PPID
* .MAKE.UID
* .MAKE.GID

This change does not affect the .SHELL and .SUFFIXES variables, as well
as variables that are manually turned read-only by the special .READONLY
target.
 1.6 26-Jan-2023  sjg make: some variables should be read-only

Make variables like .newline and .MAKE.{GID,PID,PPID,UID} read-only.

Reviewed by: rillig
 1.5 17-Jan-2023  rillig tests/make: test backslash-newline after macro expansion in command
 1.4 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.3 19-Aug-2020  rillig make(1): add test for the .newline variable
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 01-Jun-2024  rillig tests/make: cover purging the realpath cache

In purge_relative_cached_realpaths, the hash table containing the cache
is modified while being iterated, which needs extra care, so add a test
that covers this code in at least a single simple scenario.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 01-Jun-2024  rillig tests/make: cover purging the realpath cache

In purge_relative_cached_realpaths, the hash table containing the cache
is modified while being iterated, which needs extra care, so add a test
that covers this code in at least a single simple scenario.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.7 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.6 21-Jun-2023  rillig branches: 1.6.2;
tests/make: document a few tests
 1.5 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.4 21-Sep-2020  rillig make(1): fix tests for .PARSEDIR/.PARSEFILE

The output of these tests previously depended upon whether the test
makefile was specified as relative or as absolute path. In NetBSD, it
is specified as relative path, in FreeBSD as absolute path.

Adjust the expected output to hide this difference; in the .rawout files
it is still visible.
 1.3 12-Sep-2020  rillig make(1): add test for .PARSEFILE
 1.2 12-Sep-2020  rillig make(1): add test for .PARSEDIR
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.6.2.1 02-Aug-2025  perseant Sync with HEAD
 1.8 21-Jun-2023  rillig tests/make: document a few tests
 1.7 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.6 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.5 21-Sep-2020  rillig make(1): fix tests for .PARSEDIR/.PARSEFILE

The output of these tests previously depended upon whether the test
makefile was specified as relative or as absolute path. In NetBSD, it
is specified as relative path, in FreeBSD as absolute path.

Adjust the expected output to hide this difference; in the .rawout files
it is still visible.
 1.4 12-Sep-2020  rillig make(1): add test for .PARSEFILE
 1.3 12-Sep-2020  rillig make(1): add test for .PARSEDIR
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.6 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.5 21-Jun-2023  rillig branches: 1.5.2;
tests/make: document a few tests
 1.4 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.3 21-Sep-2020  rillig make(1): fix tests for .PARSEDIR/.PARSEFILE

The output of these tests previously depended upon whether the test
makefile was specified as relative or as absolute path. In NetBSD, it
is specified as relative path, in FreeBSD as absolute path.

Adjust the expected output to hide this difference; in the .rawout files
it is still visible.
 1.2 12-Sep-2020  rillig make(1): add test for .PARSEFILE
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.5.2.1 02-Aug-2025  perseant Sync with HEAD
 1.7 21-Jun-2023  rillig tests/make: document a few tests
 1.6 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.5 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.4 21-Sep-2020  rillig make(1): fix tests for .PARSEDIR/.PARSEFILE

The output of these tests previously depended upon whether the test
makefile was specified as relative or as absolute path. In NetBSD, it
is specified as relative path, in FreeBSD as absolute path.

Adjust the expected output to hide this difference; in the .rawout files
it is still visible.
 1.3 12-Sep-2020  rillig make(1): add test for .PARSEFILE
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 02-Oct-2020  rillig make(1): add test for the special .PATH target and variable
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.23 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.22 31-Oct-2024  rillig make: in the debug log, always qualify line number with filename

Previously, to find out the filename corresponding to a line number from
a 'Parsing' line, it was necessary to find the preceding
'SetFilenameVars' line, which was unnecessarily time-consuming and
distracting.

The 'filename:line' format matches the one used in PrintStackTrace, and
it differs from the one used in PrintLocation, as the former format is
more common in other tools.

Most of the affected unit tests only use the 'Parsing' lines to give
additional context to their debug log, so no structural changes there.
 1.21 14-Apr-2024  rillig branches: 1.21.2;
make: add debug logging for .if and .for lines in -dp mode

This helps track down in which line a condition is evaluated.
 1.20 20-Dec-2023  rillig make: use consistent debug messages style when ignoring variables

When a variable is not modified or not deleted, clearly say so and state
the reason. Use the same style of debug messages everywhere, putting
the word 'ignoring' at the front. Previously, that word sticked out to
the right, but only in some cases.
 1.19 20-Dec-2023  rillig make: fix confusing debug logging when deleting a variable

Be clear when deleting a variable is ignored and state the reason,
instead of only providing a keyword as a hint for insiders.
 1.18 10-Dec-2023  rillig make: explain in the debug log why a variable assignment is ignored
 1.17 09-Dec-2023  sjg make: Var_SetWithFlags set fromCmd for SCOPE_CMDLINE

Set fromCmd true for SCOPE_CMDLINE
regardless of the variable name.

Reviewed by: rillig
 1.16 26-Mar-2022  rillig make: avoid trailing whitespace in debug log for variables

Since trailing whitespace is invisible, describe the variable value in
words to make it visible.
 1.15 26-Mar-2022  rillig make: add space after colon in debug logging for variables

These log messages are intended for human interpretation, so don't make
them unnecessarily hard to read.
 1.14 03-Mar-2022  rillig make: make debug logging for comparisons less technical
 1.13 28-Dec-2021  rillig make: make debug logging a bit more human-friendly

The previous log format "ParseReadLine (%d): '%s'" focused on the
implementation, it was not immediately obvious to a casual reader that
the number in parentheses was the line number. Additionally, having
both a colon and quotes in a log message is uncommon. The quotes have
been added in parse.c 1.127 from 2007-01-01.

The new log format "Parsing line %d: %s" is meant to be easier readable
by humans. The quotes are not needed since ParseReadLine always strips
trailing whitespace, leaving no room for ambiguities. The other log
messages follow common punctuation rules, which makes the beginning of
the line equally unambiguous. Before var.c 1.911 from 2021-04-05,
variable assignments were logged with the format "%s:%s = %s", without a
space after the colon.
 1.12 05-Apr-2021  rillig make: in debug log, add space between scope and variable name

Without this space, the debug log looked more like line noise, even
though the only punctuation was a single innocent ':'. From a make
user's perspective, the variable name is a word of its own and should
not be visually glued to its namespace.
 1.11 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.10 15-Mar-2021  rillig make: change debug log for variable evaluation flags to lowercase

This makes them easier distinguishable from variable names since the
latter are usually uppercase.

No functional change outside debug mode.
 1.9 28-Dec-2020  rillig make(1): replace global preserveUndefined with VARE_KEEP_UNDEF

Controlling the expansion of variable expressions using a global
variable and a VARE flag was inconsistent.

Converting the global variable into a flag had to prerequisites:

1. The unintended duplicate variable assignment had to be fixed, as
done in parse.c 1.520 from 2020-12-27. Without this fix, it would have
been necessary to add more flags to Var_Exists and Var_SetWithFlags, and
this would have become too complex.

2. There had to be a unit test demonstrating that VARE_KEEP_DOLLAR only
applies to the top-level expression and is not passed to the
subexpressions, while VARE_KEEP_UNDEF applies to all subexpressions as
well. This test is in var-op-expand.mk 1.10 from 2020-12-28, at least
for the ':@word@' modifier. In ParseModifierPartSubst, VARE_KEEP_UNDEF
is not passed down either, in the same way.
 1.8 08-Nov-2020  rillig make(1): rename VARE_ASSIGN to VARE_KEEP_DOLLAR

The other flags in VarEvalFlags already describe their effects, not the
place where they are used. It's more important to know the effect.

Only a single unit test had to be adjusted. This probably means that
there are too few tests where the special effects of VARE_KEEP_DOLLAR
come into play. It could also mean that the effects are so simple and
obvious that they don't need any debug log, but that's not the case.
 1.7 30-Oct-2020  rillig make(1): prevent appending to read-only variables
 1.6 30-Oct-2020  rillig make(1): demonstrate how to append to a read-only variable
 1.5 30-Oct-2020  rillig make(1): move test flags for varname-dot-shell to the test itself
 1.4 22-Sep-2020  rillig make(1): move VAR_JUNK and VAR_KEEP away from VarFlags

These two flags have nothing to do with a variable. They are only used
while evaluating a variable expression.

While here, rename the flags and make their documentation more precise.
 1.3 13-Sep-2020  rillig make(1): shorten debug output of ApplyModifiers

Having the words "eflags" and "vflags" in the debug output was too
repetitive. That they are flags is made obvious by the '|' separator,
and the flags have clearly distinguishable names (VARE_* vs. VAR_*),
which lowers the chance for confusion.
 1.2 23-Aug-2020  rillig make(1): fix assertion failure in debug output for read-only variables
 1.1 23-Aug-2020  rillig make(1): add test for the newly added .SHELL variable
 1.21.2.1 02-Aug-2025  perseant Sync with HEAD
 1.7 04-Feb-2021  rillig make: rename context and ctxt to scope

This continues the previous commit, in which VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE were renamed.

Renaming the variable 'ctxt' was trivial since that word is used nowhere
else. In the comments though, each occurrence of the word 'context' had
to be checked individually since the word 'context' was not only used
for referring to a variable scope. It is also used to distinguish
different situations where characters are escaped in a certain way
('parsing context') and in a few other expressions.
 1.6 30-Oct-2020  rillig make(1): prevent appending to read-only variables
 1.5 30-Oct-2020  rillig make(1): demonstrate how to append to a read-only variable
 1.4 30-Oct-2020  rillig make(1): move test flags for varname-dot-shell to the test itself
 1.3 24-Oct-2020  rillig make(1): indent directives like .info, .if, .for consistently

Done by "pkglint -F *.mk", no manual corrections.
 1.2 23-Aug-2020  rillig make(1): fix assertion failure in debug output for read-only variables
 1.1 23-Aug-2020  rillig make(1): add test for the newly added .SHELL variable
 1.9 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.8 29-Dec-2023  rillig branches: 1.8.2;
make: simplify debug message for the ':@var@...@' modifier

The previous variant was hard to understand.
 1.7 20-Dec-2023  rillig make: use consistent debug messages style when ignoring variables

When a variable is not modified or not deleted, clearly say so and state
the reason. Use the same style of debug messages everywhere, putting
the word 'ignoring' at the front. Previously, that word sticked out to
the right, but only in some cases.
 1.6 20-Dec-2023  rillig make: fix confusing debug logging when deleting a variable

Be clear when deleting a variable is ignored and state the reason,
instead of only providing a keyword as a hint for insiders.
 1.5 23-Aug-2022  rillig make: revert parsing of modifier parts (since 2022-08-08)

The modifier ':@var@body@' parses the body in parse-only mode and later
uses Var_Subst on it, in which each literal '$' must be written as '$$'.

Trying to parse the loop body using Var_Parse treated the text
'$${var:-0}' as a single '$' followed by the expression '${var:-0}',
wrongly complaining about the 'Unknown modifier "-0"'.

Found by sjg.
 1.4 08-Aug-2022  rillig make: fix parsing of modifiers containing unbalanced subexpressions
 1.3 26-Mar-2022  rillig make: avoid trailing whitespace in debug log for variables

Since trailing whitespace is invisible, describe the variable value in
words to make it visible.
 1.2 26-Mar-2022  rillig make: add space after colon in debug logging for variables

These log messages are intended for human interpretation, so don't make
them unnecessarily hard to read.
 1.1 12-Dec-2021  rillig tests/make: test and document the newly added "variable" .SUFFIXES
 1.8.2.1 02-Aug-2025  perseant Sync with HEAD
 1.5 20-Dec-2023  rillig make: use consistent debug messages style when ignoring variables

When a variable is not modified or not deleted, clearly say so and state
the reason. Use the same style of debug messages everywhere, putting
the word 'ignoring' at the front. Previously, that word sticked out to
the right, but only in some cases.
 1.4 20-Dec-2023  rillig make: fix confusing debug logging when deleting a variable

Be clear when deleting a variable is ignored and state the reason,
instead of only providing a keyword as a hint for insiders.
 1.3 15-Apr-2022  rillig tests/make: adjust expectations to actual behavior

The bug in deptgt-silent-jobs.mk has been fixed, the debug logging for
comparing conditions and for deleting global variables has changed
intentionally.
 1.2 15-Jan-2022  rillig tests/make: ensure that the 'expect' comments in tests are correct

Based on tests/usr.bin/xlint/check-expect.lua.

For now, this extra check needs to be run manually.
 1.1 12-Dec-2021  rillig tests/make: test and document the newly added "variable" .SUFFIXES
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.24 20-May-2025  sjg Revert export of MAKEFLAGS from Cmd_Exec

Until we work out what the issue is.
Revert related unit-test changes as well
 1.23 18-May-2025  sjg make: Cmd_Exec call Main_ExportMAKEFLAGS

export MAKEFLAGS the fist time Cmd_Exec is called.
This allows ${.MAKE} run via x!= to see them.

Remove test case from varname-dot-makeflags that checked
this does not happen.

Reviewed by: christos
 1.22 20-Dec-2023  rillig make: use consistent debug messages style when ignoring variables

When a variable is not modified or not deleted, clearly say so and state
the reason. Use the same style of debug messages everywhere, putting
the word 'ignoring' at the front. Previously, that word sticked out to
the right, but only in some cases.
 1.21 20-Dec-2023  rillig make: fix confusing debug logging when deleting a variable

Be clear when deleting a variable is ignored and state the reason,
instead of only providing a keyword as a hint for insiders.
 1.20 26-Mar-2022  rillig make: avoid trailing whitespace in debug log for variables

Since trailing whitespace is invisible, describe the variable value in
words to make it visible.
 1.19 26-Mar-2022  rillig make: add space after colon in debug logging for variables

These log messages are intended for human interpretation, so don't make
them unnecessarily hard to read.
 1.18 10-Jan-2022  rillig make: add debug logging for capturing the output of external commands

This applies to all 4 situations in which the output of an external
command is used for modifying a variable or an expression:

* the assignment operator '!='
* the assignment modifier '::!='
* the SUN shell modifier ':sh'
* the other shell modifier ':!cmd!'

Previously, only the shell modifier ':!cmd!' had debug logging.

Suggested by Christoph Badura.
 1.17 19-Oct-2021  sjg Replace ${.OBJDIR} with <curdir> for consistent results.

If we replace ${.OBJDIR} with <objdir> some tests produce
different results depending on the value of .OBJDIR

For similar reasons eliminate .OBJDIR and .PATH from output of
varname-empty

Reviewed by: rillig
 1.16 14-Apr-2021  rillig make: remove unnecessary modifier ':U' for certain fixed expressions

No functional change, since the expression is evaluated using
VARE_WANTRES, not using VARE_UNDEFERR.
 1.15 10-Apr-2021  rillig make: reword debug log message for empty variable name

The function names did not match anymore, after one of the many
refactorings in the last few months.
 1.14 10-Apr-2021  rillig make: reduce debug logging and memory allocation for ${:U...}

Expressions of the form ${:U...} are often generated by .for loops.
Since these expressions are not generated knowingly by the make user, do
not fill the debug log with them since that would interrupt the normal
reading flow of the -dv log for nested expressions.
 1.13 05-Apr-2021  rillig make: in debug log, add space between scope and variable name

Without this space, the debug log looked more like line noise, even
though the only punctuation was a single innocent ':'. From a make
user's perspective, the variable name is a word of its own and should
not be visually glued to its namespace.
 1.12 05-Apr-2021  rillig make: be more verbose in -dv debug logging

The previous log output was too brief to be understandable. Give more
hints by describing each part of the expression when evaluating a
modifier. Distinguish between parse-only mode and eval mode since in
parse-only mode most of the details are irrelevant.
 1.11 03-Apr-2021  rillig make: remove VarFlags from debug logging

Before the introduction of ExprDefined, VarFlags contained whether the
expression was defined or not, which was useful to know since the final
value of the expression depends on this information. The other VarFlags
do not influence the evaluation, so there is no point logging them.
 1.10 15-Mar-2021  rillig make: change debug log for variable evaluation flags to lowercase

This makes them easier distinguishable from variable names since the
latter are usually uppercase.

No functional change outside debug mode.
 1.9 15-Feb-2021  rillig make: rename ExprDefined constants for debug logging
 1.8 04-Feb-2021  rillig make: remove .PARSEDIR from test output of varname-empty

The .PARSEDIR has nothing to do with .CURDIR. This wrong assumption
made the NetBSD test suite fail since the actual .PARSEDIR was not
replaced with "<curdir>".
 1.7 03-Feb-2021  rillig make: fix double expansion when appending to a new variable
 1.6 03-Feb-2021  rillig make: in the test varname-empty, keep more debug output

Filtering out the interesting lines based on the very specific pattern
"Var_Set" was surprising.
 1.5 15-Nov-2020  rillig make(1): fix typo in test for variable with empty name
 1.4 23-Oct-2020  rillig make(1): add tests for the variable named ""
 1.3 22-Aug-2020  rillig make(1): try to set the variable named "" using the command line

Before 2020-08-22, the command line argument '=cmline-plain' triggered
undefined behavior, just like the assignment '=assigned' in the Makefile.
 1.2 22-Aug-2020  rillig make(1): prevent assignment to the variable with the empty name
 1.1 22-Aug-2020  rillig make(1): add test for assigning to the variable named ""

This has been possible at least since 2013, probably much longer.
 1.10 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.9 04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.8 03-Feb-2021  rillig make: in the test varname-empty, keep more debug output

Filtering out the interesting lines based on the very specific pattern
"Var_Set" was surprising.
 1.7 23-Oct-2020  rillig make(1): add tests for the variable named ""
 1.6 24-Sep-2020  rillig make(1): extend documentation in the varname-empty test
 1.5 22-Aug-2020  rillig make(1): try to set the variable named "" using the command line

Before 2020-08-22, the command line argument '=cmline-plain' triggered
undefined behavior, just like the assignment '=assigned' in the Makefile.
 1.4 22-Aug-2020  rillig make(1): fix undefined behavior when assigning to variable ""

Using a programming language with built-in array bounds checks would
have prevented this bug, and many others as well.
 1.3 22-Aug-2020  rillig make(1): try a bit harder to set the variable with the empty name

There is not only the != assignment operator, but a few others as well.
Especially the += operator is interesting since it has a different code
path. But all is good.
 1.2 22-Aug-2020  rillig make(1): prevent assignment to the variable with the empty name
 1.1 22-Aug-2020  rillig make(1): add test for assigning to the variable named ""

This has been possible at least since 2013, probably much longer.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.2 13-Dec-2020  rillig branches: 1.2.8;
make(1): add tests for variable expansion in .ERROR handling
 1.1 23-Oct-2020  rillig make(1): add test for .ERROR_CMD in jobs mode
 1.2.8.1 02-Aug-2025  perseant Sync with HEAD
 1.4 19-Nov-2023  rillig tests/make: replace 'variable expressions' with 'expressions'
 1.3 04-Feb-2021  rillig make: rename some VAR constants to SCOPE

The word "context" does not fit perfectly to the variables that are
associate with a GNode, as the context is usually something from the
outside and the variables are more like properties inherent to the
GNode.

The term "global context" fits even less. Since the thing where
variables are looked up is commonly named a scope, use that term
instead.

This commit only renames the global variables VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE, plus a few very closely related comments. These are:

GNode.vars (because of line breaks)
GNode_Free (dito)
varname-make_print_var_on_error.mk
varname-make_print_var_on_error-jobs.mk

The debug message in Var_Stats is left as-is since there is no unit test
for it yet.

The other renamings (variable names "context", "ctxt", as well as
further comments) will be done in a follow-up commit.
 1.2 13-Dec-2020  rillig make(1): add tests for variable expansion in .ERROR handling
 1.1 23-Oct-2020  rillig make(1): add test for .ERROR_CMD in jobs mode
 1.4 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.3 13-Dec-2020  rillig branches: 1.3.8;
make(1): add tests for variable expansion in .ERROR handling
 1.2 23-Oct-2020  rillig make(1): add test for MAKE_PRINT_VAR_ON_ERROR
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3.8.1 02-Aug-2025  perseant Sync with HEAD
 1.6 04-Feb-2021  rillig make: rename some VAR constants to SCOPE

The word "context" does not fit perfectly to the variables that are
associate with a GNode, as the context is usually something from the
outside and the variables are more like properties inherent to the
GNode.

The term "global context" fits even less. Since the thing where
variables are looked up is commonly named a scope, use that term
instead.

This commit only renames the global variables VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE, plus a few very closely related comments. These are:

GNode.vars (because of line breaks)
GNode_Free (dito)
varname-make_print_var_on_error.mk
varname-make_print_var_on_error-jobs.mk

The debug message in Var_Stats is left as-is since there is no unit test
for it yet.

The other renamings (variable names "context", "ctxt", as well as
further comments) will be done in a follow-up commit.
 1.5 13-Dec-2020  rillig make(1): add tests for variable expansion in .ERROR handling
 1.4 23-Oct-2020  rillig make(1): add test for .ERROR_CMD in jobs mode
 1.3 23-Oct-2020  rillig make(1): add test for MAKE_PRINT_VAR_ON_ERROR
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 13-Jun-2025  rillig branches: 1.1.4;
make: add on-demand inter-process stack traces

When debugging a build that heavily uses nested calls to sub-makes, the
chain of calls is useful to quickly assess the situation. If explicitly
requested, include the actions from any parent processes in the stack
traces.

Reviewed by: sjg
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 13-Jun-2025  perseant file varname-make_stack_trace.exp was added on branch perseant-exfatfs on 2025-08-02 05:58:40 +0000
 1.1 13-Jun-2025  rillig branches: 1.1.4;
make: add on-demand inter-process stack traces

When debugging a build that heavily uses nested calls to sub-makes, the
chain of calls is useful to quickly assess the situation. If explicitly
requested, include the actions from any parent processes in the stack
traces.

Reviewed by: sjg
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 13-Jun-2025  perseant file varname-make_stack_trace.mk was added on branch perseant-exfatfs on 2025-08-02 05:58:40 +0000
 1.2 09-Nov-2020  rillig make(1): add test for MAKEFILE after reading all files
 1.1 04-Sep-2020  rillig make(1): add test for the special variable MAKEFILE
 1.3 09-Nov-2020  rillig make(1): add test for MAKEFILE after reading all files
 1.2 05-Sep-2020  rillig make(1): fix test for the MAKEFILE variable

That test had assumed that it would always be run with CURDIR ==
PARSEDIR, which is not the case for ./build.sh.
 1.1 04-Sep-2020  rillig make(1): add test for the special variable MAKEFILE
 1.2 25-Feb-2023  rillig tests/make: move tests for MAKRFLAGS to the correct file

I had accidentally added these tests to the file for the special
variable '.MAKEFLAGS' instead of the file for the environment variable
'MAKEFLAGS'. While here, add a basic test that shows how 'MAKEFLAGS' is
built from '.MAKEFLAGS' and '.MAKEOVERRIDES'.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.8 01-Jun-2023  rillig tests/make: clean up comments, extend a few tests
 1.7 25-Feb-2023  rillig tests/make: clean up tests for MAKEFLAGS and related variables
 1.6 25-Feb-2023  rillig tests/make: move tests for MAKRFLAGS to the correct file

I had accidentally added these tests to the file for the special
variable '.MAKEFLAGS' instead of the file for the environment variable
'MAKEFLAGS'. While here, add a basic test that shows how 'MAKEFLAGS' is
built from '.MAKEFLAGS' and '.MAKEOVERRIDES'.
 1.5 16-Jan-2022  sjg Ensure make gets -r

Apart from ensuring no influence from /usr/share/mk
when bmake is built for the first time on a non-BSD
system, sys.mk will not be found
 1.4 27-Dec-2021  rillig tests/make: test MAKEFLAGS in POSIX mode

This test covers the function 'explode' in main.c, the case in which the
flags are actually expanded.
 1.3 01-Dec-2020  rillig make(1): add test for the special .MAKEFLAGS variable
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.3 06-Jul-2025  rillig make: improve debug log message for 'exists' function

The previous wording came from a time where the return type of
FuncExists was a string; this wording neither matches the current
implementation nor is it understandable without knowing the code.
 1.2 10-Nov-2020  rillig branches: 1.2.8;
make(1): add test for the obsolete variable VPATH
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.2.8.1 02-Aug-2025  perseant Sync with HEAD
 1.3 10-Nov-2020  rillig make(1): add test for the obsolete variable VPATH
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.27 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.26 12-Jun-2025  rillig tests/make: add tests for detection of GNU-make-style expressions
 1.25 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.24 14-Jan-2025  rillig make: simplify parsing of dependency lines

The evaluation modes that allow or deny undefined variables have the same
effect in this case, as Var_Subst does not return an error marker.
 1.23 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.22 06-Aug-2024  rillig make: add details to error messages about missing ')'
 1.21 04-Jul-2024  rillig make: on error, print the targets to be made

This helps to understand situations with several nested sub-makes in
varying directories.
 1.20 19-Aug-2023  rillig branches: 1.20.2;
make: show realistic invalid line in error message

Previously, the error message 'Invalid line' showed only the expanded
line, which might or might not show the actual problem. To be more
helpful, add the unexpanded line to the error message in case they
differ.

Remove the special handling of invalid lines that result from merge
conflicts. RCS is not commonly used anymore, and mentioning CVS was too
specific. By echoing the whole line, the patterns '<<<<<<' and '>>>>>>'
are clear enough to hint at the problem.
 1.19 19-Aug-2023  rillig make: add more details to error message about invalid lines
 1.18 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.17 10-Apr-2021  rillig make: reduce debug logging and memory allocation for ${:U...}

Expressions of the form ${:U...} are often generated by .for loops.
Since these expressions are not generated knowingly by the make user, do
not fill the debug log with them since that would interrupt the normal
reading flow of the -dv log for nested expressions.
 1.16 05-Apr-2021  rillig make: in debug log, add space between scope and variable name

Without this space, the debug log looked more like line noise, even
though the only punctuation was a single innocent ':'. From a make
user's perspective, the variable name is a word of its own and should
not be visually glued to its namespace.
 1.15 05-Apr-2021  rillig make: be more verbose in -dv debug logging

The previous log output was too brief to be understandable. Give more
hints by describing each part of the expression when evaluating a
modifier. Distinguish between parse-only mode and eval mode since in
parse-only mode most of the details are irrelevant.
 1.14 03-Apr-2021  rillig make: remove VarFlags from debug logging

Before the introduction of ExprDefined, VarFlags contained whether the
expression was defined or not, which was useful to know since the final
value of the expression depends on this information. The other VarFlags
do not influence the evaluation, so there is no point logging them.
 1.13 15-Mar-2021  rillig make: change debug log for variable evaluation flags to lowercase

This makes them easier distinguishable from variable names since the
latter are usually uppercase.

No functional change outside debug mode.
 1.12 15-Feb-2021  rillig make: rename ExprDefined constants for debug logging
 1.11 02-Feb-2021  rillig make: replace VarExprFlags with VarExprStatus

The combination of !VEF_UNDEF && VEF_DEF was not possible, which made it
rather strange to model this state as a bit set.

The only functional change is the renamed constants in the debug output.

Using ENUM_VALUE_RTTI_2 felt like overengineering since it's harder to
understand than a simple array of names.
 1.10 01-Feb-2021  rillig make: replace parse error "Need an operator" with better message

The previous error message is not easily understandable since it is
missing a crucial detail, the column where the operator is needed.
Without this information, the author of the makefile gets no useful
hint. Furthermore, there are several types of operators in makefiles:

the dependency operators ':', '!', '::',
the variable assignment operators '=', '!=', '+=', '?=', ':=',
the conditional operators '&&', '||', '!',
the comparison operators '==', '!=', '>', '>=', '<', '<='.

This leaves too much ambiguity.

Replace this error message with "Invalid line type", which is more
generic, more accurate and thus less misleading.
 1.9 07-Nov-2020  rillig make(1): properly handle errors for malformed archive target names

Error messages don't belong on stdout.
 1.8 02-Nov-2020  rillig make(1): document test for parsing of variable assignments
 1.7 02-Nov-2020  rillig make(1): fix line numbers in test output of varname.mk
 1.6 02-Nov-2020  rillig make(1): document undefined behavior in Parse_IsVar

Sigh. If only C could be compiled in strict mode that detects these
out-of-bounds memory accesses.
 1.5 02-Nov-2020  rillig make(1): fix test for parsing obscure variable names

I had forgotten the :U modifier. Without that modifier, there's no
chance that the variable names would come out correctly.
 1.4 02-Nov-2020  rillig make(1): add tests for parsing ob obscure variable names
 1.3 18-Oct-2020  rillig make(1): sort variables in debug output

This way it's easier to see whether an expected variable is missing, or
to compare the values of related variables, since they usually share a
common prefix. Any sorting criterion is better than the hash code.

Sorting the variables by name changed the order of the output in
varname.mk. That test didn't test anything meaningful, it was just a
playground to understand and demonstrate the current implementation of
how the variables are stored, therefore it has been removed.
 1.2 05-Sep-2020  rillig make(1): add expected test result for hashing variable names
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.20.2.1 02-Aug-2025  perseant Sync with HEAD
 1.18 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.17 12-Jun-2025  rillig tests/make: add tests for detection of GNU-make-style expressions
 1.16 11-Jan-2025  rillig tests/make: force correct order of expected messages
 1.15 06-Aug-2024  rillig make: add details to error messages about missing ')'
 1.14 19-Nov-2023  rillig branches: 1.14.2;
tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.13 19-Aug-2023  rillig make: show realistic invalid line in error message

Previously, the error message 'Invalid line' showed only the expanded
line, which might or might not show the actual problem. To be more
helpful, add the unexpanded line to the error message in case they
differ.

Remove the special handling of invalid lines that result from merge
conflicts. RCS is not commonly used anymore, and mentioning CVS was too
specific. By echoing the whole line, the patterns '<<<<<<' and '>>>>>>'
are clear enough to hint at the problem.
 1.12 19-Aug-2023  rillig make: add more details to error message about invalid lines
 1.11 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.10 09-Feb-2022  rillig make: fix mistakes, spelling and typos in comments and manual page

No binary change for -DNDEBUG.
 1.9 27-Jan-2022  rillig tests/make: test hash code collisions of variable names

In HashEntry_KeyEquals, the line 'return false' was not covered by any
tests before. Since it is an edge case that two variable names (or
other keys) have the same 32-bit hash code and still differ, better test
for that edge case explicitly since a bug in this place would be rare
and hard to find.
 1.8 02-Nov-2020  rillig make(1): document test for parsing of variable assignments
 1.7 02-Nov-2020  rillig make(1): document undefined behavior in Parse_IsVar

Sigh. If only C could be compiled in strict mode that detects these
out-of-bounds memory accesses.
 1.6 02-Nov-2020  rillig make(1): fix test for parsing obscure variable names

I had forgotten the :U modifier. Without that modifier, there's no
chance that the variable names would come out correctly.
 1.5 02-Nov-2020  rillig make(1): add tests for parsing ob obscure variable names
 1.4 18-Oct-2020  rillig make(1): sort variables in debug output

This way it's easier to see whether an expected variable is missing, or
to compare the values of related variables, since they usually share a
common prefix. Any sorting criterion is better than the hash code.

Sorting the variables by name changed the order of the output in
varname.mk. That test didn't test anything meaningful, it was just a
playground to understand and demonstrate the current implementation of
how the variables are stored, therefore it has been removed.
 1.3 05-Sep-2020  rillig make(1): add test for intentional hash collision for variable names

Hash collisions may slow down make in certain special situations. There
is no point though in maliciously triggering such a situation since
anyone who can inject values into makefiles can easily run shell
commands using the :!cmd! modifier or similar mechanisms. Crafting
variable names just to slow down make is thus not an attack vector.
 1.2 16-Aug-2020  rillig make(1): describe the purpose of each newly added unit test dummy
 1.1 16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.14.2.1 02-Aug-2025  perseant Sync with HEAD
 1.6 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.5 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.4 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.3 01-Jun-2023  rillig branches: 1.3.2;
tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.2 26-Jul-2020  rillig make(1): fix off-by-one error in Var_Parse for dynamic variables
 1.1 26-Jul-2020  rillig make(1): add test for off-by-one error in Var_Parse
 1.3.2.1 02-Aug-2025  perseant Sync with HEAD
 1.10 11-Jan-2025  rillig make: replace "Malformed conditional" with "Variable is undefined"

Evaluating a conditional such as ".if ${UNDEF}" produced a "Malformed
conditional" error, even though the form of the conditional was correct,
it was the content of the variable that was wrong.

Replace this message with the more accurate "Variable is undefined",
revealing which of the possibly many variables is actually undefined.
 1.9 06-Aug-2024  rillig make: in error message about conditionals, use single quotes

Single quotes are used less often in the conditionals themselves, which
leads to fewer confusions.
 1.8 19-Nov-2023  rillig branches: 1.8.2;
tests/make: replace 'variable expressions' with 'expressions'
 1.7 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.6 01-Jun-2023  rillig tests/make: clean up comments, extend a few tests
 1.5 22-Feb-2021  rillig make: update constant names in comments

No functional change.
 1.4 04-Feb-2021  rillig make: rename context and ctxt to scope

This continues the previous commit, in which VAR_GLOBAL, VAR_INTERNAL
and VAR_CMDLINE were renamed.

Renaming the variable 'ctxt' was trivial since that word is used nowhere
else. In the comments though, each occurrence of the word 'context' had
to be checked individually since the word 'context' was not only used
for referring to a variable scope. It is also used to distinguish
different situations where characters are escaped in a certain way
('parsing context') and in a few other expressions.
 1.3 21-Nov-2020  rillig make(1): add test for dynamic variable with modifiers in global context
 1.2 13-Sep-2020  rillig make(1): add test for dynamic variable with modifiers in Var_Parse
 1.1 26-Jul-2020  rillig make(1): add test for off-by-one error in Var_Parse
 1.8.2.1 02-Aug-2025  perseant Sync with HEAD
 1.21 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.20 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.19 29-Mar-2025  rillig make: let unknown ":O" modifiers fall back to the ":from=to" modifier

Inspired by https://bugs.freebsd.org/285726, which concerns the ":t"
modifier instead.

This means that future extensions to the ":O" modifier must not contain
a "=" anywhere, otherwise they may break existing code.
 1.18 29-Mar-2025  rillig make: in a stack trace with details and includes, list the current file
 1.17 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.16 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.15 20-Jul-2024  rillig make: remove wrong error message about an undefined variable
 1.14 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.13 05-Jul-2024  rillig make: error out on unclosed expressions during parse time

In exchange, this adds location information.

For unnamed expressions, the value is no longer printed. This will be
added back in a follow-up commit.
 1.12 04-Jul-2024  rillig make: error out on the "Bad modifier" error message

Previously, the "Bad modifier" error message did not affect make's exit
status. As a side effect, this kind of error now gets more context
information.
 1.11 20-Apr-2024  rillig branches: 1.11.2;
make: provide more context information for parse/evaluate errors
 1.10 19-Nov-2023  rillig make: replace 'variable expression' with 'expression' in diagnostics
 1.9 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.8 14-Feb-2023  rillig make: remove redundant type VarParseResult

No functional change.
 1.7 24-Aug-2022  rillig make: prevent future out-of-bounds errors when parsing expressions

A modifier in an expression ends not only at the next ':' or at the
closing '}' or ')', but also at the end of the string.

Previously, testing for the end of the string had been done separately,
which was error-prone since 2006-05-11, when indirect modifiers were
introduced. Since then, it was possible that the string terminator '\0'
was accidentally skipped in cases where the loop condition only tested
for the ending character. When parsing indirect modifiers, the ending
character is indeed '\0', but when parsing direct modifiers, it is '}'
or ')'.

A welcome side effect is that in the case of unclosed expressions such
as '${VAR:Modifier', the amount of error messages is reduced from 2 or 3
to only 1. The removed error messages were wrong and thus confusing
anyway.
 1.6 24-Aug-2022  rillig tests/make: test misleading error messages on unclosed expressions

The error messages say 'Unknown modifier' or 'Bad modifier', which is
not entirely correct. The modifier in itself is valid, it's just that
make doesn't expect the end of the string after the modifier.
 1.5 24-Jan-2022  rillig tests/make: demonstrate that the 'static' in Var_Parse has an effect
 1.4 23-Feb-2021  rillig make: improve error message for unknown modifier

Back in 1995, the modifiers were all single-character, and it made sense
to print only the first character. Nowadays, with ':S', ':@var@...@',
'::=' and several others, a little more context is useful to see where
the exact error is. The actual modifier is still guessed, and the guess
may be wrong as soon as backslashes get involved, but it is still better
than before.
 1.3 20-Dec-2020  rillig make(1): error out on unknown variable modifiers at parse time

Before, make printed an "error message" that did not include the word
error and thus was not easily identified as such. This "error message"
also did not influence the exit status in the default mode but only in
-dL mode. The error message also didn't include any line number
information and was thus rude.
 1.2 01-Dec-2020  rillig make(1): add test for parse errors in variable name in Var_SetWithFlags
 1.1 08-Nov-2020  rillig make(1): add test for expanding variable expressions
 1.11.2.1 02-Aug-2025  perseant Sync with HEAD
 1.26 28-Jun-2025  rillig make: consistently use double quotes in error messages

Previously, some error messages used single quotes, very few used
backticks or parentheses, most already used double quotes.

While here, reword a few error messages to be clearer or more consistent
with related error messages.
 1.25 03-May-2025  rillig make: miscellaneous cleanups
 1.24 30-Mar-2025  rillig make: use '"filename" line 123' for locations instead of 'filename:123'

The format 'filename:123' is commonly used for identifying a location in
a file. Text editors recognize it and allow quick navigation through it.
The previous format was specific to make and would have required custom
support in editors.

The new format was already used in stack traces, except for the first
line. Now all lines use the same format.
 1.23 30-Mar-2025  rillig tests/make: fix test for printing the stack trace

Depending on the exact environment in which the test is run, the "./"
path component may or may not be trimmed from the output. Use an
absolute path instead.
 1.22 29-Mar-2025  rillig make: let unknown ":O" modifiers fall back to the ":from=to" modifier

Inspired by https://bugs.freebsd.org/285726, which concerns the ":t"
modifier instead.

This means that future extensions to the ":O" modifier must not contain
a "=" anywhere, otherwise they may break existing code.
 1.21 29-Mar-2025  rillig make: in a stack trace with details and includes, list the current file
 1.20 29-Mar-2025  rillig make: add ":" to error message about unknown modifier

In the manual page, the modifiers are listed with a preceding ":", so
use the same pattern in the error message. This removes an inconsistency
between the error messages "Unknown modifier" and "Bad modifier".
 1.19 29-Aug-2024  rillig make: reduce line length in error messages

The error messages for deeply nested parse errors were hard to decipher,
due to the large amount of text. Split these messages into individual
lines, just as in the backtrace for .include files and .for loops. This
unified backtrace makes the output more uniform.
 1.18 20-Jul-2024  rillig make: remove wrong error message about an undefined variable
 1.17 05-Jul-2024  rillig make: in error messages for anonymous variables, log the value
 1.16 05-Jul-2024  rillig make: error out on unclosed expressions during parse time

In exchange, this adds location information.

For unnamed expressions, the value is no longer printed. This will be
added back in a follow-up commit.
 1.15 05-Jul-2024  rillig tests/make: add expected messages for "Unclosed expression"
 1.14 04-Jul-2024  rillig make: error out on the "Bad modifier" error message

Previously, the "Bad modifier" error message did not affect make's exit
status. As a side effect, this kind of error now gets more context
information.
 1.13 02-Jun-2024  rillig branches: 1.13.2;
make: sync VarEvalMode constant names with their debug log names
 1.12 20-Apr-2024  rillig make: provide more context information for parse/evaluate errors
 1.11 19-Nov-2023  rillig tests/make: replace 'variable expressions' with 'expressions'
 1.10 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.9 01-Jun-2023  rillig tests/make: force line-based diagnostics to be listed in the tests

This way, contradictions between the intended output and the actual
output are closer together and have a better chance of being spotted.
 1.8 14-Feb-2023  rillig make: remove redundant type VarParseResult

No functional change.
 1.7 24-Aug-2022  rillig make: prevent future out-of-bounds errors when parsing expressions

A modifier in an expression ends not only at the next ':' or at the
closing '}' or ')', but also at the end of the string.

Previously, testing for the end of the string had been done separately,
which was error-prone since 2006-05-11, when indirect modifiers were
introduced. Since then, it was possible that the string terminator '\0'
was accidentally skipped in cases where the loop condition only tested
for the ending character. When parsing indirect modifiers, the ending
character is indeed '\0', but when parsing direct modifiers, it is '}'
or ')'.

A welcome side effect is that in the case of unclosed expressions such
as '${VAR:Modifier', the amount of error messages is reduced from 2 or 3
to only 1. The removed error messages were wrong and thus confusing
anyway.
 1.6 24-Aug-2022  rillig tests/make: test misleading error messages on unclosed expressions

The error messages say 'Unknown modifier' or 'Bad modifier', which is
not entirely correct. The modifier in itself is valid, it's just that
make doesn't expect the end of the string after the modifier.
 1.5 24-Jan-2022  rillig tests/make: demonstrate that the 'static' in Var_Parse has an effect
 1.4 15-Mar-2021  rillig make: replace enum bit-field with struct bit-field for VarEvalFlags

This makes the code easier to read, especially in var.c. It also makes
debugging sessions easier since some debuggers don't show enum
bit-fields symbolically as soon as more than one bit is set.

The code outside var.c is basically unchanged, except that instead of
passing the individual flags, there are 4 predefined evaluation modes.
These suffice for all practical use cases. Only in the implementation
deep inside var.c, the value of the flags keepDollar and keepUndef
differs.

There is no way of passing the struct to EnumFlags_ToString, which means
the ToString function has to be spelled out explicitly. This allows for
fine-tuning the representation in the debug log, to reduce the amount of
uppercae letters.

No functional change.
 1.3 20-Dec-2020  rillig make(1): error out on unknown variable modifiers at parse time

Before, make printed an "error message" that did not include the word
error and thus was not easily identified as such. This "error message"
also did not influence the exit status in the default mode but only in
-dL mode. The error message also didn't include any line number
information and was thus rude.
 1.2 01-Dec-2020  rillig make(1): add test for parse errors in variable name in Var_SetWithFlags
 1.1 08-Nov-2020  rillig make(1): add test for expanding variable expressions
 1.13.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 02-Oct-2020  rillig make(1): add tests for parsing and exporting variables

Once again, there are a few surprises deeply hidden inside the edge
cases.
 1.2 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.1 02-Oct-2020  rillig make(1): add tests for parsing and exporting variables

Once again, there are a few surprises deeply hidden inside the edge
cases.
 1.1 25-Sep-2020  rillig make(1): add test for partial expansion of undefined variables
 1.5 07-Jan-2024  rillig make: clean up comments, constify shell name
 1.4 19-Nov-2023  rillig tests/make: replace 'variable expression' with 'expression'

Each expression is based on a variable, there's no need for the
verbosity. The wording in make's diagnostics will be changed in a
follow-up commit.
 1.3 04-Nov-2020  rillig make(1): fix typo and reasoning in test varparse-undef-partial.mk
 1.2 27-Sep-2020  rillig make(1): fix CRLF line endings in unit tests
 1.1 25-Sep-2020  rillig make(1): add test for partial expansion of undefined variables
 1.3 08-May-2022  rillig tests/make: remove test varquote

The test varmod-quote-dollar covers the same topic.
 1.2 27-May-2018  christos branches: 1.2.2; 1.2.4;
- Introduce :q modifier for make variables and make it double escape $'s so
that passing variables to recursive makes with :q works as expected.
- Revert :Q to work as before.
- Adjust makefiles that use recursive make to use :q

Discussed on tech-toolchain@
XXX: pullup 8
 1.1 24-May-2018  christos unit test for $ underquoting in :Q modifier
 1.2.4.2 25-Jun-2018  pgoyette Sync with HEAD
 1.2.4.1 27-May-2018  pgoyette file varquote.exp was added on branch pgoyette-compat on 2018-06-25 07:26:11 +0000
 1.2.2.2 09-Jun-2018  martin Pull up following revision(s) (requested by christos in ticket #870):

sys/lib/libgnuefi/Makefile.inc: revision 1.5
external/mit/xorg/xorg-pkg-ver.mk: revision 1.9
sys/arch/i386/stand/lib/Makefile.inc: revision 1.17
sys/compat/common/Makefile.inc: revision 1.25
usr.bin/make/unit-tests/varquote.exp: revision 1.1, 1.2
sys/lib/libsa/Makefile.inc: revision 1.24
usr.bin/make/var.c: revision 1.220
sys/arch/ia64/stand/efi/libefi/Makefile.inc: revision 1.5
sys/arch/hppa/spmath/Makefile.inc: revision 1.10
usr.bin/make/unit-tests/varquote.mk: revision 1.1, 1.2
usr.bin/make/unit-tests/Makefile: revision 1.53
sys/lib/libkern/Makefile.inc: revision 1.45
sys/arch/acorn32/stand/lib/Makefile.inc: revision 1.4
sys/arch/m68k/fpsp/Makefile.inc: revision 1.21
usr.bin/make/make.1: revision 1.273
sys/lib/libz/Makefile.inc: revision 1.17

- Introduce :q modifier for make variables and make it double escape $'s so
that passing variables to recursive makes with :q works as expected.
- Adjust makefiles that use recursive make to use :q

Discussed on tech-toolchain@

XXX: pullup 8
 1.2.2.1 27-May-2018  martin file varquote.exp was added on branch netbsd-8 on 2018-06-09 15:35:38 +0000
 1.6 08-May-2022  rillig tests/make: remove test varquote

The test varmod-quote-dollar covers the same topic.
 1.5 28-Dec-2021  rillig tests/make: use tabs instead of spaces for indentation
 1.4 16-Dec-2018  christos use %s formats to avoid -flag confusion (from sjg)
 1.3 16-Dec-2018  christos Use printf instead of echo since we can't portably use \ in string (from sjg@)
http://pubs.opengroup.org/onlinepubs/009695399/utilities/echo.html
 1.2 27-May-2018  christos branches: 1.2.2; 1.2.4; 1.2.6;
- Introduce :q modifier for make variables and make it double escape $'s so
that passing variables to recursive makes with :q works as expected.
- Revert :Q to work as before.
- Adjust makefiles that use recursive make to use :q

Discussed on tech-toolchain@
XXX: pullup 8
 1.1 24-May-2018  christos unit test for $ underquoting in :Q modifier
 1.2.6.1 10-Jun-2019  christos Sync with HEAD
 1.2.4.3 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.2.4.2 25-Jun-2018  pgoyette Sync with HEAD
 1.2.4.1 27-May-2018  pgoyette file varquote.mk was added on branch pgoyette-compat on 2018-06-25 07:26:11 +0000
 1.2.2.2 09-Jun-2018  martin Pull up following revision(s) (requested by christos in ticket #870):

sys/lib/libgnuefi/Makefile.inc: revision 1.5
external/mit/xorg/xorg-pkg-ver.mk: revision 1.9
sys/arch/i386/stand/lib/Makefile.inc: revision 1.17
sys/compat/common/Makefile.inc: revision 1.25
usr.bin/make/unit-tests/varquote.exp: revision 1.1, 1.2
sys/lib/libsa/Makefile.inc: revision 1.24
usr.bin/make/var.c: revision 1.220
sys/arch/ia64/stand/efi/libefi/Makefile.inc: revision 1.5
sys/arch/hppa/spmath/Makefile.inc: revision 1.10
usr.bin/make/unit-tests/varquote.mk: revision 1.1, 1.2
usr.bin/make/unit-tests/Makefile: revision 1.53
sys/lib/libkern/Makefile.inc: revision 1.45
sys/arch/acorn32/stand/lib/Makefile.inc: revision 1.4
sys/arch/m68k/fpsp/Makefile.inc: revision 1.21
usr.bin/make/make.1: revision 1.273
sys/lib/libz/Makefile.inc: revision 1.17

- Introduce :q modifier for make variables and make it double escape $'s so
that passing variables to recursive makes with :q works as expected.
- Adjust makefiles that use recursive make to use :q

Discussed on tech-toolchain@

XXX: pullup 8
 1.2.2.1 27-May-2018  martin file varquote.mk was added on branch netbsd-8 on 2018-06-09 15:35:38 +0000
 1.2 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.1 20-Aug-2014  apb Add tests for VAR != command.
 1.4 09-Nov-2020  rillig make(1): move test for != assignments to var-op-shell
 1.3 04-Jul-2020  rillig make(1): add post-processing for tests

By defining SED_CMDS.${test}, a test can do additional post-processing
on its output, for example to normalize paths or error messages.

The Makefile for the tests now follows the common style to have all
relevant definitions at the top of the file, and all the implementation
details at the bottom.

By using the += instead of backslashed lists, it becomes easier to
comment out a single test, either temporarily or permanently (such as
the POSIX tests).

The :C modifier has been replaced with the simpler :S, some :S modifiers
have been replaced with simpler := modifiers.

The postprocessing commands have been extracted from the actual command.
This makes editing and commenting them easier.
 1.2 10-Apr-2015  sjg export-all.mk should be including export.mk
sadly some shells do not grok named signals.
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).
 1.5 09-Nov-2020  rillig make(1): move test for != assignments to var-op-shell
 1.4 24-Oct-2020  rillig make(1): use consistent indentation in variable assignments

Initial work by "pkglint -F *.mk", manually adjusted in a few places.
 1.3 24-Oct-2020  rillig make(1): use consistent RCS Id in test files
 1.2 10-Apr-2015  sjg export-all.mk should be including export.mk
sadly some shells do not grok named signals.
 1.1 21-Aug-2014  apb Give each group of tests its own output file.

* Rename each sub-makefile to *.mk;
* Add a *.exp file of expected output for each sub-makefile;
* Remove test.exp, which is replaced by all the other *.exp files.
* Use suffix rules to generate *.rawout and *.out files for
each test case.
* Rewrite the test and accept targets to adapt to the new way.

The old (now removed) test.exp file is almost identical to the
concatenation (in the correct order) of all the new *.exp files. There
are expected differences in makefile names embedded in the output, and
the new "exit status" lines. Some old "*** Error code 1 (ignored)"
lines are also removed (replaced by new "exit status 1" lines).

RSS XML Feed