History log of /netbsd-current/usr.bin/make/arch.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.219 02-Jun-2024 rillig

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.


Revision tags: netbsd-10-0-RELEASE netbsd-10-0-RC6 netbsd-10-0-RC5 netbsd-10-0-RC4 netbsd-10-0-RC3 netbsd-10-0-RC2 netbsd-10-0-RC1 netbsd-10-base
# 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.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1
# 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.


Revision tags: cjep_staticlib_x-base
# 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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-3-RELEASE netbsd-9-4-RELEASE netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: netbsd-10-0-RELEASE netbsd-10-0-RC6 netbsd-10-0-RC5 netbsd-10-0-RC4 netbsd-10-0-RC3 netbsd-10-0-RC2 netbsd-10-0-RC1 netbsd-10-base
# 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.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1
# 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.


Revision tags: cjep_staticlib_x-base
# 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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-3-RELEASE netbsd-9-4-RELEASE netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: netbsd-10-0-RELEASE netbsd-10-0-RC6 netbsd-10-0-RC5 netbsd-10-0-RC4 netbsd-10-0-RC3 netbsd-10-0-RC2 netbsd-10-0-RC1 netbsd-10-base
# 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.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1
# 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.


Revision tags: cjep_staticlib_x-base
# 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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-4-RELEASE netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: netbsd-10-0-RC4 netbsd-10-0-RC3 netbsd-10-0-RC2 netbsd-10-0-RC1 netbsd-10-base
# 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.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1
# 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.


Revision tags: cjep_staticlib_x-base
# 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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: netbsd-10-0-RC1 netbsd-10-base
# 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.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1
# 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.


Revision tags: cjep_staticlib_x-base
# 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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.213 14-Feb-2023 rillig

make: reduce complexity of evaluating expressions

No functional change.


Revision tags: netbsd-10-base
# 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.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1
# 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.


Revision tags: cjep_staticlib_x-base
# 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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1
# 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.


Revision tags: cjep_staticlib_x-base
# 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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1
# 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.


Revision tags: cjep_staticlib_x-base
# 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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1
# 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.


Revision tags: cjep_staticlib_x-base
# 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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1
# 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.


Revision tags: cjep_staticlib_x-base
# 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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1
# 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.


Revision tags: cjep_staticlib_x-base
# 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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1
# 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.


Revision tags: cjep_staticlib_x-base
# 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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1
# 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.


Revision tags: cjep_staticlib_x-base
# 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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1
# 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.


Revision tags: cjep_staticlib_x-base
# 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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1
# 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.


Revision tags: cjep_staticlib_x-base
# 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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: cjep_staticlib_x-base
# 1.199 03-Apr-2021 rillig

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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.199 03-Apr-2021 rillig

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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-1-RELEASE netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.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.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406 phil-wifi-20191119
# 1.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-8-2-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

branches: 1.70.12;
Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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.71 05-Oct-2019 mrg

use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


Revision tags: netbsd-9-base phil-wifi-20190609 netbsd-8-1-RELEASE netbsd-8-1-RC1 pgoyette-compat-merge-20190127 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-2-RELEASE netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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


Revision tags: prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.70 16-Apr-2017 riastradh

Check return value of fseek.

CID 975275
CID 975276


Revision tags: pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107 pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 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


Revision tags: netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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


Revision tags: pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.69 06-Apr-2016 gson

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


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base dholland-make-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 tls-maxphys-base
# 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.


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 yamt-pagecache-base5 yamt-pagecache-base4 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base matt-mips64-premerge-20101231
# 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.


Revision tags: matt-premerge-20091211 jym-xensuspend-nbase jym-xensuspend-base
# 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 :-)


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 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.


Revision tags: mjf-devfs2-base wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 wrstuden-revivesa-base yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase hpcarm-cleanup-base
# 1.55 15-Feb-2008 christos

back all changes out until I fix it properly.


Revision tags: christos-broken
# 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


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 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.


Revision tags: abandoned-netbsd-4-base
# 1.51 29-Jun-2006 rillig

Fixed gcc warnings about signed vs. unsigned in comparisons.


Revision tags: chap-midi-nbase chap-midi-base
# 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


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 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


Revision tags: netbsd-2-0-base
# 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).


Revision tags: fvdl_fs64_base
# 1.35 15-Jun-2002 wiz

Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 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


Revision tags: netbsd-1-5-PATCH003 netbsd-1-5-PATCH002 netbsd-1-5-PATCH001 netbsd-1-5-RELEASE netbsd-1-5-BETA2 netbsd-1-5-BETA netbsd-1-5-ALPHA2 netbsd-1-5-base minoura-xpg4dl-base
# 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


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base comdex-fall-1999-base
# 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.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 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


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 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.


Revision tags: netbsd-1-2-RELEASE netbsd-1-2-BETA netbsd-1-2-base
# 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.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 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 :-)]


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 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.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 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