Home | History | Annotate | Download | only in make
History log of /src/usr.bin/make/targ.c
RevisionDateAuthorComments
 1.185  07-May-2025  rillig make: add end marker for -dg1, -dg2 and -dg3 debug log

The marker helps distinguish the output from sub-makes from the output
of the primary make.
 1.184  07-Jul-2024  rillig make: move initialization of variable scopes to targ.c

The variable scopes are freed by Targ_End, so initialize them there as
well. Separate printing statistics and freeing memory, which makes
Var_End unnecessary.
 1.183  25-May-2024  rillig branches: 1.183.2;
make: fix memory leak for command strings
 1.182  25-May-2024  rillig make: fix a few more memory leaks
 1.181  27-Apr-2024  rillig make: simplify freeing of lists
 1.180  10-Mar-2024  sjg make: record exit status in GNode

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

Reviewed by:
 1.179  06-Dec-2022  rillig make: clean up comments

No binary change.
 1.178  27-Sep-2022  rillig make: set WARNS to 6, from the default 5

No binary change on x86_64.
 1.177  15-Apr-2022  rillig make: add .USEBEFORE to Targ_PrintType

When .USEBEFORE was added in targ.c 1.22 from 2001-07-03, it was not
added to Targ_PrintType, probably because the PRINTBIT macro hid the
identifier OP_USE and only used USE.
 1.176  07-Jan-2022  rillig make: merge duplicate variables for the main target

No functional change.
 1.175  07-Jan-2022  rillig make: clean up comments, variable names, function names

The comment in ApplyDependencySourceOther repeated the code, its second
half didn't match any current code.

The comment above ParseDependencySourcesEmpty repeated the code.

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

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

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

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

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

No functional change.
 1.172  12-Sep-2021  rillig make: reduce number of relocations in Targ_PrintType

On x86_64, this saves 120 bytes of .text.

No functional change.
 1.171  12-Sep-2021  rillig make: fix lint warnings for strict bool mode

In strict bool mode, lint does not consider 'x & y' as having type bool,
if x and y have integer type, it only allows this for enums.

No functional change.
 1.170  12-Sep-2021  rillig make: fix Targ_PrintType for pre-C99 compilers
 1.169  12-Sep-2021  rillig make: make Targ_PrintType simpler

No functional change.
 1.168  03-Apr-2021  rillig make: use standard %H in strftime instead of %k

The conversion specifier %k is neither in C99 nor in C90.

These timestamps are only used in the debug output.
 1.167  03-Apr-2021  rillig make: use C99 bool type instead of defining its own

No functional change.
 1.166  22-Feb-2021  rillig make: update constant names in comments

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

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

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

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

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

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

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

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

The other renamings (variable names "context", "ctxt", as well as
further comments) will be done in a follow-up commit.
 1.163  03-Feb-2021  rillig make: replace Global_AppendExpand with Global_Append

All callers with a variable name that is guaranteed to not contain a
dollar sign have been converted to call Global_Append instead of the
previous Global_AppendExpand. After that, Global_AppendExpand was
unused, therefore it was effectively just renamed.
 1.162  03-Feb-2021  rillig make: use shortcut functions Global_SetExpand and Global_AppendExpand

There are many places where global variables are set or appended to. To
reduce clutter and code size, encode the VAR_GLOBAL in the function
name.

The word Expand in the function names says that the variable name is
expanded. In most of the cases, this is not necessary, but there are no
corresponding functions Global_Set or Global_Append yet.

Encoding the information whether the name is expanded or not in the
function name will make inconsistencies obvious in future manual code
reviews. Letting the compiler check this by using different types for
unexpanded and expanded variable names is probably not worth the effort.
There are still a few bugs to be fixed, such as in SetVar, which expands
the variable name twice in a row.
 1.161  02-Feb-2021  rillig make: remove overengineered Enum_ValueToString

For printing the status of a GNode, there was already made_name (now
renamed to GNodeMade_Name), which prints user-friendly text instead of
the bare enum constant names.

To do this change confidently, I first had to demonstrate that the
output really affects something other than just the word "UNMADE". There
had not been a test for that case before, and the test immediately
discovered a bug in the -dg2 and -dg3 options. This bug is one of the
oldest in make, dating back to at least 1993.
 1.160  10-Jan-2021  rillig make(1): make a few more bool expressions more precise

The previous version of lint(1) from a few hours ago didn't catch all
occurrences. And even the current one doesn't catch everything.
Function arguments and return types still need some work. The "return
quietly" from shouldDieQuietly still implicitly converts from int to
_Bool.

No functional change.
 1.159  18-Dec-2020  rillig make(1): spell nonexistent consistently
 1.158  18-Dec-2020  rillig make(1): use symbolic time for 0 in Make_Recheck

This makes the test depsrc-optional independent from the current time
zone.
 1.157  18-Dec-2020  rillig make(1): constify Targ_FmtTime
 1.156  15-Dec-2020  rillig make(1): format function definitions consistently
 1.155  12-Dec-2020  rillig make(1): inline Targ_Ignore and Targ_Silent

Each of these functions was only used 2 times, and each of these calls
used a different part of the whole expression.
 1.154  07-Dec-2020  rillig make(1): clean up debug logging
 1.153  06-Dec-2020  rillig make(1): inline macros for debug logging

No changes to the resulting binary, except for the line numbers in
assertions.
 1.152  05-Dec-2020  rillig make(1): define constants for enum zero-values
 1.151  05-Dec-2020  rillig make(1): don't concatenate identifiers in Targ_PrintType

Concatenating identifiers makes it difficult to spot them when searching
the code. This gets rid of the special case for OP_MEMBER and MEMBER.

The same pattern is applied in the DEBUG macro, by the way.
 1.150  05-Dec-2020  rillig make(1): indent targ.c with tabs instead of spaces

Explain the tricky details of GNode_Free.

Invert a condition in Targ_PrintNode to reduce the overall indentation.
 1.149  04-Dec-2020  rillig make(1): use consistent variable names for list nodes
 1.148  29-Nov-2020  rillig make(1): reduce memory allocation for target handling
 1.147  29-Nov-2020  rillig make(1): reduce memory allocation for targets

This change moves the initialization and finalization of the list of
targets to the same function. They had been split before.
 1.146  28-Nov-2020  rillig make(1): reduce pointer indirection for GNode.implicitParents
 1.145  28-Nov-2020  rillig make(1): reduce pointer indirection for GNode.cohorts
 1.144  28-Nov-2020  rillig make(1): reduce pointer indirection for GNode.order_pred and order_succ
 1.143  28-Nov-2020  rillig make(1): reduce memory allocation for GNode.parents and GNode.children
 1.142  28-Nov-2020  rillig make(1): remove pointer indirection from GNode.commands

Just to save a few memory allocations. No noticeable effect on the
performance though.
 1.141  23-Nov-2020  rillig make(1): use comparisons in boolean expressions

The generated code stays exactly the same.
 1.140  22-Nov-2020  rillig make(1): add remark to add a "reasonable way" to format time_t 0
 1.139  21-Nov-2020  rillig make(1): rename GNode.context to vars

Especially in the variables module, the expression 'ctxt->context' looked
redundant. Having a GNode as a context sounds ok, but a context of a
context just doesn't make sense.
 1.138  21-Nov-2020  rillig make(1): add more debug logging for suffix handling

One notable thing is that there is no debug output when adding a
transformation rule like ".c.o", which means that these rules don't end
up in the global allTargets variable.

This may or may not be intentional. It seems not intentional since this
is one of the causes for the suff-rebuild test to behave unexpectedly.
 1.137  21-Nov-2020  rillig make(1): improve comment style in GNode_Free

It was unclear what the ellipsis referred to. It was meant to refer to
the function call Lst_Free, but that was not necessarily obvious to a
casual reader.
 1.136  21-Nov-2020  rillig make(1): fix comment for allTargets

Source nodes are also included in this list. What's not includes is
nodes that are _only_ source nodes.
 1.135  16-Nov-2020  rillig make(1): clean up code style in targ.c
 1.134  16-Nov-2020  rillig make(1): initialize and free GNode fields in declaration order

Initialization and destruction of the fields is independent from the
other fields. Therefore use declaration order, which allows to quickly
see whether a field was forgotten.

While here, add comments that in cleanup mode, not all memory is freed.
The variables of a node and the suffix survive right now.
 1.133  16-Nov-2020  rillig make(1): rename variables in targ.c

The previous names didn't make it obvious that 'allTargets' and 'targets'
belong together. Naming both 'allTargets' provides a stronger hint.
 1.132  16-Nov-2020  rillig make(1): clean up and extend comments in targ.c
 1.131  16-Nov-2020  rillig make(1): make some GNode functions const
 1.130  16-Nov-2020  rillig make(1): in CLEANUP mode, preallocate list of all GNodes

This makes the code simpler and more uniform.
 1.129  16-Nov-2020  rillig make(1): rename TargFreeGN to GNode_Free

This is the usual counterpart to a New function, like for Lst, HashTable,
Buffer.
 1.128  16-Nov-2020  rillig make(1): rename Targ_NewGN to GNode_New

This function is a classical constructor function, and if it weren't for
CLEANUP mode, it would have no dependencies on anything else besides the
memory allocator. Therefore it doesn't really matter which module
defines this function, and there is no need for the "Targ" to be part of
the function name.
 1.127  05-Nov-2020  rillig make(1): remove redundant parentheses from sizeof operator

The parentheses are only needed if the argument is a type, not an
expression.
 1.126  30-Oct-2020  rillig make(1): rename VAR_CMD to VAR_CMDLINE

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

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

The struct also suggests to extract the initialization code out of main,
which is still too large, having more than 400 lines of code and
covering far too many topics.
 1.124  25-Oct-2020  rillig make(1): add GNode_Path to access the path of a GNode
 1.123  25-Oct-2020  rillig make(1): rename hash functions to identify the type name

This makes it easier to spot mismatches between the function name and
its first parameter, although the compiler should already catch most of
them. Except for void pointers.
 1.122  23-Oct-2020  rillig make(1): rename GNode.cmgn to youngestChild

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

This mainly affects the void pointers in callback functions for lists.
These had been necessary once when the parameter type was still
ClientData instead of void pointer.
 1.119  19-Oct-2020  rillig make(1): clean up headers, no functional change
 1.118  19-Oct-2020  rillig make(1): remove void pointers from suffix debug printing
 1.117  19-Oct-2020  rillig make(1): fix variable names in Targ_Propagate

List nodes are called ln, not pn or cn.

While here, extract a common subexpression to save a few instructions.
The compiler cannot know that gn->type will not change during the whole
loop. For this, it would have to know that a GNode cannot have itself
as a cohort, and this is not expressed anywhere in the code.
 1.116  18-Oct-2020  rillig make(1): rename Lst_Init to Lst_New

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

For consistency with the other type names, such as GNodeListNode.
 1.114  18-Oct-2020  rillig make(1): extract GNode_OpName from Targ_PrintNode
 1.113  17-Oct-2020  rillig make(1): normalize initialization and cleanup of the modules
 1.112  05-Oct-2020  rillig make(1): enable format string truncation warnings for parse.c

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

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

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

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

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

Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
 1.109  03-Oct-2020  rillig make(1): clean up #include sections
 1.108  28-Sep-2020  rillig make(1): replace Lst_Open with direct iteration
 1.107  28-Sep-2020  rillig make(1): make debug logging simpler

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

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

Having a separate function had only been necessary for Lst_ForEachUntil.
 1.104  27-Sep-2020  rillig make(1): inline Lst_ForEachUntil in Targ_PrintNodes

Printing a node does not modify the structure of the node, therefore the
additional housekeeping of Lst_ForEachUntil is not needed here.

Inlining the callback function also removes a lot of pointer stuff that
is more difficult to read than necessary.
 1.103  27-Sep-2020  mrg fix usr.bin/make build (which uses more warnings):

remove static only prototype TargPrintOnlySrc().
PrintOnlySources() does not return a value, make it void.
 1.102  26-Sep-2020  rillig make(1): revert migration from Lst_ForEachUntil to Lst_ForEach

There is a crucial difference between these functions, in that
Lst_ForEachUntil can cope with a few concurrent modifications while
iterating over the list. This is something that Lst_ForEach doesn't do.

This difference led to a crash very early in NetBSD's build.sh.
 1.101  26-Sep-2020  rillig make(1): inline and remove LstNode_Prev and LstNode_Next

These functions made the code larger than necessary. The prev and next
fields are published intentionally since navigating in a doubly-linked
list is simple to do and there is no need to wrap this in a layer of
function calls, not even syntactically. (On the execution level, the
function calls had been inlined anyway.)
 1.100  26-Sep-2020  rillig make(1): inline Lst_ForEach in Targ_PrintGraph
 1.99  26-Sep-2020  rillig make(1): replace a few Lst_ForEachUntil with simpler Lst_ForEach
 1.98  26-Sep-2020  rillig make(1): clean up obsolete comments about TARG constants
 1.97  26-Sep-2020  rillig make(1): remove useless comment from TargFreeGN

GNode.fname is a const char *, therefore it cannot be freed anyway.
 1.96  26-Sep-2020  rillig make(1): inline Targ_FindNodeImpl

The 3 callers of this function passed different flags, and these flags
led to code paths that almost did not overlap.

It's a bit strange that GCC 5 didn't get that, and even marking the
function as inline did not produce much smaller code, even though the
conditions inside that function were obviously constant. Clang 9 did a
better job here.

But even for human readers, inlining the function and then throwing away
the dead code leads to much easier code.

This pattern of squeezing completely different code into a single
function has already occurred in a different part of make, though I
don't remember where exactly.
 1.95  26-Sep-2020  rillig make(1): clean up API for finding and creating GNodes

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

Splitting the function into 3 separate functions avoids this confusion.
It also reveals several places where the complicated API led to
unreachable code. Such code has been removed.
 1.94  26-Sep-2020  rillig make(1): replace Hash_FindEntry with Hash_FindValue in Targ_FindNode
 1.93  24-Sep-2020  rillig make(1): inline Lst_ForEach in Targ_PrintCmds
 1.92  24-Sep-2020  rillig make(1): rename Lst_ForEach to Lst_ForEachUntil

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

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

In a follow-up commit, Lst_ForEach will be added back with a much
simpler implementation that iterates over the list naively, without a
terminating condition and without taking the iteration state from
Lst_Open/Lst_Next/Lst_Close into account. The migration to this simpler
implementation will be done step by step since each callback function
needs to be examined closely.
 1.91  24-Sep-2020  rillig make(1): refactor add_wait_dep to not use Lst_ForEachFrom anymore

It was the last remaining use of that function outside of lst.c.

While here, clean up the code of add_wait_dep by removing unreachable
code (the GNode lists never contain NULL, only the GNode.commands lists
do that).
 1.90  23-Sep-2020  rillig make(1): fix assertion failure in -j mode with .END node

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

The code in JobRun heads over to Compat_Make without calling Compat_Run
first, which left the variable ENDNode uninitialized.
 1.89  22-Sep-2020  rillig make(1): use fine-grained type names for lists and their nodes

This is only intended to help the human reader. There is no additional
type safety yet.
 1.88  13-Sep-2020  rillig make(1): clean up RCSID blocks

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

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

To avoid "defined but unused" warnings from GCC in the case where
MAKE_NATIVE is not defined, I had to add volatile. Adding
MAKE_ATTR_UNUSED alone would not preserve the rcsid variable in the
resulting binary.
 1.87  12-Sep-2020  rillig make(1): fix API of Targ_PrintNode

There was no need to export Targ_PrintNode at all. All the callers need
is a high-level API for printing a single node or a list of nodes. The
implementation detail that Targ_PrintNode was used as a callback to
Lst_ForEach should have never leaked into the API.
 1.86  12-Sep-2020  rillig make(1): remove unintended noinline from previous commit
 1.85  12-Sep-2020  rillig make(1): fix trailing space in output of related node names (-dg2)
 1.84  12-Sep-2020  rillig make(1): fix API for Targ_PrintCmd

The previous API was too low-level and not strictly typed.
 1.83  05-Sep-2020  rillig make(1): remove initial size argument from Hash_InitTable

In all but one case this argument was set to auto-detect anyway. The
one case where it was set was not worth keeping this complicated API.
 1.82  05-Sep-2020  rillig make(1): remove trailing whitespace in -dg1 debug output
 1.81  01-Sep-2020  rillig make(1): inline constant for hash table size

The name HTSIZE didn't provide any explanation for the value 191, and it
is obvious that this is a hash table size. Therefore giving the
constant a name didn't explain anything or make it less magic.
 1.80  30-Aug-2020  rillig make(1): rename GNode.iParents to implicitParents

The i alone was too ambiguous. It could have meant ignore, implicit,
interactive, and probably many more.
 1.79  30-Aug-2020  rillig make(1): rename Lst_Datum to LstNode_Datum
 1.78  29-Aug-2020  rillig make(1): use loops instead of Lst_ForEach for propagating to cohorts

For one-liners, Lst_ForEach creates a lot of overhead, both at runtime
and for reading and understanding the code.

In this simple case where the structure of the traversed nodes is not
modified, a simple loop is enough. This avoids a lot of conversions to
void * and thus prevents type mistakes.
 1.77  28-Aug-2020  rillig make(1): clean up targ.c

The main part is removing redundant or outdated information from
comments. In a few places, the expression cond ? TRUE : FALSE has been
simplified.
 1.76  28-Aug-2020  rillig make(1): remove trailing 'S' from names of Lst functions

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

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

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

Most lists are always valid. Only the "targets" variable may be null in
some cases, probably.
 1.73  26-Aug-2020  rillig make(1): add stricter variants for remaining Lst functions

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

While here, remove a few statements that were only useful when the Lst
functions handled circular lists.
 1.72  24-Aug-2020  rillig make(1): in debug mode, print GNode details in symbols

A string like OP_DEPENDS|OP_OPTIONAL|OP_PRECIOUS is much easier to read
and understand than the bit pattern 00000089.

The implementation in enum.h looks really bloated and ugly, but using
this API is as simple and natural as possible. That's the trade-off.

In enum.h, I thought about choosing the numbers in the macros such that
it is always possible to combine two of them in order to reach an
arbitrary number, because of the "part1, part2" in the ENUM__SPEC macro.
The powers of 2 are not these numbers, as 7 cannot be expressed as the
sum of two of them. Neither are the fibonacci numbers since 12 cannot
be expressed as the sum of 2 fibonacci numbers. I tried to find a
general pattern to generate these minimal 2-sum numbers, but failed.
 1.71  22-Aug-2020  rillig make(1): restructure GNode types and documentation

Having a numbered list above the type was not helpful since the numbers
didn't serve any purpose, they just consumed screen space.

Several of these list items didn't have an obvious relationship to the
struct fields. It's better to have just a rough introduction as the
type level documentation, leaving the details to the individual fields.

Converting the types and flags and other constants into separate types
and defining them outside the struct leaves more space to see the
relationship of the struct fields.

Limiting the documentation of each field to a single line, as suggested
by the end-of-line comments, reduces clarity since several of the fields
need way more documentation to be properly understood.
 1.70  22-Aug-2020  rillig make(1): replace Lst_Datum with non-null guaranteeing Lst_DatumS
 1.69  22-Aug-2020  rillig make(1): convert remaining Lst_AtEnd to the stricter Lst_Append

The general-purpose list library that is included in make allows to call
Lst_AtEnd for invalid lists, silently ignoring this programming error.
This is a flexibility that make doesn't need.

Another unneeded "feature" is that list items can theoretically be null
pointers. This doesn't make sense as well and is therefore not needed
by make.

These programming errors are now caught early by assertions.
 1.68  22-Aug-2020  rillig make(1): replace "(void)Lst_AtEnd" with stricter "Lst_AppendS"

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

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

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

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

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

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

After replacing Lst_Init(FALSE) with Lst_Init(), only a single call to
Lst_Init remained with a non-constant argument, and that was in
Lst_Concat, which was to be expected.
 1.64  20-Jul-2020  sjg Make DEBUG_HASH less of a fire-hose.

Reporting keys on every lookup is overkill unless
playing with a new HASH, so wrap in #ifdef DEBUG_HASH_LOOKUP
Also add some stats at the end so we can see
final size and max chain length - maxchain is a better
variable name than maxlen.
 1.63  03-Jul-2020  rillig make(1): remove redundant parentheses around return values
 1.62  16-Apr-2017  riastradh Use, don't kludge, MAKE_ATTR_UNUSED.

CID 1300234
CID 1300237
CID 1300238
CID 1300245
CID 1300255
CID 1300267
CID 1300284
 1.61  17-Jan-2016  christos branches: 1.61.2; 1.61.4;
remove free NULL checks (Tilman Sauerbeck)
 1.60  25-May-2015  manu Fix warning about uninitialized variable

This warning gets fatal when including make(1) as a crunchgen(1) binary.
 1.59  07-Sep-2014  joerg Revert all make changes except the unit tests to the state of three
weeks ago. Individual changes can be reapplied after review.
 1.58  23-Aug-2014  christos PR/46096: Jarmo Jaakkola: fix many problems with dependencies (PR 49086)

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

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

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

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

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

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

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

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

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

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

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

Other improvements in the Suff module include:
- better debug messages for transformation rule search (length of
the chain is now visualized by indentation)
- Suff structures are created, destroyed and moved around by a set
of maintenance functions so their reference counts are easier
to track (this also gets rid of a lot of code duplication)
- some unreasonably long functions were split into smaller ones
- many local variables had their names changed to describe their
purpose instead of their type
 1.57  12-Jun-2012  joerg branches: 1.57.10;
Replace __dead, __unused and the various printf format attributes
with versions prefixed by MAKE_ATTR_* to avoid modifying the
implementation namespace. Make sure they are available in all places
using nonints.h to fix bootstrap on Linux.
 1.56  25-Nov-2010  christos branches: 1.56.6;
Instead of keeping around the mtime of the youngest child, keep a pointer
to it, so that we can print it when we do the out of date determination.
 1.55  23-Jan-2009  dsl Change 'ClientData' to 'void *' so that relevant parameters can
be made 'const void *'.
 1.54  13-Dec-2008  dsl Use NULL instead of -1 cast to the relavant type (usually via NIL).
This was a suggestion from christos - so blame him if there is a deep
reason for using -1 :-)
 1.53  06-Oct-2008  joerg Don't use emalloc and friends directly, but call them consistently
bmake_malloc and friends. Implement them via macros for the native case
and provide fallback implementations otherwise. Avoid polluting the
namespace by not defining enomem globally. Don't bother to provide
strdup and strndup, they were only used for the estrdup and estrndup
comapt code.

This addresses the presence of emalloc in system libraries on A/UX and
resulted strange issues as reported by Timothy E. Larson.
 1.52  15-Feb-2008  christos back all changes out until I fix it properly.
 1.51  14-Feb-2008  christos - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
 1.50  21-Dec-2007  dsl If make can't find a rule to create a file it needs to satisfy a rule
that came from .depend then just output a message and contine.
 1.49  21-Dec-2006  dsl branches: 1.49.4;
Fix breakage of previous commit.
 1.48  20-Dec-2006  dsl Fix detection and reporting of dependency loops in parallel makes.
make's unit_tests should now run again.
 1.47  18-Dec-2006  christos From Anon Ymous:
Removed two "(void)&" constructs as there is no setjmp() or vfork() insight.
Flagged a few parameters __unused so this will compile with -Wextra now.
 1.46  04-Dec-2006  dsl There really is no point calling estrdup() to get a copy of the makefile name
into every 'gnode' (aka target), instead just copy a pointer to the string
and avoid freeing the original name when we close the file.
I can't imagine any makefile set where this gives a larger footprint!
 1.45  17-Nov-2006  dsl branches: 1.45.2;
A rather large rototil in the way the parallel make code schedules jobs.
This gives a considerable speedup in the processing of .WAIT and .ORDER.
Both .WAIT and .ORDER stop both the commands of the node, and its dependant
nodes being built until the LH nodes are complete.
.WAIT only applies to the dependency line on which it appears, whereas
.ORDER applies globally between the two nodes.
In both cases dependant nodes can be built because other targets need them.
make now processes the target list left to right, scheduling child nodes
as they are needed to make other nodes (instead of attempting to generate
a bottom-up dependency graph at the start). This means that 'make -j1'
will tend to build in the same order as a non-parallel make.
Note that:
all: x y
x: a .WAIT b
y: b .WAIT a
does not generate a dependency loop.
But
x: y
.ORDER y x
does (unless something elswhere causes 'y' to be built).
 1.44  27-Oct-2006  dsl Since 'ClientData' is 'void *', nuke almost all the (ClientData) casts.
 1.43  15-Oct-2006  dsl Output all debug trace output through 'debug_file' defaulting to 'stdout'.
(Almost all the debug output went there, but some went to stderr.)
Split the parsing of -d (debug flags) out into its own routine.
Allow the output filename to be changed by specifying -dF<file> to create
a log file, or -dF+<file> to append to it. <file> may be stdout or stderr.
Also change so that -d-<flags> acts on <flags> locally but doesn't copy
them to MAKEFLAGS so they aren't inherited by child makes.
I'm not 100% happy with the command line syntax for the above, so they are
currently undocumented.
 1.42  26-Feb-2006  apb Make ".WAIT" apply recursively to all children of nodes on the right
hand side of the .WAIT, except when the recursive interpretation would
cause a cycle in the dependency graph.

Discussed in tech-toolchain. Reviewed by christos, sjg.
 1.41  11-Feb-2006  dsl Delete obsolete static defn.
Trace number of unmade children on pass 1
 1.40  11-Feb-2006  dsl Debug trace all the targets we are actually intending making.
De-optimise the getting of a job token so we don't re-order the job
list when there are no tokens.
This might have helped etc/Makefile, but isn't enough.
 1.39  08-Jan-2006  dsl Include the 'preds' and 'successors' in the diag output.
These are the values that are actually used to control what is built.
(I suspect .WAIT info added in the previous delta isn't always useful.)
 1.38  08-Jan-2006  dsl Include .WAIT in the debug output for dependency lists.
 1.37  08-Aug-2005  christos From Max Okumoto:
- Remove casts to NULL.
- Remove space between cast and object.
 1.36  05-Aug-2005  christos More KNF cleanups from Max Okumoto
 1.35  25-Jul-2005  christos Whitespace KNF cleanup from Max Okumoto
 1.34  16-Feb-2005  christos PR/29203, PR/29204: Max Okumoto: KNF changes to make [no functional changes]
 1.33  01-Jul-2004  jmc Change to use __unused instead and provide a compat definition in make.h if
not already defined from cdefs.h
 1.32  01-Jul-2004  jmc Add some checks for gcc around a few function declarations and note the
unused variables. Also fix a few other warnings that PR#22118 shows when
trying to compile bmake on non-NetBSD hosts
 1.31  07-May-2004  ross Simplify build, no functional changes.

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

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

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.29  14-Jul-2003  christos Pass WARNS=3
 1.28  15-Jun-2002  wiz Remove !__STDC__ stuff, de-__P(), ANSIfy, and de-register.
 1.27  20-Mar-2002  pk Xref: parse.c, rev 1.46; make.c, rev 1.23

In these revisions `::' dependency handling was simplified by not linking
the cohort nodes into the dependency graph. This broke dependency checking
on all but the first instance of a `::' target since all of the cohort nodes
now just form a collection of disconnected dependency graphs.

Fix this by keeping a back-reference in each cohort to its leader (the
first instance of a :: node with the same name) and a count of the number
of cohorts that need to be made before dependent nodes are scheduled.

Classically, we'd need six centurions for cohort, but in this case one
suffices...
 1.26  10-Feb-2002  pk Targ_PrintType(): include .PHONY and .MADE attributes.
 1.25  27-Jan-2002  reinoud Fix major bug in make(1) ... due to shadowing of the dotLast path used for
the .DOTLAST primitive by a boolean variable with the same name, this whole
mechanism was broken ... it doesn't save much stat calls but it was wrong.

Thanks to Jason Thorpe for the other shadow-variable fixing patches he
made.
 1.24  12-Nov-2001  tv Add new make variable .ALLTARGETS, which lists all targets in the Makefile.
(Makes it possible to search the target list for particular things and
apply attributes to all the relevant targets.)
 1.23  20-Aug-2001  wiz precede, not preceed.
 1.22  03-Jul-2001  christos add .USEBEFORE Attribute
 1.21  14-Jan-2001  christos - make the second list of commands override the first like gmake does
- remember where the first command definition occured so that we can debug
things.
 1.20  16-Sep-1999  mycroft Some minor cleanup of :: tests.
 1.19  15-Sep-1999  mycroft Rework how :: dependencies are handled.
Build a list of `cohorts' as before, but do *not* link each one into all the
parent nodes; instead, copy the `cohort' lists into the stream of targets to
be built inside Make_ExpandUse(). Also do the attribute propagation as a
separate pass after parsing.
This eliminates several O(n^2) algorithms.
 1.18  15-Sep-1999  mycroft Don't bother iterating through all the data structures to free(3) everything
right before exiting.
(The code is still present, `#ifdef CLEANUP', in case someone needs it...)
 1.17  15-Sep-1999  mycroft Replace the linear variable list in the GNode with a hash table. Gives a
small (~10% on my machine) speedup building libc.
Changes by: perry (+ bug fix and minor change by me)
Reviewed by: mycroft sommerfeld
 1.16  11-Nov-1998  christos This patch fixes the problem introduced in the previous commit where
parents would be get remade, even if children were not really updated
by the commands executed for them. It also makes all the children have
the real modification time set if possible, so it should fix some other
timing weirdnesses...

- collapse childMade and make fields into flags and convert them to bits
CHILDMADE and REMAKE
- introduce FORCE flag that gets set in all the parents of a child that
has no sources and does not exist.
- set oodate if the FORCE flag is set, and not if CHILDMADE
- centralize the RECHECK into Make_Recheck() and use this in make.c and compat.c
- use Make_TimeStamp for all child -> parent timestamp propagations
 1.15  04-Feb-1998  christos Y2K fixes: use strftime(), and add a fake strftime() for systems that do
not have it.
 1.14  28-Sep-1997  lukem branches: 1.14.2;
wrap #include <sys/cdefs.h>, __RCSID(...) stuff in #ifndef MAKE_BOOTSTRAP
 1.13  01-Jul-1997  christos Add WARNS=1
RCSID police
 1.12  02-May-1997  christos - Target searching addition:
Make used to only use the search path for nodes that were pure
sources (not targets of other sources). This has been corrected
and now gnu-autoconf generated Makefiles work in directories other
than the source one.

- Suffix transformation rescanning:
Suffix transformations (.c.o:; cc ...) were only recognized in
the past when both suffixes were members of the suffix list.
Thus a sequence like:
.z.b:
echo ${.TARGET}
.SUFFIXES: .z
would cause .z.b: to be inserted as a regular target (and the main
target in this case). Other make programs always add rules that
start with a period in the transformation list and never consider
them as targets. We cannot do that (consider .depend files) so we
resort to scanning the list of the current targets every time a
suffix gets added, and we mutate existing targets that are now
valid transformation rules into transformation rules. If the
transformed target was also the main target, we set the main target
to be the next target in the targets list.
 1.11  20-Feb-1997  christos Reported by cgd: fix .USE directive problems:
1. ${.*} variables did not get expanded in dependencies.
2. expanded ${.*} variables in .USE dependencies can cause tree
restructuring; handle it.
3. in compat mode, expand .USE before evaluating the list of targets,
instead of doing .USE expansions on demand, because they can cause
tree restructuring.
 1.10  06-Nov-1996  christos - Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
 1.9  30-Aug-1996  thorpej Tidy up some RCS ids a bit.
 1.8  13-Aug-1996  christos Add estrdup(), a checked version of strdup and use it.
 1.7  08-Apr-1996  jtc branches: 1.7.4;
Changed to use 1900 + tm_year instead of hardcoding "19" as the century.
From PR #2308 by Stephen J. Roznowski <sjr@zombie.ncsc.mil>.
 1.6  16-Dec-1995  christos - Added .WAIT to synchronize between sources like other pmake variants.
- Updated documentation to include .ORDER .PARALLEL .NO_PARALLEL .NONPARALLEL
 1.5  14-Jun-1995  christos - $NetBSD$ rcsids
- Fixed so that .[A-Z]* targets that do not match keywords are ignored as
Posix mandates
- Added .PHONY target keyword
 1.4  06-Jun-1994  jtc Fixes from Christos Zoulas, who used purify, objectcenter and testcenter
to find memory leaks and illegal memory accesses.
 1.3  05-Mar-1994  cgd fixes/improvements from Christos Zoulas <christos@deshaw.com>.
 1.2  01-Aug-1993  mycroft Add RCS identifiers.
 1.1  21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2  28-Dec-1996  tls Import 4.4BSD-Lite2 sources onto CSRG branch (already merged at head)
 1.1.1.1  21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7.4.1  26-Jan-1997  rat Update make(1) from trunk, by request from Christos Zoulas. Fixes many bugs.
 1.14.2.1  08-May-1998  mycroft Sync with trunk, per request of christos.
 1.30.2.1  10-May-2004  tron Pull up revision 1.31 (requested by sjg in ticket #282):
Simplify build, no functional changes.
Instead of adding MAKE_BOOTSTRAP for hosted environments, i.e., when
you want things simple, instead add MAKE_NATIVE to get those hugely
important features like __RCSID().
It's now possible to build make on some hosts with: cc *.c */*.c
 1.45.2.2  05-Jun-2007  bouyer Apply patch (requested by tron in ticket #696):
usr.bin/make/compat.c patch
usr.bin/make/cond.c patch
usr.bin/make/dir.c patch
usr.bin/make/for.c patch
usr.bin/make/main.c patch
usr.bin/make/make.1 patch
usr.bin/make/make.c patch
usr.bin/make/make.h patch
usr.bin/make/nonints.h patch
usr.bin/make/parse.c patch
usr.bin/make/str.c patch
usr.bin/make/targ.c patch
usr.bin/make/util.c patch
usr.bin/make/var.c patch

Synchronize make(1) with HEAD branch to increase perfomance and
improve stability.
 1.45.2.1  20-Dec-2006  bouyer branches: 1.45.2.1.2;
Pull up following revision(s) (requested by dsl in ticket #285):
usr.bin/make/cond.c: revision 1.36
usr.bin/make/parse.c: revision 1.121-1.124
usr.bin/make/make.h: revision 1.65
usr.bin/make/targ.c: revision 1.46
usr.bin/make/main.c: revision 1.138-1.139
Simplify the code that processes .if lines.
It doesn't need a two-dimensional array to remember the states of .if lines.
It would be even simpler if we didn't try to detect .else and .elif lines
that follow .else lines.
Unfortunately this isn't the code that is stupendously slow...
Unknot this code slightly by avoiding 'break/return; else' and by putting
the short parts of some conditionals first.
First step towards speeding up the parsing of makefiles (esp. the unwanted
parts of .if clauses).
There should be no changes to the logic.
There really is no point calling estrdup() to get a copy of the makefile name
into every 'gnode' (aka target), instead just copy a pointer to the string
and avoid freeing the original name when we close the file.
I can't imagine any makefile set where this gives a larger footprint!
Add anewline to the end of the error message output when the debug log
file cannot be opened.
Put the big block of code that was common to ParseDoInclude() and
ParseTraditionalInclude() into a separate routine.
Fix the 'use after free' and 'free on item not malloced' that got added
to ParseTraditionalInclude() in Feb 2006 (rev 1.111).
Kill the 'PTR' struct and put both its members into IFile.
Remove the parameter from ParseEOF(), 1 of the 3 calls passed the wrong value!
Fortunately another test stopped anything nasty happening, we'll use that
test instead.
Revert part of a recent commit.
ParseEOF() shouldn't close the original file.
Some minor changes:
- Only test 'printVars' once.
Has side effect of not trying to find the 'main' target for '-V varname'.
- Only reap the single child process in Cmd_Exec(),
I think this is for 'xx != cmd' so probobably no other children should exist.
- Don't read and parse .depend if '-r' and '-V varname' are set.
I suspect that .depend shouldn't affect the output of any -V command...
 1.45.2.1.2.1  03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.49.4.1  09-Jan-2008  matt sync with HEAD
 1.56.6.1  30-Oct-2012  yamt sync with head
 1.57.10.1  01-Jun-2015  snj Pull up following revision(s) (requested by manu in ticket #810):
usr.bin/make/targ.c: revision 1.60
Fix warning about uninitialized variable
This warning gets fatal when including make(1) as a crunchgen(1) binary.
 1.61.4.1  21-Apr-2017  bouyer Sync with HEAD
 1.61.2.1  26-Apr-2017  pgoyette Sync with HEAD
 1.183.2.1  02-Aug-2025  perseant Sync with HEAD

RSS XML Feed