Commit Graph

728 Commits

Author SHA1 Message Date
rillig 2864ddb2e9 make: clean up API for iterating over hash tables 2024-05-31 05:50:11 +00:00
rillig f3426a08ed make: use fewer technical terms in debug message for dependency 2024-05-25 22:08:35 +00:00
rillig 734fc80208 make: fix memory leak for command strings 2024-05-25 21:07:48 +00:00
rillig c05c85b7d7 make: fix some more memory leaks 2024-05-25 08:03:19 +00:00
rillig dd76681b7b make: fix a few more memory leaks 2024-05-25 00:00:25 +00:00
sjg c86b32d1f8 make: use separate function to include makefiles.
Have Dir_FindFile and Dir_FindInclude call FindFile with a
bool flag to indicate whether .CURDIR should be be searched at all.
2024-05-19 20:09:40 +00:00
rillig 1bf9200945 make: simplify freeing of lists 2024-04-27 17:33:46 +00:00
rillig 3f936286b0 make: clean up comments, code and tests 2024-04-23 22:51:28 +00:00
rillig 873c42efc3 make: provide more context information for parse/evaluate errors 2024-04-20 10:18:55 +00:00
rillig 141cc6832d make: add debug logging for .if and .for lines in -dp mode
This helps track down in which line a condition is evaluated.
2024-04-14 12:30:47 +00:00
rillig 311476f316 make: exit immediately after reading a null byte from a makefile
The chance of other garbage bytes in such a file is just too high.
2024-04-01 12:26:02 +00:00
rillig 0dd36725b6 make: remove unneeded conditional-compilation toggles
The toggles INCLUDES, LIBRARIES, POSIX, SYSVINCLUDE, SYSVVARSUB,
GMAKEEXPORT and SUNSHCMD are no longer needed, they were unconditionally
set.

The toggle NO_REGEX was configurable from the command line, but
disabling it would result in various error messages about the unknown
':C' modifier.

OK sjg@.
2024-02-07 06:43:02 +00:00
rillig 1ef9033a57 make: clean up comments, constify shell name 2024-01-07 11:39:04 +00:00
rillig f60719f052 make: miscellaneous cleanups 2024-01-05 23:22:06 +00:00
sjg 8779a040c6 make: do not add newline to an empty buffer
When LoadFile reads from /dev/null the buffer will be empty,
appending "\n" just results in an unnecessary extra call
to ParseRawLine.

Reviewed by: rillig
2024-01-03 20:24:16 +00:00
rillig e13d43880d make: unexport list memory management functions
They are only used in a single source file.

No functional change.
2023-12-29 20:43:58 +00:00
rillig d3b2cbfcdf make: clean up comments
No binary change, except for line numbers in assertions.
2023-12-19 19:33:39 +00:00
rillig 81cbe5a1c0 make: clean up names of local variables
No binary change.
2023-12-17 08:53:54 +00:00
rillig f2b68e81c5 make: replace 'variable expression' with 'expression' in comments
No binary change.
2023-11-19 22:50:11 +00:00
rillig 10b0fc2dcb make: miscellaneous cleanups
No functional change.
2023-11-02 05:55:22 +00:00
rillig a76be09c2a make: clean up comments
No functional change.
2023-11-02 05:40:49 +00:00
rillig 713aa52bfd make: inline a single-line cross-file function
No functional change.
2023-11-02 04:50:44 +00:00
rillig 2c49585ea5 make: show realistic invalid line in error message
Previously, the error message 'Invalid line' showed only the expanded
line, which might or might not show the actual problem.  To be more
helpful, add the unexpanded line to the error message in case they
differ.

Remove the special handling of invalid lines that result from merge
conflicts.  RCS is not commonly used anymore, and mentioning CVS was too
specific.  By echoing the whole line, the patterns '<<<<<<' and '>>>>>>'
are clear enough to hint at the problem.
2023-08-19 11:09:02 +00:00
rillig 64c6dcb455 make: add more details to error message about invalid lines 2023-08-19 10:52:13 +00:00
rillig 5d5041ee0f make: sync a comment with reality
No binary change.
2023-06-23 06:08:56 +00:00
rillig cb47d8fabf make: skip a file protected by a multiple-inclusion guard more often
In practice, the common situation is that a file is first included,
defines its multiple-inclusion guard and is then skipped instead of
being included again.

The other way round is that the multiple-inclusion guard is defined when
the file is included first.  In that case, the file is now regarded as
guarded as well.
2023-06-21 14:33:36 +00:00
rillig d7881bb6ea make: allow targets to be used as multiple-inclusion guards
This style is used by FreeBSD, among others.
2023-06-20 09:25:33 +00:00
rillig 9bda8c7f54 make: clean up code for skipping files with multiple-inclusion guard
No functional change.
2023-06-19 17:30:56 +00:00
rillig 389a96d8da make: if a makefile is protected by a guard, only include it once
"looks reasonable" sjg@
2023-06-19 12:53:57 +00:00
rillig 72cb4673f3 make: error out on a .break directive with arguments 2023-06-01 06:25:34 +00:00
rillig e1e6d6961e make: don't print null filename in stack traces
~~~makefile
!= printf '%s\n' '.include "2.mk"' > 1.mk
!= printf '%s\n' '!= rm 1.mk' '.info message' > 2.mk

.MAKEFLAGS: -dp
.include "1.mk"
.MAKEFLAGS: -d0

all:
~~~
2023-05-10 16:10:02 +00:00
rillig b828d76d72 make: clean up comments 2023-05-10 15:57:16 +00:00
rillig 6d7e33c958 make: inline macros for variable names
The variable name '.MAKEOVERRIDES' was already used in the non-macro
form.

No binary change.
2023-02-15 06:52:58 +00:00
rillig 20bc004c0c make: inline macro for variable name ".MAKE.EXPORTED"
The variable name is distinctive enough to be searched directly in the
code instead of having a named constant for it.

No binary change.
2023-02-15 06:31:51 +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
rillig 192d43a788 make: reduce complexity of evaluating expressions
No functional change.
2023-02-14 21:08:00 +00:00
sjg 8e4b5cfef0 make: .SYSPATH: to add dirs to sysIncPath
.SYSPATH: with no sources will clear sysIncPath
otherwise sources are added

Reviewed by: rillig
2023-01-24 00:24:02 +00:00
sjg ca0cc05370 make: .[NO]READONLY for control of read-only variables
Reviewed by: rillig
2023-01-23 23:01:52 +00:00
rillig 2d37fb2a80 make: add more details to warning 'Extra targets ignored'
Seen in binutils/zlib/Makefile.in:1283, which defines both '.MAKE' and
'.PHONY' in the same line.
2023-01-03 00:00:45 +00:00
rillig 7b4583082f make: use consistent variable names in parser
No functional change.
2022-10-01 09:25:06 +00:00
rillig 04db2675e2 make: set WARNS to 6, from the default 5
No binary change on x86_64.
2022-09-27 17:46:58 +00:00
rillig 87712b206e make: clean up tracking of depth of nested .if directives
The variable cond_min_depth was redundant.  It was only accessed while
parsing the makefiles.  Merging it into struct IncludedFile removes the
possible confusion between cond_min_depth and including_cond_min_depth.

No functional change.
2022-09-24 16:13:48 +00:00
rillig 427aba400c make: only access the list of included files if it is non-empty 2022-09-24 16:09:04 +00:00
rillig 495788510c make: fix variable and function names relating to .if nesting
The previous names were confusing since they suggested that cond_depth
instead of cond_min_depth would be saved and restored.

No functional change.
2022-09-24 10:26:31 +00:00
sjg a819e1f47a Cond_reset_depth just use cond_min_depth
To avoid errors from unclosed conditionals on .break
it is sufficient to just set cond_depth = cond_min_depth.

Patch from rillig
2022-09-23 22:58:15 +00:00
rillig 863fcc7b0b make: clean up handling of .break in .for loops
Move For_Break further up, as the functions in that file are sorted from
small to big.  The cast from size_t to unsigned int is required by lint.

In parse.c, move the code into a separate function to keep
ParseDirective small.  Its only job is to parse the directive and then
delegate to another function doing the actual work.

In the manual page, remove empty lines.

In the test, ensure that .break stops processing of the .for loop
immediately; anything after the .break is not processed anymore.
Replace ':=' with '=', as there is no need to evaluate '$i' early.
Check the expected value in the .mk file instead of the .exp file, to
keep the reading scope as small as possible.
2022-09-03 00:50:07 +00:00
sjg 5cc8492191 make: add .break to terminate .for loop early
When .break is encountered within a .for loop
it causes immediate termination.

Outside of a .for loop .break causes a parse error.

Reviewed by: christos
2022-09-02 16:24:31 +00:00
rillig 6e619e7e36 make: fix out-of-bounds read when parsing an invalid line
Reported by Robert Morris in https://bugs.freebsd.org/265119.

Since 2021-12-14.
2022-07-24 20:25:23 +00:00
rillig 67f66322f4 make: reorganize Parse_Error
Determining the location where the error occurred is now done by
ParseVErrorInternal.  This frees the remaining code from keeping the
filename and the line number together.  It also makes Parse_Error short
enough that it might be worth providing a separate function for each of
the 3 log levels.

No functional change.
2022-06-12 13:37:32 +00:00
rillig 78deb0379f make: fix memory leak in wildcard targets and sources
$ cat <<'EOF' > glob-leak.mk
all:
	@pid=$$$$; \
	ppid=$$(ps -o ppid -p "$$pid" | sed 1d); \
	ps -o vsz,rsz -p $$ppid | sed 1d

.for _ in ${:U:${:Urange=$n}}
bin/*: source
.endfor
EOF

$ make.before -r -f glob-leak.mk n=1
19424 5280
$ make.before -r -f glob-leak.mk n=10
24220 10208
$ make.before -r -f glob-leak.mk n=100
71280 58504
$ make.before -r -f glob-leak.mk n=1000
556356 541620

$ make.after -r -f glob-leak.mk n=1
19208 5040
$ make.after -r -f glob-leak.mk n=10
22132 8092
$ make.after -r -f glob-leak.mk n=100
49040 35940
$ make.after -r -f glob-leak.mk n=1000
324160 314400

That's a saving of 40% already.  The remaining 60% are suspicious as
well since after the first iteration of the .for loop, make's internal
state doesn't change conceptually, so there's no need to throw more
memory at it.
2022-06-11 17:58:15 +00:00