History log of /openbsd-current/usr.bin/make/var.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.106 04-Sep-2023 espie

GC old code that was originally implemented to facilitate adoption by
other BSDs, which never happened, so make things simpler for further
development.

Ditches config.h entirely since it gets reduced to 2 defines.

okay tb@


# 1.105 10-Aug-2023 espie

Add support for .VARIABLES, to which I have use.
This is an extension but also exists in gnu-make.
okay millert@, kn@, thfr@
(I've added an XXX comment on top of the patch you've seen,
no actual further code change)


Revision tags: OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.104 09-Jun-2022 espie

point developers to the other place where the remaining flags values are
defined (nice gotcha when you come back to the code after a few months).


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.103 22-Dec-2019 espie

we also have "VAR_*" constants in parsevar with totally different meanings.
Rename to avoid ambiguity
- VAR_IS_SHELL (in var.c): the SHELL variable, which has specific
POSIX semantics
- VAR_SHELL (in parsevar.c): assign the result of running the command
to the variable.

no actual code change


# 1.102 21-Dec-2019 espie

yet another mostly cosmetic diff
- rename context into localvars, which is more meaningful and less generic
- instantiate the random rumbling at the start of gnode.h with actual
variable names
- explain and group gnode.h variables better
- make some comments terser/more meaningful

okay millert@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.101 23-Oct-2016 espie

add !!=
feedback and okay millert@


# 1.100 14-Oct-2016 natano

Implement the ${<D} and ${<F} variables, as documented in the manual.
They are equivalent to ${<:H} and ${<:T} repectively, however the former
variants are more portable, as they are understood by GNU, FreeBSD and
NetBSD make too.

absence of those variables reported by Dario Niedermann <dnied at tiscali.it>
ok millert espie


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.99 27-Sep-2015 guenther

Mark all the error printing functions as printf-like; fix two format
mismatches this revealed

ok espie@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.98 12-May-2014 espie

adjust to ohash being in libutil now, and to the interface changes.
fix potential integer overflows in memory allocation (mostly for pedagogical
purposes, these are unlikely to overflow in practice)
move the rest of lst.lib stuff into its own directory.


Revision tags: OPENBSD_5_5_BASE
# 1.97 29-Jan-2014 espie

I'm a bit dyslexic. Found out by Jan Klemkow. Thanks.


# 1.96 06-Jan-2014 espie

this actually requires a comment. I would never have figured it out if
it wasn't for the arm error.


# 1.95 06-Jan-2014 espie

fix error messages, avoid dereferencing null pointers.
- the code becomes too indented, pull it into a separate function
- add an extra hint, the current_gnode.
- specifically, variables may be expanded during
target: prereq solving in Suff_FindDeps, this is after parsing,
not during command execution, and the only actual indication with have is
that we're resolving a prereq of.

(this ought to fix mk35, and partially solve mk34)


Revision tags: OPENBSD_5_4_BASE
# 1.94 23-Apr-2013 espie

remove TIMESTAMP abstraction layer, prodded by theo.
while there, clean up includes.
use strtoll for ar timestamps (pretty much unused in reality, more
standard conforming than anything)

use idea from Todd to adapt to time_t being 32 bits OR 64 bits
(pedantically correct: INT_MIN would work just fine up to 1910 or so...)

okay millert@, gone thru a make build.


Revision tags: OPENBSD_5_3_BASE
# 1.93 15-Feb-2013 espie

turns out if a line ends with a $, the var module will run off the cliff
while expanding it.
shows up very prominently with MALLOC_OPTIONS=S

Problem found by jasper@

okay'd by jasper@ and kind-of duh'd by miod@


# 1.92 09-Oct-2012 espie

new interface: look in command lines for variables that indicate a list of
targets is actually separate targets.


# 1.91 02-Oct-2012 espie

more changes, discussed and tested by various people.
- put back some job control, turns out it's necessary when we don't run a
shell.
- zap old #ifdef CLEANUP code... probably doesn't even compile.
- kill most of the OP_LIB code. Just keep a wee little bit for compatibility
(deprecated .LIBS and .INCLUDES, warns for weird dependencies instead of
erroring out).
- much improved debugging and -p output: sort variables, targets, rules,
output stuff in a nicer format mimicing input.
- better error message when no command is found, explain where the target comes from.
- sort final error list by file.
- show system files in errors as <bsd.prog.mk>
- reincorporate random delay, that was dropped
- optimize siginfo output by not regenerating the whole string each time.
- finish zapping old LocationInfo field that's no longer used.


# 1.90 25-Aug-2012 espie

- make wrong variable specs (unterminated) parse errors.
- add info to be able to pinpoint parse errors at runtime.
- let job runners abort when a parse error happens while expanding a variable
during execution
- fix an infinite loop when compiling without FEATURE_RECVARS.

okay millert@, krw@
the very few errors found out by this (less than 10 over src/X/ports)
fixed trivially beforehand, as requested by deraadt@


Revision tags: OPENBSD_5_2_BASE
# 1.89 22-Mar-2012 espie

minor cleanup: error messages include lineno and fileno together, so
recognize that and create a struct Location_ for it.

mostly from Jonathan Calmels, a few nits from me.

okay otto@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.88 20-Jun-2011 espie

fix a segfault found by jasper@
ok miod@, otto@, jasper@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.87 19-Jul-2010 espie

Correct $OpenBSD$ stuff


# 1.86 25-Apr-2010 espie

pure whitespace cleanup


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.85 13-May-2009 espie

fix loopvar debug prints. Issue reported by naddy@


Revision tags: OPENBSD_4_5_BASE
# 1.84 09-Nov-2008 tobias

typo fixed (overriden -> overridden)

ok espie, jmc


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.83 17-Nov-2007 espie

simplify dynamic variable handling a great deal:
first remove all usage of Varq_Append by building the string directly.
then replace `common' handling with specialized handling for dynamic
strings (since they no longer need a buffer). Finally, identify the place
where the variable value needs to be copied because it's going to be free'd
or erased soon, and finally, use simple char* pointers.

Shaves about 80 bytes off every gnode structure, and kills quite a few
unnecessary malloc()s as well.


# 1.82 04-Nov-2007 espie

prevent gcc from complaining


# 1.81 03-Nov-2007 deraadt

fix some lint FALLTHROUGH


# 1.80 17-Sep-2007 espie

more blank space removal


# 1.79 17-Sep-2007 espie

more zap spaces


# 1.78 17-Sep-2007 espie

zap more spaces at end of line


# 1.77 17-Sep-2007 espie

kill extra spaces at end of line


# 1.76 16-Sep-2007 espie

remove warnings


# 1.75 16-Sep-2007 espie

remove dead code: #define RECHECK is always on


Revision tags: OPENBSD_4_2_BASE
# 1.74 30-Jul-2007 espie

introduce a Var_Substi to substitute on intervals.
Since we don't really know how to change Var_Subst and dependent functions,
we cheat, and copy the string to a buffer instead.

Clean-up the parser a bit: reorganize the include files lookup function:
introduce a resolve_include_filename function that figures out the full name
of the file, introduce a handle_include_file that does all the include file
handling, and rename the functions into handle_xxx_include, so that we
can remove most comments.

Rename ParseIsCond into handle_bsd_command, cut most of its code into
constituent functions.

Semantic changes:
- follow the rules that, if an optional construct does not parse correctly,
then it's not a real extension, and give the normal parser a chance to figure
it out. If the syntax checks out, semantic errors ARE real errors.
- allow variables to not be defined in include file names, no reason not to.

okay miod@


# 1.73 30-Jul-2007 espie

everywhere except in Var_Parse, we always add/append variables to the
VAR_GLOBAL context, so make it the common case: rename the basic functions
to Var_Set_with_ctxt/Var_Append_with_ctxt, define Var_Set and Var_Append
as macros that specify VAR_GLOBAL, and use these.

okay miod@


# 1.72 30-Jul-2007 espie

now that it's clean enough, one can extract some common code from
Var_Parse and Var_ParseSkip (the code that figures out the variable name
up to eventual modifiers).

okay miod@


# 1.71 24-Jul-2007 espie

zap unused variable


# 1.70 24-Jul-2007 espie

simplify computations in the var module: instead of advancing a char *
and keeping track of a length, we just advance the char *, and ditch
the length. We can still get the length at the end of the top-level
functions to satisfy existing interfaces.

Much simpler code, less error-prone.

Okay millert@


# 1.69 24-Jul-2007 espie

move the code that grabs a value in Var_Parse in its own function,
get_expanded_value.

Extend the code a bit to be much more thorough in case of a recursive
expansion: shows exactly the cycle of variable names involved.

okay millert@


# 1.68 24-Jul-2007 espie

change Var_ParseSkip API to increment the position instead of returning a
length, simplifies code.

(warns a bit, symptom of some further issues to fix).

okay millert@


# 1.67 22-Jul-2007 espie

make sure loop variables use their own buffers.
(causes .for loops to give weird results very infrequently, memory handling
was slightly wrong, but not enough to break things thoroughly).
noticed by naddy@


# 1.66 20-Jul-2007 espie

big clean-up patch:
- rename a few functions in var.c to names that make more sense.
- introduce Var_Deletei because it makes more sense.
- rewrite .for loops to use a local LoopVar construct to avoid looking up more
stuff.
- reformat var.c to near K&R
- rewrite most comments in var.c

shown to a few people. millert@ gave me his okay since it passes through
ports correctly.


# 1.65 20-Jul-2007 espie

reorder stuff in var.c so that the next patch is more readable.


# 1.64 08-Jul-2007 espie

rename variable to errorIsOkay. What does oldVars mean anyway ?


# 1.63 08-Jul-2007 espie

missed part: add check to avoid poison checking inexistent local vars,
and do for loops for real.


# 1.62 08-Jul-2007 espie

A set of big related changes. okay millert@, tested further by kettenis@
and matthieu@

This all revolves around putting ALL global variables into one single big
hash, and using flags. This removes some impossible to understand stuff,
like old varfind, and allows for some nice stuff.
- each time we reference a global variable, we create it, possibly as a dummy
variable.
- each time we go to the environment, we remember it, thus we no longer go
back to it.

Lists of dependant changes:
- isolate changes to oldVars and checkEnvFirst.
- remove VAR_CMD and VAR_GLOBAL contexts. The only distinction is in parsevar.
Split Parse_DoVar into Parse_DoVar and Parse_CmdlineVar
- rework var modules around obtain_global_var, observe flags in various
functions like Var_Value and Var_Seti.
- Var_Seti/Var_Appendi are almost the same code, use that internally.
- add magic to handle the very special SHELL variable.
- introduce Var_Definedi for the cases where we don't want the actual
value, to simplify tests.
- add keyword .poison, parse it and set global flags accordingly.
- do poison_checks where needed.
- document poison.
- in for loops, set variable temporarily, so that Var_SubstVar will also
substitute it in varmodifiers expressions.


Revision tags: OPENBSD_4_1_BASE
# 1.61 02-Jan-2007 espie

VarDelete is no longer used by list functions, so let it do type-checking
correctly.


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.60 20-Jan-2006 espie

use stdint.h where appropriate. okay millert@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.59 07-Apr-2004 espie

ISO function declarations, trim a few comments, rename a few variables to
more explicit/more consistent names.

okay otto@


Revision tags: OPENBSD_3_5_BASE
# 1.58 07-Oct-2003 fgsch

- check if result is valid before using it.
- correctly set *freePtr, not freePtr.
input and ok espie@.


Revision tags: OPENBSD_3_4_BASE
# 1.57 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.56 05-Jun-2002 espie

tweak quick_lookup for a faster path.
okay millert@


Revision tags: OPENBSD_3_0_BASE OPENBSD_3_1_BASE
# 1.55 23-May-2001 espie

Mostly clean-up:
- cut up those huge include files into separate interfaces for all modules.
Put the interface documentation there, and not with the implementation.
- light-weight includes for needed concrete types (lst_t.h, timestamp_t.h).
- cut out some more logically separate parts: cmd_exec, varname, parsevar,
timestamp.
- put all error handling functions together, so that we will be able to
clean them up.
- more systematic naming: functioni to handle interval, function to handle
string.
- put the init/end code apart to minimize coupling.
- kill weird types like ReturnStatus and Boolean. Use standard bool (with a
fallback for non-iso systems)
- better interface documentation for lots of subsystems.

As a result, make compilation goes somewhat faster (5%, even considering
the largish BSD copyrights to read). The corresponding preprocessed
source goes down from 1,5M to 1M.

A few minor code changes as well: Parse_DoVar is no longer destructive.
Parse_IsVar functionality is folded into Parse_DoVar (as it knows what an
assignment is), a few more interval handling functions. Avoid calling
XXX_End when they do nothing, just #define XXX_End to nothing.

Parse_DoVar is slightly more general: it will handle compound assignments
as long as they make sense, e.g., VAR +!= cmd
will work. As a side effect, VAR++=value now triggers an error
(two + in assignment).
- this stuff doesn't occur in portable Makefiles.
- writing VAR++ = value or VAR+ +=value disambiguates it.
- this is a good thing, it uncovered a bug in bsd.port.mk.

Tested by naddy@. Okayed millert@. I'll handle the fallback if there is
any. This went through a full make build anyways, including isakmpd
(without mickey's custom binutils, as he didn't see fit to share it with me).


# 1.54 15-May-2001 espie

Don't go beyond end of string.
Handles unterminated variables, and fixes regression test #10


# 1.53 03-May-2001 espie

Synch with my current work.
Numerous changes:
- generate can build several tables
- style cleanup
- statistics code
- use variable names throughout (struct Name)
- recursive variables everywhere
- faster parser (pass buffer along instead of allocating multiple copies)
- correct parser. Handles comments everywhere, and ; correctly
- more string intervals
- simplified dir.c, less recursion.
- extended for loops
- sinclude()
- finished removing extra junk from Lst_*
- handles ${@D} and friends in a simpler way
- cleaned up and modular VarModifiers handling.
- recognizes some gnu Makefile usages and errors out about them.

Additionally, some extra functionality is defined by FEATURES. The set of
functionalities is currently hardcoded to OpenBSD defaults, but this may
include support for some NetBSD extensions, like ODE modifiers.

Backed by miod@ and millert@, who finally got sick of my endless patches...


Revision tags: OPENBSD_2_9_BASE
# 1.52 02-Mar-2001 espie

Use the ohash_* that's now in libc.


# 1.51 07-Dec-2000 espie

Forgot to copy end of name in nested variable names, so that
${BC_${A}} worked but not ${${A}_BC}.
Noticed by fries@


# 1.50 24-Nov-2000 espie

Take advantage of VarModifiers_Apply, which can parse a variable spec
and expand it directly, without needing a variable context.

Use it in Var_SubstVar, so that .for loops values don't need to be entered
into any context nor looked up.

This speeds up .for loops some, and avoids nasty variable capture
side-effects.

Ok'd millert@, miod@, naddy@ (naddy spotted a problem with the first
version of that change).


Revision tags: OPENBSD_2_8_BASE
# 1.49 13-Oct-2000 espie

esetenv: does a setenv and bails out if error.


# 1.48 14-Sep-2000 espie

Some systematic clean-up.
- UNUSED macro that expands to __attribute__((unused)) for gcc
- move rcsid around so that they can be tagged UNUSED.
- activate -Wunused.
- use UNUSED instead of kludgy junk for function arguments.
- add extern to all extern prototypes.
- update comments in lst.h.
- clean up var.c a little bit, constifying arguments, updating comments...


# 1.47 21-Aug-2000 espie

Var_Append needs to set v for DEBUG(VAR) to work.
Obvious fix.
Problem reported by Gregory Steuck, thanks a lot !


# 1.46 18-Jul-2000 espie

Handle MAKEFLAGS variation mandated by POSIX.

Code to pass variable definitions to submakes through make flags.
Not activated yet, need to fix src/ first.


# 1.45 17-Jul-2000 espie

parse embedded variable specs, e.g., ${VAR_${SUB}}

- need braces, as we don't want to change what $$A means,
- this assumes this kind of construct is very infrequent, thus
this does NOT copy the variable name needlessly.
- the expansion code is in a separate function for clarity.

Reviewed by miod@, as previous patches.


# 1.44 17-Jul-2000 espie

- let VarModifiers_Apply accept NULL string gracefully,
- simplify Var_Parse: use varfind, then leverage on the result
to recognize `special case' dynamic parsing.

VarModifiers_Apply need to be called on NULL strings, to be able to parse
modifiers applied to non-existent variables.

(Alternately, we could call VarModifiers_Apply on a dummy string, but
this is less efficient).


# 1.43 17-Jul-2000 espie

Major unobfuscation: split var modifiers handling to a separate file.
This does finally make var handling somewhat readable.


# 1.42 17-Jul-2000 espie

separate modifiers handling from Var_Parse into a separate
VarModifiers_apply function.

for env lookup, create variable structure first, so that we can get away
without terminating the variable name in main Var_Parse.


# 1.41 17-Jul-2000 espie

This does replace Str_Match with a better routine, which handles negated
intervals, and \\ in intervals.

Accordingly, var.c no longer needs to copy the :Marg to replace \: with :

We don't use fnmatch(3) because of various optimizations which are harder
to achieve in a generic setting.

Also add regression suite for the Str_Match function.


# 1.40 17-Jul-2000 espie

Constify a few functions, propagated from VarModify.
Replace a few int -> size_t

Reviewed by miod@


# 1.39 17-Jul-2000 espie

- recognize that FIND_CMD and FIND_GLOBAL are always used together,
- introduce VarFind_interval function. This avoids having to copy variable
names in VarParse,
- expose internals of VarFind* function (not used yet, but this will avoid
multiple lookups in VarParse),
- constify a few functions.

Reviewed by miod@


# 1.38 23-Jun-2000 espie

This is the speed-up patch, which doubles make speed (almost).

Use the open hashing functions for global contexts instead of List in
var.c.

All the preliminary work to trim down local contexts means that we don't
suffer from the heavy initialization work that a hash table entails.

There is some make kludgery to:
- build the hashing functions as a library,
- recreate hashconsts.h, even if make depend was not invoked.

One point of the hashing scheme written was to separate the computation
of the hash function, and the hash lookup itself. This is very convenient
for make, because of those pesky special variables. hashconsts.h is there
to pre-hash the correct values, which replaces a few expensive string
comparisons with quick hash value comparisons, followed by one expensive
string comparison. The modulus MAGICSLOTS chosen in the Makefile is
ad-hoc: it is small enough to write a small switch without collision,
and will need changing if the hash function changes...

The function quick_lookup is the most important:
it either returns an index, for a local variable, or it does compute a
hashing value, and returns -1.

Another somewhat controversial decision is the use of string intervals.
This avoids either copying a string, or twiddling with a byte for cases
such as ${VAR}.

Finally, the variable name is stored within the variable itself. Since
a given variable name never changes, this makes sense. All that was needed
was a hash library with support for this. Note that the hashing table
holds only a variable pointer AND the corresponding hashing value, WITHOUT
a modulo hashtablesize. Two reasons:
- hash resizes can be done faster, without having to recompute hashing values.
- locality of access. The hash table fits into memory without problem. Once
a candidate slot is found, we check the complete hashing value. Probability
of a collision is very small (32 bits...). So bringing up the whole
variable in memory at once is good: the name will almost always match, in
which case we want the variable value as well, so it makes sense to put
them together.

The ohash functions implement open hashing, as described in Knuth, but with
a variable table size. Choosing powers of 2 sizes does not yield more
collisions, but it makes the hashing scheme much simpler. The thresholds at
which to expand/shrink the tables seem to work well in practice. The
default sizes were chosen such that the tables hardly ever shrink or expand
anyways (though I've tried with smaller/larger sizes to verify that the
shrinking/expanding worked correctly): larger Makefiles hold roughly
500/600 variables, which fits without trouble into a 1024-sized variable.

Disregard #ifdef STATS_HASH, this is some internal scaffolding I'm using
to measure make performance.

The only known issue with open-hashing is that deletions cannot create
empty slots, but do leave slots marked as `occupied once' so that lookup
works. We use a well-known optimization which records those pseudo-empty
slots while looking up values. If the value is not found, the pseudo-empty
slot is returned to be filled. If the value is found, it is swapped with
the pseudo-empty slot. This is an improvement in both cases, since this
shortens the length of lookup chains, eventually pushing the pseudo-empty
slots to the end.

Reviewed by millert@ and miod@


# 1.37 23-Jun-2000 espie

This patch separates local contexts from global contexts for good.
Apart from a few casts, VAR_GLOBAL and friends are separate
data structures, so we use a small array for local variables.

We also junk allVars, since TargFreeGN can release local nodes,
and var.c has explicit lists for its variables already.

Reviewed millert@ and miod@.


# 1.36 23-Jun-2000 espie

In various places, VAR_CMD is used to actually mean `no real context',
since lookup will start with VAR_CMD in any case.
This fixes VarFind and Var_Parse to handle ctxt == NULL correctly, and
replace those confusing VAR_CMD with proper NULL pointers.

This patch also handles three small details:
- .CURDIR is necessarily set in VAR_GLOBAL,
- suffix handling for archives copies two hard-coded variables, for
which it can use a quick path,
- typos in TargFreeGN.

Reviewed millert@, miod@.


# 1.35 23-Jun-2000 espie

Once those special variable are taken care of, other Var functions can take
the GNode's context directly. We rename that special Lst to `SymTable *'
in prevision of things to come.

Along the line, we lose the special GNodes affected to VAR_CMD, VAR_GLOBAL,
VAR_ENV, which become simple Lsts... This is not a problem, except when
getting to a context's name for debugging (handled very nicely by
offsetof).

Again, this is a preparatory patch, which does not gain anything except
for cleaning up issues...

Reviewed by millert@ and miod@, like the previous patch


# 1.34 23-Jun-2000 espie

Start of variable fixes and speed-ups.

This patch may seem a bit non-sensical at first. It simply introduces some
new interface. Specifically, recognizes that some variable names
(.TARGET/$@, .OODATE/$?, .ALLSRC/$>, .IMPSRC/$<, .PREFIX/$*, .ARCHIVE/$!,
.MEMBER/$%) are `special' (the actual variables which are local to a
target, e.g. GNode).

Currently, The Varq functions (for Varquick access) are only stubs to the
normal functions.

This fixes a very important detail before proceeding to turn variable lists
into hash tables: if every GNode holds a hash table, initialization times
for those will be very costly. But generic GNodes only hold those seven
special variables... which can be stored directly into a small array;
the only general cases are the environment, the command line and
global variables.


# 1.33 17-Jun-2000 espie

This patch introduces a distinction between
Lst_Init (constructor) and Lst_New (allocation + construction)
Lst_Destroy (destructor) and Lst_Delete (deallocation + destruction),
and uses that to turn most dynamic allocation of lists (Lst pointers)
into static structures (LIST).

Most of this is mundane, except for allGNs in targ.c, where the code must
be checked to verify that Targ_Init is called soon enough.

Lst_New is a temporary addition. All lists will soon be static.

Reviewed by millert@, like the previous patch.


# 1.32 10-Jun-2000 espie

Clean-up patch: use `void *' instead of old-fashioned ClientData/Address.


# 1.31 10-Jun-2000 espie

Thus, Lst_ForEach no longer needs returning a status.
In fact, it can become a macro based on Lst_ForEachFrom.
This also introduces Lst_Every, as a shortcut for the very common case where
Lst_ForEach does not need any user data.

Finally, make consistent use of a few function typedefs, instead of having
explicit void (*)(Lst) arguments all over the place.


Revision tags: OPENBSD_2_7_BASE
# 1.30 26-Mar-2000 espie

Remove idiotic, braindead casts T* -> void*
They serve no purpose, except hiding potential bugs.

In particular, remove (ClientData) cast from macro, showing potentially
troublesome use of Hashes to store time_t.


# 1.29 08-Jan-2000 espie

Finish changing all Var_Parse arguments to size_t. Thanks to millert@
for reminding me.


# 1.28 19-Dec-1999 espie

Rearrange Lst_Find interface to conform better with other functions.


# 1.27 18-Dec-1999 espie

Nothing ever checks ReturnStatus on Lst_Insert, Lst_Append, Lst_AtFront,
Lst_AtEnd, Lst_Concat, Lst_Remove, Lst_Replace.

Don't bother returning one.


# 1.26 18-Dec-1999 espie

NIL, NILGNODE, etc, are only glorified NULL.
Get rid of them.

Get rid of list.h, nothing uses it anyway.


# 1.25 18-Dec-1999 espie

make does not use circular lists, get rid of the extra weight.


# 1.24 16-Dec-1999 espie

Var_Subst is actually two distinct functions folded into one:
split the function specific to for.c out, and give them more sensible
arguments at the same time.

This makes .for loop handling more efficient, as we have some heuristic
to evaluate the size of the buffer needed...


# 1.23 16-Dec-1999 espie

Allocate buffers as static data structures.
This cuts down quite a lot of malloc, since in actual use,
buffer usage is mostly static.


# 1.22 16-Dec-1999 espie

Remove unneeded extraneous zeros at the end of buffers.

Actually, one of these needs to be there, because of two bugs in cond.c


# 1.21 16-Dec-1999 espie

Split Buf_GetAll into Buf_Retrieve/Buf_Size.
(idiotic to retrieve size every time when it's used half the time)


# 1.20 16-Dec-1999 espie

Start cleaning up buf.c in earnest.

- Buf_Discard is only used to remove all the bytes in a buffer,
replace with Buf_Reset,
- buffer values are not read unless accessed first through Buf_GetAll,
no need to null-terminate it at every point.
- Buf_Expand need not check if the expansion is needed. That's Buf_AddChar
and Buf_AddChars responsability (otherwise, Buf_AddChar checks twice)
- Buf_Overflow only handles overflow. Adding the character is done in
every case anyway.


# 1.19 09-Dec-1999 espie

Introduce `common usage' buf patterns and use them.


# 1.18 06-Dec-1999 espie

Extra parameter no longer needed, ditch.


# 1.17 06-Dec-1999 espie

Instead of retrieving var values from the environment again and again,
it is much better to keep them in the global context, marked read-only.

This also makes the next simplification possible, since var values need no
longer be free'd by client code.

(reviewed by ho@, like other patches)


# 1.16 06-Dec-1999 espie

Clean up buffers interface somewhat:

- buf.c deals exclusively with chars. Be explicit about it, and remove
extraneous dumb casts to char (can hide real type errors).
- buffer sizes are size_t. Note that bp->left can never become NULL.
- Buf_GetAll is happy with a NULL pointer for the size, remove unneeded
extra pointers.
- Propagate size_t to all places where buffer functions are used.


# 1.15 11-Nov-1999 espie

Kill Str_FindSubString, it's strstr.


# 1.14 10-Nov-1999 espie

Turn on strict-prototypes, add missing prototypes.
Move main prototype to main.c, as this is not used
from any other file.

Close open bug.


# 1.13 06-Nov-1999 espie

Bug-fix: when expanding a specific variable v in $A,
check that v is PRECISELY A.

Other BSDs, take notice.


Revision tags: OPENBSD_2_6_BASE
# 1.12 28-Sep-1999 espie

Fix
.if defined(VAR) && ${VAR:m}

cond.c has special code (set err to 0) to tell VarParse it shouldn't care
if the variable is not defined.

But this was not completely added, namely the path that deals with
modifiers was blissfully unaware of that.


# 1.11 25-Sep-1999 espie

Add :L/:U modificators (lowercase/uppercase)
To use to get ports building more user-friendly.


Revision tags: OPENBSD_2_5_BASE
# 1.10 05-Dec-1998 espie

Modifications from netbsd:
- don't interfere with MACHINE/MACHINE_ARCH defines for bootstrap
- type clean-up, time_t, and printing `unknown' ints
- fix TARGET/MEMBER bug in archive rules
- memmove...
- cleaner Error handler.
- reentrant brk_string
- .MAKE env variable
- preliminary scaffolding for .NOPATH

Other improvements:
- efree
- shellneed streamlined
- display Stop in .CURDIR after an error.
- document most features and misfeatures.
- add a few OpenBSD notes to the tutorial.


Revision tags: OPENBSD_2_4_BASE
# 1.9 23-Jul-1998 deraadt

portable bootstrap thing; lidl@eng.us.uu.net


Revision tags: OPENBSD_2_3_BASE
# 1.8 30-Mar-1998 deraadt

Y2K fixes from Andreas.Gunnarsson@emw.ericsson.se; culled from various places


# 1.7 18-Dec-1997 deraadt

for the test following test case, do not output FOOBAR=bar (should be FOOBAR=)
problem reported by mark@thuvia.demon.co.uk

FOO=
FOOBAR=$(FOO:=bar)


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.6 01-Apr-1997 millert

Sync with NetBSD (mostly by christos initial substitution/regexp from Der Mouse)

- fix the variable substitution code in make [PR/2748]
1. change s/a/b/ so that it substitutes the first occurance of the
pattern on each word, not only the first word.
2. add flag '1' to the variable substitution so that the substitutions
get performed only once.

***THIS IS AN INCOMPATIBLE CHANGE!***

Unfortunately there was no way to make things consistent without
modifying the current behavior. Fortunately none of our Makefiles
depended on this.

OLD:

VAR = aa1 aa2 aa3 aa4

S/a/b/ = ba1 aa2 aa3 aa4
S/a/b/g = bb1 bb2 bb3 bb4

NEW:
VAR = aa1 aa2 aa3 aa4

S/a/b/ = ba1 ba2 ba3 ba4
S/a/b/1 = ba1 aa2 aa3 aa4
S/a/b/g = bb1 bb2 bb3 bb4
S/a/b/1g = bb1 aa2 aa3 aa4
- add regexp variable substitution via 'C/foo/bar/' [PR/2752]
- add variable quoting via the ${VAR:Q} modifier. This is useful when running
recursive invocations of make(1):

make VAR=${VAR:Q}

will always work... (This may prove useful in the kernel builds...) [PR/2981]
- BSD did not traditionally have <sys/cdefs.h>; use BSD4_4 instead and include
<sys/param.h> to grab it.
- Don't compile the regex code if MAKE_BOOTSTRAP (from gwr)
- Use explicit .c.o rule in Makefile.boot so that the bootstrap process works.
- Use only integral types in procedure arguments. [buf.c buf.h]
- Include <stdlib.h> to get getenv() prototype on SVR4
- if __STDC__ -> ifdef __STDC__ to appease SVR4
- Define const and volatile for non __STDC__
- Implement snprintf() and vsnprintf() for non BSD4_4 systems.
- Make $MACHINE_ARCH settable from the environment.
- Fix .USE directive problems: (reported by cgd)
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.
- Add a .MADE directive to indicated that the children of a target are
up-to-date, even when they are not. This is to simulate our current
make install behavior with proper dependencies.
- Fix problems in the RE substitution error handling.
- Locate all the children of a node marked as MADE.
- Do not compile-in ${MACHINE} (as per NetBSD PR#3386)
- Disable globbing for targets/dependencies when POSIX is defined.
- Fix globbing so that patterns that don't have a matching number of [] or {}
don't get expanded. (before the [ case got expanded to nothing!) This is
disabled.
- Make sure that the children of nodes that are marked .MADE, are marked
UPTODATE and their timestamps are consistent.
- Don't disable wildcards completely; they are used by other Makefiles.


# 1.5 30-Nov-1996 millert

Sync with NetBSD:
- 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.
- Fix NetBSD PR #2930: declare missing variable.


Revision tags: OPENBSD_2_0_BASE
# 1.4 02-Sep-1996 briggs

Sync up with NetBSD:
(christos)
Fix bug reported by Greg Hudson where leaf (source only) nodes were
referenced only by their basename and not by their full pathname. This
breaks when .PATH or MAKEOBJDIR are used. There might be Makefiles
around that try to work around this bug by prepending ${.CURDIR} to
the sources, and they should be found and fixed. Also a lot of the gunk
in suff.c that was attempting to work around the same problem could be
removed.
(christos)
- Move -D flags from Makefile to config.h and explain what they do. Add
-Wall -Wno-unused to CFLAGS. Add new define SYSVVARSUB to enable SysV
style variable substitutions and enable them.
- Add SunOS style command substitutions via SUNSHCMD
- Fix core dump with '{variable = value'
(christos)
Fix bug where make will always exit with 0, even when one or more
parallel jobs failed. (Only affects parallel make code)
(christos)
Protect __P from being multiply defined (for systems that already
define it)
(christos) Add strdup() since ultrix is missing it.
From Larry Schwimmer <rosebud@cyclone.Stanford.EDU>
(christos) Add estrdup(), a checked version of strdup and use it.
(christos) Recognize SVR4 style long filename entries in archives.
(thorpej) Tidy up some RCS ids a bit.


# 1.3 26-Jun-1996 deraadt

rcsid


# 1.2 14-Dec-1995 deraadt

from christos@netbsd:
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.
- Turn compat mode on by default. It gets turned off when the -j without
the -B flag is specified. [Thus you can use -j 1 to turn it off].
- Fix malloc -> emalloc as Gordon noted.
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.

from cgd@netbsd:
pull in make.h. (PAlloc() now uses emalloc(), which is prototyped in
make.h. If the prototype is not in scope on the Alpha, I see lots
of "cast to pointer from integer of different size" warnings.)


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.105 10-Aug-2023 espie

Add support for .VARIABLES, to which I have use.
This is an extension but also exists in gnu-make.
okay millert@, kn@, thfr@
(I've added an XXX comment on top of the patch you've seen,
no actual further code change)


Revision tags: OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.104 09-Jun-2022 espie

point developers to the other place where the remaining flags values are
defined (nice gotcha when you come back to the code after a few months).


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.103 22-Dec-2019 espie

we also have "VAR_*" constants in parsevar with totally different meanings.
Rename to avoid ambiguity
- VAR_IS_SHELL (in var.c): the SHELL variable, which has specific
POSIX semantics
- VAR_SHELL (in parsevar.c): assign the result of running the command
to the variable.

no actual code change


# 1.102 21-Dec-2019 espie

yet another mostly cosmetic diff
- rename context into localvars, which is more meaningful and less generic
- instantiate the random rumbling at the start of gnode.h with actual
variable names
- explain and group gnode.h variables better
- make some comments terser/more meaningful

okay millert@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.101 23-Oct-2016 espie

add !!=
feedback and okay millert@


# 1.100 14-Oct-2016 natano

Implement the ${<D} and ${<F} variables, as documented in the manual.
They are equivalent to ${<:H} and ${<:T} repectively, however the former
variants are more portable, as they are understood by GNU, FreeBSD and
NetBSD make too.

absence of those variables reported by Dario Niedermann <dnied at tiscali.it>
ok millert espie


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.99 27-Sep-2015 guenther

Mark all the error printing functions as printf-like; fix two format
mismatches this revealed

ok espie@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.98 12-May-2014 espie

adjust to ohash being in libutil now, and to the interface changes.
fix potential integer overflows in memory allocation (mostly for pedagogical
purposes, these are unlikely to overflow in practice)
move the rest of lst.lib stuff into its own directory.


Revision tags: OPENBSD_5_5_BASE
# 1.97 29-Jan-2014 espie

I'm a bit dyslexic. Found out by Jan Klemkow. Thanks.


# 1.96 06-Jan-2014 espie

this actually requires a comment. I would never have figured it out if
it wasn't for the arm error.


# 1.95 06-Jan-2014 espie

fix error messages, avoid dereferencing null pointers.
- the code becomes too indented, pull it into a separate function
- add an extra hint, the current_gnode.
- specifically, variables may be expanded during
target: prereq solving in Suff_FindDeps, this is after parsing,
not during command execution, and the only actual indication with have is
that we're resolving a prereq of.

(this ought to fix mk35, and partially solve mk34)


Revision tags: OPENBSD_5_4_BASE
# 1.94 23-Apr-2013 espie

remove TIMESTAMP abstraction layer, prodded by theo.
while there, clean up includes.
use strtoll for ar timestamps (pretty much unused in reality, more
standard conforming than anything)

use idea from Todd to adapt to time_t being 32 bits OR 64 bits
(pedantically correct: INT_MIN would work just fine up to 1910 or so...)

okay millert@, gone thru a make build.


Revision tags: OPENBSD_5_3_BASE
# 1.93 15-Feb-2013 espie

turns out if a line ends with a $, the var module will run off the cliff
while expanding it.
shows up very prominently with MALLOC_OPTIONS=S

Problem found by jasper@

okay'd by jasper@ and kind-of duh'd by miod@


# 1.92 09-Oct-2012 espie

new interface: look in command lines for variables that indicate a list of
targets is actually separate targets.


# 1.91 02-Oct-2012 espie

more changes, discussed and tested by various people.
- put back some job control, turns out it's necessary when we don't run a
shell.
- zap old #ifdef CLEANUP code... probably doesn't even compile.
- kill most of the OP_LIB code. Just keep a wee little bit for compatibility
(deprecated .LIBS and .INCLUDES, warns for weird dependencies instead of
erroring out).
- much improved debugging and -p output: sort variables, targets, rules,
output stuff in a nicer format mimicing input.
- better error message when no command is found, explain where the target comes from.
- sort final error list by file.
- show system files in errors as <bsd.prog.mk>
- reincorporate random delay, that was dropped
- optimize siginfo output by not regenerating the whole string each time.
- finish zapping old LocationInfo field that's no longer used.


# 1.90 25-Aug-2012 espie

- make wrong variable specs (unterminated) parse errors.
- add info to be able to pinpoint parse errors at runtime.
- let job runners abort when a parse error happens while expanding a variable
during execution
- fix an infinite loop when compiling without FEATURE_RECVARS.

okay millert@, krw@
the very few errors found out by this (less than 10 over src/X/ports)
fixed trivially beforehand, as requested by deraadt@


Revision tags: OPENBSD_5_2_BASE
# 1.89 22-Mar-2012 espie

minor cleanup: error messages include lineno and fileno together, so
recognize that and create a struct Location_ for it.

mostly from Jonathan Calmels, a few nits from me.

okay otto@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.88 20-Jun-2011 espie

fix a segfault found by jasper@
ok miod@, otto@, jasper@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.87 19-Jul-2010 espie

Correct $OpenBSD$ stuff


# 1.86 25-Apr-2010 espie

pure whitespace cleanup


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.85 13-May-2009 espie

fix loopvar debug prints. Issue reported by naddy@


Revision tags: OPENBSD_4_5_BASE
# 1.84 09-Nov-2008 tobias

typo fixed (overriden -> overridden)

ok espie, jmc


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.83 17-Nov-2007 espie

simplify dynamic variable handling a great deal:
first remove all usage of Varq_Append by building the string directly.
then replace `common' handling with specialized handling for dynamic
strings (since they no longer need a buffer). Finally, identify the place
where the variable value needs to be copied because it's going to be free'd
or erased soon, and finally, use simple char* pointers.

Shaves about 80 bytes off every gnode structure, and kills quite a few
unnecessary malloc()s as well.


# 1.82 04-Nov-2007 espie

prevent gcc from complaining


# 1.81 03-Nov-2007 deraadt

fix some lint FALLTHROUGH


# 1.80 17-Sep-2007 espie

more blank space removal


# 1.79 17-Sep-2007 espie

more zap spaces


# 1.78 17-Sep-2007 espie

zap more spaces at end of line


# 1.77 17-Sep-2007 espie

kill extra spaces at end of line


# 1.76 16-Sep-2007 espie

remove warnings


# 1.75 16-Sep-2007 espie

remove dead code: #define RECHECK is always on


Revision tags: OPENBSD_4_2_BASE
# 1.74 30-Jul-2007 espie

introduce a Var_Substi to substitute on intervals.
Since we don't really know how to change Var_Subst and dependent functions,
we cheat, and copy the string to a buffer instead.

Clean-up the parser a bit: reorganize the include files lookup function:
introduce a resolve_include_filename function that figures out the full name
of the file, introduce a handle_include_file that does all the include file
handling, and rename the functions into handle_xxx_include, so that we
can remove most comments.

Rename ParseIsCond into handle_bsd_command, cut most of its code into
constituent functions.

Semantic changes:
- follow the rules that, if an optional construct does not parse correctly,
then it's not a real extension, and give the normal parser a chance to figure
it out. If the syntax checks out, semantic errors ARE real errors.
- allow variables to not be defined in include file names, no reason not to.

okay miod@


# 1.73 30-Jul-2007 espie

everywhere except in Var_Parse, we always add/append variables to the
VAR_GLOBAL context, so make it the common case: rename the basic functions
to Var_Set_with_ctxt/Var_Append_with_ctxt, define Var_Set and Var_Append
as macros that specify VAR_GLOBAL, and use these.

okay miod@


# 1.72 30-Jul-2007 espie

now that it's clean enough, one can extract some common code from
Var_Parse and Var_ParseSkip (the code that figures out the variable name
up to eventual modifiers).

okay miod@


# 1.71 24-Jul-2007 espie

zap unused variable


# 1.70 24-Jul-2007 espie

simplify computations in the var module: instead of advancing a char *
and keeping track of a length, we just advance the char *, and ditch
the length. We can still get the length at the end of the top-level
functions to satisfy existing interfaces.

Much simpler code, less error-prone.

Okay millert@


# 1.69 24-Jul-2007 espie

move the code that grabs a value in Var_Parse in its own function,
get_expanded_value.

Extend the code a bit to be much more thorough in case of a recursive
expansion: shows exactly the cycle of variable names involved.

okay millert@


# 1.68 24-Jul-2007 espie

change Var_ParseSkip API to increment the position instead of returning a
length, simplifies code.

(warns a bit, symptom of some further issues to fix).

okay millert@


# 1.67 22-Jul-2007 espie

make sure loop variables use their own buffers.
(causes .for loops to give weird results very infrequently, memory handling
was slightly wrong, but not enough to break things thoroughly).
noticed by naddy@


# 1.66 20-Jul-2007 espie

big clean-up patch:
- rename a few functions in var.c to names that make more sense.
- introduce Var_Deletei because it makes more sense.
- rewrite .for loops to use a local LoopVar construct to avoid looking up more
stuff.
- reformat var.c to near K&R
- rewrite most comments in var.c

shown to a few people. millert@ gave me his okay since it passes through
ports correctly.


# 1.65 20-Jul-2007 espie

reorder stuff in var.c so that the next patch is more readable.


# 1.64 08-Jul-2007 espie

rename variable to errorIsOkay. What does oldVars mean anyway ?


# 1.63 08-Jul-2007 espie

missed part: add check to avoid poison checking inexistent local vars,
and do for loops for real.


# 1.62 08-Jul-2007 espie

A set of big related changes. okay millert@, tested further by kettenis@
and matthieu@

This all revolves around putting ALL global variables into one single big
hash, and using flags. This removes some impossible to understand stuff,
like old varfind, and allows for some nice stuff.
- each time we reference a global variable, we create it, possibly as a dummy
variable.
- each time we go to the environment, we remember it, thus we no longer go
back to it.

Lists of dependant changes:
- isolate changes to oldVars and checkEnvFirst.
- remove VAR_CMD and VAR_GLOBAL contexts. The only distinction is in parsevar.
Split Parse_DoVar into Parse_DoVar and Parse_CmdlineVar
- rework var modules around obtain_global_var, observe flags in various
functions like Var_Value and Var_Seti.
- Var_Seti/Var_Appendi are almost the same code, use that internally.
- add magic to handle the very special SHELL variable.
- introduce Var_Definedi for the cases where we don't want the actual
value, to simplify tests.
- add keyword .poison, parse it and set global flags accordingly.
- do poison_checks where needed.
- document poison.
- in for loops, set variable temporarily, so that Var_SubstVar will also
substitute it in varmodifiers expressions.


Revision tags: OPENBSD_4_1_BASE
# 1.61 02-Jan-2007 espie

VarDelete is no longer used by list functions, so let it do type-checking
correctly.


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.60 20-Jan-2006 espie

use stdint.h where appropriate. okay millert@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.59 07-Apr-2004 espie

ISO function declarations, trim a few comments, rename a few variables to
more explicit/more consistent names.

okay otto@


Revision tags: OPENBSD_3_5_BASE
# 1.58 07-Oct-2003 fgsch

- check if result is valid before using it.
- correctly set *freePtr, not freePtr.
input and ok espie@.


Revision tags: OPENBSD_3_4_BASE
# 1.57 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.56 05-Jun-2002 espie

tweak quick_lookup for a faster path.
okay millert@


Revision tags: OPENBSD_3_0_BASE OPENBSD_3_1_BASE
# 1.55 23-May-2001 espie

Mostly clean-up:
- cut up those huge include files into separate interfaces for all modules.
Put the interface documentation there, and not with the implementation.
- light-weight includes for needed concrete types (lst_t.h, timestamp_t.h).
- cut out some more logically separate parts: cmd_exec, varname, parsevar,
timestamp.
- put all error handling functions together, so that we will be able to
clean them up.
- more systematic naming: functioni to handle interval, function to handle
string.
- put the init/end code apart to minimize coupling.
- kill weird types like ReturnStatus and Boolean. Use standard bool (with a
fallback for non-iso systems)
- better interface documentation for lots of subsystems.

As a result, make compilation goes somewhat faster (5%, even considering
the largish BSD copyrights to read). The corresponding preprocessed
source goes down from 1,5M to 1M.

A few minor code changes as well: Parse_DoVar is no longer destructive.
Parse_IsVar functionality is folded into Parse_DoVar (as it knows what an
assignment is), a few more interval handling functions. Avoid calling
XXX_End when they do nothing, just #define XXX_End to nothing.

Parse_DoVar is slightly more general: it will handle compound assignments
as long as they make sense, e.g., VAR +!= cmd
will work. As a side effect, VAR++=value now triggers an error
(two + in assignment).
- this stuff doesn't occur in portable Makefiles.
- writing VAR++ = value or VAR+ +=value disambiguates it.
- this is a good thing, it uncovered a bug in bsd.port.mk.

Tested by naddy@. Okayed millert@. I'll handle the fallback if there is
any. This went through a full make build anyways, including isakmpd
(without mickey's custom binutils, as he didn't see fit to share it with me).


# 1.54 15-May-2001 espie

Don't go beyond end of string.
Handles unterminated variables, and fixes regression test #10


# 1.53 03-May-2001 espie

Synch with my current work.
Numerous changes:
- generate can build several tables
- style cleanup
- statistics code
- use variable names throughout (struct Name)
- recursive variables everywhere
- faster parser (pass buffer along instead of allocating multiple copies)
- correct parser. Handles comments everywhere, and ; correctly
- more string intervals
- simplified dir.c, less recursion.
- extended for loops
- sinclude()
- finished removing extra junk from Lst_*
- handles ${@D} and friends in a simpler way
- cleaned up and modular VarModifiers handling.
- recognizes some gnu Makefile usages and errors out about them.

Additionally, some extra functionality is defined by FEATURES. The set of
functionalities is currently hardcoded to OpenBSD defaults, but this may
include support for some NetBSD extensions, like ODE modifiers.

Backed by miod@ and millert@, who finally got sick of my endless patches...


Revision tags: OPENBSD_2_9_BASE
# 1.52 02-Mar-2001 espie

Use the ohash_* that's now in libc.


# 1.51 07-Dec-2000 espie

Forgot to copy end of name in nested variable names, so that
${BC_${A}} worked but not ${${A}_BC}.
Noticed by fries@


# 1.50 24-Nov-2000 espie

Take advantage of VarModifiers_Apply, which can parse a variable spec
and expand it directly, without needing a variable context.

Use it in Var_SubstVar, so that .for loops values don't need to be entered
into any context nor looked up.

This speeds up .for loops some, and avoids nasty variable capture
side-effects.

Ok'd millert@, miod@, naddy@ (naddy spotted a problem with the first
version of that change).


Revision tags: OPENBSD_2_8_BASE
# 1.49 13-Oct-2000 espie

esetenv: does a setenv and bails out if error.


# 1.48 14-Sep-2000 espie

Some systematic clean-up.
- UNUSED macro that expands to __attribute__((unused)) for gcc
- move rcsid around so that they can be tagged UNUSED.
- activate -Wunused.
- use UNUSED instead of kludgy junk for function arguments.
- add extern to all extern prototypes.
- update comments in lst.h.
- clean up var.c a little bit, constifying arguments, updating comments...


# 1.47 21-Aug-2000 espie

Var_Append needs to set v for DEBUG(VAR) to work.
Obvious fix.
Problem reported by Gregory Steuck, thanks a lot !


# 1.46 18-Jul-2000 espie

Handle MAKEFLAGS variation mandated by POSIX.

Code to pass variable definitions to submakes through make flags.
Not activated yet, need to fix src/ first.


# 1.45 17-Jul-2000 espie

parse embedded variable specs, e.g., ${VAR_${SUB}}

- need braces, as we don't want to change what $$A means,
- this assumes this kind of construct is very infrequent, thus
this does NOT copy the variable name needlessly.
- the expansion code is in a separate function for clarity.

Reviewed by miod@, as previous patches.


# 1.44 17-Jul-2000 espie

- let VarModifiers_Apply accept NULL string gracefully,
- simplify Var_Parse: use varfind, then leverage on the result
to recognize `special case' dynamic parsing.

VarModifiers_Apply need to be called on NULL strings, to be able to parse
modifiers applied to non-existent variables.

(Alternately, we could call VarModifiers_Apply on a dummy string, but
this is less efficient).


# 1.43 17-Jul-2000 espie

Major unobfuscation: split var modifiers handling to a separate file.
This does finally make var handling somewhat readable.


# 1.42 17-Jul-2000 espie

separate modifiers handling from Var_Parse into a separate
VarModifiers_apply function.

for env lookup, create variable structure first, so that we can get away
without terminating the variable name in main Var_Parse.


# 1.41 17-Jul-2000 espie

This does replace Str_Match with a better routine, which handles negated
intervals, and \\ in intervals.

Accordingly, var.c no longer needs to copy the :Marg to replace \: with :

We don't use fnmatch(3) because of various optimizations which are harder
to achieve in a generic setting.

Also add regression suite for the Str_Match function.


# 1.40 17-Jul-2000 espie

Constify a few functions, propagated from VarModify.
Replace a few int -> size_t

Reviewed by miod@


# 1.39 17-Jul-2000 espie

- recognize that FIND_CMD and FIND_GLOBAL are always used together,
- introduce VarFind_interval function. This avoids having to copy variable
names in VarParse,
- expose internals of VarFind* function (not used yet, but this will avoid
multiple lookups in VarParse),
- constify a few functions.

Reviewed by miod@


# 1.38 23-Jun-2000 espie

This is the speed-up patch, which doubles make speed (almost).

Use the open hashing functions for global contexts instead of List in
var.c.

All the preliminary work to trim down local contexts means that we don't
suffer from the heavy initialization work that a hash table entails.

There is some make kludgery to:
- build the hashing functions as a library,
- recreate hashconsts.h, even if make depend was not invoked.

One point of the hashing scheme written was to separate the computation
of the hash function, and the hash lookup itself. This is very convenient
for make, because of those pesky special variables. hashconsts.h is there
to pre-hash the correct values, which replaces a few expensive string
comparisons with quick hash value comparisons, followed by one expensive
string comparison. The modulus MAGICSLOTS chosen in the Makefile is
ad-hoc: it is small enough to write a small switch without collision,
and will need changing if the hash function changes...

The function quick_lookup is the most important:
it either returns an index, for a local variable, or it does compute a
hashing value, and returns -1.

Another somewhat controversial decision is the use of string intervals.
This avoids either copying a string, or twiddling with a byte for cases
such as ${VAR}.

Finally, the variable name is stored within the variable itself. Since
a given variable name never changes, this makes sense. All that was needed
was a hash library with support for this. Note that the hashing table
holds only a variable pointer AND the corresponding hashing value, WITHOUT
a modulo hashtablesize. Two reasons:
- hash resizes can be done faster, without having to recompute hashing values.
- locality of access. The hash table fits into memory without problem. Once
a candidate slot is found, we check the complete hashing value. Probability
of a collision is very small (32 bits...). So bringing up the whole
variable in memory at once is good: the name will almost always match, in
which case we want the variable value as well, so it makes sense to put
them together.

The ohash functions implement open hashing, as described in Knuth, but with
a variable table size. Choosing powers of 2 sizes does not yield more
collisions, but it makes the hashing scheme much simpler. The thresholds at
which to expand/shrink the tables seem to work well in practice. The
default sizes were chosen such that the tables hardly ever shrink or expand
anyways (though I've tried with smaller/larger sizes to verify that the
shrinking/expanding worked correctly): larger Makefiles hold roughly
500/600 variables, which fits without trouble into a 1024-sized variable.

Disregard #ifdef STATS_HASH, this is some internal scaffolding I'm using
to measure make performance.

The only known issue with open-hashing is that deletions cannot create
empty slots, but do leave slots marked as `occupied once' so that lookup
works. We use a well-known optimization which records those pseudo-empty
slots while looking up values. If the value is not found, the pseudo-empty
slot is returned to be filled. If the value is found, it is swapped with
the pseudo-empty slot. This is an improvement in both cases, since this
shortens the length of lookup chains, eventually pushing the pseudo-empty
slots to the end.

Reviewed by millert@ and miod@


# 1.37 23-Jun-2000 espie

This patch separates local contexts from global contexts for good.
Apart from a few casts, VAR_GLOBAL and friends are separate
data structures, so we use a small array for local variables.

We also junk allVars, since TargFreeGN can release local nodes,
and var.c has explicit lists for its variables already.

Reviewed millert@ and miod@.


# 1.36 23-Jun-2000 espie

In various places, VAR_CMD is used to actually mean `no real context',
since lookup will start with VAR_CMD in any case.
This fixes VarFind and Var_Parse to handle ctxt == NULL correctly, and
replace those confusing VAR_CMD with proper NULL pointers.

This patch also handles three small details:
- .CURDIR is necessarily set in VAR_GLOBAL,
- suffix handling for archives copies two hard-coded variables, for
which it can use a quick path,
- typos in TargFreeGN.

Reviewed millert@, miod@.


# 1.35 23-Jun-2000 espie

Once those special variable are taken care of, other Var functions can take
the GNode's context directly. We rename that special Lst to `SymTable *'
in prevision of things to come.

Along the line, we lose the special GNodes affected to VAR_CMD, VAR_GLOBAL,
VAR_ENV, which become simple Lsts... This is not a problem, except when
getting to a context's name for debugging (handled very nicely by
offsetof).

Again, this is a preparatory patch, which does not gain anything except
for cleaning up issues...

Reviewed by millert@ and miod@, like the previous patch


# 1.34 23-Jun-2000 espie

Start of variable fixes and speed-ups.

This patch may seem a bit non-sensical at first. It simply introduces some
new interface. Specifically, recognizes that some variable names
(.TARGET/$@, .OODATE/$?, .ALLSRC/$>, .IMPSRC/$<, .PREFIX/$*, .ARCHIVE/$!,
.MEMBER/$%) are `special' (the actual variables which are local to a
target, e.g. GNode).

Currently, The Varq functions (for Varquick access) are only stubs to the
normal functions.

This fixes a very important detail before proceeding to turn variable lists
into hash tables: if every GNode holds a hash table, initialization times
for those will be very costly. But generic GNodes only hold those seven
special variables... which can be stored directly into a small array;
the only general cases are the environment, the command line and
global variables.


# 1.33 17-Jun-2000 espie

This patch introduces a distinction between
Lst_Init (constructor) and Lst_New (allocation + construction)
Lst_Destroy (destructor) and Lst_Delete (deallocation + destruction),
and uses that to turn most dynamic allocation of lists (Lst pointers)
into static structures (LIST).

Most of this is mundane, except for allGNs in targ.c, where the code must
be checked to verify that Targ_Init is called soon enough.

Lst_New is a temporary addition. All lists will soon be static.

Reviewed by millert@, like the previous patch.


# 1.32 10-Jun-2000 espie

Clean-up patch: use `void *' instead of old-fashioned ClientData/Address.


# 1.31 10-Jun-2000 espie

Thus, Lst_ForEach no longer needs returning a status.
In fact, it can become a macro based on Lst_ForEachFrom.
This also introduces Lst_Every, as a shortcut for the very common case where
Lst_ForEach does not need any user data.

Finally, make consistent use of a few function typedefs, instead of having
explicit void (*)(Lst) arguments all over the place.


Revision tags: OPENBSD_2_7_BASE
# 1.30 26-Mar-2000 espie

Remove idiotic, braindead casts T* -> void*
They serve no purpose, except hiding potential bugs.

In particular, remove (ClientData) cast from macro, showing potentially
troublesome use of Hashes to store time_t.


# 1.29 08-Jan-2000 espie

Finish changing all Var_Parse arguments to size_t. Thanks to millert@
for reminding me.


# 1.28 19-Dec-1999 espie

Rearrange Lst_Find interface to conform better with other functions.


# 1.27 18-Dec-1999 espie

Nothing ever checks ReturnStatus on Lst_Insert, Lst_Append, Lst_AtFront,
Lst_AtEnd, Lst_Concat, Lst_Remove, Lst_Replace.

Don't bother returning one.


# 1.26 18-Dec-1999 espie

NIL, NILGNODE, etc, are only glorified NULL.
Get rid of them.

Get rid of list.h, nothing uses it anyway.


# 1.25 18-Dec-1999 espie

make does not use circular lists, get rid of the extra weight.


# 1.24 16-Dec-1999 espie

Var_Subst is actually two distinct functions folded into one:
split the function specific to for.c out, and give them more sensible
arguments at the same time.

This makes .for loop handling more efficient, as we have some heuristic
to evaluate the size of the buffer needed...


# 1.23 16-Dec-1999 espie

Allocate buffers as static data structures.
This cuts down quite a lot of malloc, since in actual use,
buffer usage is mostly static.


# 1.22 16-Dec-1999 espie

Remove unneeded extraneous zeros at the end of buffers.

Actually, one of these needs to be there, because of two bugs in cond.c


# 1.21 16-Dec-1999 espie

Split Buf_GetAll into Buf_Retrieve/Buf_Size.
(idiotic to retrieve size every time when it's used half the time)


# 1.20 16-Dec-1999 espie

Start cleaning up buf.c in earnest.

- Buf_Discard is only used to remove all the bytes in a buffer,
replace with Buf_Reset,
- buffer values are not read unless accessed first through Buf_GetAll,
no need to null-terminate it at every point.
- Buf_Expand need not check if the expansion is needed. That's Buf_AddChar
and Buf_AddChars responsability (otherwise, Buf_AddChar checks twice)
- Buf_Overflow only handles overflow. Adding the character is done in
every case anyway.


# 1.19 09-Dec-1999 espie

Introduce `common usage' buf patterns and use them.


# 1.18 06-Dec-1999 espie

Extra parameter no longer needed, ditch.


# 1.17 06-Dec-1999 espie

Instead of retrieving var values from the environment again and again,
it is much better to keep them in the global context, marked read-only.

This also makes the next simplification possible, since var values need no
longer be free'd by client code.

(reviewed by ho@, like other patches)


# 1.16 06-Dec-1999 espie

Clean up buffers interface somewhat:

- buf.c deals exclusively with chars. Be explicit about it, and remove
extraneous dumb casts to char (can hide real type errors).
- buffer sizes are size_t. Note that bp->left can never become NULL.
- Buf_GetAll is happy with a NULL pointer for the size, remove unneeded
extra pointers.
- Propagate size_t to all places where buffer functions are used.


# 1.15 11-Nov-1999 espie

Kill Str_FindSubString, it's strstr.


# 1.14 10-Nov-1999 espie

Turn on strict-prototypes, add missing prototypes.
Move main prototype to main.c, as this is not used
from any other file.

Close open bug.


# 1.13 06-Nov-1999 espie

Bug-fix: when expanding a specific variable v in $A,
check that v is PRECISELY A.

Other BSDs, take notice.


Revision tags: OPENBSD_2_6_BASE
# 1.12 28-Sep-1999 espie

Fix
.if defined(VAR) && ${VAR:m}

cond.c has special code (set err to 0) to tell VarParse it shouldn't care
if the variable is not defined.

But this was not completely added, namely the path that deals with
modifiers was blissfully unaware of that.


# 1.11 25-Sep-1999 espie

Add :L/:U modificators (lowercase/uppercase)
To use to get ports building more user-friendly.


Revision tags: OPENBSD_2_5_BASE
# 1.10 05-Dec-1998 espie

Modifications from netbsd:
- don't interfere with MACHINE/MACHINE_ARCH defines for bootstrap
- type clean-up, time_t, and printing `unknown' ints
- fix TARGET/MEMBER bug in archive rules
- memmove...
- cleaner Error handler.
- reentrant brk_string
- .MAKE env variable
- preliminary scaffolding for .NOPATH

Other improvements:
- efree
- shellneed streamlined
- display Stop in .CURDIR after an error.
- document most features and misfeatures.
- add a few OpenBSD notes to the tutorial.


Revision tags: OPENBSD_2_4_BASE
# 1.9 23-Jul-1998 deraadt

portable bootstrap thing; lidl@eng.us.uu.net


Revision tags: OPENBSD_2_3_BASE
# 1.8 30-Mar-1998 deraadt

Y2K fixes from Andreas.Gunnarsson@emw.ericsson.se; culled from various places


# 1.7 18-Dec-1997 deraadt

for the test following test case, do not output FOOBAR=bar (should be FOOBAR=)
problem reported by mark@thuvia.demon.co.uk

FOO=
FOOBAR=$(FOO:=bar)


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.6 01-Apr-1997 millert

Sync with NetBSD (mostly by christos initial substitution/regexp from Der Mouse)

- fix the variable substitution code in make [PR/2748]
1. change s/a/b/ so that it substitutes the first occurance of the
pattern on each word, not only the first word.
2. add flag '1' to the variable substitution so that the substitutions
get performed only once.

***THIS IS AN INCOMPATIBLE CHANGE!***

Unfortunately there was no way to make things consistent without
modifying the current behavior. Fortunately none of our Makefiles
depended on this.

OLD:

VAR = aa1 aa2 aa3 aa4

S/a/b/ = ba1 aa2 aa3 aa4
S/a/b/g = bb1 bb2 bb3 bb4

NEW:
VAR = aa1 aa2 aa3 aa4

S/a/b/ = ba1 ba2 ba3 ba4
S/a/b/1 = ba1 aa2 aa3 aa4
S/a/b/g = bb1 bb2 bb3 bb4
S/a/b/1g = bb1 aa2 aa3 aa4
- add regexp variable substitution via 'C/foo/bar/' [PR/2752]
- add variable quoting via the ${VAR:Q} modifier. This is useful when running
recursive invocations of make(1):

make VAR=${VAR:Q}

will always work... (This may prove useful in the kernel builds...) [PR/2981]
- BSD did not traditionally have <sys/cdefs.h>; use BSD4_4 instead and include
<sys/param.h> to grab it.
- Don't compile the regex code if MAKE_BOOTSTRAP (from gwr)
- Use explicit .c.o rule in Makefile.boot so that the bootstrap process works.
- Use only integral types in procedure arguments. [buf.c buf.h]
- Include <stdlib.h> to get getenv() prototype on SVR4
- if __STDC__ -> ifdef __STDC__ to appease SVR4
- Define const and volatile for non __STDC__
- Implement snprintf() and vsnprintf() for non BSD4_4 systems.
- Make $MACHINE_ARCH settable from the environment.
- Fix .USE directive problems: (reported by cgd)
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.
- Add a .MADE directive to indicated that the children of a target are
up-to-date, even when they are not. This is to simulate our current
make install behavior with proper dependencies.
- Fix problems in the RE substitution error handling.
- Locate all the children of a node marked as MADE.
- Do not compile-in ${MACHINE} (as per NetBSD PR#3386)
- Disable globbing for targets/dependencies when POSIX is defined.
- Fix globbing so that patterns that don't have a matching number of [] or {}
don't get expanded. (before the [ case got expanded to nothing!) This is
disabled.
- Make sure that the children of nodes that are marked .MADE, are marked
UPTODATE and their timestamps are consistent.
- Don't disable wildcards completely; they are used by other Makefiles.


# 1.5 30-Nov-1996 millert

Sync with NetBSD:
- 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.
- Fix NetBSD PR #2930: declare missing variable.


Revision tags: OPENBSD_2_0_BASE
# 1.4 02-Sep-1996 briggs

Sync up with NetBSD:
(christos)
Fix bug reported by Greg Hudson where leaf (source only) nodes were
referenced only by their basename and not by their full pathname. This
breaks when .PATH or MAKEOBJDIR are used. There might be Makefiles
around that try to work around this bug by prepending ${.CURDIR} to
the sources, and they should be found and fixed. Also a lot of the gunk
in suff.c that was attempting to work around the same problem could be
removed.
(christos)
- Move -D flags from Makefile to config.h and explain what they do. Add
-Wall -Wno-unused to CFLAGS. Add new define SYSVVARSUB to enable SysV
style variable substitutions and enable them.
- Add SunOS style command substitutions via SUNSHCMD
- Fix core dump with '{variable = value'
(christos)
Fix bug where make will always exit with 0, even when one or more
parallel jobs failed. (Only affects parallel make code)
(christos)
Protect __P from being multiply defined (for systems that already
define it)
(christos) Add strdup() since ultrix is missing it.
From Larry Schwimmer <rosebud@cyclone.Stanford.EDU>
(christos) Add estrdup(), a checked version of strdup and use it.
(christos) Recognize SVR4 style long filename entries in archives.
(thorpej) Tidy up some RCS ids a bit.


# 1.3 26-Jun-1996 deraadt

rcsid


# 1.2 14-Dec-1995 deraadt

from christos@netbsd:
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.
- Turn compat mode on by default. It gets turned off when the -j without
the -B flag is specified. [Thus you can use -j 1 to turn it off].
- Fix malloc -> emalloc as Gordon noted.
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.

from cgd@netbsd:
pull in make.h. (PAlloc() now uses emalloc(), which is prototyped in
make.h. If the prototype is not in scope on the Alpha, I see lots
of "cast to pointer from integer of different size" warnings.)


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.104 09-Jun-2022 espie

point developers to the other place where the remaining flags values are
defined (nice gotcha when you come back to the code after a few months).


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.103 22-Dec-2019 espie

we also have "VAR_*" constants in parsevar with totally different meanings.
Rename to avoid ambiguity
- VAR_IS_SHELL (in var.c): the SHELL variable, which has specific
POSIX semantics
- VAR_SHELL (in parsevar.c): assign the result of running the command
to the variable.

no actual code change


# 1.102 21-Dec-2019 espie

yet another mostly cosmetic diff
- rename context into localvars, which is more meaningful and less generic
- instantiate the random rumbling at the start of gnode.h with actual
variable names
- explain and group gnode.h variables better
- make some comments terser/more meaningful

okay millert@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.101 23-Oct-2016 espie

add !!=
feedback and okay millert@


# 1.100 14-Oct-2016 natano

Implement the ${<D} and ${<F} variables, as documented in the manual.
They are equivalent to ${<:H} and ${<:T} repectively, however the former
variants are more portable, as they are understood by GNU, FreeBSD and
NetBSD make too.

absence of those variables reported by Dario Niedermann <dnied at tiscali.it>
ok millert espie


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.99 27-Sep-2015 guenther

Mark all the error printing functions as printf-like; fix two format
mismatches this revealed

ok espie@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.98 12-May-2014 espie

adjust to ohash being in libutil now, and to the interface changes.
fix potential integer overflows in memory allocation (mostly for pedagogical
purposes, these are unlikely to overflow in practice)
move the rest of lst.lib stuff into its own directory.


Revision tags: OPENBSD_5_5_BASE
# 1.97 29-Jan-2014 espie

I'm a bit dyslexic. Found out by Jan Klemkow. Thanks.


# 1.96 06-Jan-2014 espie

this actually requires a comment. I would never have figured it out if
it wasn't for the arm error.


# 1.95 06-Jan-2014 espie

fix error messages, avoid dereferencing null pointers.
- the code becomes too indented, pull it into a separate function
- add an extra hint, the current_gnode.
- specifically, variables may be expanded during
target: prereq solving in Suff_FindDeps, this is after parsing,
not during command execution, and the only actual indication with have is
that we're resolving a prereq of.

(this ought to fix mk35, and partially solve mk34)


Revision tags: OPENBSD_5_4_BASE
# 1.94 23-Apr-2013 espie

remove TIMESTAMP abstraction layer, prodded by theo.
while there, clean up includes.
use strtoll for ar timestamps (pretty much unused in reality, more
standard conforming than anything)

use idea from Todd to adapt to time_t being 32 bits OR 64 bits
(pedantically correct: INT_MIN would work just fine up to 1910 or so...)

okay millert@, gone thru a make build.


Revision tags: OPENBSD_5_3_BASE
# 1.93 15-Feb-2013 espie

turns out if a line ends with a $, the var module will run off the cliff
while expanding it.
shows up very prominently with MALLOC_OPTIONS=S

Problem found by jasper@

okay'd by jasper@ and kind-of duh'd by miod@


# 1.92 09-Oct-2012 espie

new interface: look in command lines for variables that indicate a list of
targets is actually separate targets.


# 1.91 02-Oct-2012 espie

more changes, discussed and tested by various people.
- put back some job control, turns out it's necessary when we don't run a
shell.
- zap old #ifdef CLEANUP code... probably doesn't even compile.
- kill most of the OP_LIB code. Just keep a wee little bit for compatibility
(deprecated .LIBS and .INCLUDES, warns for weird dependencies instead of
erroring out).
- much improved debugging and -p output: sort variables, targets, rules,
output stuff in a nicer format mimicing input.
- better error message when no command is found, explain where the target comes from.
- sort final error list by file.
- show system files in errors as <bsd.prog.mk>
- reincorporate random delay, that was dropped
- optimize siginfo output by not regenerating the whole string each time.
- finish zapping old LocationInfo field that's no longer used.


# 1.90 25-Aug-2012 espie

- make wrong variable specs (unterminated) parse errors.
- add info to be able to pinpoint parse errors at runtime.
- let job runners abort when a parse error happens while expanding a variable
during execution
- fix an infinite loop when compiling without FEATURE_RECVARS.

okay millert@, krw@
the very few errors found out by this (less than 10 over src/X/ports)
fixed trivially beforehand, as requested by deraadt@


Revision tags: OPENBSD_5_2_BASE
# 1.89 22-Mar-2012 espie

minor cleanup: error messages include lineno and fileno together, so
recognize that and create a struct Location_ for it.

mostly from Jonathan Calmels, a few nits from me.

okay otto@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.88 20-Jun-2011 espie

fix a segfault found by jasper@
ok miod@, otto@, jasper@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.87 19-Jul-2010 espie

Correct $OpenBSD$ stuff


# 1.86 25-Apr-2010 espie

pure whitespace cleanup


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.85 13-May-2009 espie

fix loopvar debug prints. Issue reported by naddy@


Revision tags: OPENBSD_4_5_BASE
# 1.84 09-Nov-2008 tobias

typo fixed (overriden -> overridden)

ok espie, jmc


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.83 17-Nov-2007 espie

simplify dynamic variable handling a great deal:
first remove all usage of Varq_Append by building the string directly.
then replace `common' handling with specialized handling for dynamic
strings (since they no longer need a buffer). Finally, identify the place
where the variable value needs to be copied because it's going to be free'd
or erased soon, and finally, use simple char* pointers.

Shaves about 80 bytes off every gnode structure, and kills quite a few
unnecessary malloc()s as well.


# 1.82 04-Nov-2007 espie

prevent gcc from complaining


# 1.81 03-Nov-2007 deraadt

fix some lint FALLTHROUGH


# 1.80 17-Sep-2007 espie

more blank space removal


# 1.79 17-Sep-2007 espie

more zap spaces


# 1.78 17-Sep-2007 espie

zap more spaces at end of line


# 1.77 17-Sep-2007 espie

kill extra spaces at end of line


# 1.76 16-Sep-2007 espie

remove warnings


# 1.75 16-Sep-2007 espie

remove dead code: #define RECHECK is always on


Revision tags: OPENBSD_4_2_BASE
# 1.74 30-Jul-2007 espie

introduce a Var_Substi to substitute on intervals.
Since we don't really know how to change Var_Subst and dependent functions,
we cheat, and copy the string to a buffer instead.

Clean-up the parser a bit: reorganize the include files lookup function:
introduce a resolve_include_filename function that figures out the full name
of the file, introduce a handle_include_file that does all the include file
handling, and rename the functions into handle_xxx_include, so that we
can remove most comments.

Rename ParseIsCond into handle_bsd_command, cut most of its code into
constituent functions.

Semantic changes:
- follow the rules that, if an optional construct does not parse correctly,
then it's not a real extension, and give the normal parser a chance to figure
it out. If the syntax checks out, semantic errors ARE real errors.
- allow variables to not be defined in include file names, no reason not to.

okay miod@


# 1.73 30-Jul-2007 espie

everywhere except in Var_Parse, we always add/append variables to the
VAR_GLOBAL context, so make it the common case: rename the basic functions
to Var_Set_with_ctxt/Var_Append_with_ctxt, define Var_Set and Var_Append
as macros that specify VAR_GLOBAL, and use these.

okay miod@


# 1.72 30-Jul-2007 espie

now that it's clean enough, one can extract some common code from
Var_Parse and Var_ParseSkip (the code that figures out the variable name
up to eventual modifiers).

okay miod@


# 1.71 24-Jul-2007 espie

zap unused variable


# 1.70 24-Jul-2007 espie

simplify computations in the var module: instead of advancing a char *
and keeping track of a length, we just advance the char *, and ditch
the length. We can still get the length at the end of the top-level
functions to satisfy existing interfaces.

Much simpler code, less error-prone.

Okay millert@


# 1.69 24-Jul-2007 espie

move the code that grabs a value in Var_Parse in its own function,
get_expanded_value.

Extend the code a bit to be much more thorough in case of a recursive
expansion: shows exactly the cycle of variable names involved.

okay millert@


# 1.68 24-Jul-2007 espie

change Var_ParseSkip API to increment the position instead of returning a
length, simplifies code.

(warns a bit, symptom of some further issues to fix).

okay millert@


# 1.67 22-Jul-2007 espie

make sure loop variables use their own buffers.
(causes .for loops to give weird results very infrequently, memory handling
was slightly wrong, but not enough to break things thoroughly).
noticed by naddy@


# 1.66 20-Jul-2007 espie

big clean-up patch:
- rename a few functions in var.c to names that make more sense.
- introduce Var_Deletei because it makes more sense.
- rewrite .for loops to use a local LoopVar construct to avoid looking up more
stuff.
- reformat var.c to near K&R
- rewrite most comments in var.c

shown to a few people. millert@ gave me his okay since it passes through
ports correctly.


# 1.65 20-Jul-2007 espie

reorder stuff in var.c so that the next patch is more readable.


# 1.64 08-Jul-2007 espie

rename variable to errorIsOkay. What does oldVars mean anyway ?


# 1.63 08-Jul-2007 espie

missed part: add check to avoid poison checking inexistent local vars,
and do for loops for real.


# 1.62 08-Jul-2007 espie

A set of big related changes. okay millert@, tested further by kettenis@
and matthieu@

This all revolves around putting ALL global variables into one single big
hash, and using flags. This removes some impossible to understand stuff,
like old varfind, and allows for some nice stuff.
- each time we reference a global variable, we create it, possibly as a dummy
variable.
- each time we go to the environment, we remember it, thus we no longer go
back to it.

Lists of dependant changes:
- isolate changes to oldVars and checkEnvFirst.
- remove VAR_CMD and VAR_GLOBAL contexts. The only distinction is in parsevar.
Split Parse_DoVar into Parse_DoVar and Parse_CmdlineVar
- rework var modules around obtain_global_var, observe flags in various
functions like Var_Value and Var_Seti.
- Var_Seti/Var_Appendi are almost the same code, use that internally.
- add magic to handle the very special SHELL variable.
- introduce Var_Definedi for the cases where we don't want the actual
value, to simplify tests.
- add keyword .poison, parse it and set global flags accordingly.
- do poison_checks where needed.
- document poison.
- in for loops, set variable temporarily, so that Var_SubstVar will also
substitute it in varmodifiers expressions.


Revision tags: OPENBSD_4_1_BASE
# 1.61 02-Jan-2007 espie

VarDelete is no longer used by list functions, so let it do type-checking
correctly.


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.60 20-Jan-2006 espie

use stdint.h where appropriate. okay millert@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.59 07-Apr-2004 espie

ISO function declarations, trim a few comments, rename a few variables to
more explicit/more consistent names.

okay otto@


Revision tags: OPENBSD_3_5_BASE
# 1.58 07-Oct-2003 fgsch

- check if result is valid before using it.
- correctly set *freePtr, not freePtr.
input and ok espie@.


Revision tags: OPENBSD_3_4_BASE
# 1.57 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.56 05-Jun-2002 espie

tweak quick_lookup for a faster path.
okay millert@


Revision tags: OPENBSD_3_0_BASE OPENBSD_3_1_BASE
# 1.55 23-May-2001 espie

Mostly clean-up:
- cut up those huge include files into separate interfaces for all modules.
Put the interface documentation there, and not with the implementation.
- light-weight includes for needed concrete types (lst_t.h, timestamp_t.h).
- cut out some more logically separate parts: cmd_exec, varname, parsevar,
timestamp.
- put all error handling functions together, so that we will be able to
clean them up.
- more systematic naming: functioni to handle interval, function to handle
string.
- put the init/end code apart to minimize coupling.
- kill weird types like ReturnStatus and Boolean. Use standard bool (with a
fallback for non-iso systems)
- better interface documentation for lots of subsystems.

As a result, make compilation goes somewhat faster (5%, even considering
the largish BSD copyrights to read). The corresponding preprocessed
source goes down from 1,5M to 1M.

A few minor code changes as well: Parse_DoVar is no longer destructive.
Parse_IsVar functionality is folded into Parse_DoVar (as it knows what an
assignment is), a few more interval handling functions. Avoid calling
XXX_End when they do nothing, just #define XXX_End to nothing.

Parse_DoVar is slightly more general: it will handle compound assignments
as long as they make sense, e.g., VAR +!= cmd
will work. As a side effect, VAR++=value now triggers an error
(two + in assignment).
- this stuff doesn't occur in portable Makefiles.
- writing VAR++ = value or VAR+ +=value disambiguates it.
- this is a good thing, it uncovered a bug in bsd.port.mk.

Tested by naddy@. Okayed millert@. I'll handle the fallback if there is
any. This went through a full make build anyways, including isakmpd
(without mickey's custom binutils, as he didn't see fit to share it with me).


# 1.54 15-May-2001 espie

Don't go beyond end of string.
Handles unterminated variables, and fixes regression test #10


# 1.53 03-May-2001 espie

Synch with my current work.
Numerous changes:
- generate can build several tables
- style cleanup
- statistics code
- use variable names throughout (struct Name)
- recursive variables everywhere
- faster parser (pass buffer along instead of allocating multiple copies)
- correct parser. Handles comments everywhere, and ; correctly
- more string intervals
- simplified dir.c, less recursion.
- extended for loops
- sinclude()
- finished removing extra junk from Lst_*
- handles ${@D} and friends in a simpler way
- cleaned up and modular VarModifiers handling.
- recognizes some gnu Makefile usages and errors out about them.

Additionally, some extra functionality is defined by FEATURES. The set of
functionalities is currently hardcoded to OpenBSD defaults, but this may
include support for some NetBSD extensions, like ODE modifiers.

Backed by miod@ and millert@, who finally got sick of my endless patches...


Revision tags: OPENBSD_2_9_BASE
# 1.52 02-Mar-2001 espie

Use the ohash_* that's now in libc.


# 1.51 07-Dec-2000 espie

Forgot to copy end of name in nested variable names, so that
${BC_${A}} worked but not ${${A}_BC}.
Noticed by fries@


# 1.50 24-Nov-2000 espie

Take advantage of VarModifiers_Apply, which can parse a variable spec
and expand it directly, without needing a variable context.

Use it in Var_SubstVar, so that .for loops values don't need to be entered
into any context nor looked up.

This speeds up .for loops some, and avoids nasty variable capture
side-effects.

Ok'd millert@, miod@, naddy@ (naddy spotted a problem with the first
version of that change).


Revision tags: OPENBSD_2_8_BASE
# 1.49 13-Oct-2000 espie

esetenv: does a setenv and bails out if error.


# 1.48 14-Sep-2000 espie

Some systematic clean-up.
- UNUSED macro that expands to __attribute__((unused)) for gcc
- move rcsid around so that they can be tagged UNUSED.
- activate -Wunused.
- use UNUSED instead of kludgy junk for function arguments.
- add extern to all extern prototypes.
- update comments in lst.h.
- clean up var.c a little bit, constifying arguments, updating comments...


# 1.47 21-Aug-2000 espie

Var_Append needs to set v for DEBUG(VAR) to work.
Obvious fix.
Problem reported by Gregory Steuck, thanks a lot !


# 1.46 18-Jul-2000 espie

Handle MAKEFLAGS variation mandated by POSIX.

Code to pass variable definitions to submakes through make flags.
Not activated yet, need to fix src/ first.


# 1.45 17-Jul-2000 espie

parse embedded variable specs, e.g., ${VAR_${SUB}}

- need braces, as we don't want to change what $$A means,
- this assumes this kind of construct is very infrequent, thus
this does NOT copy the variable name needlessly.
- the expansion code is in a separate function for clarity.

Reviewed by miod@, as previous patches.


# 1.44 17-Jul-2000 espie

- let VarModifiers_Apply accept NULL string gracefully,
- simplify Var_Parse: use varfind, then leverage on the result
to recognize `special case' dynamic parsing.

VarModifiers_Apply need to be called on NULL strings, to be able to parse
modifiers applied to non-existent variables.

(Alternately, we could call VarModifiers_Apply on a dummy string, but
this is less efficient).


# 1.43 17-Jul-2000 espie

Major unobfuscation: split var modifiers handling to a separate file.
This does finally make var handling somewhat readable.


# 1.42 17-Jul-2000 espie

separate modifiers handling from Var_Parse into a separate
VarModifiers_apply function.

for env lookup, create variable structure first, so that we can get away
without terminating the variable name in main Var_Parse.


# 1.41 17-Jul-2000 espie

This does replace Str_Match with a better routine, which handles negated
intervals, and \\ in intervals.

Accordingly, var.c no longer needs to copy the :Marg to replace \: with :

We don't use fnmatch(3) because of various optimizations which are harder
to achieve in a generic setting.

Also add regression suite for the Str_Match function.


# 1.40 17-Jul-2000 espie

Constify a few functions, propagated from VarModify.
Replace a few int -> size_t

Reviewed by miod@


# 1.39 17-Jul-2000 espie

- recognize that FIND_CMD and FIND_GLOBAL are always used together,
- introduce VarFind_interval function. This avoids having to copy variable
names in VarParse,
- expose internals of VarFind* function (not used yet, but this will avoid
multiple lookups in VarParse),
- constify a few functions.

Reviewed by miod@


# 1.38 23-Jun-2000 espie

This is the speed-up patch, which doubles make speed (almost).

Use the open hashing functions for global contexts instead of List in
var.c.

All the preliminary work to trim down local contexts means that we don't
suffer from the heavy initialization work that a hash table entails.

There is some make kludgery to:
- build the hashing functions as a library,
- recreate hashconsts.h, even if make depend was not invoked.

One point of the hashing scheme written was to separate the computation
of the hash function, and the hash lookup itself. This is very convenient
for make, because of those pesky special variables. hashconsts.h is there
to pre-hash the correct values, which replaces a few expensive string
comparisons with quick hash value comparisons, followed by one expensive
string comparison. The modulus MAGICSLOTS chosen in the Makefile is
ad-hoc: it is small enough to write a small switch without collision,
and will need changing if the hash function changes...

The function quick_lookup is the most important:
it either returns an index, for a local variable, or it does compute a
hashing value, and returns -1.

Another somewhat controversial decision is the use of string intervals.
This avoids either copying a string, or twiddling with a byte for cases
such as ${VAR}.

Finally, the variable name is stored within the variable itself. Since
a given variable name never changes, this makes sense. All that was needed
was a hash library with support for this. Note that the hashing table
holds only a variable pointer AND the corresponding hashing value, WITHOUT
a modulo hashtablesize. Two reasons:
- hash resizes can be done faster, without having to recompute hashing values.
- locality of access. The hash table fits into memory without problem. Once
a candidate slot is found, we check the complete hashing value. Probability
of a collision is very small (32 bits...). So bringing up the whole
variable in memory at once is good: the name will almost always match, in
which case we want the variable value as well, so it makes sense to put
them together.

The ohash functions implement open hashing, as described in Knuth, but with
a variable table size. Choosing powers of 2 sizes does not yield more
collisions, but it makes the hashing scheme much simpler. The thresholds at
which to expand/shrink the tables seem to work well in practice. The
default sizes were chosen such that the tables hardly ever shrink or expand
anyways (though I've tried with smaller/larger sizes to verify that the
shrinking/expanding worked correctly): larger Makefiles hold roughly
500/600 variables, which fits without trouble into a 1024-sized variable.

Disregard #ifdef STATS_HASH, this is some internal scaffolding I'm using
to measure make performance.

The only known issue with open-hashing is that deletions cannot create
empty slots, but do leave slots marked as `occupied once' so that lookup
works. We use a well-known optimization which records those pseudo-empty
slots while looking up values. If the value is not found, the pseudo-empty
slot is returned to be filled. If the value is found, it is swapped with
the pseudo-empty slot. This is an improvement in both cases, since this
shortens the length of lookup chains, eventually pushing the pseudo-empty
slots to the end.

Reviewed by millert@ and miod@


# 1.37 23-Jun-2000 espie

This patch separates local contexts from global contexts for good.
Apart from a few casts, VAR_GLOBAL and friends are separate
data structures, so we use a small array for local variables.

We also junk allVars, since TargFreeGN can release local nodes,
and var.c has explicit lists for its variables already.

Reviewed millert@ and miod@.


# 1.36 23-Jun-2000 espie

In various places, VAR_CMD is used to actually mean `no real context',
since lookup will start with VAR_CMD in any case.
This fixes VarFind and Var_Parse to handle ctxt == NULL correctly, and
replace those confusing VAR_CMD with proper NULL pointers.

This patch also handles three small details:
- .CURDIR is necessarily set in VAR_GLOBAL,
- suffix handling for archives copies two hard-coded variables, for
which it can use a quick path,
- typos in TargFreeGN.

Reviewed millert@, miod@.


# 1.35 23-Jun-2000 espie

Once those special variable are taken care of, other Var functions can take
the GNode's context directly. We rename that special Lst to `SymTable *'
in prevision of things to come.

Along the line, we lose the special GNodes affected to VAR_CMD, VAR_GLOBAL,
VAR_ENV, which become simple Lsts... This is not a problem, except when
getting to a context's name for debugging (handled very nicely by
offsetof).

Again, this is a preparatory patch, which does not gain anything except
for cleaning up issues...

Reviewed by millert@ and miod@, like the previous patch


# 1.34 23-Jun-2000 espie

Start of variable fixes and speed-ups.

This patch may seem a bit non-sensical at first. It simply introduces some
new interface. Specifically, recognizes that some variable names
(.TARGET/$@, .OODATE/$?, .ALLSRC/$>, .IMPSRC/$<, .PREFIX/$*, .ARCHIVE/$!,
.MEMBER/$%) are `special' (the actual variables which are local to a
target, e.g. GNode).

Currently, The Varq functions (for Varquick access) are only stubs to the
normal functions.

This fixes a very important detail before proceeding to turn variable lists
into hash tables: if every GNode holds a hash table, initialization times
for those will be very costly. But generic GNodes only hold those seven
special variables... which can be stored directly into a small array;
the only general cases are the environment, the command line and
global variables.


# 1.33 17-Jun-2000 espie

This patch introduces a distinction between
Lst_Init (constructor) and Lst_New (allocation + construction)
Lst_Destroy (destructor) and Lst_Delete (deallocation + destruction),
and uses that to turn most dynamic allocation of lists (Lst pointers)
into static structures (LIST).

Most of this is mundane, except for allGNs in targ.c, where the code must
be checked to verify that Targ_Init is called soon enough.

Lst_New is a temporary addition. All lists will soon be static.

Reviewed by millert@, like the previous patch.


# 1.32 10-Jun-2000 espie

Clean-up patch: use `void *' instead of old-fashioned ClientData/Address.


# 1.31 10-Jun-2000 espie

Thus, Lst_ForEach no longer needs returning a status.
In fact, it can become a macro based on Lst_ForEachFrom.
This also introduces Lst_Every, as a shortcut for the very common case where
Lst_ForEach does not need any user data.

Finally, make consistent use of a few function typedefs, instead of having
explicit void (*)(Lst) arguments all over the place.


Revision tags: OPENBSD_2_7_BASE
# 1.30 26-Mar-2000 espie

Remove idiotic, braindead casts T* -> void*
They serve no purpose, except hiding potential bugs.

In particular, remove (ClientData) cast from macro, showing potentially
troublesome use of Hashes to store time_t.


# 1.29 08-Jan-2000 espie

Finish changing all Var_Parse arguments to size_t. Thanks to millert@
for reminding me.


# 1.28 19-Dec-1999 espie

Rearrange Lst_Find interface to conform better with other functions.


# 1.27 18-Dec-1999 espie

Nothing ever checks ReturnStatus on Lst_Insert, Lst_Append, Lst_AtFront,
Lst_AtEnd, Lst_Concat, Lst_Remove, Lst_Replace.

Don't bother returning one.


# 1.26 18-Dec-1999 espie

NIL, NILGNODE, etc, are only glorified NULL.
Get rid of them.

Get rid of list.h, nothing uses it anyway.


# 1.25 18-Dec-1999 espie

make does not use circular lists, get rid of the extra weight.


# 1.24 16-Dec-1999 espie

Var_Subst is actually two distinct functions folded into one:
split the function specific to for.c out, and give them more sensible
arguments at the same time.

This makes .for loop handling more efficient, as we have some heuristic
to evaluate the size of the buffer needed...


# 1.23 16-Dec-1999 espie

Allocate buffers as static data structures.
This cuts down quite a lot of malloc, since in actual use,
buffer usage is mostly static.


# 1.22 16-Dec-1999 espie

Remove unneeded extraneous zeros at the end of buffers.

Actually, one of these needs to be there, because of two bugs in cond.c


# 1.21 16-Dec-1999 espie

Split Buf_GetAll into Buf_Retrieve/Buf_Size.
(idiotic to retrieve size every time when it's used half the time)


# 1.20 16-Dec-1999 espie

Start cleaning up buf.c in earnest.

- Buf_Discard is only used to remove all the bytes in a buffer,
replace with Buf_Reset,
- buffer values are not read unless accessed first through Buf_GetAll,
no need to null-terminate it at every point.
- Buf_Expand need not check if the expansion is needed. That's Buf_AddChar
and Buf_AddChars responsability (otherwise, Buf_AddChar checks twice)
- Buf_Overflow only handles overflow. Adding the character is done in
every case anyway.


# 1.19 09-Dec-1999 espie

Introduce `common usage' buf patterns and use them.


# 1.18 06-Dec-1999 espie

Extra parameter no longer needed, ditch.


# 1.17 06-Dec-1999 espie

Instead of retrieving var values from the environment again and again,
it is much better to keep them in the global context, marked read-only.

This also makes the next simplification possible, since var values need no
longer be free'd by client code.

(reviewed by ho@, like other patches)


# 1.16 06-Dec-1999 espie

Clean up buffers interface somewhat:

- buf.c deals exclusively with chars. Be explicit about it, and remove
extraneous dumb casts to char (can hide real type errors).
- buffer sizes are size_t. Note that bp->left can never become NULL.
- Buf_GetAll is happy with a NULL pointer for the size, remove unneeded
extra pointers.
- Propagate size_t to all places where buffer functions are used.


# 1.15 11-Nov-1999 espie

Kill Str_FindSubString, it's strstr.


# 1.14 10-Nov-1999 espie

Turn on strict-prototypes, add missing prototypes.
Move main prototype to main.c, as this is not used
from any other file.

Close open bug.


# 1.13 06-Nov-1999 espie

Bug-fix: when expanding a specific variable v in $A,
check that v is PRECISELY A.

Other BSDs, take notice.


Revision tags: OPENBSD_2_6_BASE
# 1.12 28-Sep-1999 espie

Fix
.if defined(VAR) && ${VAR:m}

cond.c has special code (set err to 0) to tell VarParse it shouldn't care
if the variable is not defined.

But this was not completely added, namely the path that deals with
modifiers was blissfully unaware of that.


# 1.11 25-Sep-1999 espie

Add :L/:U modificators (lowercase/uppercase)
To use to get ports building more user-friendly.


Revision tags: OPENBSD_2_5_BASE
# 1.10 05-Dec-1998 espie

Modifications from netbsd:
- don't interfere with MACHINE/MACHINE_ARCH defines for bootstrap
- type clean-up, time_t, and printing `unknown' ints
- fix TARGET/MEMBER bug in archive rules
- memmove...
- cleaner Error handler.
- reentrant brk_string
- .MAKE env variable
- preliminary scaffolding for .NOPATH

Other improvements:
- efree
- shellneed streamlined
- display Stop in .CURDIR after an error.
- document most features and misfeatures.
- add a few OpenBSD notes to the tutorial.


Revision tags: OPENBSD_2_4_BASE
# 1.9 23-Jul-1998 deraadt

portable bootstrap thing; lidl@eng.us.uu.net


Revision tags: OPENBSD_2_3_BASE
# 1.8 30-Mar-1998 deraadt

Y2K fixes from Andreas.Gunnarsson@emw.ericsson.se; culled from various places


# 1.7 18-Dec-1997 deraadt

for the test following test case, do not output FOOBAR=bar (should be FOOBAR=)
problem reported by mark@thuvia.demon.co.uk

FOO=
FOOBAR=$(FOO:=bar)


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.6 01-Apr-1997 millert

Sync with NetBSD (mostly by christos initial substitution/regexp from Der Mouse)

- fix the variable substitution code in make [PR/2748]
1. change s/a/b/ so that it substitutes the first occurance of the
pattern on each word, not only the first word.
2. add flag '1' to the variable substitution so that the substitutions
get performed only once.

***THIS IS AN INCOMPATIBLE CHANGE!***

Unfortunately there was no way to make things consistent without
modifying the current behavior. Fortunately none of our Makefiles
depended on this.

OLD:

VAR = aa1 aa2 aa3 aa4

S/a/b/ = ba1 aa2 aa3 aa4
S/a/b/g = bb1 bb2 bb3 bb4

NEW:
VAR = aa1 aa2 aa3 aa4

S/a/b/ = ba1 ba2 ba3 ba4
S/a/b/1 = ba1 aa2 aa3 aa4
S/a/b/g = bb1 bb2 bb3 bb4
S/a/b/1g = bb1 aa2 aa3 aa4
- add regexp variable substitution via 'C/foo/bar/' [PR/2752]
- add variable quoting via the ${VAR:Q} modifier. This is useful when running
recursive invocations of make(1):

make VAR=${VAR:Q}

will always work... (This may prove useful in the kernel builds...) [PR/2981]
- BSD did not traditionally have <sys/cdefs.h>; use BSD4_4 instead and include
<sys/param.h> to grab it.
- Don't compile the regex code if MAKE_BOOTSTRAP (from gwr)
- Use explicit .c.o rule in Makefile.boot so that the bootstrap process works.
- Use only integral types in procedure arguments. [buf.c buf.h]
- Include <stdlib.h> to get getenv() prototype on SVR4
- if __STDC__ -> ifdef __STDC__ to appease SVR4
- Define const and volatile for non __STDC__
- Implement snprintf() and vsnprintf() for non BSD4_4 systems.
- Make $MACHINE_ARCH settable from the environment.
- Fix .USE directive problems: (reported by cgd)
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.
- Add a .MADE directive to indicated that the children of a target are
up-to-date, even when they are not. This is to simulate our current
make install behavior with proper dependencies.
- Fix problems in the RE substitution error handling.
- Locate all the children of a node marked as MADE.
- Do not compile-in ${MACHINE} (as per NetBSD PR#3386)
- Disable globbing for targets/dependencies when POSIX is defined.
- Fix globbing so that patterns that don't have a matching number of [] or {}
don't get expanded. (before the [ case got expanded to nothing!) This is
disabled.
- Make sure that the children of nodes that are marked .MADE, are marked
UPTODATE and their timestamps are consistent.
- Don't disable wildcards completely; they are used by other Makefiles.


# 1.5 30-Nov-1996 millert

Sync with NetBSD:
- 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.
- Fix NetBSD PR #2930: declare missing variable.


Revision tags: OPENBSD_2_0_BASE
# 1.4 02-Sep-1996 briggs

Sync up with NetBSD:
(christos)
Fix bug reported by Greg Hudson where leaf (source only) nodes were
referenced only by their basename and not by their full pathname. This
breaks when .PATH or MAKEOBJDIR are used. There might be Makefiles
around that try to work around this bug by prepending ${.CURDIR} to
the sources, and they should be found and fixed. Also a lot of the gunk
in suff.c that was attempting to work around the same problem could be
removed.
(christos)
- Move -D flags from Makefile to config.h and explain what they do. Add
-Wall -Wno-unused to CFLAGS. Add new define SYSVVARSUB to enable SysV
style variable substitutions and enable them.
- Add SunOS style command substitutions via SUNSHCMD
- Fix core dump with '{variable = value'
(christos)
Fix bug where make will always exit with 0, even when one or more
parallel jobs failed. (Only affects parallel make code)
(christos)
Protect __P from being multiply defined (for systems that already
define it)
(christos) Add strdup() since ultrix is missing it.
From Larry Schwimmer <rosebud@cyclone.Stanford.EDU>
(christos) Add estrdup(), a checked version of strdup and use it.
(christos) Recognize SVR4 style long filename entries in archives.
(thorpej) Tidy up some RCS ids a bit.


# 1.3 26-Jun-1996 deraadt

rcsid


# 1.2 14-Dec-1995 deraadt

from christos@netbsd:
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.
- Turn compat mode on by default. It gets turned off when the -j without
the -B flag is specified. [Thus you can use -j 1 to turn it off].
- Fix malloc -> emalloc as Gordon noted.
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.

from cgd@netbsd:
pull in make.h. (PAlloc() now uses emalloc(), which is prototyped in
make.h. If the prototype is not in scope on the Alpha, I see lots
of "cast to pointer from integer of different size" warnings.)


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.103 22-Dec-2019 espie

we also have "VAR_*" constants in parsevar with totally different meanings.
Rename to avoid ambiguity
- VAR_IS_SHELL (in var.c): the SHELL variable, which has specific
POSIX semantics
- VAR_SHELL (in parsevar.c): assign the result of running the command
to the variable.

no actual code change


# 1.102 21-Dec-2019 espie

yet another mostly cosmetic diff
- rename context into localvars, which is more meaningful and less generic
- instantiate the random rumbling at the start of gnode.h with actual
variable names
- explain and group gnode.h variables better
- make some comments terser/more meaningful

okay millert@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.101 23-Oct-2016 espie

add !!=
feedback and okay millert@


# 1.100 14-Oct-2016 natano

Implement the ${<D} and ${<F} variables, as documented in the manual.
They are equivalent to ${<:H} and ${<:T} repectively, however the former
variants are more portable, as they are understood by GNU, FreeBSD and
NetBSD make too.

absence of those variables reported by Dario Niedermann <dnied at tiscali.it>
ok millert espie


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.99 27-Sep-2015 guenther

Mark all the error printing functions as printf-like; fix two format
mismatches this revealed

ok espie@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.98 12-May-2014 espie

adjust to ohash being in libutil now, and to the interface changes.
fix potential integer overflows in memory allocation (mostly for pedagogical
purposes, these are unlikely to overflow in practice)
move the rest of lst.lib stuff into its own directory.


Revision tags: OPENBSD_5_5_BASE
# 1.97 29-Jan-2014 espie

I'm a bit dyslexic. Found out by Jan Klemkow. Thanks.


# 1.96 06-Jan-2014 espie

this actually requires a comment. I would never have figured it out if
it wasn't for the arm error.


# 1.95 06-Jan-2014 espie

fix error messages, avoid dereferencing null pointers.
- the code becomes too indented, pull it into a separate function
- add an extra hint, the current_gnode.
- specifically, variables may be expanded during
target: prereq solving in Suff_FindDeps, this is after parsing,
not during command execution, and the only actual indication with have is
that we're resolving a prereq of.

(this ought to fix mk35, and partially solve mk34)


Revision tags: OPENBSD_5_4_BASE
# 1.94 23-Apr-2013 espie

remove TIMESTAMP abstraction layer, prodded by theo.
while there, clean up includes.
use strtoll for ar timestamps (pretty much unused in reality, more
standard conforming than anything)

use idea from Todd to adapt to time_t being 32 bits OR 64 bits
(pedantically correct: INT_MIN would work just fine up to 1910 or so...)

okay millert@, gone thru a make build.


Revision tags: OPENBSD_5_3_BASE
# 1.93 15-Feb-2013 espie

turns out if a line ends with a $, the var module will run off the cliff
while expanding it.
shows up very prominently with MALLOC_OPTIONS=S

Problem found by jasper@

okay'd by jasper@ and kind-of duh'd by miod@


# 1.92 09-Oct-2012 espie

new interface: look in command lines for variables that indicate a list of
targets is actually separate targets.


# 1.91 02-Oct-2012 espie

more changes, discussed and tested by various people.
- put back some job control, turns out it's necessary when we don't run a
shell.
- zap old #ifdef CLEANUP code... probably doesn't even compile.
- kill most of the OP_LIB code. Just keep a wee little bit for compatibility
(deprecated .LIBS and .INCLUDES, warns for weird dependencies instead of
erroring out).
- much improved debugging and -p output: sort variables, targets, rules,
output stuff in a nicer format mimicing input.
- better error message when no command is found, explain where the target comes from.
- sort final error list by file.
- show system files in errors as <bsd.prog.mk>
- reincorporate random delay, that was dropped
- optimize siginfo output by not regenerating the whole string each time.
- finish zapping old LocationInfo field that's no longer used.


# 1.90 25-Aug-2012 espie

- make wrong variable specs (unterminated) parse errors.
- add info to be able to pinpoint parse errors at runtime.
- let job runners abort when a parse error happens while expanding a variable
during execution
- fix an infinite loop when compiling without FEATURE_RECVARS.

okay millert@, krw@
the very few errors found out by this (less than 10 over src/X/ports)
fixed trivially beforehand, as requested by deraadt@


Revision tags: OPENBSD_5_2_BASE
# 1.89 22-Mar-2012 espie

minor cleanup: error messages include lineno and fileno together, so
recognize that and create a struct Location_ for it.

mostly from Jonathan Calmels, a few nits from me.

okay otto@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.88 20-Jun-2011 espie

fix a segfault found by jasper@
ok miod@, otto@, jasper@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.87 19-Jul-2010 espie

Correct $OpenBSD$ stuff


# 1.86 25-Apr-2010 espie

pure whitespace cleanup


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.85 13-May-2009 espie

fix loopvar debug prints. Issue reported by naddy@


Revision tags: OPENBSD_4_5_BASE
# 1.84 09-Nov-2008 tobias

typo fixed (overriden -> overridden)

ok espie, jmc


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.83 17-Nov-2007 espie

simplify dynamic variable handling a great deal:
first remove all usage of Varq_Append by building the string directly.
then replace `common' handling with specialized handling for dynamic
strings (since they no longer need a buffer). Finally, identify the place
where the variable value needs to be copied because it's going to be free'd
or erased soon, and finally, use simple char* pointers.

Shaves about 80 bytes off every gnode structure, and kills quite a few
unnecessary malloc()s as well.


# 1.82 04-Nov-2007 espie

prevent gcc from complaining


# 1.81 03-Nov-2007 deraadt

fix some lint FALLTHROUGH


# 1.80 17-Sep-2007 espie

more blank space removal


# 1.79 17-Sep-2007 espie

more zap spaces


# 1.78 17-Sep-2007 espie

zap more spaces at end of line


# 1.77 17-Sep-2007 espie

kill extra spaces at end of line


# 1.76 16-Sep-2007 espie

remove warnings


# 1.75 16-Sep-2007 espie

remove dead code: #define RECHECK is always on


Revision tags: OPENBSD_4_2_BASE
# 1.74 30-Jul-2007 espie

introduce a Var_Substi to substitute on intervals.
Since we don't really know how to change Var_Subst and dependent functions,
we cheat, and copy the string to a buffer instead.

Clean-up the parser a bit: reorganize the include files lookup function:
introduce a resolve_include_filename function that figures out the full name
of the file, introduce a handle_include_file that does all the include file
handling, and rename the functions into handle_xxx_include, so that we
can remove most comments.

Rename ParseIsCond into handle_bsd_command, cut most of its code into
constituent functions.

Semantic changes:
- follow the rules that, if an optional construct does not parse correctly,
then it's not a real extension, and give the normal parser a chance to figure
it out. If the syntax checks out, semantic errors ARE real errors.
- allow variables to not be defined in include file names, no reason not to.

okay miod@


# 1.73 30-Jul-2007 espie

everywhere except in Var_Parse, we always add/append variables to the
VAR_GLOBAL context, so make it the common case: rename the basic functions
to Var_Set_with_ctxt/Var_Append_with_ctxt, define Var_Set and Var_Append
as macros that specify VAR_GLOBAL, and use these.

okay miod@


# 1.72 30-Jul-2007 espie

now that it's clean enough, one can extract some common code from
Var_Parse and Var_ParseSkip (the code that figures out the variable name
up to eventual modifiers).

okay miod@


# 1.71 24-Jul-2007 espie

zap unused variable


# 1.70 24-Jul-2007 espie

simplify computations in the var module: instead of advancing a char *
and keeping track of a length, we just advance the char *, and ditch
the length. We can still get the length at the end of the top-level
functions to satisfy existing interfaces.

Much simpler code, less error-prone.

Okay millert@


# 1.69 24-Jul-2007 espie

move the code that grabs a value in Var_Parse in its own function,
get_expanded_value.

Extend the code a bit to be much more thorough in case of a recursive
expansion: shows exactly the cycle of variable names involved.

okay millert@


# 1.68 24-Jul-2007 espie

change Var_ParseSkip API to increment the position instead of returning a
length, simplifies code.

(warns a bit, symptom of some further issues to fix).

okay millert@


# 1.67 22-Jul-2007 espie

make sure loop variables use their own buffers.
(causes .for loops to give weird results very infrequently, memory handling
was slightly wrong, but not enough to break things thoroughly).
noticed by naddy@


# 1.66 20-Jul-2007 espie

big clean-up patch:
- rename a few functions in var.c to names that make more sense.
- introduce Var_Deletei because it makes more sense.
- rewrite .for loops to use a local LoopVar construct to avoid looking up more
stuff.
- reformat var.c to near K&R
- rewrite most comments in var.c

shown to a few people. millert@ gave me his okay since it passes through
ports correctly.


# 1.65 20-Jul-2007 espie

reorder stuff in var.c so that the next patch is more readable.


# 1.64 08-Jul-2007 espie

rename variable to errorIsOkay. What does oldVars mean anyway ?


# 1.63 08-Jul-2007 espie

missed part: add check to avoid poison checking inexistent local vars,
and do for loops for real.


# 1.62 08-Jul-2007 espie

A set of big related changes. okay millert@, tested further by kettenis@
and matthieu@

This all revolves around putting ALL global variables into one single big
hash, and using flags. This removes some impossible to understand stuff,
like old varfind, and allows for some nice stuff.
- each time we reference a global variable, we create it, possibly as a dummy
variable.
- each time we go to the environment, we remember it, thus we no longer go
back to it.

Lists of dependant changes:
- isolate changes to oldVars and checkEnvFirst.
- remove VAR_CMD and VAR_GLOBAL contexts. The only distinction is in parsevar.
Split Parse_DoVar into Parse_DoVar and Parse_CmdlineVar
- rework var modules around obtain_global_var, observe flags in various
functions like Var_Value and Var_Seti.
- Var_Seti/Var_Appendi are almost the same code, use that internally.
- add magic to handle the very special SHELL variable.
- introduce Var_Definedi for the cases where we don't want the actual
value, to simplify tests.
- add keyword .poison, parse it and set global flags accordingly.
- do poison_checks where needed.
- document poison.
- in for loops, set variable temporarily, so that Var_SubstVar will also
substitute it in varmodifiers expressions.


Revision tags: OPENBSD_4_1_BASE
# 1.61 02-Jan-2007 espie

VarDelete is no longer used by list functions, so let it do type-checking
correctly.


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.60 20-Jan-2006 espie

use stdint.h where appropriate. okay millert@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.59 07-Apr-2004 espie

ISO function declarations, trim a few comments, rename a few variables to
more explicit/more consistent names.

okay otto@


Revision tags: OPENBSD_3_5_BASE
# 1.58 07-Oct-2003 fgsch

- check if result is valid before using it.
- correctly set *freePtr, not freePtr.
input and ok espie@.


Revision tags: OPENBSD_3_4_BASE
# 1.57 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.56 05-Jun-2002 espie

tweak quick_lookup for a faster path.
okay millert@


Revision tags: OPENBSD_3_0_BASE OPENBSD_3_1_BASE
# 1.55 23-May-2001 espie

Mostly clean-up:
- cut up those huge include files into separate interfaces for all modules.
Put the interface documentation there, and not with the implementation.
- light-weight includes for needed concrete types (lst_t.h, timestamp_t.h).
- cut out some more logically separate parts: cmd_exec, varname, parsevar,
timestamp.
- put all error handling functions together, so that we will be able to
clean them up.
- more systematic naming: functioni to handle interval, function to handle
string.
- put the init/end code apart to minimize coupling.
- kill weird types like ReturnStatus and Boolean. Use standard bool (with a
fallback for non-iso systems)
- better interface documentation for lots of subsystems.

As a result, make compilation goes somewhat faster (5%, even considering
the largish BSD copyrights to read). The corresponding preprocessed
source goes down from 1,5M to 1M.

A few minor code changes as well: Parse_DoVar is no longer destructive.
Parse_IsVar functionality is folded into Parse_DoVar (as it knows what an
assignment is), a few more interval handling functions. Avoid calling
XXX_End when they do nothing, just #define XXX_End to nothing.

Parse_DoVar is slightly more general: it will handle compound assignments
as long as they make sense, e.g., VAR +!= cmd
will work. As a side effect, VAR++=value now triggers an error
(two + in assignment).
- this stuff doesn't occur in portable Makefiles.
- writing VAR++ = value or VAR+ +=value disambiguates it.
- this is a good thing, it uncovered a bug in bsd.port.mk.

Tested by naddy@. Okayed millert@. I'll handle the fallback if there is
any. This went through a full make build anyways, including isakmpd
(without mickey's custom binutils, as he didn't see fit to share it with me).


# 1.54 15-May-2001 espie

Don't go beyond end of string.
Handles unterminated variables, and fixes regression test #10


# 1.53 03-May-2001 espie

Synch with my current work.
Numerous changes:
- generate can build several tables
- style cleanup
- statistics code
- use variable names throughout (struct Name)
- recursive variables everywhere
- faster parser (pass buffer along instead of allocating multiple copies)
- correct parser. Handles comments everywhere, and ; correctly
- more string intervals
- simplified dir.c, less recursion.
- extended for loops
- sinclude()
- finished removing extra junk from Lst_*
- handles ${@D} and friends in a simpler way
- cleaned up and modular VarModifiers handling.
- recognizes some gnu Makefile usages and errors out about them.

Additionally, some extra functionality is defined by FEATURES. The set of
functionalities is currently hardcoded to OpenBSD defaults, but this may
include support for some NetBSD extensions, like ODE modifiers.

Backed by miod@ and millert@, who finally got sick of my endless patches...


Revision tags: OPENBSD_2_9_BASE
# 1.52 02-Mar-2001 espie

Use the ohash_* that's now in libc.


# 1.51 07-Dec-2000 espie

Forgot to copy end of name in nested variable names, so that
${BC_${A}} worked but not ${${A}_BC}.
Noticed by fries@


# 1.50 24-Nov-2000 espie

Take advantage of VarModifiers_Apply, which can parse a variable spec
and expand it directly, without needing a variable context.

Use it in Var_SubstVar, so that .for loops values don't need to be entered
into any context nor looked up.

This speeds up .for loops some, and avoids nasty variable capture
side-effects.

Ok'd millert@, miod@, naddy@ (naddy spotted a problem with the first
version of that change).


Revision tags: OPENBSD_2_8_BASE
# 1.49 13-Oct-2000 espie

esetenv: does a setenv and bails out if error.


# 1.48 14-Sep-2000 espie

Some systematic clean-up.
- UNUSED macro that expands to __attribute__((unused)) for gcc
- move rcsid around so that they can be tagged UNUSED.
- activate -Wunused.
- use UNUSED instead of kludgy junk for function arguments.
- add extern to all extern prototypes.
- update comments in lst.h.
- clean up var.c a little bit, constifying arguments, updating comments...


# 1.47 21-Aug-2000 espie

Var_Append needs to set v for DEBUG(VAR) to work.
Obvious fix.
Problem reported by Gregory Steuck, thanks a lot !


# 1.46 18-Jul-2000 espie

Handle MAKEFLAGS variation mandated by POSIX.

Code to pass variable definitions to submakes through make flags.
Not activated yet, need to fix src/ first.


# 1.45 17-Jul-2000 espie

parse embedded variable specs, e.g., ${VAR_${SUB}}

- need braces, as we don't want to change what $$A means,
- this assumes this kind of construct is very infrequent, thus
this does NOT copy the variable name needlessly.
- the expansion code is in a separate function for clarity.

Reviewed by miod@, as previous patches.


# 1.44 17-Jul-2000 espie

- let VarModifiers_Apply accept NULL string gracefully,
- simplify Var_Parse: use varfind, then leverage on the result
to recognize `special case' dynamic parsing.

VarModifiers_Apply need to be called on NULL strings, to be able to parse
modifiers applied to non-existent variables.

(Alternately, we could call VarModifiers_Apply on a dummy string, but
this is less efficient).


# 1.43 17-Jul-2000 espie

Major unobfuscation: split var modifiers handling to a separate file.
This does finally make var handling somewhat readable.


# 1.42 17-Jul-2000 espie

separate modifiers handling from Var_Parse into a separate
VarModifiers_apply function.

for env lookup, create variable structure first, so that we can get away
without terminating the variable name in main Var_Parse.


# 1.41 17-Jul-2000 espie

This does replace Str_Match with a better routine, which handles negated
intervals, and \\ in intervals.

Accordingly, var.c no longer needs to copy the :Marg to replace \: with :

We don't use fnmatch(3) because of various optimizations which are harder
to achieve in a generic setting.

Also add regression suite for the Str_Match function.


# 1.40 17-Jul-2000 espie

Constify a few functions, propagated from VarModify.
Replace a few int -> size_t

Reviewed by miod@


# 1.39 17-Jul-2000 espie

- recognize that FIND_CMD and FIND_GLOBAL are always used together,
- introduce VarFind_interval function. This avoids having to copy variable
names in VarParse,
- expose internals of VarFind* function (not used yet, but this will avoid
multiple lookups in VarParse),
- constify a few functions.

Reviewed by miod@


# 1.38 23-Jun-2000 espie

This is the speed-up patch, which doubles make speed (almost).

Use the open hashing functions for global contexts instead of List in
var.c.

All the preliminary work to trim down local contexts means that we don't
suffer from the heavy initialization work that a hash table entails.

There is some make kludgery to:
- build the hashing functions as a library,
- recreate hashconsts.h, even if make depend was not invoked.

One point of the hashing scheme written was to separate the computation
of the hash function, and the hash lookup itself. This is very convenient
for make, because of those pesky special variables. hashconsts.h is there
to pre-hash the correct values, which replaces a few expensive string
comparisons with quick hash value comparisons, followed by one expensive
string comparison. The modulus MAGICSLOTS chosen in the Makefile is
ad-hoc: it is small enough to write a small switch without collision,
and will need changing if the hash function changes...

The function quick_lookup is the most important:
it either returns an index, for a local variable, or it does compute a
hashing value, and returns -1.

Another somewhat controversial decision is the use of string intervals.
This avoids either copying a string, or twiddling with a byte for cases
such as ${VAR}.

Finally, the variable name is stored within the variable itself. Since
a given variable name never changes, this makes sense. All that was needed
was a hash library with support for this. Note that the hashing table
holds only a variable pointer AND the corresponding hashing value, WITHOUT
a modulo hashtablesize. Two reasons:
- hash resizes can be done faster, without having to recompute hashing values.
- locality of access. The hash table fits into memory without problem. Once
a candidate slot is found, we check the complete hashing value. Probability
of a collision is very small (32 bits...). So bringing up the whole
variable in memory at once is good: the name will almost always match, in
which case we want the variable value as well, so it makes sense to put
them together.

The ohash functions implement open hashing, as described in Knuth, but with
a variable table size. Choosing powers of 2 sizes does not yield more
collisions, but it makes the hashing scheme much simpler. The thresholds at
which to expand/shrink the tables seem to work well in practice. The
default sizes were chosen such that the tables hardly ever shrink or expand
anyways (though I've tried with smaller/larger sizes to verify that the
shrinking/expanding worked correctly): larger Makefiles hold roughly
500/600 variables, which fits without trouble into a 1024-sized variable.

Disregard #ifdef STATS_HASH, this is some internal scaffolding I'm using
to measure make performance.

The only known issue with open-hashing is that deletions cannot create
empty slots, but do leave slots marked as `occupied once' so that lookup
works. We use a well-known optimization which records those pseudo-empty
slots while looking up values. If the value is not found, the pseudo-empty
slot is returned to be filled. If the value is found, it is swapped with
the pseudo-empty slot. This is an improvement in both cases, since this
shortens the length of lookup chains, eventually pushing the pseudo-empty
slots to the end.

Reviewed by millert@ and miod@


# 1.37 23-Jun-2000 espie

This patch separates local contexts from global contexts for good.
Apart from a few casts, VAR_GLOBAL and friends are separate
data structures, so we use a small array for local variables.

We also junk allVars, since TargFreeGN can release local nodes,
and var.c has explicit lists for its variables already.

Reviewed millert@ and miod@.


# 1.36 23-Jun-2000 espie

In various places, VAR_CMD is used to actually mean `no real context',
since lookup will start with VAR_CMD in any case.
This fixes VarFind and Var_Parse to handle ctxt == NULL correctly, and
replace those confusing VAR_CMD with proper NULL pointers.

This patch also handles three small details:
- .CURDIR is necessarily set in VAR_GLOBAL,
- suffix handling for archives copies two hard-coded variables, for
which it can use a quick path,
- typos in TargFreeGN.

Reviewed millert@, miod@.


# 1.35 23-Jun-2000 espie

Once those special variable are taken care of, other Var functions can take
the GNode's context directly. We rename that special Lst to `SymTable *'
in prevision of things to come.

Along the line, we lose the special GNodes affected to VAR_CMD, VAR_GLOBAL,
VAR_ENV, which become simple Lsts... This is not a problem, except when
getting to a context's name for debugging (handled very nicely by
offsetof).

Again, this is a preparatory patch, which does not gain anything except
for cleaning up issues...

Reviewed by millert@ and miod@, like the previous patch


# 1.34 23-Jun-2000 espie

Start of variable fixes and speed-ups.

This patch may seem a bit non-sensical at first. It simply introduces some
new interface. Specifically, recognizes that some variable names
(.TARGET/$@, .OODATE/$?, .ALLSRC/$>, .IMPSRC/$<, .PREFIX/$*, .ARCHIVE/$!,
.MEMBER/$%) are `special' (the actual variables which are local to a
target, e.g. GNode).

Currently, The Varq functions (for Varquick access) are only stubs to the
normal functions.

This fixes a very important detail before proceeding to turn variable lists
into hash tables: if every GNode holds a hash table, initialization times
for those will be very costly. But generic GNodes only hold those seven
special variables... which can be stored directly into a small array;
the only general cases are the environment, the command line and
global variables.


# 1.33 17-Jun-2000 espie

This patch introduces a distinction between
Lst_Init (constructor) and Lst_New (allocation + construction)
Lst_Destroy (destructor) and Lst_Delete (deallocation + destruction),
and uses that to turn most dynamic allocation of lists (Lst pointers)
into static structures (LIST).

Most of this is mundane, except for allGNs in targ.c, where the code must
be checked to verify that Targ_Init is called soon enough.

Lst_New is a temporary addition. All lists will soon be static.

Reviewed by millert@, like the previous patch.


# 1.32 10-Jun-2000 espie

Clean-up patch: use `void *' instead of old-fashioned ClientData/Address.


# 1.31 10-Jun-2000 espie

Thus, Lst_ForEach no longer needs returning a status.
In fact, it can become a macro based on Lst_ForEachFrom.
This also introduces Lst_Every, as a shortcut for the very common case where
Lst_ForEach does not need any user data.

Finally, make consistent use of a few function typedefs, instead of having
explicit void (*)(Lst) arguments all over the place.


Revision tags: OPENBSD_2_7_BASE
# 1.30 26-Mar-2000 espie

Remove idiotic, braindead casts T* -> void*
They serve no purpose, except hiding potential bugs.

In particular, remove (ClientData) cast from macro, showing potentially
troublesome use of Hashes to store time_t.


# 1.29 08-Jan-2000 espie

Finish changing all Var_Parse arguments to size_t. Thanks to millert@
for reminding me.


# 1.28 19-Dec-1999 espie

Rearrange Lst_Find interface to conform better with other functions.


# 1.27 18-Dec-1999 espie

Nothing ever checks ReturnStatus on Lst_Insert, Lst_Append, Lst_AtFront,
Lst_AtEnd, Lst_Concat, Lst_Remove, Lst_Replace.

Don't bother returning one.


# 1.26 18-Dec-1999 espie

NIL, NILGNODE, etc, are only glorified NULL.
Get rid of them.

Get rid of list.h, nothing uses it anyway.


# 1.25 18-Dec-1999 espie

make does not use circular lists, get rid of the extra weight.


# 1.24 16-Dec-1999 espie

Var_Subst is actually two distinct functions folded into one:
split the function specific to for.c out, and give them more sensible
arguments at the same time.

This makes .for loop handling more efficient, as we have some heuristic
to evaluate the size of the buffer needed...


# 1.23 16-Dec-1999 espie

Allocate buffers as static data structures.
This cuts down quite a lot of malloc, since in actual use,
buffer usage is mostly static.


# 1.22 16-Dec-1999 espie

Remove unneeded extraneous zeros at the end of buffers.

Actually, one of these needs to be there, because of two bugs in cond.c


# 1.21 16-Dec-1999 espie

Split Buf_GetAll into Buf_Retrieve/Buf_Size.
(idiotic to retrieve size every time when it's used half the time)


# 1.20 16-Dec-1999 espie

Start cleaning up buf.c in earnest.

- Buf_Discard is only used to remove all the bytes in a buffer,
replace with Buf_Reset,
- buffer values are not read unless accessed first through Buf_GetAll,
no need to null-terminate it at every point.
- Buf_Expand need not check if the expansion is needed. That's Buf_AddChar
and Buf_AddChars responsability (otherwise, Buf_AddChar checks twice)
- Buf_Overflow only handles overflow. Adding the character is done in
every case anyway.


# 1.19 09-Dec-1999 espie

Introduce `common usage' buf patterns and use them.


# 1.18 06-Dec-1999 espie

Extra parameter no longer needed, ditch.


# 1.17 06-Dec-1999 espie

Instead of retrieving var values from the environment again and again,
it is much better to keep them in the global context, marked read-only.

This also makes the next simplification possible, since var values need no
longer be free'd by client code.

(reviewed by ho@, like other patches)


# 1.16 06-Dec-1999 espie

Clean up buffers interface somewhat:

- buf.c deals exclusively with chars. Be explicit about it, and remove
extraneous dumb casts to char (can hide real type errors).
- buffer sizes are size_t. Note that bp->left can never become NULL.
- Buf_GetAll is happy with a NULL pointer for the size, remove unneeded
extra pointers.
- Propagate size_t to all places where buffer functions are used.


# 1.15 11-Nov-1999 espie

Kill Str_FindSubString, it's strstr.


# 1.14 10-Nov-1999 espie

Turn on strict-prototypes, add missing prototypes.
Move main prototype to main.c, as this is not used
from any other file.

Close open bug.


# 1.13 06-Nov-1999 espie

Bug-fix: when expanding a specific variable v in $A,
check that v is PRECISELY A.

Other BSDs, take notice.


Revision tags: OPENBSD_2_6_BASE
# 1.12 28-Sep-1999 espie

Fix
.if defined(VAR) && ${VAR:m}

cond.c has special code (set err to 0) to tell VarParse it shouldn't care
if the variable is not defined.

But this was not completely added, namely the path that deals with
modifiers was blissfully unaware of that.


# 1.11 25-Sep-1999 espie

Add :L/:U modificators (lowercase/uppercase)
To use to get ports building more user-friendly.


Revision tags: OPENBSD_2_5_BASE
# 1.10 05-Dec-1998 espie

Modifications from netbsd:
- don't interfere with MACHINE/MACHINE_ARCH defines for bootstrap
- type clean-up, time_t, and printing `unknown' ints
- fix TARGET/MEMBER bug in archive rules
- memmove...
- cleaner Error handler.
- reentrant brk_string
- .MAKE env variable
- preliminary scaffolding for .NOPATH

Other improvements:
- efree
- shellneed streamlined
- display Stop in .CURDIR after an error.
- document most features and misfeatures.
- add a few OpenBSD notes to the tutorial.


Revision tags: OPENBSD_2_4_BASE
# 1.9 23-Jul-1998 deraadt

portable bootstrap thing; lidl@eng.us.uu.net


Revision tags: OPENBSD_2_3_BASE
# 1.8 30-Mar-1998 deraadt

Y2K fixes from Andreas.Gunnarsson@emw.ericsson.se; culled from various places


# 1.7 18-Dec-1997 deraadt

for the test following test case, do not output FOOBAR=bar (should be FOOBAR=)
problem reported by mark@thuvia.demon.co.uk

FOO=
FOOBAR=$(FOO:=bar)


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.6 01-Apr-1997 millert

Sync with NetBSD (mostly by christos initial substitution/regexp from Der Mouse)

- fix the variable substitution code in make [PR/2748]
1. change s/a/b/ so that it substitutes the first occurance of the
pattern on each word, not only the first word.
2. add flag '1' to the variable substitution so that the substitutions
get performed only once.

***THIS IS AN INCOMPATIBLE CHANGE!***

Unfortunately there was no way to make things consistent without
modifying the current behavior. Fortunately none of our Makefiles
depended on this.

OLD:

VAR = aa1 aa2 aa3 aa4

S/a/b/ = ba1 aa2 aa3 aa4
S/a/b/g = bb1 bb2 bb3 bb4

NEW:
VAR = aa1 aa2 aa3 aa4

S/a/b/ = ba1 ba2 ba3 ba4
S/a/b/1 = ba1 aa2 aa3 aa4
S/a/b/g = bb1 bb2 bb3 bb4
S/a/b/1g = bb1 aa2 aa3 aa4
- add regexp variable substitution via 'C/foo/bar/' [PR/2752]
- add variable quoting via the ${VAR:Q} modifier. This is useful when running
recursive invocations of make(1):

make VAR=${VAR:Q}

will always work... (This may prove useful in the kernel builds...) [PR/2981]
- BSD did not traditionally have <sys/cdefs.h>; use BSD4_4 instead and include
<sys/param.h> to grab it.
- Don't compile the regex code if MAKE_BOOTSTRAP (from gwr)
- Use explicit .c.o rule in Makefile.boot so that the bootstrap process works.
- Use only integral types in procedure arguments. [buf.c buf.h]
- Include <stdlib.h> to get getenv() prototype on SVR4
- if __STDC__ -> ifdef __STDC__ to appease SVR4
- Define const and volatile for non __STDC__
- Implement snprintf() and vsnprintf() for non BSD4_4 systems.
- Make $MACHINE_ARCH settable from the environment.
- Fix .USE directive problems: (reported by cgd)
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.
- Add a .MADE directive to indicated that the children of a target are
up-to-date, even when they are not. This is to simulate our current
make install behavior with proper dependencies.
- Fix problems in the RE substitution error handling.
- Locate all the children of a node marked as MADE.
- Do not compile-in ${MACHINE} (as per NetBSD PR#3386)
- Disable globbing for targets/dependencies when POSIX is defined.
- Fix globbing so that patterns that don't have a matching number of [] or {}
don't get expanded. (before the [ case got expanded to nothing!) This is
disabled.
- Make sure that the children of nodes that are marked .MADE, are marked
UPTODATE and their timestamps are consistent.
- Don't disable wildcards completely; they are used by other Makefiles.


# 1.5 30-Nov-1996 millert

Sync with NetBSD:
- 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.
- Fix NetBSD PR #2930: declare missing variable.


Revision tags: OPENBSD_2_0_BASE
# 1.4 02-Sep-1996 briggs

Sync up with NetBSD:
(christos)
Fix bug reported by Greg Hudson where leaf (source only) nodes were
referenced only by their basename and not by their full pathname. This
breaks when .PATH or MAKEOBJDIR are used. There might be Makefiles
around that try to work around this bug by prepending ${.CURDIR} to
the sources, and they should be found and fixed. Also a lot of the gunk
in suff.c that was attempting to work around the same problem could be
removed.
(christos)
- Move -D flags from Makefile to config.h and explain what they do. Add
-Wall -Wno-unused to CFLAGS. Add new define SYSVVARSUB to enable SysV
style variable substitutions and enable them.
- Add SunOS style command substitutions via SUNSHCMD
- Fix core dump with '{variable = value'
(christos)
Fix bug where make will always exit with 0, even when one or more
parallel jobs failed. (Only affects parallel make code)
(christos)
Protect __P from being multiply defined (for systems that already
define it)
(christos) Add strdup() since ultrix is missing it.
From Larry Schwimmer <rosebud@cyclone.Stanford.EDU>
(christos) Add estrdup(), a checked version of strdup and use it.
(christos) Recognize SVR4 style long filename entries in archives.
(thorpej) Tidy up some RCS ids a bit.


# 1.3 26-Jun-1996 deraadt

rcsid


# 1.2 14-Dec-1995 deraadt

from christos@netbsd:
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.
- Turn compat mode on by default. It gets turned off when the -j without
the -B flag is specified. [Thus you can use -j 1 to turn it off].
- Fix malloc -> emalloc as Gordon noted.
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.

from cgd@netbsd:
pull in make.h. (PAlloc() now uses emalloc(), which is prototyped in
make.h. If the prototype is not in scope on the Alpha, I see lots
of "cast to pointer from integer of different size" warnings.)


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.101 23-Oct-2016 espie

add !!=
feedback and okay millert@


# 1.100 14-Oct-2016 natano

Implement the ${<D} and ${<F} variables, as documented in the manual.
They are equivalent to ${<:H} and ${<:T} repectively, however the former
variants are more portable, as they are understood by GNU, FreeBSD and
NetBSD make too.

absence of those variables reported by Dario Niedermann <dnied at tiscali.it>
ok millert espie


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.99 27-Sep-2015 guenther

Mark all the error printing functions as printf-like; fix two format
mismatches this revealed

ok espie@


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.98 12-May-2014 espie

adjust to ohash being in libutil now, and to the interface changes.
fix potential integer overflows in memory allocation (mostly for pedagogical
purposes, these are unlikely to overflow in practice)
move the rest of lst.lib stuff into its own directory.


Revision tags: OPENBSD_5_5_BASE
# 1.97 29-Jan-2014 espie

I'm a bit dyslexic. Found out by Jan Klemkow. Thanks.


# 1.96 06-Jan-2014 espie

this actually requires a comment. I would never have figured it out if
it wasn't for the arm error.


# 1.95 06-Jan-2014 espie

fix error messages, avoid dereferencing null pointers.
- the code becomes too indented, pull it into a separate function
- add an extra hint, the current_gnode.
- specifically, variables may be expanded during
target: prereq solving in Suff_FindDeps, this is after parsing,
not during command execution, and the only actual indication with have is
that we're resolving a prereq of.

(this ought to fix mk35, and partially solve mk34)


Revision tags: OPENBSD_5_4_BASE
# 1.94 23-Apr-2013 espie

remove TIMESTAMP abstraction layer, prodded by theo.
while there, clean up includes.
use strtoll for ar timestamps (pretty much unused in reality, more
standard conforming than anything)

use idea from Todd to adapt to time_t being 32 bits OR 64 bits
(pedantically correct: INT_MIN would work just fine up to 1910 or so...)

okay millert@, gone thru a make build.


Revision tags: OPENBSD_5_3_BASE
# 1.93 15-Feb-2013 espie

turns out if a line ends with a $, the var module will run off the cliff
while expanding it.
shows up very prominently with MALLOC_OPTIONS=S

Problem found by jasper@

okay'd by jasper@ and kind-of duh'd by miod@


# 1.92 09-Oct-2012 espie

new interface: look in command lines for variables that indicate a list of
targets is actually separate targets.


# 1.91 02-Oct-2012 espie

more changes, discussed and tested by various people.
- put back some job control, turns out it's necessary when we don't run a
shell.
- zap old #ifdef CLEANUP code... probably doesn't even compile.
- kill most of the OP_LIB code. Just keep a wee little bit for compatibility
(deprecated .LIBS and .INCLUDES, warns for weird dependencies instead of
erroring out).
- much improved debugging and -p output: sort variables, targets, rules,
output stuff in a nicer format mimicing input.
- better error message when no command is found, explain where the target comes from.
- sort final error list by file.
- show system files in errors as <bsd.prog.mk>
- reincorporate random delay, that was dropped
- optimize siginfo output by not regenerating the whole string each time.
- finish zapping old LocationInfo field that's no longer used.


# 1.90 25-Aug-2012 espie

- make wrong variable specs (unterminated) parse errors.
- add info to be able to pinpoint parse errors at runtime.
- let job runners abort when a parse error happens while expanding a variable
during execution
- fix an infinite loop when compiling without FEATURE_RECVARS.

okay millert@, krw@
the very few errors found out by this (less than 10 over src/X/ports)
fixed trivially beforehand, as requested by deraadt@


Revision tags: OPENBSD_5_2_BASE
# 1.89 22-Mar-2012 espie

minor cleanup: error messages include lineno and fileno together, so
recognize that and create a struct Location_ for it.

mostly from Jonathan Calmels, a few nits from me.

okay otto@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.88 20-Jun-2011 espie

fix a segfault found by jasper@
ok miod@, otto@, jasper@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.87 19-Jul-2010 espie

Correct $OpenBSD$ stuff


# 1.86 25-Apr-2010 espie

pure whitespace cleanup


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.85 13-May-2009 espie

fix loopvar debug prints. Issue reported by naddy@


Revision tags: OPENBSD_4_5_BASE
# 1.84 09-Nov-2008 tobias

typo fixed (overriden -> overridden)

ok espie, jmc


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.83 17-Nov-2007 espie

simplify dynamic variable handling a great deal:
first remove all usage of Varq_Append by building the string directly.
then replace `common' handling with specialized handling for dynamic
strings (since they no longer need a buffer). Finally, identify the place
where the variable value needs to be copied because it's going to be free'd
or erased soon, and finally, use simple char* pointers.

Shaves about 80 bytes off every gnode structure, and kills quite a few
unnecessary malloc()s as well.


# 1.82 04-Nov-2007 espie

prevent gcc from complaining


# 1.81 03-Nov-2007 deraadt

fix some lint FALLTHROUGH


# 1.80 17-Sep-2007 espie

more blank space removal


# 1.79 17-Sep-2007 espie

more zap spaces


# 1.78 17-Sep-2007 espie

zap more spaces at end of line


# 1.77 17-Sep-2007 espie

kill extra spaces at end of line


# 1.76 16-Sep-2007 espie

remove warnings


# 1.75 16-Sep-2007 espie

remove dead code: #define RECHECK is always on


Revision tags: OPENBSD_4_2_BASE
# 1.74 30-Jul-2007 espie

introduce a Var_Substi to substitute on intervals.
Since we don't really know how to change Var_Subst and dependent functions,
we cheat, and copy the string to a buffer instead.

Clean-up the parser a bit: reorganize the include files lookup function:
introduce a resolve_include_filename function that figures out the full name
of the file, introduce a handle_include_file that does all the include file
handling, and rename the functions into handle_xxx_include, so that we
can remove most comments.

Rename ParseIsCond into handle_bsd_command, cut most of its code into
constituent functions.

Semantic changes:
- follow the rules that, if an optional construct does not parse correctly,
then it's not a real extension, and give the normal parser a chance to figure
it out. If the syntax checks out, semantic errors ARE real errors.
- allow variables to not be defined in include file names, no reason not to.

okay miod@


# 1.73 30-Jul-2007 espie

everywhere except in Var_Parse, we always add/append variables to the
VAR_GLOBAL context, so make it the common case: rename the basic functions
to Var_Set_with_ctxt/Var_Append_with_ctxt, define Var_Set and Var_Append
as macros that specify VAR_GLOBAL, and use these.

okay miod@


# 1.72 30-Jul-2007 espie

now that it's clean enough, one can extract some common code from
Var_Parse and Var_ParseSkip (the code that figures out the variable name
up to eventual modifiers).

okay miod@


# 1.71 24-Jul-2007 espie

zap unused variable


# 1.70 24-Jul-2007 espie

simplify computations in the var module: instead of advancing a char *
and keeping track of a length, we just advance the char *, and ditch
the length. We can still get the length at the end of the top-level
functions to satisfy existing interfaces.

Much simpler code, less error-prone.

Okay millert@


# 1.69 24-Jul-2007 espie

move the code that grabs a value in Var_Parse in its own function,
get_expanded_value.

Extend the code a bit to be much more thorough in case of a recursive
expansion: shows exactly the cycle of variable names involved.

okay millert@


# 1.68 24-Jul-2007 espie

change Var_ParseSkip API to increment the position instead of returning a
length, simplifies code.

(warns a bit, symptom of some further issues to fix).

okay millert@


# 1.67 22-Jul-2007 espie

make sure loop variables use their own buffers.
(causes .for loops to give weird results very infrequently, memory handling
was slightly wrong, but not enough to break things thoroughly).
noticed by naddy@


# 1.66 20-Jul-2007 espie

big clean-up patch:
- rename a few functions in var.c to names that make more sense.
- introduce Var_Deletei because it makes more sense.
- rewrite .for loops to use a local LoopVar construct to avoid looking up more
stuff.
- reformat var.c to near K&R
- rewrite most comments in var.c

shown to a few people. millert@ gave me his okay since it passes through
ports correctly.


# 1.65 20-Jul-2007 espie

reorder stuff in var.c so that the next patch is more readable.


# 1.64 08-Jul-2007 espie

rename variable to errorIsOkay. What does oldVars mean anyway ?


# 1.63 08-Jul-2007 espie

missed part: add check to avoid poison checking inexistent local vars,
and do for loops for real.


# 1.62 08-Jul-2007 espie

A set of big related changes. okay millert@, tested further by kettenis@
and matthieu@

This all revolves around putting ALL global variables into one single big
hash, and using flags. This removes some impossible to understand stuff,
like old varfind, and allows for some nice stuff.
- each time we reference a global variable, we create it, possibly as a dummy
variable.
- each time we go to the environment, we remember it, thus we no longer go
back to it.

Lists of dependant changes:
- isolate changes to oldVars and checkEnvFirst.
- remove VAR_CMD and VAR_GLOBAL contexts. The only distinction is in parsevar.
Split Parse_DoVar into Parse_DoVar and Parse_CmdlineVar
- rework var modules around obtain_global_var, observe flags in various
functions like Var_Value and Var_Seti.
- Var_Seti/Var_Appendi are almost the same code, use that internally.
- add magic to handle the very special SHELL variable.
- introduce Var_Definedi for the cases where we don't want the actual
value, to simplify tests.
- add keyword .poison, parse it and set global flags accordingly.
- do poison_checks where needed.
- document poison.
- in for loops, set variable temporarily, so that Var_SubstVar will also
substitute it in varmodifiers expressions.


Revision tags: OPENBSD_4_1_BASE
# 1.61 02-Jan-2007 espie

VarDelete is no longer used by list functions, so let it do type-checking
correctly.


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.60 20-Jan-2006 espie

use stdint.h where appropriate. okay millert@


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.59 07-Apr-2004 espie

ISO function declarations, trim a few comments, rename a few variables to
more explicit/more consistent names.

okay otto@


Revision tags: OPENBSD_3_5_BASE
# 1.58 07-Oct-2003 fgsch

- check if result is valid before using it.
- correctly set *freePtr, not freePtr.
input and ok espie@.


Revision tags: OPENBSD_3_4_BASE
# 1.57 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.56 05-Jun-2002 espie

tweak quick_lookup for a faster path.
okay millert@


Revision tags: OPENBSD_3_0_BASE OPENBSD_3_1_BASE
# 1.55 23-May-2001 espie

Mostly clean-up:
- cut up those huge include files into separate interfaces for all modules.
Put the interface documentation there, and not with the implementation.
- light-weight includes for needed concrete types (lst_t.h, timestamp_t.h).
- cut out some more logically separate parts: cmd_exec, varname, parsevar,
timestamp.
- put all error handling functions together, so that we will be able to
clean them up.
- more systematic naming: functioni to handle interval, function to handle
string.
- put the init/end code apart to minimize coupling.
- kill weird types like ReturnStatus and Boolean. Use standard bool (with a
fallback for non-iso systems)
- better interface documentation for lots of subsystems.

As a result, make compilation goes somewhat faster (5%, even considering
the largish BSD copyrights to read). The corresponding preprocessed
source goes down from 1,5M to 1M.

A few minor code changes as well: Parse_DoVar is no longer destructive.
Parse_IsVar functionality is folded into Parse_DoVar (as it knows what an
assignment is), a few more interval handling functions. Avoid calling
XXX_End when they do nothing, just #define XXX_End to nothing.

Parse_DoVar is slightly more general: it will handle compound assignments
as long as they make sense, e.g., VAR +!= cmd
will work. As a side effect, VAR++=value now triggers an error
(two + in assignment).
- this stuff doesn't occur in portable Makefiles.
- writing VAR++ = value or VAR+ +=value disambiguates it.
- this is a good thing, it uncovered a bug in bsd.port.mk.

Tested by naddy@. Okayed millert@. I'll handle the fallback if there is
any. This went through a full make build anyways, including isakmpd
(without mickey's custom binutils, as he didn't see fit to share it with me).


# 1.54 15-May-2001 espie

Don't go beyond end of string.
Handles unterminated variables, and fixes regression test #10


# 1.53 03-May-2001 espie

Synch with my current work.
Numerous changes:
- generate can build several tables
- style cleanup
- statistics code
- use variable names throughout (struct Name)
- recursive variables everywhere
- faster parser (pass buffer along instead of allocating multiple copies)
- correct parser. Handles comments everywhere, and ; correctly
- more string intervals
- simplified dir.c, less recursion.
- extended for loops
- sinclude()
- finished removing extra junk from Lst_*
- handles ${@D} and friends in a simpler way
- cleaned up and modular VarModifiers handling.
- recognizes some gnu Makefile usages and errors out about them.

Additionally, some extra functionality is defined by FEATURES. The set of
functionalities is currently hardcoded to OpenBSD defaults, but this may
include support for some NetBSD extensions, like ODE modifiers.

Backed by miod@ and millert@, who finally got sick of my endless patches...


Revision tags: OPENBSD_2_9_BASE
# 1.52 02-Mar-2001 espie

Use the ohash_* that's now in libc.


# 1.51 07-Dec-2000 espie

Forgot to copy end of name in nested variable names, so that
${BC_${A}} worked but not ${${A}_BC}.
Noticed by fries@


# 1.50 24-Nov-2000 espie

Take advantage of VarModifiers_Apply, which can parse a variable spec
and expand it directly, without needing a variable context.

Use it in Var_SubstVar, so that .for loops values don't need to be entered
into any context nor looked up.

This speeds up .for loops some, and avoids nasty variable capture
side-effects.

Ok'd millert@, miod@, naddy@ (naddy spotted a problem with the first
version of that change).


Revision tags: OPENBSD_2_8_BASE
# 1.49 13-Oct-2000 espie

esetenv: does a setenv and bails out if error.


# 1.48 14-Sep-2000 espie

Some systematic clean-up.
- UNUSED macro that expands to __attribute__((unused)) for gcc
- move rcsid around so that they can be tagged UNUSED.
- activate -Wunused.
- use UNUSED instead of kludgy junk for function arguments.
- add extern to all extern prototypes.
- update comments in lst.h.
- clean up var.c a little bit, constifying arguments, updating comments...


# 1.47 21-Aug-2000 espie

Var_Append needs to set v for DEBUG(VAR) to work.
Obvious fix.
Problem reported by Gregory Steuck, thanks a lot !


# 1.46 18-Jul-2000 espie

Handle MAKEFLAGS variation mandated by POSIX.

Code to pass variable definitions to submakes through make flags.
Not activated yet, need to fix src/ first.


# 1.45 17-Jul-2000 espie

parse embedded variable specs, e.g., ${VAR_${SUB}}

- need braces, as we don't want to change what $$A means,
- this assumes this kind of construct is very infrequent, thus
this does NOT copy the variable name needlessly.
- the expansion code is in a separate function for clarity.

Reviewed by miod@, as previous patches.


# 1.44 17-Jul-2000 espie

- let VarModifiers_Apply accept NULL string gracefully,
- simplify Var_Parse: use varfind, then leverage on the result
to recognize `special case' dynamic parsing.

VarModifiers_Apply need to be called on NULL strings, to be able to parse
modifiers applied to non-existent variables.

(Alternately, we could call VarModifiers_Apply on a dummy string, but
this is less efficient).


# 1.43 17-Jul-2000 espie

Major unobfuscation: split var modifiers handling to a separate file.
This does finally make var handling somewhat readable.


# 1.42 17-Jul-2000 espie

separate modifiers handling from Var_Parse into a separate
VarModifiers_apply function.

for env lookup, create variable structure first, so that we can get away
without terminating the variable name in main Var_Parse.


# 1.41 17-Jul-2000 espie

This does replace Str_Match with a better routine, which handles negated
intervals, and \\ in intervals.

Accordingly, var.c no longer needs to copy the :Marg to replace \: with :

We don't use fnmatch(3) because of various optimizations which are harder
to achieve in a generic setting.

Also add regression suite for the Str_Match function.


# 1.40 17-Jul-2000 espie

Constify a few functions, propagated from VarModify.
Replace a few int -> size_t

Reviewed by miod@


# 1.39 17-Jul-2000 espie

- recognize that FIND_CMD and FIND_GLOBAL are always used together,
- introduce VarFind_interval function. This avoids having to copy variable
names in VarParse,
- expose internals of VarFind* function (not used yet, but this will avoid
multiple lookups in VarParse),
- constify a few functions.

Reviewed by miod@


# 1.38 23-Jun-2000 espie

This is the speed-up patch, which doubles make speed (almost).

Use the open hashing functions for global contexts instead of List in
var.c.

All the preliminary work to trim down local contexts means that we don't
suffer from the heavy initialization work that a hash table entails.

There is some make kludgery to:
- build the hashing functions as a library,
- recreate hashconsts.h, even if make depend was not invoked.

One point of the hashing scheme written was to separate the computation
of the hash function, and the hash lookup itself. This is very convenient
for make, because of those pesky special variables. hashconsts.h is there
to pre-hash the correct values, which replaces a few expensive string
comparisons with quick hash value comparisons, followed by one expensive
string comparison. The modulus MAGICSLOTS chosen in the Makefile is
ad-hoc: it is small enough to write a small switch without collision,
and will need changing if the hash function changes...

The function quick_lookup is the most important:
it either returns an index, for a local variable, or it does compute a
hashing value, and returns -1.

Another somewhat controversial decision is the use of string intervals.
This avoids either copying a string, or twiddling with a byte for cases
such as ${VAR}.

Finally, the variable name is stored within the variable itself. Since
a given variable name never changes, this makes sense. All that was needed
was a hash library with support for this. Note that the hashing table
holds only a variable pointer AND the corresponding hashing value, WITHOUT
a modulo hashtablesize. Two reasons:
- hash resizes can be done faster, without having to recompute hashing values.
- locality of access. The hash table fits into memory without problem. Once
a candidate slot is found, we check the complete hashing value. Probability
of a collision is very small (32 bits...). So bringing up the whole
variable in memory at once is good: the name will almost always match, in
which case we want the variable value as well, so it makes sense to put
them together.

The ohash functions implement open hashing, as described in Knuth, but with
a variable table size. Choosing powers of 2 sizes does not yield more
collisions, but it makes the hashing scheme much simpler. The thresholds at
which to expand/shrink the tables seem to work well in practice. The
default sizes were chosen such that the tables hardly ever shrink or expand
anyways (though I've tried with smaller/larger sizes to verify that the
shrinking/expanding worked correctly): larger Makefiles hold roughly
500/600 variables, which fits without trouble into a 1024-sized variable.

Disregard #ifdef STATS_HASH, this is some internal scaffolding I'm using
to measure make performance.

The only known issue with open-hashing is that deletions cannot create
empty slots, but do leave slots marked as `occupied once' so that lookup
works. We use a well-known optimization which records those pseudo-empty
slots while looking up values. If the value is not found, the pseudo-empty
slot is returned to be filled. If the value is found, it is swapped with
the pseudo-empty slot. This is an improvement in both cases, since this
shortens the length of lookup chains, eventually pushing the pseudo-empty
slots to the end.

Reviewed by millert@ and miod@


# 1.37 23-Jun-2000 espie

This patch separates local contexts from global contexts for good.
Apart from a few casts, VAR_GLOBAL and friends are separate
data structures, so we use a small array for local variables.

We also junk allVars, since TargFreeGN can release local nodes,
and var.c has explicit lists for its variables already.

Reviewed millert@ and miod@.


# 1.36 23-Jun-2000 espie

In various places, VAR_CMD is used to actually mean `no real context',
since lookup will start with VAR_CMD in any case.
This fixes VarFind and Var_Parse to handle ctxt == NULL correctly, and
replace those confusing VAR_CMD with proper NULL pointers.

This patch also handles three small details:
- .CURDIR is necessarily set in VAR_GLOBAL,
- suffix handling for archives copies two hard-coded variables, for
which it can use a quick path,
- typos in TargFreeGN.

Reviewed millert@, miod@.


# 1.35 23-Jun-2000 espie

Once those special variable are taken care of, other Var functions can take
the GNode's context directly. We rename that special Lst to `SymTable *'
in prevision of things to come.

Along the line, we lose the special GNodes affected to VAR_CMD, VAR_GLOBAL,
VAR_ENV, which become simple Lsts... This is not a problem, except when
getting to a context's name for debugging (handled very nicely by
offsetof).

Again, this is a preparatory patch, which does not gain anything except
for cleaning up issues...

Reviewed by millert@ and miod@, like the previous patch


# 1.34 23-Jun-2000 espie

Start of variable fixes and speed-ups.

This patch may seem a bit non-sensical at first. It simply introduces some
new interface. Specifically, recognizes that some variable names
(.TARGET/$@, .OODATE/$?, .ALLSRC/$>, .IMPSRC/$<, .PREFIX/$*, .ARCHIVE/$!,
.MEMBER/$%) are `special' (the actual variables which are local to a
target, e.g. GNode).

Currently, The Varq functions (for Varquick access) are only stubs to the
normal functions.

This fixes a very important detail before proceeding to turn variable lists
into hash tables: if every GNode holds a hash table, initialization times
for those will be very costly. But generic GNodes only hold those seven
special variables... which can be stored directly into a small array;
the only general cases are the environment, the command line and
global variables.


# 1.33 17-Jun-2000 espie

This patch introduces a distinction between
Lst_Init (constructor) and Lst_New (allocation + construction)
Lst_Destroy (destructor) and Lst_Delete (deallocation + destruction),
and uses that to turn most dynamic allocation of lists (Lst pointers)
into static structures (LIST).

Most of this is mundane, except for allGNs in targ.c, where the code must
be checked to verify that Targ_Init is called soon enough.

Lst_New is a temporary addition. All lists will soon be static.

Reviewed by millert@, like the previous patch.


# 1.32 10-Jun-2000 espie

Clean-up patch: use `void *' instead of old-fashioned ClientData/Address.


# 1.31 10-Jun-2000 espie

Thus, Lst_ForEach no longer needs returning a status.
In fact, it can become a macro based on Lst_ForEachFrom.
This also introduces Lst_Every, as a shortcut for the very common case where
Lst_ForEach does not need any user data.

Finally, make consistent use of a few function typedefs, instead of having
explicit void (*)(Lst) arguments all over the place.


Revision tags: OPENBSD_2_7_BASE
# 1.30 26-Mar-2000 espie

Remove idiotic, braindead casts T* -> void*
They serve no purpose, except hiding potential bugs.

In particular, remove (ClientData) cast from macro, showing potentially
troublesome use of Hashes to store time_t.


# 1.29 08-Jan-2000 espie

Finish changing all Var_Parse arguments to size_t. Thanks to millert@
for reminding me.


# 1.28 19-Dec-1999 espie

Rearrange Lst_Find interface to conform better with other functions.


# 1.27 18-Dec-1999 espie

Nothing ever checks ReturnStatus on Lst_Insert, Lst_Append, Lst_AtFront,
Lst_AtEnd, Lst_Concat, Lst_Remove, Lst_Replace.

Don't bother returning one.


# 1.26 18-Dec-1999 espie

NIL, NILGNODE, etc, are only glorified NULL.
Get rid of them.

Get rid of list.h, nothing uses it anyway.


# 1.25 18-Dec-1999 espie

make does not use circular lists, get rid of the extra weight.


# 1.24 16-Dec-1999 espie

Var_Subst is actually two distinct functions folded into one:
split the function specific to for.c out, and give them more sensible
arguments at the same time.

This makes .for loop handling more efficient, as we have some heuristic
to evaluate the size of the buffer needed...


# 1.23 16-Dec-1999 espie

Allocate buffers as static data structures.
This cuts down quite a lot of malloc, since in actual use,
buffer usage is mostly static.


# 1.22 16-Dec-1999 espie

Remove unneeded extraneous zeros at the end of buffers.

Actually, one of these needs to be there, because of two bugs in cond.c


# 1.21 16-Dec-1999 espie

Split Buf_GetAll into Buf_Retrieve/Buf_Size.
(idiotic to retrieve size every time when it's used half the time)


# 1.20 16-Dec-1999 espie

Start cleaning up buf.c in earnest.

- Buf_Discard is only used to remove all the bytes in a buffer,
replace with Buf_Reset,
- buffer values are not read unless accessed first through Buf_GetAll,
no need to null-terminate it at every point.
- Buf_Expand need not check if the expansion is needed. That's Buf_AddChar
and Buf_AddChars responsability (otherwise, Buf_AddChar checks twice)
- Buf_Overflow only handles overflow. Adding the character is done in
every case anyway.


# 1.19 09-Dec-1999 espie

Introduce `common usage' buf patterns and use them.


# 1.18 06-Dec-1999 espie

Extra parameter no longer needed, ditch.


# 1.17 06-Dec-1999 espie

Instead of retrieving var values from the environment again and again,
it is much better to keep them in the global context, marked read-only.

This also makes the next simplification possible, since var values need no
longer be free'd by client code.

(reviewed by ho@, like other patches)


# 1.16 06-Dec-1999 espie

Clean up buffers interface somewhat:

- buf.c deals exclusively with chars. Be explicit about it, and remove
extraneous dumb casts to char (can hide real type errors).
- buffer sizes are size_t. Note that bp->left can never become NULL.
- Buf_GetAll is happy with a NULL pointer for the size, remove unneeded
extra pointers.
- Propagate size_t to all places where buffer functions are used.


# 1.15 11-Nov-1999 espie

Kill Str_FindSubString, it's strstr.


# 1.14 10-Nov-1999 espie

Turn on strict-prototypes, add missing prototypes.
Move main prototype to main.c, as this is not used
from any other file.

Close open bug.


# 1.13 06-Nov-1999 espie

Bug-fix: when expanding a specific variable v in $A,
check that v is PRECISELY A.

Other BSDs, take notice.


Revision tags: OPENBSD_2_6_BASE
# 1.12 28-Sep-1999 espie

Fix
.if defined(VAR) && ${VAR:m}

cond.c has special code (set err to 0) to tell VarParse it shouldn't care
if the variable is not defined.

But this was not completely added, namely the path that deals with
modifiers was blissfully unaware of that.


# 1.11 25-Sep-1999 espie

Add :L/:U modificators (lowercase/uppercase)
To use to get ports building more user-friendly.


Revision tags: OPENBSD_2_5_BASE
# 1.10 05-Dec-1998 espie

Modifications from netbsd:
- don't interfere with MACHINE/MACHINE_ARCH defines for bootstrap
- type clean-up, time_t, and printing `unknown' ints
- fix TARGET/MEMBER bug in archive rules
- memmove...
- cleaner Error handler.
- reentrant brk_string
- .MAKE env variable
- preliminary scaffolding for .NOPATH

Other improvements:
- efree
- shellneed streamlined
- display Stop in .CURDIR after an error.
- document most features and misfeatures.
- add a few OpenBSD notes to the tutorial.


Revision tags: OPENBSD_2_4_BASE
# 1.9 23-Jul-1998 deraadt

portable bootstrap thing; lidl@eng.us.uu.net


Revision tags: OPENBSD_2_3_BASE
# 1.8 30-Mar-1998 deraadt

Y2K fixes from Andreas.Gunnarsson@emw.ericsson.se; culled from various places


# 1.7 18-Dec-1997 deraadt

for the test following test case, do not output FOOBAR=bar (should be FOOBAR=)
problem reported by mark@thuvia.demon.co.uk

FOO=
FOOBAR=$(FOO:=bar)


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.6 01-Apr-1997 millert

Sync with NetBSD (mostly by christos initial substitution/regexp from Der Mouse)

- fix the variable substitution code in make [PR/2748]
1. change s/a/b/ so that it substitutes the first occurance of the
pattern on each word, not only the first word.
2. add flag '1' to the variable substitution so that the substitutions
get performed only once.

***THIS IS AN INCOMPATIBLE CHANGE!***

Unfortunately there was no way to make things consistent without
modifying the current behavior. Fortunately none of our Makefiles
depended on this.

OLD:

VAR = aa1 aa2 aa3 aa4

S/a/b/ = ba1 aa2 aa3 aa4
S/a/b/g = bb1 bb2 bb3 bb4

NEW:
VAR = aa1 aa2 aa3 aa4

S/a/b/ = ba1 ba2 ba3 ba4
S/a/b/1 = ba1 aa2 aa3 aa4
S/a/b/g = bb1 bb2 bb3 bb4
S/a/b/1g = bb1 aa2 aa3 aa4
- add regexp variable substitution via 'C/foo/bar/' [PR/2752]
- add variable quoting via the ${VAR:Q} modifier. This is useful when running
recursive invocations of make(1):

make VAR=${VAR:Q}

will always work... (This may prove useful in the kernel builds...) [PR/2981]
- BSD did not traditionally have <sys/cdefs.h>; use BSD4_4 instead and include
<sys/param.h> to grab it.
- Don't compile the regex code if MAKE_BOOTSTRAP (from gwr)
- Use explicit .c.o rule in Makefile.boot so that the bootstrap process works.
- Use only integral types in procedure arguments. [buf.c buf.h]
- Include <stdlib.h> to get getenv() prototype on SVR4
- if __STDC__ -> ifdef __STDC__ to appease SVR4
- Define const and volatile for non __STDC__
- Implement snprintf() and vsnprintf() for non BSD4_4 systems.
- Make $MACHINE_ARCH settable from the environment.
- Fix .USE directive problems: (reported by cgd)
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.
- Add a .MADE directive to indicated that the children of a target are
up-to-date, even when they are not. This is to simulate our current
make install behavior with proper dependencies.
- Fix problems in the RE substitution error handling.
- Locate all the children of a node marked as MADE.
- Do not compile-in ${MACHINE} (as per NetBSD PR#3386)
- Disable globbing for targets/dependencies when POSIX is defined.
- Fix globbing so that patterns that don't have a matching number of [] or {}
don't get expanded. (before the [ case got expanded to nothing!) This is
disabled.
- Make sure that the children of nodes that are marked .MADE, are marked
UPTODATE and their timestamps are consistent.
- Don't disable wildcards completely; they are used by other Makefiles.


# 1.5 30-Nov-1996 millert

Sync with NetBSD:
- 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.
- Fix NetBSD PR #2930: declare missing variable.


Revision tags: OPENBSD_2_0_BASE
# 1.4 02-Sep-1996 briggs

Sync up with NetBSD:
(christos)
Fix bug reported by Greg Hudson where leaf (source only) nodes were
referenced only by their basename and not by their full pathname. This
breaks when .PATH or MAKEOBJDIR are used. There might be Makefiles
around that try to work around this bug by prepending ${.CURDIR} to
the sources, and they should be found and fixed. Also a lot of the gunk
in suff.c that was attempting to work around the same problem could be
removed.
(christos)
- Move -D flags from Makefile to config.h and explain what they do. Add
-Wall -Wno-unused to CFLAGS. Add new define SYSVVARSUB to enable SysV
style variable substitutions and enable them.
- Add SunOS style command substitutions via SUNSHCMD
- Fix core dump with '{variable = value'
(christos)
Fix bug where make will always exit with 0, even when one or more
parallel jobs failed. (Only affects parallel make code)
(christos)
Protect __P from being multiply defined (for systems that already
define it)
(christos) Add strdup() since ultrix is missing it.
From Larry Schwimmer <rosebud@cyclone.Stanford.EDU>
(christos) Add estrdup(), a checked version of strdup and use it.
(christos) Recognize SVR4 style long filename entries in archives.
(thorpej) Tidy up some RCS ids a bit.


# 1.3 26-Jun-1996 deraadt

rcsid


# 1.2 14-Dec-1995 deraadt

from christos@netbsd:
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.
- Turn compat mode on by default. It gets turned off when the -j without
the -B flag is specified. [Thus you can use -j 1 to turn it off].
- Fix malloc -> emalloc as Gordon noted.
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.

from cgd@netbsd:
pull in make.h. (PAlloc() now uses emalloc(), which is prototyped in
make.h. If the prototype is not in scope on the Alpha, I see lots
of "cast to pointer from integer of different size" warnings.)


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision