History log of /freebsd-9.3-release/usr.bin/make/main.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 267654 19-Jun-2014 gjb

Copy stable/9 to releng/9.3 as part of the 9.3-RELEASE cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation

# 225736 22-Sep-2011 kensmith

Copy head to stable/9 as part of 9.0-RELEASE release cycle.

Approved by: re (implicit)


# 213494 06-Oct-2010 imp

Remove hack needed by 6.x machines and older machines to run newer
makes on FreeBSD/pc98. The need for this hack has passed. If you are
one of the rare people that may need this, then you should setenv
MACHINE=pc98 as a workaround.


# 213493 06-Oct-2010 imp

Use more portable errx instead of errc. The latter doesn't buy us
anyting anyway, since the error EAGAIN's error message doesn't add
anything to the error strings that are there now.


# 206241 06-Apr-2010 imp

Remove yet another vestage of alpha support.


# 201526 04-Jan-2010 obrien

Add ability to search up the directory hierarchy for the system directory.
Do by specifying ".../" with '-m' or MAKESYSPATH (new) environment variable.

Reviewed by: <sjg@NetBSD.org>
Obtained from: NetBSD (+ embellishment by me, sent back to NetBSD)


# 198199 18-Oct-2009 fjoe

Reset UPTODATE gnodes after remaking makefiles when make
is not going to be restarted: such nodes could be marked UPTODATE
without doing rebuild due to remakingMakefiles being TRUE.


# 190821 07-Apr-2009 fjoe

Avoid infinite loops when remaking makefiles not only
for Makefile targets but also for targets they depend on.


# 188001 02-Feb-2009 fjoe

Remove duplicate OPTFLAGS definition.


# 187995 02-Feb-2009 imp

Sort the options, per style(9).

Reviewed by: obrien@


# 187968 31-Jan-2009 imp

David doesn't consider the prior -s behavior a bug. Back out this
change.


# 187921 30-Jan-2009 imp

Unbreak make -s. There's about a 10% performance improvement with -s
in many environments. The recent --- blah --- reintroduction has
killed. That output makes almost no sense when all the other output
is silenced.


# 187132 13-Jan-2009 obrien

Don't enable -Q by default - I've fixed the rescue build issue.


# 186713 03-Jan-2009 obrien

+ Add the -Q be-quiet flag for parallel jobs.
- Enable -Q by default for the moment - there is something weird
going on in the rescue build.


# 186559 29-Dec-2008 obrien

1. Add the ability to tweak the token output before targets in job mode.
E.g., .MAKE.JOB.PREFIX=${.newline}---[${.MAKE.PID}]
would produce

---[1234] target ---

2. Added ${.newline} as a simple means of being able to include '\n' in the
assignment of .MAKE.JOB.PREFIX

Obtained from: NetBSD


# 186279 18-Dec-2008 fjoe

Exit with error code 2 when run with -k (continue if errors) and build failed.


# 181021 30-Jul-2008 ed

Add POSIX -p flag to make(1).

This article [1] describes the -p flag for make(1):

Write to standard output the complete set of macro definitions and
target descriptions. The output format is unspecified.

We already support a similar flag (-d g1), but unlike -p, it still
executes commands. Our implementation just turns it into -d g1, but also
sets flag `printGraphOnly', which will cause make(1) to skip execution.

[1] http://www.opengroup.org/onlinepubs/009695399/utilities/make.html

Reviewed by: imp
PR: standards/99960


# 177101 12-Mar-2008 obrien

If the special target .MAKEFILEDEPS exists, then enable the
"remaking makefiles" feature. Otherwise, follow traditional Pmake behavior.
(hash table will be regenerated and committed follow this commit)


# 176842 05-Mar-2008 yar

The non-POSIX environment variable MAKE was superseded
by MAKEFLAGS ages ago, so don't mention it in comments.

Tested with: cmp(1)


# 176839 05-Mar-2008 yar

Don't forget to set MAKEFLAGS in the childs' environment
from the .MAKEFLAGS global variable even if it's empty or
unset. This means setting MAKEFLAGS to just an empty string
in the latter case.

If not doing so, make(1) behaved inconsistently WRT MAKEFLAGS.
In particular, it would let a `-f foo' option down to sub-makes
if .MAKEFLAGS was unset. E.g.,

env MAKEFLAGS="-f mymakefile" make

would pass `-f mymakefile' down to sub-makes via their environment
(unless mymakefile added something to .MAKEFLAGS).
But any additional options appearing would change this behaviour to
not passing `-f mymakefile' to sub-makes, as in:

env MAKEFLAGS="-f mymakefile" make -D DUMMY

or

env MAKEFLAGS="-f mymakefile -D DUMMY" make

(unless mymakefile cleared .MAKEFLAGS).

Also make(1) would leave MAKEFLAGS at its initial value if the
makefile set .MAKEFLAGS to an empty value. I.e., it was impossible
to override MAKEFLAGS with an empty value. (Note well that makefiles
are not to touch MAKEFLAGS directly, they alter .MAKEFLAGS instead.
So make(1) can filter out things such as -f when copying MAKEFLAGS
to .MAKEFLAGS at startup. Direct modifications to MAKEFLAGS just go
nowhere.)

While the original intentions of the BSD make authors are somewhat
unclear here, the bug proves that NOT passing -f options down is
the settled behaviour because the opposite behaviour is totally
unreliable in the presence of any other options. In addition, not
passing down -f's found in the environment is consistent with doing
so WRT the command line.

Update the manpage accordingly and make the whole description of
MAKEFLAGS and .MAKEFLAGS more consistent as this change indeed
brings more consistency into the reliable behaviour of make(1).

Submitted by: ru (main.c)
Tested with: make world


# 176786 04-Mar-2008 imp

Note 7.0 was the first version that FreeBSD/pc98 had a MACHINE of pc98
instead of i386.


# 173919 25-Nov-2007 fjoe

Fix -jX when makefiles are remade.


# 170179 01-Jun-2007 fjoe

Change directory back to ${.CURDIR} when remaking Makefiles.

Pointed out by: ru


# 168892 20-Apr-2007 fjoe

When remaking makefiles check that mtime has actually changed.

This fixes infinite restart in the following case:

Makefile: foo

foo: bar
do-something

Unlike GNU make, BSD make considers "Makefile" node as remade even
if "foo" is up-to-date and was not actually rebuilt.
GNU make does not consider nodes without commands as remade if child nodes
were not actually rebuilt.

Most probably, more proper fix would be to bring BSD make behaviour in-line
with GNU make but this would be more intrusive change.


# 167330 08-Mar-2007 fjoe

Implement "Remaking Makefiles" feature:

After reading Makefile and all the files that are included using .include
or .sinclude directives (source Makefiles) make considers each source
Makefile as a target and tries to rebuild it. Both explicit and implicit
rules are checked and all source Makefiles are updated if necessary. If
any of the source Makefiles were rebuilt, make restarts from clean state.

To prevent infinite loops the following source Makefile targets are
ignored:
- :: targets that have no prerequisites but have commands
- ! targets
- targets that have .PHONY or .EXEC attributes
- targets without prerequisites and without commands

When remaking a source Makefile options -t (touch target), -q (query
mode), and -n (no exec) do not take effect, unless source Makefile is
specified explicitly as a target in make command line.
Additionally, system makefiles and .depend are not considered as a
Makefiles that can be rebuilt.

Reviewed by: harti


# 160442 17-Jul-2006 obrien

whitespace fixing


# 153115 05-Dec-2005 ru

Prepare for MACHINE and hw.machine switching to "pc98" on FreeBSD/pc98.

Reviewed by: nyan


# 152982 01-Dec-2005 davidxu

Quickly fix brokeness in revision 1.157, that change was
free()ing stack memory which causes the program to abort,
and I can no longer make buildworld.


# 152969 30-Nov-2005 fjoe

- match_var: do not address memory at invalid address (`len' can be greater
than strlen(var) + 1)
- ReadMakeFile: prevent `fname' memory leak
- ReadMakeFile: prevent double free (caused by double fclose) --
ParsePopInput() closes input file

Reviewed by: harti


# 149844 07-Sep-2005 harti

Fix the type of the variable 'debug'. It is used as a bitmap, so the
type should be int rather than Boolean.

PR: bin/84528
Submitted by: Max Okumoto <okumoto@ucsd.edu>
MFC after: 3 weeks


# 146581 24-May-2005 harti

The caller of Var_Value() should not change the variable value. Make
this clear by constifying the return value.

Obtained from: DragonFlyBSD


# 146580 24-May-2005 harti

Get rid of the third argument to Var_Value() the pointer it pointed
to has always been set to NULL for some time now.

Obtained from: DragonFlyBSD


# 146572 24-May-2005 harti

Factor out all the .SHELL parsing related stuff into its own file and
rename the function to be consistent with the naming scheme in the rest
of make. No functional changes.

Obtained from: DragonFlyBSD (idea and most of shell.h)


# 146560 24-May-2005 harti

Before doing any parsing parse the builtin shell specifications and
set the current shell to DEFSHELL. Put all these specifications into
a list. Add user specified new shells to this list. If the user
just selects one of the already know shells just pick the right one
off the list. This let's one do something like:

# Full specification of the user's shell. This also selects the shell.
.SHELL: name=myshell path=/somewhere/foo echo=loud ...

FOO != bar # use myshell here

.SHELL: name=sh

BAR != baz # use /bin/sh here

.SHELL: name=myshell # no need for full spec here.

# continue to use the user's special shell.


# 146345 18-May-2005 harti

Get rid of global variables for argument vectors produced by brk_string()
introduce a struct that holds all the information about an argument
vector and pass that around.

Author: Max Okumoto <okumoto@ucsd.edu>
Obtained from: DragonFlyBSD


# 146157 12-May-2005 harti

Make sure machine is initialize before use. Also make two pointers const
to get rid of the last two const warnings.


# 146146 12-May-2005 harti

Cleanup. Move initialisation of file and program global variables
to top of main() and sort them. Make chdir_verify_path() static - it
is used only here.

Submitted by: Max Okumoto <okumoto@ucsd.edu> (7.238)


# 146145 12-May-2005 harti

Replace a lot of Var_Set(..., VAR_GLOBAL) by Var_SetGlobal().

Submitted by: Max Okumoto <okumoto@ucsd.edu> (7.237)


# 146144 12-May-2005 harti

Cleanup main(). Move catching SIGCHLD into job.c. Move unsetenv("ENV")
into job.c. Move retrieving of environment nearer to the place where it
is actually used and invert the preprocessor conditionals to use
positive logic.

Submitted by: Max Okumoto <okumoto@ucsd.edu> (7.236)


# 146143 12-May-2005 harti

Reshuffle functions to get rid of prototypes.

Submitted by: Max Okumoto <okumoto@ucsd.edu> (7.235)


# 146141 12-May-2005 harti

Move variable printing from main.c to var.c

Submitted by: Max Okumoto <okumoto@ucsd.edu> (7.233)


# 146140 12-May-2005 harti

Fix the fix for bin/72510 applied in job.c:1.70. Actually there have
been two maxJobs variables: one static in job.c and one global used in
main.c and parse.c. Makeing one global out of these was the wrong way
to fix the problem. Instead rename the global one to jobLimit and keep
maxJobs static in job.c.

Suggested by: rwatson
PR: bin/72510


# 146134 12-May-2005 harti

Move some global variables to the correct files.

Submitted by: Max Okumoto <okumoto@ucsd.edu> (7.232)


# 146064 10-May-2005 harti

Path_Expand() expects its first argument to be writeable so put the
default system directory into a writeable character array before passing
it to Path_Expand().

Submitted by: Max Okumoto <okumoto@ucsd.edu> (7.210)


# 146060 10-May-2005 harti

Move the remaining two prototypes from nonints.h to make.h and
remove nonints.h.

Patch: 7.204
Submitted by: Max Okumoto <okumoto@ucsd.edu>


# 146056 10-May-2005 harti

Merge compat.c into job.c. There is a lot in common between these
files and we are going to factor this out.

Patch: 7.199 (slightly changed)
Submitted by: Max Okumoto <okumoto@ucsd.edu>


# 146054 10-May-2005 harti

Move Cmd_Exec() from main.c to job.c and fix its prototype. This
results in a warning that will go away soon.

Patch: 7.198
Submitted by: Max Okumoto <okumoto@ucsd.edu>


# 146038 10-May-2005 harti

Make make a little bit more POSIXish with regard to option parsing:
take everything after -- as either a macro assignment or a target.
Note that make still reorders arguments before --: anything starting
with a dash is considered an option, anything which contains an equal
sign is considered a macro assignment and everything else a target.
This still is not POSIX with regard to the options, but it will probably
not change because it has been make's behaviour for ages.
Add a new function Var_Match() that correctly skips a macro call by just
doing the same as Var_Subst() but without producing output. This will help
making the parser more robust.

Patches: 7.190,7.191
Submitted by: Max Okumoto <okumoto@ucsd.edu>


# 146027 09-May-2005 harti

Split Var_Subst() into two functions: Var_SubstOnly() which substitutes
only one variable and Var_Subst() which substitutes all. Split out the
test whether a variable should not be expanded into match_var().
Make access to the input string consistently using str[]. Remove two
unused functions: Var_GetTail() and Var_GetHead().

Patches: 7.184-7.189
Submitted by: Max Okumoto <okumoto@ucsd.edu>


# 145971 06-May-2005 harti

Introduce a new pseudo-target .EXPORTVAR which allows to put a
make macro into the environment of programs executed by make. This
has approximately the same function as gmake's export directive.
The form of a pseudo target was deliberately choosen to minimize work
for POSIX compatibility (Makefiles are not allowed to use any targets
starting with a dot and consisting only of uppercase letters except those
specified in the standard when they want POSIX compatible behaviour, so
such a Makefile can never contain .EXPORTVAR.)
Change the handling of macros coming from the environment: instead
of asking the environment for each variable we could not find otherwise
put all the environment variables in a special variable environment just
at start up.

This has been tested on the ports cluster by kris.

Submitted by: Max Okumoto <okumoto@ucsd.edu>


# 145679 29-Apr-2005 harti

Implement a pseudo-target .WARN that allows toggeling the warning flags
for the current make. This does not override flags specified on the
command line and these settings are not passed to sub-makes.


# 145627 28-Apr-2005 harti

Introduce a flag to enable extended warnings (-x) and make them off
by default. This should fix the problem of getting lots of errors
when building with an up-to-date make and old *.mk files.


# 144896 11-Apr-2005 harti

Remove an unneccesary forward declaration for MainParseArgs().
getopt() may be called several times - make sure to set optreset
to reset it. Cleanup handling of non-option arguments.
Remove some misleading comments.

Patch: 7.171

Submitted by: Max Okumoto <okumoto@ucsd.edu>


# 144895 11-Apr-2005 harti

Remove the call to Parse_Init() - there is no need to initialize
a static variable to NULL. Forgot this in the previous commit to
parse.[ch].


# 144475 01-Apr-2005 harti

Style: Indentation.


# 144387 31-Mar-2005 harti

Almost complete rewrite of the archive code (except for the Makefile parsing
part). Archive handling was broken at least since the move from BSD ar/ranlib
to GNU binutils because of the different archive format. This rewrite fixes
this by making make to carry around the defines for all formats (it supports)
so it can support all of them independent of the actually used one. The
supported formats are: traditional BSD (this seems to come from V7 at least,
short names only and __.SYMDEF), BSD4.4 (long names with #1/ and __.SYMDEF)
and SysV (extra name table and //). The only format not supported are broken
traditional archives where the member names are truncated to 15 characters.

Errors in the archive are not ignored anymore, but cause make to stop with
an error message. The command line option -A causes these errors to become
non-fatal. This is almost compatible with previous usage except for the
error message printed in any case.

Use a type-safe intrusive list for the archive cache.

Reviewed by: Max Okumoto <okumoto@ucsd.edu> (without new error handling)


# 144020 23-Mar-2005 harti

Make paths an explicite datatype instead of using the generic Lst.
A Path is now a TAILQ of PathElements each of which just points to
a reference counted directory. Rename all functions dealing with Paths
from the Dir_ prefix to a Path_ prefix.


# 143960 22-Mar-2005 harti

An automatic variable in a local scope is (conceptionally) destroyed with
the closing brace so it is unwise to keep a pointer to it. Make
the variable static to fix this.

Patch: 7.152

Submitted by: Max Okumoto <okumoto@ucsd.edu>


# 143959 22-Mar-2005 harti

Simplify buffer access by using Buf_Data() and Buf_Peel() where
appropriate.

Patch: 7.147-7.151

Submitted by: Max Okumoto <okumoto@ucsd.edu>


# 143808 18-Mar-2005 harti

Replace a bogus use of Lst_Find with explicite LST_FOREACH calls
and remove the unneeded second argument to ReadMakefile.


# 143412 11-Mar-2005 harti

Remove leading underscores from the pathname defines. All identifiers
with leading underscore followed by an uppercase letter are in the
implementation namespace.


# 143292 08-Mar-2005 harti

Use Buf_Peel to get rid of a local variable.


# 142807 28-Feb-2005 harti

Buf_GetAll wants a pointer as its second argument, not a boolean -
replace FALSE by NULL.

Submitted by: Max Okumoto <okumoto@ucsd.edu>


# 142457 25-Feb-2005 harti

Change the return value of Var_Subst to return a Buffer instead
of a char *.

Patch: 7.49

Submitted by: Max Okumoto <okumoto@ucsd.edu>


# 142008 17-Feb-2005 harti

Fix two typos in comments.

Submitted by: ru & Max Okumoto <okumoto@ucsd.edu>


# 141974 16-Feb-2005 harti

Mostly stylistic issues: move a variable into local scope, make
condition positive and fix long lines.

Submitted by: Max Okumoto <okumoto@ucsd.edu>


# 141969 16-Feb-2005 harti

Better version of the patch in 1.117: bring a variable into local scope
to prepare for function splitting and slightly reorganise the code
in anticipation of Var_Subst returning a Buffer.

Submitted by: Max Okumoto <okumoto@ucsd.edu> (with slight changes)


# 141799 13-Feb-2005 harti

Back out the previous commit. There is an obvious bug in it.

Pointy hat to: harti


# 141697 11-Feb-2005 harti

Stylistic fixes: push variable into a local context (this part is going
to be split out into a function soon). Also there is no need to write
back the colon that we have NUL-ed - the string is going to be freed
anyway.

Submitted by: Max Okumoto <okumoto@ucsd.edu>


# 141454 07-Feb-2005 harti

Introduce Buf_StripNewLines() and use it where appropriate.

Submitted by: Max Okumoto <okumoto@ucsd.edu>


# 141252 04-Feb-2005 harti

Some more easy constification.

Submitted by: Max Okumoto <okumoto@ucsd.edu>


# 141133 02-Feb-2005 harti

Convert several typedefs from beeing pointers to structs to be the structs
itself. This will ease constification (think of what 'const Ptr foo'
means if Ptr is a pointer to a struct).

Submitted by: Max Okumoto <okumoto@ucsd.edu>


# 141107 01-Feb-2005 harti

Remove debugging stuff that crept in in the previous commit.


# 141104 01-Feb-2005 harti

Clean up include files and file including. Split nonints.h into pieces
that get included just where they are needed. All headers include the
headers that they need to compile (just with an empty .c file). Sort
includes alphabetically where apropriate and fix some duplicate commenting
for struct Job, struct GNode and struct Shell by removing one version and
inlining the comments into the structure declaration (the comments have been
somewhat outdated).

This patch does not contain functional changes (checked with md5).

Submitted by: Max Okumoto <okumoto@ucsd.edu>


# 140870 26-Jan-2005 harti

Fix quoting of the MAKEFLAGS environment variable by only quoting spaces
and tabs. This is still not correct for command line variable values
ending in a backslash because this would require a larger effort.
Document this limitation in the BUGS section of the man page. The
quoting is mostly compatible with that of gmake and smake.

Tested by: Max Okumoto and Joerg Sonnenberger from DragonFly BSD
Reviewed by: ru (man page, partly)


# 138972 17-Dec-2004 harti

Remove all the cleanup functions. There is no reason to free memory
just before exiting (especially given the number of memory leaks) -
it just costs time.


# 138920 16-Dec-2004 ru

Fix a long-standing bug when make(1) is passed the -V and
-f options in MAKEFLAGS environment variable, and some of
these options are also specified on the command line.

Thanks to: marcel
Reviewed by: harti


# 138916 16-Dec-2004 harti

Instead of dynamically allocating list heads allocated them statically
now that their size is only two pointers. This eliminates a lot of calls
to Lst_Init and from there to malloc together with many calls to
Lst_Destroy (in places where the list is obviously empty). This also
reduces the chance to leave a list uninitilized so we can remove more
NULL pointer checks and probably eliminates a couple of memory leaks.


# 138561 08-Dec-2004 harti

Constify the arguments to the list compare function. This temporarily
requires to make a copy of the filename in ReadMakefile and to duplicate
two small functions in suff.c. This hopefully will go away when everything
is constified.

Submitted by: Max Okumoto <okumoto@ucsd.edu> (partly)


# 138512 07-Dec-2004 harti

Typedefs of pointers to structs are evil. Make Lst and LstNode typedef of
the structs itself not of pointers to them. This will simplify constification.

Checked by: diff on the object files


# 138510 07-Dec-2004 harti

Make needs no circular lists so remove them from the list code.


# 138346 03-Dec-2004 harti

Fix breakage introduced on 64-bit platforms with my last commit. Need
to change to size_t in a couple of other places too.


# 138264 01-Dec-2004 harti

Style: remove a lot of unnecessary casts, add some and spell the null
pointer constant as NULL.

Checked by: diff -r on the object files before and after


# 138232 30-Nov-2004 harti

Stylification: missing spaces, extra space after function names, casts
and the sizeof operator, missing empty lines, void casts, extra empty lines.

Checked by: diff on make *.o lst.lib/*.o

Submitted by: Max Okumoto <okumoto@soe.ucsd.edu> (partly)


# 138192 29-Nov-2004 harti

Use typedefs for the types of the functions that are passed as arguments
to the list functions for better readability.

Submitted by: Max Okumoto <okumoto@ucsd.edu>


# 138092 25-Nov-2004 harti

Include sys/sysctl.h on all architectures not only i386.


# 138071 24-Nov-2004 jmallett

Gentle code cleanup for the maximum make(1) level foo. This moves it to a
function, and moves the related defines out of the middle of code body.

Submitted by: Max Okumoto less-than okumoto at ucsd dot edu greater-than


# 137810 17-Nov-2004 harti

Eliminate the define for POSIX and build with Posix behaviour.
Our make has been build with POSIX enabled from the first day
and the ifdef'ed out code served no purpose.


# 137626 12-Nov-2004 phk

If -B is specified to get compat mode (as opposed to just not giving
a -j arg which does the same thing), remove the MAKE_JOBS_FIFO
environment variable so we decouple any resulting sub-makes from
the token pool.


# 137606 12-Nov-2004 phk

Add code to enforce the paralleism count (-j N) for the entire tree
of submakes spawned during processing.

We create a fifo and stuff one character into it for each job we are
allowed to run. The name of the fifo is passed to child processes
in the MAKE_JOBS_FIFO environment variable.

A make which finds this variable on startup will open the fifo and
only spawn jobs when it managed to read a token from the fifo.
When the job completes a token is writen back to the fifo.

Slave make processes get one token for free: the one their parent
make got in order to run them. This makes the make processes
themselves invisible in the process counts.

The net effect is that "make -j 12 -s buildworld" will start at
most 12 jobs at the same time, instead of as previously up to
65 jobs would get started.


# 137572 11-Nov-2004 phk

Get rid of more local/remote leftovers


# 137571 11-Nov-2004 phk

Get rid of now unused maxLocal variables.


# 137202 04-Nov-2004 harti

Remove the remote stuff from make. This actually never worked in our make
because the necessary files were not imported with the original import.
If somebody really needs it, there is still the devel/pmake port.

This is just the first step and removes just everything that is ifdef'ed out.
Otherwise the code is unchanged.

Checked by: md5

Approved by: no objections on arch@


# 136840 23-Oct-2004 ru

Expand the scope of the .SHELL specification to also cover
the compat mode of operation and the != operator.

While here, fixed a bug in the .SHELL directive processing
when only the name= attribute is specified and no built-in
shell matches this name, causing null pointer dereference.

Obtained from: NetBSD (except for bugs)


# 133562 12-Aug-2004 harti

Put variable assignments on .MAKEFLAGS and .MFLAGS targets into
the .MAKEFLAGS variable so that these are also passed to sub-makes.
This makes the handling of variables in the command environment more
consistent.

PR: bin/68853
Submitted by: Martin Kamerhofer <data@sbox.tugraz.at>


# 133085 03-Aug-2004 harti

Put variable assignments from the command line into the MAKEFLAGS
variable as required by POSIX. This causes such variables to be
pushed into all sub-makes called by the make (except when the MAKEFLAGS
variable is explicitely changed in the sub-make's environment).
This makes them also mostly un-overrideable in sub-makes except on the
sub-make's command line. Therefor specifying 'make CC=icc' will cause
icc to be used as C compiler in all sub-makes no matter what the Makefiles
itself try to do to the CC variable.

This patch also corrects the handling of the MFLAGS variable. MFLAGS
contains all the command line flags but not the command line variable
assignments. The evaluation of the .MFLAGS or .MAKEFLAGS target now
changes both MFLAGS and MAKEFLAGS (they used to change MAKEFLAGS only).
Makefiles can use MFLAGS for their own purposes given that they do not
except MFLAGS to be undefined at the beginning and that they don't evaluate
.MFLAGS or .MAKEFLAGS. MFLAGS should be removed for POSIX compliance,
but it is unfortunately heavily used by the X makefiles.

This has been extensively tested by port builds (thanks to portmgr), new
worlds and kernels.

PR: standards/57295 (1st part above)
Submitted by: James E. Flemer <jflemer@alum.rpi.edu>
Approved by: portmgr
Obtained from: NetBSD (1st part above)
MFC after: 4 weeks


# 133082 03-Aug-2004 harti

Make the SIGCHLD handler static and declare its argument
as unused, so that make can be compiled with WARNS=3 again.


# 127899 05-Apr-2004 ru

Unbreak compilation on RELENG_4.

Submitted by: des


# 127880 05-Apr-2004 des

Sort #includes, remove <sys/types.h> (made redundant by <sys/param.h>),
add <signal.h> (needed for sigaction())

Noticed by: Stefan Farfeleder <stefan@fafoe.narf.at>


# 123513 13-Dec-2003 des

Install a SIGCHLD handler so select(2) will be interrupted when a child
terminates. Without this patch, 'make -j1 buildworld' takes about 30%
longer than 'make -B buildworld' on my 2.4 GHz P4; the difference is
probably even larger on faster systems. With this patch, there is no
perceptible difference in wall time between the two.

Submitted by: bde
MFC after: 3 days


# 120718 03-Oct-2003 ru

Make the -q option DTRT in the compat mode.

PR: 48210


# 120053 14-Sep-2003 ru

- Cut out the code that caches the "." directory out of Dir_Init()
into a separate function, Dir_InitDot().

- Postpone the current and object directories detection (and caching
of the "." directory) until after all command line arguments are
parsed. This makes the -C option DTRT.

PR: bin/47149


# 113512 15-Apr-2003 ru

Sync usage() with SYNOPSIS.


# 113044 04-Apr-2003 imp

No need to check to see if we're running a version of FreeBSD 3.0 current or
newer anymore.


# 107964 17-Dec-2002 seanc

Check the return status of chdir() when using the -C option.

Reviewed by: bright && jmallet
MFC after: 1 day


# 105826 23-Oct-2002 jmallett

Remove efree(), it isn't used consistently enough to even pretend that it
might help on the systems it could possibly be used as a bandaid for. In
fact, the only thing it's useful for is instrumenting free(3) calls, and in
that capacity, it's better served as a local patch, than a public wrapper.


# 104818 10-Oct-2002 jmallett

Move utilitarian routines to util.c, which isn't the same as the old
compatability-geared util.c. These are things like message printers
and the PrintAddr function for traversing lists. Other general-purpose
utilities inside make(1) can go here, in time.


# 104696 09-Oct-2002 jmallett

Convert make(1) to use ANSI style function declarations. Variable
documentation already adequatedly existed in the description in most
cases. Where it did not, it was added. If no documentation existed
beforehand, then none was added. Some unused dummies for use in the
traversal functions were marked as __unused during the conversion.
Occasionally, local style fixes were applied to lines already being
modified or influenced.

Now make(1) should always build with WARNS=3.


# 104693 08-Oct-2002 jmallett

Remove extern declarations from functions and source files where they would
happily fit into headers.


# 104692 08-Oct-2002 jmallett

Remove unused local-locals, where upper-level locals may safely be used.


# 104689 08-Oct-2002 jmallett

Reference the correct local variable in all parts of a for loop, so we
operate on the correct data (properly).

Tracked down by: Dan Nelson


# 104395 03-Oct-2002 jmallett

In lieu of a good way to prevent every possible looping in make(1), stop
there from being more than 500 processes forked by make(1), to prevent a
forkbomb from happening, in a dumb and mechanical way.

PR: alane
Submitted by: bin/42772
MFC after: 2 weeks


# 104123 28-Sep-2002 jmallett

Fix ability to use csh(1) as the make(1) shell.

Sponsored by: Bright Path Solutions


# 104121 28-Sep-2002 jmallett

Make make(1) WARNS=6 clean except for const issues. This mostly involves
renaming variables to not shadow libc functions or greater scope locals. Kinda
makes one wonder if the extern ones weren't meant in some of these places :)

The only thing I'd still like to do WRT this is possibly combine rstat and
status in compat.c -- that should be fine, as I do not think the codepaths
will want both around at once.

Sponsored by: Bright Path Solutions


# 103545 18-Sep-2002 jmallett

Make the DEBUGF() macro portable by (ugh) adding a Debug() function, which
is merely printf() but to stderr. This takes care of the caveat which lead
to the use of a vararg macro -- getting everything to stderr.


# 102393 25-Aug-2002 jmallett

Add a -C ala GNU make(1) for Makefiles which are too lazy to use $(MAKE) and
this particular GNU flag. It changes into the given directory for the
operation in question. This just goes into said directory at the time of
parsing the argument for getopt(3).

Submitted by: Rachel Hestilow <rachel@jerkcity.com>


# 101672 11-Aug-2002 ru

main.c:450: warning: `targs' might be used uninitialized in this function

Spotted by: patrick@godloveya.com, naddy, -Wuninitialized

This segfaulted alpha and sparc64; i386 had this magically zeroed.


# 101460 07-Aug-2002 ru

Pacify ``make -f /dev/null -V FOO''.


# 100733 26-Jul-2002 imp

Back out jmallett's realpath changes. They break a set of makefiles that
we use in sublte ways with relative paths. Until they can be resolved,
back out these changes and put a big comment about why using realpath is
busted.

Approved by: jmallett
MFC After: 100 millifortnights


# 98163 13-Jun-2002 jmallett

Use %p to print a pointer, not %lx and a cast to (unsigned long). Yuck.


# 98162 13-Jun-2002 jmallett

Don't do stupid things to avoid unused parameters, mark them __unused.


# 98138 12-Jun-2002 jmallett

String lengths and sizeof()s are size_t not int. Mark an unused parameter
of ReadMakefile as __unused, it's there because this function is used by
the abstracted list interface which normally deals with item handlers which
take two arguments. Add a missing static prototype.


# 98136 12-Jun-2002 jmallett

The error functions take constant pointers to strings for their format.


# 97251 24-May-2002 ru

Back out the ``run shell from $PATH'' change; this was an overkill
and is insecure.

Requested by: bde


# 97163 23-May-2002 jmallett

Set the MAKEFILE variable to the value passed to ReadMakefile(), not the full
path to it. Use the full path only for parsing it.


# 97122 22-May-2002 ru

Do not run shell from /bin, run it from $PATH.
Bump MAKE_VERSION to 5200205221.


# 97121 22-May-2002 ru

Added the MAKE_VERSION global that could be useful in determining
if a given make(1) is feature-compatible with a set of makefiles.

When merged, this will be used to replace the ugly upgrade_checks
hacks in src/Makefile.

Version has the RYYYYMMDDX format, where R is from RELENG_<R> and
X allows for 10 distinguishable changes per day.

Discussed with: bde


# 97077 21-May-2002 jmallett

Make ReadMakefile() operate using the realpath(3) name for the file handed to
it, which means that relative paths will be expanded to absolute paths, and
filenames without a path will end up with their absolute path included as
well. This aids tremendously in debugging a build using our make(1) with
multiple Makefile's, such as when there is a syntax error in a file in a
sub-directory as per <bsd.subdir.mk>. Normally we'd end up with just
"Makefile" known about the Makefile in question, which means that an error
would be useless for someone trying to debug their build system, now we
end up with a complete real pathname for the Makefile.

So mostly this is useful in a debugging context, but possibly others too
(I haven't thought of them yet, but they probably are more useful if you
make Dir_FindFile use realpath(3), but that's another story).

Reviewed by: -current
MFC after: 2 weeks


# 94990 18-Apr-2002 ru

Do not reset MAKEFILE when reading ".depend" as this rather
eliminates the usefulness of ${MAKEFILE}.

Obtained from: NetBSD
MFC after: 1 week


# 94595 13-Apr-2002 obrien

Fix a minor lint warning.


# 94594 13-Apr-2002 obrien

Prefer BSDmakefile over makefile and Makefile.

Submitted by: jmallett
Obtained from: OpenBSD


# 94589 13-Apr-2002 obrien

Fix copyrights, and undo SCS ID damage.


# 94587 13-Apr-2002 obrien

Update SCM ID method.


# 94506 12-Apr-2002 charnier

Reorder #include. Cast arg #2 of lseek to an off_t when constant. No need to
test if failsafe memory allocation fails, it can't. perror -> warn. Use
failsafe memory allocation provided.

Use .Pa and .Ar. Uppercase (first letter) programname after dot.


# 93056 23-Mar-2002 imp

o unifdef -D__STDC__
o remove badly bit-rotted compat file that likely won't work on the systems
it purports to support.


# 92921 21-Mar-2002 imp

remove __P


# 75974 25-Apr-2001 ru

unifdef -UWANT_ENV_PWD.

No one ever going to use this bugfeature.


# 75973 25-Apr-2001 ru

Make ${.OBJDIR} canonical.

Reviewed by: bde


# 73262 01-Mar-2001 imp

MAXPATHLEN includes the trailing NUL.

Correct array sizes to reflect this.
Correct NUL termination after strncpy.

# Didn't to strncpy -> strlcpy change.


# 72679 19-Feb-2001 kris

Introduce support for using OpenSSL ASM optimizations. This is done
through the use of a new build directive, MACHINE_CPU, which contains a
list of the CPU generations/features for which optimizations are desired.
This feature will be extended to cover the ports tree in the future.

Currently OpenSSL provides optimizations for i386, i586 and i686-class
CPUs. Currently it has not been tested on an i386 or i486.

Teach make(1) to provide sensible defaults for MACHINE_CPU if it is not
defined (namely, the lowest common denominator CPU we support for each
architecture). Currently this is i386 for the i386 architecture and ev4
for the alpha. sys.mk also sets the variable as a last resort for
consistency with MACHINE_ARCH and bootstrapping from very old versions of
make.

Benchmarks show a significant speed increase even in the i386 case, with
additional improvements for i586 and i686 systems. For maximum performance
define MACHINE_CPU=i686 i586 i386 in /etc/make.conf.

Based on a patch submitted by: Mike Silbersack <silby@silby.com>
Reviewed by: current


# 69531 02-Dec-2000 will

There's also no point in #typedef'ing void/char pointers. Accordingly,
rip out ClientData/Address pointers and use standard types.

Obtained from: OpenBSD


# 69527 02-Dec-2000 will

There's no reason to use fancy forms of NULL. Replace all instances
of NIL, NILLST, NILLGNODE, etc. with NULL.

Obtained from: OpenBSD


# 69390 30-Nov-2000 will

Format string paranoia. This should avoid potential buffer overflows from
user input (in its ever-broadening definition).

Obtained from: NetBSD


# 66366 25-Sep-2000 peter

Previous commit was to add an -X switch to disable recursive expansion with
-V.

PR: bin/17188
Submitted by: Mark Valentine <mark@thuvia.demon.co.uk>


# 66365 25-Sep-2000 peter

*** empty log message ***


# 64739 16-Aug-2000 green

Allow use of the ${MAKE_SHELL} variable to specify alternate shells for
make(1) to use. Setting it to "sh" and "ksh" are the only values which
work right ATM; I wouldn't expect "csh" to get you far ;)


# 63955 28-Jul-2000 imp

Do include <unistd.h> for getopt interface.
Don't extern it.


# 62835 09-Jul-2000 ache

Fix assembler error messages - there is no \n allowed in __COPYRIGHT macro


# 62833 09-Jul-2000 wsanchez

Use __RCSID()


# 60569 14-May-2000 will

Add loud debugging facility (-dl option) which allows programmers/developers
to override @-prefixed commands in Makefiles. It is especially useful for
debugging ports and/or complex Makefiles in such a manner that is basically
a last resort, but is quite effective if the output is well-handled.

I'll update the manpage after dinner. ;-)

Better patch submitted by: steve
Reviewed by: phk, steve, chuckr, obrien,
Lyndon Nerenberg <lyndon@orthanc.ab.ca>


# 53631 23-Nov-1999 marcel

Improve backward compatibility.

make(1) uses sysctlbyname() to find out if it is running on a PC98
machine. This check has been added on 1998/9/9. The MIB variable was
added on 1998/8/31. At that time __FreeBSD_version was 300003. So,
only perform the check *if* __FreeBSD_version is defined and if it's
greater than 300003.

For the record: sysctlbyname was added on 1997/5/30 so this change
automaticly handles that...


# 50477 27-Aug-1999 peter

$Id$ -> $FreeBSD$


# 49938 16-Aug-1999 hoek

Merge style- and trivial- only changes from OpenBSD (dated 1999/07/29-19:55+1).

Obtained from: OpenBSD, sometimes indirected from NetBSD; myself


# 49332 31-Jul-1999 hoek

Add a -E flag, similar to -e (overide variables from environment) except
that -E only operates for a specified variable. Useful since the -e option
will often pull-in many unwanted variable overrides (esp. in a make world
situation). Uses include overriding BINOWN (which cannot be done by normal
methods or through abuses of MAKEFLAGS) or likely for ports to honour CFLAGS
(provided they're running on a system whose make(1) has this option).


# 49331 31-Jul-1999 hoek

Print an error message on illegal numerical arguments.

Submitted by: bin/9349 (slightly modified) Assar Westerlund <assar@sics.se>


# 44362 01-Mar-1999 imp

Make MACHINE_ARCH sensitive to the environment, as well as using the
compiled in default in case it isn't defined. This is needed to make
cross compilation work in some edge cases. It also makes cross
compiling on FreeBSD other BSD's easier as well.

Obtained from: NetBSD, OpenBSD (predates the split)


# 41161 15-Nov-1998 bde

Fixed missing 'v' in usage message.


# 41151 14-Nov-1998 dg

Added a -v (verbose) option and hid multi-job file banner generation
behind it.


# 40500 17-Oct-1998 obrien

Only process the ``PWD'' environmental var if built with "WANT_ENV_PWD"
defined. Bash v2 sets PWD and it creates major problems for those of us
with /usr/src being a symlink. See the lists for examples of the problems.


# 39006 09-Sep-1998 kato

Set the `pc98' string to the MACHINE if machdep.ispc98 != 0.


# 37872 26-Jul-1998 imp

Use malloc + sprintf rather than asprintf to ensure portability to
other, less advanced architecutres. This should minorly help porting
efforts of FreeBSD. I've done several make worlds since this came up
with this change, as well as debugging several interesting nits with
-V (which is the only thing this change will affect really).


# 36942 13-Jun-1998 peter

Make -V expand it's arguments. This means that instead of 'make -V OBJS'
printing something useless (to a shell) like: ${SRCS:N*.h:R:S/$/.o/g}
it will instead print the actual ${OBJS} value.


# 29957 29-Sep-1997 imp

Add #include <stdlib.h> to pick up prototypes for getenv and friends.


# 28828 27-Aug-1997 jkh

Don't preferentially execute Makefiles in ${OBJDIR} - it just causes
confusion and suffering. Tested by "make world".
Submitted by: gibbs


# 28746 25-Aug-1997 fsmp

Make explicit '-B' option propigate to submakes.

No one has said this would be a bad thing, so given the dearth of comments
I decided to add it, as its an important step towards getting "make world"
'parallel-ized'.

Reviewed by: silence
Submitted by: nnd@itfs.nsk.su


# 28228 14-Aug-1997 fsmp

Better fix, as originally submitted by reporter.

Submitted by: N.Dudorov <nnd@itfs.nsk.su>


# 28191 14-Aug-1997 fsmp

Fix PR bin/4291: /usr/bin/make - inconsistent -j<n> flag parsing.

Submitted by: N.Dudorov <nnd@itfs.nsk.su>


# 27644 24-Jul-1997 charnier

Use err(3). Cosmetic in usage string.


# 24360 29-Mar-1997 imp

compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.


# 23006 22-Feb-1997 peter

Revert $FreeBSD$ to $Id$


# 21673 14-Jan-1997 jkh

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# 18877 12-Oct-1996 steve

Remove extraneous comment, fix second-level tabs (one
tab and four spaces), and return error message in *err
instead of calling Parse_Error.

Suggested by: Bruce Evans <bde@zeta.org.au>


# 18864 11-Oct-1996 steve

Reinstate '!=' fix by Bruce Evans. The original commit message from
parse.c(1.9) was:

revision 1.9
date: 1996/09/12 03:03:25; author: bde; state: Exp; lines: +7 -6
Fixed handling of `!=' assignment. Don't warn if the shell's output is
null, but warn if there was an error reading it.

Suggested by: Bruce Evans <bde@zeta.org.au>


# 18804 08-Oct-1996 steve

O' to be bitten by CVS. Cleanup after import
of Christos' version of make(1) and add Id's.

Set straight by: Bruce Evans and Peter Wemm :)


# 18759 06-Oct-1996 steve

Clarify the rule used to determine the object
directory location.


# 18730 06-Oct-1996 steve

Merge in NetBSD's changes to make(1). Changes include:

- Add the .PHONY, .PARALLEL, and .WAIT directives
- Added the -B and -m commandline flags
- misc. man page cleanups
- numerous job-related enhancements
- removed unused header file (bit.h)
- add util.c for functions not found in other envs.
- and a few coordinated whitespace changes

Special thanks to Christos Zoulas <christos@netbsd.org>
for help in the merge. A 'diff -ur' between Net and
FreeBSD now only contains sccsid-related diffs. :)

Obtained from: NetBSD, christos@netbsd.org, and me


# 18339 18-Sep-1996 swallace

Restore previous compatibility of ${.CURDIR}/obj.`uname -m` and
$(.CURDIR}/obj search while retaining compatability of new
prefix with cwd for the current source tree builds.
.TARGETOBJDIR has been removed from make and CANONICALOBJDIR set in
bsd.obj.mk

The builtin object directory searching is defined specifically as:

If MAKEOBJDIRPREFIX is defined, the search order is
${MAKEOBJDIRPREFIX}${.CURDIR}
${.CURDIR}

Else if MAKEOBJDIR is defined, the search order is
${MAKEOBJDIR}
${.CURDIR}

Otherwise, default to the search order
${.CURDIR}/obj.`uname -m`
$(.CURDIR}/obj
/usr/obj${.CURDIR}
${.CURDIR}

Reviewed by: bde


# 17970 31-Aug-1996 bde

Fixed a missing colon in `notyet' code.


# 17193 17-Jul-1996 bde

Added a -V option to print make's idea of the value of a variable.

Submitted by: mark@linus.demon.co.uk (Mark Valentine)

Fixed bugs and inconsistencies in synopsis and usage message.


# 16885 01-Jul-1996 jkh

Put back the $PWD override behavior of revision 1.4. The concensus
*seems* to be that it was the right thing to do.


# 16809 27-Jun-1996 jkh

Remove code which overrode the opinion of getcwd() with an often bogus
value for $PWD.


# 16663 24-Jun-1996 jkh

Bring in my changes for removing the pestilent obj links (unless you
really want them) from /usr/src. This is the final version of the
patches, incorporating the feedback I've received from -current.


# 8874 30-May-1995 rgrimes

Remove trailing whitespace.


# 5814 23-Jan-1995 jkh

Bring in a number of changes from NetBSD's make, fixing quite a few
problems in the process:

1. Quoting should work properly now. In particular, Chet's reported bash
make problem has gone away.
2. A lot of memory that just wasn't being free'd after use is now freed.
This should cause make to take up a LOT less memory when dealing with
archive targets.
3. Give proper credit to Adam de Boor in a number of files.
Obtained from: NetBSD (and Adam de Boor)


# 1591 27-May-1994 rgrimes

This commit was generated by cvs2svn to compensate for changes in r1590,
which included commits to RCS files with non-trunk default branches.


# 1590 27-May-1994 rgrimes

BSD 4.4 Lite Usr.bin Sources