summaryrefslogtreecommitdiff
path: root/usr.bin/make/make.h
AgeCommit message (Collapse)Author
2021-12-15make: amend leftover cleanups from the previous commitsrillig
No functional change.
2021-12-15make: format comments according to /usr/share/misc/stylerillig
Assisted by indent(1), with manual corrections due to its many remaining bugs. No functional change.
2021-12-15make: remove redundant comments for multiple-inclusion guardsrillig
2021-12-15make: remove space after ':' in bit-field declarationsrillig
As seen in /usr/share/misc/style.
2021-12-15make: mark several functions whose result must be usedrillig
Suggested by sjg, to catch more bugs like the memory leak in cond.c 1.303 from 2021-12-13. No binary change.
2021-12-15make: prevent memory leaks from buffersrillig
The warning about unused function results would have prevented the memory leak that was fixed in cond.c 1.303 from 2021-12-13.
2021-12-13make: convert debugging flags from enum to bit-fieldrillig
This gets rid of the magic numbers, making it possible to add another debug flag without renumbering the others. No functional change.
2021-12-13make: fix memory leak for filenames in .for loops (since 2013-06-18)rillig
Previously, each time a .for directive pushed its buffer on the input file stack, the current filename was duplicated. This was a waste of memory. The name of a file is typically only used while it is read in. There is one situation when the filename is needed for longer, which is when a target is defined. Since .for loops are implemented as a special form of included files, each .for loop duplicated the current filename as well. $ cat << EOF > for.mk .for i in 1 2 3 4 5 6 7 8 9 0 .for i in 1 2 3 4 5 6 7 8 9 0 .for i in 1 2 3 4 5 6 7 8 9 0 .for i in 1 2 3 4 5 6 7 8 9 0 .for i in 1 2 3 4 5 6 7 8 9 0 .for i in 1 2 3 4 5 6 7 8 9 0 .for i in 1 2 3 4 5 6 7 8 9 0 .endfor .endfor .endfor .endfor .endfor .endfor .endfor all: @ps -o rsz -p ${.MAKE.PID} EOF $ make-2021.12.13.03.55.16 -r -f for.mk RSZ 10720 $ ./make -r -f for.mk RSZ 1716 The difference is 8 MB, which amounts to 1 million .for loops.
2021-11-28make: fix a few lint warnings about type mismatch in enum comparisonsrillig
These warnings were triggered with the lint flag '-e', which enables additional checks on enums. This check would have detected the type mismatch from the previous commit. The check has a few strange warnings though, complaining about initialization of 'unsigned long' with 'unsigned long', so don't enable it for the official builds. No functional change.
2021-11-28make: fix leftover typo from previous refactoringrillig
2021-11-28make: convert GNodeFlags from enum into bit-fieldsrillig
Now that Enum_ToString is implemented for each type separately, it's easy to convert them to bit-fields. This gets rid of the magic numbers 12 for CYCLE and 13 for DONECYCLE that left a suspicious gap in the numbers. This gap was not needed since the code didn't make use of the relative ordering of the enum constants. The effects of this conversion are fewer capital letters in the code, smaller scope for the GNode flags, and clearer code especially when setting a flag back to false. One strange thing is that GCC 10.3.0 doesn't optimize GNodeFlags_IsNone to an single bitmasking instruction, at least on x86_64. Instead it generates a testb instruction for each of the flags, even loading bit 8 separately from the others. Clang 12.0.1 knows this optimization though and generates the obvious sequence of movzwl, testl, jz. No functional change.
2021-11-28make: replace bloated bit-set-to-string code with simple coderillig
It was a nice idea to implement a bit-set using an enum type and have a generic ToString function for them. In the end, the implementation involved really heavy preprocessor magic and was probably difficult to understand. Replace all the code with a few bits of straight-forward preprocessor magic that can be readily understood by just looking 5 lines around, instead of digging through 130 lines of lengthy macro definitions. Curiously, this reduces the binary size even though the 3 ToString functions now have a few lines of duplicate code and there are more explicit function calls. The ToString functions are only seldom used, so the additional memory allocation is acceptable. No functional change.
2021-11-27make: remove CONSTCOND comments, lint no longer needs themrillig
2021-09-12make: error out if a pre-C99 platform defines bool in some casesrillig
On NetBSD/amd64 9.99.88, when compiling make in C90 mode, make.h defined its own boolean type as an alias for unsigned int. Not plain int since that would make the value of bit-fields -1 instead of 1. This worked fine for all files except main.c, which includes <sys/sysctl.h>, which in turn includes <stdbool.h> unconditionally, even in C90 mode. This meant that in main.c, sizeof(bool) was 1, while in all other files it was 4. This in turn led to a segmentation fault when ParseDependencySourceMain tried to access opts.create. Since parse.c assumed sizeof(bool) == 4, it computed an offset outside of struct CmdOpts, which was defined in main.c with sizeof(bool) == 1. Rather than risking these segmentation faults, prevent building make on platforms like these and suggest a proper workaround.
2021-07-31make: fix lint warningsrillig
The string functions from str.h are declared as 'static __unused' when compiled with GCC, but lint explicitly undefines __GCC__ during preprocessing. Therefore, make those functions inline, to prevent warnings that they are unused. The macro UNCONST is used in a few places, and (again) since lint undefines __GCC__, that macro expanded to a simple type cast, which lint warned about. To prevent this warning, implement UNCONST as a function that works everywhere and hides the type cast. In filemon_open, the code for closing F->in was obviously unreachable. No functional change.
2021-06-21make: document where to find tests for the dependency linesrillig
2021-04-14make: let the compiler decide whether to inline string functionsrillig
On x86_64, this reduces the binary size by 2 kB.
2021-04-11make: add types Substring and LazyBufrillig
These will be used for making the string handling more efficient, avoiding allocations, especially when evaluating variable expressions. Since the string handling has grown quite a bit in the last months, extract it into its own header file. No functional change.
2021-04-04make: rename a few functions to be more descriptiverillig
No functional change.
2021-04-03make: revert accidental change from the previous commitrillig
The definition of MAKE_GNUC_PREREQ was not supposed to be changed. This change only slipped accidentally, the test for __STDC_VERSION__ was only supposed to be for UNCONST.
2021-04-03make: backport to C90rillig
In the past few months I had accidentally used C99 features in the make code. According to tools/README, tools that are used in the build system should restrict themselves to C90. This allows make to build with GCC's options "-pedantic -Wno-system-headers -Dinline= -Wno-error=cast-qual". I didn't notice anyone actively complaining though, I just wanted to see how much work this backporting would be. The identifier __func__ is still used, as in other tools. No functional change.
2021-04-03make: use C99 bool type instead of defining its ownrillig
No functional change.
2021-02-05Avoid strdup in mkTempFilesjg
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-05make: improve documentation about variable scopesrillig
In an experiment, I tried to separate the concepts of a GNode and a variable scope. The global variables SCOPE_GLOBAL, SCOPE_INTERNAL and SCOPE_CMDLINE are implemented as GNode even though they only need the members 'name' and 'vars'. All their other members are unused. Therefore it seemed natural to extract this part of the GNode into a separate type called Scope. The resulting code was harder to read though since it had split the namespace of the functions into several parts that were not obviously related: The Var_ functions, the Scope_ functions, and the short-cut Global_ functions. Because of this, I threw away the experiment. All that is left are a few updated comments.
2021-02-04make: rename Var_ValueDirect to GNode_ValueDirectrillig
2021-02-04make: rename context and ctxt to scoperillig
This continues the previous commit, in which VAR_GLOBAL, VAR_INTERNAL and VAR_CMDLINE were renamed. Renaming the variable 'ctxt' was trivial since that word is used nowhere else. In the comments though, each occurrence of the word 'context' had to be checked individually since the word 'context' was not only used for referring to a variable scope. It is also used to distinguish different situations where characters are escaped in a certain way ('parsing context') and in a few other expressions.
2021-02-04make: rename some VAR constants to SCOPErillig
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-02make: remove unused INTERNAL flagrillig
It had been used for cached_realpaths, until this variable had its type changed from GNode to HashTable in main.c 1.469 from 2020-11-14.
2021-02-01make: clean up commentsrillig
2021-02-01make: indent preprocessor directives consistentlyrillig
As seen in share/misc/style.
2021-02-01make: always use vfork, never forkrillig
Before compat.c 1.217, job.c 1.390 and main.c 1.504 from 2020-12-27, the exported make variables were exported from each freshly forked child process. There was no practical difference though between exporting the variables from the parent process or the child process since these two processes share the same address space, except that the forked process is very limited in what it may actually do. This limitation was violated on a regular basis. When an exported variable referred to a variable that used the :sh variable modifier, this led to a fork from within vfork, which is not allowed. Since 2020-12-27, exporting the variables is done from the main process, which prevents this situation from ever occurring. Since that day, there is no need anymore to distinguish between vfork and fork, which removes any need for the macro.
2021-02-01make: use bit shifts in enum constants for GNodeFlagsrillig
Same as in the other enum bit sets. This makes it easier to spot the gap between bit 6 and bit 12.
2021-01-24make(1): convert SearchPath to structrillig
This prepares for making dotLast a simple struct member instead of a fake CachedDir, which is easier to understand.
2021-01-21make(1): merge duplicate code in Parse_MainNamerillig
2021-01-19make(1): remove do-not-format markers from commentsrillig
These markers had been used inconsistently. Furthermore the source code had not been formatted automatically before 2020 at all, otherwise there wouldn't have been any trailing whitespace left.
2021-01-16make(1): fix a few inconsistencies for lint's strict bool moderillig
2021-01-10make(1): consistently use boolean expressions in conditionsrillig
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.
2020-12-30make(1): format multi-line commentsrillig
2020-12-28make(1): replace global preserveUndefined with VARE_KEEP_UNDEFrillig
Controlling the expansion of variable expressions using a global variable and a VARE flag was inconsistent. Converting the global variable into a flag had to prerequisites: 1. The unintended duplicate variable assignment had to be fixed, as done in parse.c 1.520 from 2020-12-27. Without this fix, it would have been necessary to add more flags to Var_Exists and Var_SetWithFlags, and this would have become too complex. 2. There had to be a unit test demonstrating that VARE_KEEP_DOLLAR only applies to the top-level expression and is not passed to the subexpressions, while VARE_KEEP_UNDEF applies to all subexpressions as well. This test is in var-op-expand.mk 1.10 from 2020-12-28, at least for the ':@word@' modifier. In ParseModifierPartSubst, VARE_KEEP_UNDEF is not passed down either, in the same way.
2020-12-23make(1): fix lint warnings for constant condition in DEBUG callsrillig
2020-12-23make(1): fix MAKE_RCSID for lint moderillig
Previously, running lint mode didn't define MAKE_RCSID at all, which resulted in a syntax error. While here, reduced the indentation and nesting of the preprocessor directives.
2020-12-23make(1): rename CmdOpts.lint to strictrillig
When running lint(1) on the code, it defines the preprocessor macro "lint" to 1, which generated a syntax error in the declaration "Boolean lint", as that became "Boolean 1".
2020-12-22make(1): fix return type of macro DEBUGrillig
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-18make(1): support using C99 bool for Booleanrillig
2020-12-13make(1): constify prognamerillig
2020-12-11make(1): clean up comments for command line optionsrillig
2020-12-06make(1): clean up macros for debug loggingrillig
Using a do-while loop prevents compiler warnings about possible dangling else. It also removes the unnecessary negation.
2020-12-05make(1): define constants for enum zero-valuesrillig
2020-11-29make(1): use space instead of tab for preprocessor directivesrillig
2020-11-29make(1): reduce memory allocation for dirSearchPathrillig