summaryrefslogtreecommitdiff
path: root/usr.bin/make/parse.c
AgeCommit message (Collapse)Author
2023-06-23make: sync a comment with realityrillig
No binary change.
2023-06-21make: skip a file protected by a multiple-inclusion guard more oftenrillig
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-20make: allow targets to be used as multiple-inclusion guardsrillig
This style is used by FreeBSD, among others.
2023-06-19make: clean up code for skipping files with multiple-inclusion guardrillig
No functional change.
2023-06-19make: if a makefile is protected by a guard, only include it oncerillig
"looks reasonable" sjg@
2023-06-01make: error out on a .break directive with argumentsrillig
2023-05-10make: don't print null filename in stack tracesrillig
~~~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-10make: clean up commentsrillig
2023-02-15make: inline macros for variable namesrillig
The variable name '.MAKEOVERRIDES' was already used in the non-macro form. No binary change.
2023-02-15make: inline macro for variable name ".MAKE.EXPORTED"rillig
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-14make: clean up calls to Var_Substrillig
None of the calls to Var_Subst used the return value, and the return value was always VPR_OK. No functional change.
2023-02-14make: reduce complexity of evaluating expressionsrillig
No functional change.
2023-01-24make: .SYSPATH: to add dirs to sysIncPathsjg
.SYSPATH: with no sources will clear sysIncPath otherwise sources are added Reviewed by: rillig
2023-01-23make: .[NO]READONLY for control of read-only variablessjg
Reviewed by: rillig
2023-01-03make: add more details to warning 'Extra targets ignored'rillig
Seen in binutils/zlib/Makefile.in:1283, which defines both '.MAKE' and '.PHONY' in the same line.
2022-10-01make: use consistent variable names in parserrillig
No functional change.
2022-09-27make: set WARNS to 6, from the default 5rillig
No binary change on x86_64.
2022-09-24make: clean up tracking of depth of nested .if directivesrillig
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-24make: only access the list of included files if it is non-emptyrillig
2022-09-24make: fix variable and function names relating to .if nestingrillig
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-23Cond_reset_depth just use cond_min_depthsjg
To avoid errors from unclosed conditionals on .break it is sufficient to just set cond_depth = cond_min_depth. Patch from rillig
2022-09-03make: clean up handling of .break in .for loopsrillig
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-02make: add .break to terminate .for loop earlysjg
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-07-24make: fix out-of-bounds read when parsing an invalid linerillig
Reported by Robert Morris in https://bugs.freebsd.org/265119. Since 2021-12-14.
2022-06-12make: reorganize Parse_Errorrillig
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-11make: fix memory leak in wildcard targets and sourcesrillig
$ 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-11make: separate cases in HandleDependencyTargetMundanerillig
Most targets do not use wildcards, so there is no need to put the single item into a list. No functional change.
2022-06-11make: extract HandleSingleDependencyTargetMundanerillig
No functional change.
2022-06-11make: remove redundant include for stdint.hrillig
No functional change.
2022-06-10make: rename loadfile to LoadFilerillig
It was the only function in parse.c that had a lowercase name. No functional change.
2022-06-10make: split IncludeFile into separate functionsrillig
No functional change.
2022-06-10make: extract half of IncludeFile into a separate functionrillig
No functional change.
2022-06-10make: condense code for searching a file in the pathsrillig
No functional change.
2022-05-07make: fix off-by-one error in buffer for .WAIT nodesrillig
Strangely, GCC didn't warn about this error. For the buffer overflow to actually happen, there would have to be a billion .WAIT nodes.
2022-04-18Comment on interaction of posix.mk with[out] -rsjg
2022-04-18make: only switch to POSIX mode if '.POSIX:' is the first linerillig
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html says that in order to make a makefile POSIX-conforming, its first non-comment line must be the special dependency line '.POSIX:' without any source dependencies. Previously, make switched to POSIX mode even if such a line occurred anywhere else, which was allowed by POSIX but was deep in the "unspecified behavior" area. For NetBSD make, there is no big difference since it doesn't ship any <posix.mk> file, this change mainly affects the bmake distribution. Previously, makefiles that contain '.POSIX:' somewhere in the middle could fail due to <posix.mk> resetting .SUFFIXES, among other things. Suggested by Simon J. Gerraty, who also reviewed an earlier version of this change.
2022-03-25Include posix.mk when .POSIX: first encounteredsjg
Since .POSIX: is required to be the first non-comment line in a Makefile, including ${MAKE_POSIX_MK} or whatever _PATH_POSIX_MK is set to at this point is equivalent to an extension of sys.mk This is a minimal change that can allow a better approximation of POSIX compliance Reviewed by: rillig
2022-03-03make: improve comments and a parameter namerillig
No binary change.
2022-02-09make: remove redundant conditionsrillig
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-09make: fix mistakes, spelling and typos in comments and manual pagerillig
No binary change for -DNDEBUG.
2022-02-09make: clean up variable namesrillig
No binary change.
2022-02-07make: remove stray empty linerillig
No functional change.
2022-02-05Ensure Parse_IsVar does not step off the end of input string.sjg
2022-02-04make: use unsigned int for line numbers everywhererillig
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-01-29make: for recursive variables in commands, print locationrillig
Print the approximate location based on the last command that has been defined for the target. It would be possible to get more detailed location information by counting the number of commands of the target, but that would get messy due to .USEBEFORE, .USE and .DEFAULT, and still, this is an edge case, so don't waste too much code for it now. Having this hint about the location is more helpful than just a plain "Variable X is recursive" without any further details.
2022-01-29make: print stack trace on fatal errorsrillig
The only fatal error that occurs while the makefiles are read in is the one about recursive variables, which didn't give any hint about the location before. If a recursive variable is detected while evaluating the commands of a target to be made, there is no location information, as before.
2022-01-29make: inline functions that have a single call siterillig
No functional change.
2022-01-27make: remove trailing whitespace, break linesrillig
No binary change, except for assertion line numbers.
2022-01-27Allow local variable assignments in dependency linessjg
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-22make: add missing newline after "cannot continue" messagerillig
It was wrong of Parse_File to output an unfinished line and hope for some other code to finish it. As demonstrated in the test, PrintOnError did not do that in the case of additional debug output. To keep the overall behavior as close as possible to before, the other callers of PrintOnError now have to pass the newline themselves. Passing strings that start with newlines but don't end with them looked suspicious anyway.