Commit Graph

132 Commits

Author SHA1 Message Date
rillig
1c4ffcb2c3 make(1): remove ReturnStatus, SUCCESS and FAILURE
These are used in so few places now that it is easier to use a simple
Boolean for them.
2020-08-29 12:20:17 +00:00
rillig
15828a96ed make(1): add another Boolean variant to check during development 2020-08-29 08:09:07 +00:00
rillig
5783a5d404 make(1): allow for strict type checking for Boolean
Having Boolean aliased to int creates ambiguities since int is widely
used.  Allow to occasionally compile make with -DUSE_DOUBLE_BOOLEAN to
check that the type definitions still agree.
2020-08-29 07:52:55 +00:00
rillig
328f88448d make(1): clean up targ.c
The main part is removing redundant or outdated information from
comments.  In a few places, the expression cond ? TRUE : FALSE has been
simplified.
2020-08-28 19:14:07 +00:00
rillig
3b8b408b28 make(1): print suffix flags in the standard way
This changes the output (it is now SUFF_NULL instead of just NULL), and
the order of the flags in the output is reversed.
2020-08-28 03:35:45 +00:00
rillig
ca993cd932 make(1): remove header sprite.h
Make is independent of the Sprite operating system.
2020-08-26 23:00:47 +00:00
rillig
fa70c4fdc5 make(1): in debug mode, print GNode details in symbols
A string like OP_DEPENDS|OP_OPTIONAL|OP_PRECIOUS is much easier to read
and understand than the bit pattern 00000089.

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

In enum.h, I thought about choosing the numbers in the macros such that
it is always possible to combine two of them in order to reach an
arbitrary number, because of the "part1, part2" in the ENUM__SPEC macro.
The powers of 2 are not these numbers, as 7 cannot be expressed as the
sum of two of them.  Neither are the fibonacci numbers since 12 cannot
be expressed as the sum of 2 fibonacci numbers.  I tried to find a
general pattern to generate these minimal 2-sum numbers, but failed.
2020-08-24 20:15:51 +00:00
rillig
e8986ff18b make(1): remove unused declarations from header files 2020-08-23 17:04:21 +00:00
rillig
2ae277de3b make(1): use proper data type for GNode.type
Theoretically this should show the enum constant names when displaying
the field in the debugger.  This only happens for GNode.flags though,
but not for GNode.type.  Not sure what the exact cause is.
2020-08-23 08:26:03 +00:00
rillig
a8b40c7d03 make(1): clean up headers
Remove redundant headers that are already included by "make.h".
Make <assert.h> available to all compilation units that use "make.h".
2020-08-22 21:42:38 +00:00
rillig
18284a5949 make(1): remove wrong comment about possible Y2038 problem
The "time" that is mentioned is not clock time but a sequence number.
2020-08-22 19:27:22 +00:00
rillig
812ca946e8 make(1): remove unused variable jobServer 2020-08-22 18:47:31 +00:00
rillig
378c3ae1c2 make(1): convert GNode type constants to enum
This allows debuggers to print symbolic names for the type flags.

The names of these constants need to be revised.  These flags probably
started as the 3 dependency operators (:, !, ::), and at that time, the
prefix OP_ made sense.  The other flags are not related to the type of
the dependency operator and could have been placed in GNode.flags as
well.
2020-08-22 18:44:22 +00:00
rillig
465914358c make(1): restructure GNode types and documentation
Having a numbered list above the type was not helpful since the numbers
didn't serve any purpose, they just consumed screen space.

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

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

Limiting the documentation of each field to a single line, as suggested
by the end-of-line comments, reduces clarity since several of the fields
need way more documentation to be properly understood.
2020-08-22 18:20:31 +00:00
rillig
8c014827fb make(1): remove unused function declarations 2020-08-20 17:13:05 +00:00
rillig
fd48ee78aa make(1): fix wrong or outdated comments 2020-08-20 17:06:26 +00:00
rillig
fb8f93f536 make(1): follow naming conventions for multiple-inclusion guards
This avoids undefined behavior.
2020-08-13 03:54:57 +00:00
rillig
431c892530 make(1): convert Suff.flags from #define to enum
This increases debugging support since the debugger can now display
symbolic names instead of an integer bit mask.
2020-08-11 18:44:52 +00:00
rillig
21107e4e40 make(1): fix parameter name of str_concat
The previous documentation mentioned Str_Concat, but str_concat has been
written in lowercase for years.  The "flags" are not flags since they
cannot be combined, not even when they are written in hex.
2020-08-10 19:30:30 +00:00
rillig
3fa1773eef make(1): use enum for return values of Cond_Eval and friends 2020-08-01 18:02:37 +00:00
sjg
a826e8b769 Add -dL for LINT
When parsing variable assignments other than := and if
value contains '$' attempt Var_Subst the same as for :=,
if the value does not parse correctly, we get a fatal error
including file an line number.

This can greatly help with finding the cause of problems.

Reviewed by: christos
2020-07-31 20:22:10 +00:00
rillig
25ff14505c make(1): clean up various things in var.c 2020-07-21 21:13:24 +00:00
sjg
6625c883c8 Add -dh for DEBUG_HASH
Allow tracking of max chain length, to see how well the hash
tables are working.
Pull the actual hash operation into a marco so it can be
easily changed - for experimenting.

The current hash, is pretty good.

Reviewed by: christos
2020-07-18 21:37:38 +00:00
rillig
e42ab321d5 make(1): add more type safety for enums
There are several types of flags for variables, and these cannot be
mixed.  To prevent accidental typos, these are defined in separate enum
types.  Clang warns about direct assignments between distinct types, but
not about mixing distinct types in binary expressions like A | B.  GCC
does not warn at all.
2020-07-02 15:14:38 +00:00
sjg
66c485513e Avoid unnecessary noise when sub-make or sibling dies
When analyzing a build log, the first 'stopped' output
from make, is the end of interesting output.

Normally when a build fails deep down in a parallel build
the log ends with many blockes of error output from make,
with all but the fist being unhelpful.

We add a function dieQuietly() which will return true
if we should supress the error output from make.
If the failing node was a sub-make, we want to die quietly.

Also when we read an abort token we call dieQuietly telling we
want to die quietly.

This behavior is suppressed by -dj or
setting .MAKE.DIE_QUIETLY=no

Reviewed by: christos
2020-06-19 21:17:48 +00:00
sjg
f48d69a4a4 Revert arraycount 2020-04-03 03:35:16 +00:00
sjg
8953c85736 CHECK_VALID_META is too agressive for CMD check.
An empty CMD is perfectly valid.
So using CHECK_VALID_META results in too much rebuilding.
2020-04-03 03:32:28 +00:00
sjg
a899a18fa4 make: fix -fno-common build
debug was declared extern, but debug_file was not; correct this and define
debug_file in main.c (as debug is) to fix the -fno-common build.

-fno-common will become the default with GCC10/LLVM11.

Patch from kevans at freebsd
2020-03-30 02:41:06 +00:00
sjg
9d28f87b89 Do not treat .info as warning for -W
Reported by: lwhsu at FreeBSD.org
2018-02-12 21:38:09 +00:00
sjg
a5cccb4af8 Make compat.c handle SIGINT etc more like job.c
If there is a running child, pass the signal on, and
wait for it to exit before we self-terminate.

Reviewed by: christos
2017-07-20 19:29:54 +00:00
christos
c977da2cd4 Refactor and simplify objdir setting code. 2016-12-07 15:00:46 +00:00
dholland
9d33465685 Add a .DELETE_ON_ERROR: magic target that causes *failed* targets as
well as *interrupted* targets to be deleted. The name and behavior of
the variable matches gmake.

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

Closes PR 51376.
2016-08-26 23:28:39 +00:00
sjg
e917da0d70 Extend the mtimes cache used by dir.c so it can be used by others.
We store both st_mtime and st_mode, since some callers care about the
later.

Reviewed by: christos
2016-06-07 00:40:00 +00:00
sjg
cb28c6994f Add cached_realpath()
realpath(3) is expensive, and meta mode at least uses it extensively.
We use cached_realpath() to save the result of successful calls to
realpath(3) in a private variable context.

This improves the worst case performance (eg examining libc with
nothing to do) by a factor of 4.

Reviewed by: christos
2016-06-03 01:21:59 +00:00
christos
4d0b1055db Collapse the 3 boolean parameter to 1 flags parameter. No functional change. 2016-02-18 18:29:14 +00:00
christos
9da037e3be provide missing FD_CLOEXEC for the havenots. 2016-01-17 15:32:38 +00:00
pooka
bc0dc0b26e Add more compat defs for code compiled for !NetBSD targets.
At least GNU Hurd lacks MAXHOSTNAMELEN/MAXPATHLEN/PATH_MAX, so make sure
those have some arbitrary semi-sane values.

from Robert Millan in PR misc/50166, with some modifications from myself
2015-09-21 21:50:16 +00:00
joerg
d92bea4fa3 Revert all make changes except the unit tests to the state of three
weeks ago. Individual changes can be reapplied after review.
2014-09-07 20:55:34 +00:00
christos
defa6c58f6 PR/46096: Jarmo Jaakkola: fix many problems with dependencies (PR 49086)
Quite extensive rewrite of the Suff module.  Some ripple effects into
Parse and Targ modules too.

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

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

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

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

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

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

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

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

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

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

Other improvements in the Suff module include:
  - better debug messages for transformation rule search (length of
    the chain is now visualized by indentation)
  - Suff structures are created, destroyed and moved around by a set
    of maintenance functions so their reference counts are easier
    to track (this also gets rid of a lot of code duplication)
  - some unreasonably long functions were split into smaller ones
  - many local variables had their names changed to describe their
    purpose instead of their type
2014-08-23 15:05:40 +00:00
christos
6b5672dab1 PR/48367: David A. Holland: Mark possible submake nodes so that we can
avoid closing the job pipe on exec for them in order to make recursive
makes work in parallel.
2014-07-16 15:33:41 +00:00
sjg
cde1c40e1b Add VAR_INTERNAL as a context for variables set by make itself,
which should not override those set by makefiles.
Currently MAKEFILE is the only variable affected.

Reviewed by: christos
2013-09-04 15:38:26 +00:00
sjg
8ae5585417 Use a #define for the variable name we put in environment to pass .MAKE.LEVEL
in case we don't want to use gmake's MAKELEVEL in a different way.
2013-06-18 20:06:09 +00:00
dholland
21fc2b5d09 Fix obvious typo. 2013-02-25 01:57:14 +00:00
joerg
b1e1b1d4c2 Replace __dead, __unused and the various printf format attributes
with versions prefixed by MAKE_ATTR_* to avoid modifying the
implementation namespace. Make sure they are available in all places
using nonints.h to fix bootstrap on Linux.
2012-06-12 19:21:50 +00:00
sjg
8d38755103 Var_UnExport() and setenv() can both realloc environ.
Use a common variable (savedEnv) to track that to avoid wasting memory.
Also, if providing setenv and unsetenv, do getenv too to ensure a consistent
set.
2012-06-04 20:34:20 +00:00
joerg
84700a0331 Use __dead consistently. If it doesn't exist, define it away. 2011-09-16 15:38:03 +00:00
sjg
48587910e0 Add .MAKE.META.BAILIWICK - to identify the scope of make's control.
meta_oodate: if a file that was written or linked within our bailiwick,
but outside of .OBJDIR is missing, add it to missingFiles.
If we get to the end of the .meta file without seeing it [re]moved,
then consider the target out-of-date.
2011-05-04 20:38:31 +00:00
joerg
bfc4d64e8a Use the current directory at start time for .PARSEDIR, if the filename
contains no /.
2011-02-20 23:12:09 +00:00
christos
d670c5cfeb Instead of keeping around the mtime of the youngest child, keep a pointer
to it, so that we can print it when we do the out of date determination.
2010-11-25 21:31:08 +00:00
sjg
4db43f7e0c Add meta.c which implements "meta" mode for make.
In this mode, a .meta file is created for each target, capturing
the expanded commands used, any command output, and if filemon(9)
is available, a record of system calls which are of interest.
Not enabled unless USE_META=yes is set when building make.
Also, if FILEMON_H exists, meta.c will be compiled to use filemon(9).
2010-09-13 15:36:57 +00:00