Commit Graph

208 Commits

Author SHA1 Message Date
rillig 1bf9200945 make: simplify freeing of lists 2024-04-27 17:33:46 +00:00
rillig 9bb158b559 make: clean up unused return value of str2Lst_Append
No functional change.
2023-12-17 09:02:26 +00:00
sjg 5452dd36cb meta_ignore: check metaIgnorePaths on raw path
Some path prefixes can trigger automount, if we want to ignore them
it might be best to check metaIgnorePaths before we call realpath.
If the raw path does not match, check again after realpath.
2023-08-19 00:09:17 +00:00
rillig 3c2f2cbb8f make: declare all common symbols in headers, unexport others
No functional change.
2023-03-28 14:39:31 +00:00
sjg 18e5949a8d Use inline function rather that macro BM 2023-02-28 06:04:28 +00:00
sjg 6f6525029a meta.c: use macro to access job->bm
and if job is NULL use Mybm.

No functional change.
2023-02-25 22:52:21 +00:00
rillig a4cbe1d736 make: clean up calls to Var_Subst
None of the calls to Var_Subst used the return value, and the return
value was always VPR_OK.

No functional change.
2023-02-14 21:38:31 +00:00
sjg 9cebc24e85 Don't ignore return from snprintf or getcwd 2022-09-28 16:34:47 +00:00
rillig 588ed71a5f make: do not use __CONCAT and __STRING in meta_needed
Using __CONCAT for identifiers makes it impossible to find their usages
easily, as could be seen in targ.c 1.22 from 2001-07-03.  It also
requires that the parts of the identifier are not macros themselves.

No binary change.
2022-04-15 12:28:16 +00:00
sjg e56a2ae17f Fix some unused warnings 2022-03-04 23:17:16 +00:00
rillig b64904b413 make: remove redundant conditions
A line starting with '======' is parsed as a variable assignment, with
an empty variable name and a value starting with '=====', making that
condition unreachable.

No functional change.
2022-02-09 21:28:57 +00:00
sjg f153d1ed09 Use a variable to store command line to be filtered.
This avoids any nasty side effects from content of command line.

Reviewed by: rillig
2022-02-08 22:36:02 +00:00
rillig 54add74bf1 make: use unsigned int for line numbers everywhere
Previously, some line numbers were stored as signed int while others
were stored as size_t.  Since line numbers are never negative, use an
unsigned type.  Since the maximum file size for makefiles is 1 GB (see
loadfile), unsigned int is large enough even on 64-bit platforms.

Using a single data types reduces the number of type conversions.  Using
unsigned int improves compatibility with C90 (printf %u instead of %zu),
which is needed by bmake, which is derived from usr.bin/make.

No functional change.
2022-02-04 23:22:19 +00:00
sjg 30df8a48fa Allow local variable assignments in dependency lines
The variable is set in the context of the target.
This syntax has been supported by gmake for ~ever.
If necessary a makefile can set .MAKE.TARGET_LOCAL_VARIABLES=false
to disable this.

Expose GetBooleanExpr so parse.c can use it.
2022-01-27 06:02:59 +00:00
rillig 9c9a198116 make: clean up eat_dots for meta mode, part 2
At least on OpenBSD, "If the src and dst strings overlap, the behavior
is undefined" (since 2013-09-25), so rather use memmove instead.

Keep all other bugs for now, for example "/a/b//../" is reduced to
"/a/b/" instead of the correct "/a/", and for repeated "/././././" in
long paths, the performance is quadratic instead of linear.

Inline the two calls to eat_dots, turning the first into a two-liner.
2022-01-26 12:41:26 +00:00
rillig be6d53ad03 make: clean up eat_dots for meta mode
No binary change.
2022-01-26 12:16:03 +00:00
rillig 9c1d64c23c make: replace Var_Value with Var_Exists where applicable
The latter function already existed in 1993, no idea why it was not
used.

No functional change.
2022-01-15 19:34:07 +00:00
rillig 2ae09f1b0c make: remove unnecessary functions for expanding variable names
In meta mode, the affected variable patterns do not contain a '$'.

Outside of meta mode, Global_SetExpand was only called a single time, so
inline that call.

No functional change.
2022-01-15 19:05:23 +00:00
rillig bbf0adc973 make: merge duplicate code for expanding variable expressions
No functional change.
2022-01-15 18:34:41 +00:00
rillig 0afc365659 make: remove trailing whitespace in meta.c 2022-01-15 09:08:57 +00:00
sjg 2b8714f27a meta_cmd_cmp: use bool for once
Just use Buf_Init() some mallocs will be inevitable.
2022-01-14 18:43:23 +00:00
sjg 3e72ec5137 meta.c: add .MAKE.META.CMP_FILTER
On rare occasions it is useful to be able to filter command lines
before comparison.
2022-01-13 04:51:50 +00:00
rillig 2c4470c7fa make: fix indentation in meta.c 2021-12-13 01:51:12 +00:00
rillig 9349f183d2 make: remove CONSTCOND comments, lint no longer needs them 2021-11-27 22:04:02 +00:00
sjg 7cd58762ea Do not ignore write failures.
We should not ignore failure to write to cmdFILE,
meta files and filemon.

Reviewed by: rillig
2021-10-24 18:45:46 +00:00
rillig b0baaa75cb make: fix lint warning about strrchr discarding 'const'
No functional change.
2021-08-19 15:50:30 +00:00
rillig 1642998508 make: fix lint warning about strchr removing 'const'
No functional change.
2021-08-14 13:04:00 +00:00
rillig 730db1a03f make: rename a few functions to be more descriptive
No functional change.
2021-04-04 10:05:08 +00:00
rillig 244fd9f4c4 make: use C99 bool type instead of defining its own
No functional change.
2021-04-03 11:08:40 +00:00
rillig 2f8026b0e5 make: replace enum bit-field with struct bit-field for VarEvalFlags
This makes the code easier to read, especially in var.c.  It also makes
debugging sessions easier since some debuggers don't show enum
bit-fields symbolically as soon as more than one bit is set.

The code outside var.c is basically unchanged, except that instead of
passing the individual flags, there are 4 predefined evaluation modes.
These suffice for all practical use cases.  Only in the implementation
deep inside var.c, the value of the flags keepDollar and keepUndef
differs.

There is no way of passing the struct to EnumFlags_ToString, which means
the ToString function has to be spelled out explicitly.  This allows for
fine-tuning the representation in the debug log, to reduce the amount of
uppercae letters.

No functional change.
2021-03-15 12:15:03 +00:00
rillig 49c1680d06 make: remove freestanding freeIt variables
These variables all belong to a string variable.  Connect them using
FStr, which reduces the number of variables to keep track of.

No functional change.
2021-02-22 23:21:33 +00:00
sjg 2b67d42e71 Avoid strdup in mkTempFile
Require caller to pass a buffer and size if they
want the tempfile not unlinked.

Add Job_TempFile to handle blocking signals around
call to mkTempFile, so that meta_open_filemon can use it
in jobs mode.
2021-02-05 19:19:17 +00:00
rillig 835b4db442 make: in the Var_ functions, move the scope to the front
This change provides for a more natural reading order in the code.
Placing the scope first makes it immediately clear in which context the
remaining parameters are interpreted.

No functional change.
2021-02-05 05:15:12 +00:00
rillig 5980c2c341 make: rename some VAR constants to SCOPE
The word "context" does not fit perfectly to the variables that are
associate with a GNode, as the context is usually something from the
outside and the variables are more like properties inherent to the
GNode.

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

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

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

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

The other renamings (variable names "context", "ctxt", as well as
further comments) will be done in a follow-up commit.
2021-02-04 21:33:13 +00:00
rillig b3cadd8df0 make: rename Var_Delete to Var_DeleteExpand, Var_DeleteVar to Var_Delete
The function names now follow the naming scheme from the other functions
that handle variables.

There are several calls that remain syntactically unchanged but that
omit the call to strchr('$') now.  Since all these calls use constant
variable names, there is no functional change.
2021-02-03 15:08:17 +00:00
rillig a1bc5ad8cf make: replace Global_AppendExpand with Global_Append
All callers with a variable name that is guaranteed to not contain a
dollar sign have been converted to call Global_Append instead of the
previous Global_AppendExpand.  After that, Global_AppendExpand was
unused, therefore it was effectively just renamed.
2021-02-03 13:53:12 +00:00
rillig 87686000da make: replace Global_SetExpand with Global_Set for constant names 2021-02-03 08:08:18 +00:00
rillig 3ec10f8db6 make: use shortcut functions Global_SetExpand and Global_AppendExpand
There are many places where global variables are set or appended to.  To
reduce clutter and code size, encode the VAR_GLOBAL in the function
name.

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

Encoding the information whether the name is expanded or not in the
function name will make inconsistencies obvious in future manual code
reviews. Letting the compiler check this by using different types for
unexpanded and expanded variable names is probably not worth the effort.
There are still a few bugs to be fixed, such as in SetVar, which expands
the variable name twice in a row.
2021-02-03 08:00:36 +00:00
rillig 1baad74e75 make: clean up comments 2021-02-01 21:32:54 +00:00
rillig e820145aad make(1): fix a few inconsistencies for lint's strict bool mode 2021-01-16 20:49:31 +00:00
rillig 31940a95cd make(1): consistently use boolean expressions in conditions
Most of the make code already followed the style of explicitly writing
(ptr != NULL) instead of the shorter (ptr) in conditions.

The remaining 50 instances have been found by an experimental,
unpublished check in lint(1) that treats bool expressions as
incompatible to any other scalar type, just as in Java, C#, Pascal and
several other languages.

The only unsafe operation on Boolean that is left over is (flags &
FLAG), for an enum implementing a bit set.  If Boolean is an ordinary
integer type (the default), some high bits may get lost.  But if Boolean
is the same as _Bool (by compiling with -DUSE_C99_BOOLEAN), C99 6.3.1.2
defines that a conversion from any scalar to the type _Bool acts as a
comparison to 0, which cannot lose any bits.
2021-01-10 21:20:46 +00:00
rillig 462cbdfa37 make(1): fix lint warnings 2021-01-09 16:06:09 +00:00
rillig 71c58e78f7 make(1): replace pointers in controlling conditions with booleans 2020-12-31 17:39:36 +00:00
rillig 82632c2fd8 make(1): fix return type of macro DEBUG
This macro was supposed to return a boolean expression all the time, it
just hadn't been implemented this way.  This resulted in wrong output
for the test sh-flags, in compilation modes -DUSE_UCHAR_BOOLEAN and
-DUSE_CHAR_BOOLEAN, since in ParseCommandFlags, the expression
DEBUG(LOUD) didn't fit into a boolean.
2020-12-22 22:31:50 +00:00
rillig 94f06ed7ea make(1): fix undefined behavior in meta_oodate
Do not increment a null pointer.

Do not assign to a variable twice in the same statement.  To be fair,
this may be safe because of the sequence point when the function is
called, but anyway, it looks too close to undefined behavior.
2020-12-20 22:36:40 +00:00
rillig 06ccd6ce96 make(1): reduce scope of cp in meta_oodate
That function is way too long (550 lines) and has too creative variable
names such as fname, fname1, fname2, fname3.
2020-12-20 22:12:36 +00:00
rillig 4b4d56707b make(1): fix declared variable type in printCMDs
No functional changes since StringListNode and GNodeListNode are both
typedefs of a simple generic ListNode.
2020-12-20 22:02:54 +00:00
rillig 0307413016 make(1): change return type of Var_Value to FStr 2020-12-20 14:32:13 +00:00
rillig ed7166493f make(1): replace %zu with %u in printf calls
This is needed to compile bmake with GCC 2.8.1 on SunOS 5.9.

To support ancient systems like this, the whole code of usr.bin/make is
supposed to use only ISO C90 features, except for filemon, which is not
used on these systems.
2020-12-13 21:27:45 +00:00
rillig 7f604d4793 make(1): add str_basename to reduce duplicate code
The function basename from POSIX has a few unfortunate properties, it is
allowed to return a pointer to static memory.  This is too unreliable,
therefore this trivial own implementation.
2020-12-13 20:14:48 +00:00