-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mamake: add 4 "automatic variables" to reduce Mamfile redundancy
This is another step towards making the build system easier to maintain. The following special MAM variables are now set and updated automatically. They are inspired by similar automatic variables in make implementations, but since mamake is different, so are these variables. ${@} is the name of the rule currently being made. ${<} is the name of the prerequisite rule (make...done or prev) that was *last* processed within the current rule. ${^} is a space-separated list of names of all the current rule's previously processed prerequisites. ${?} is a space-separate list of the current rule's previously processed prerequisites that have been updated by a shell action during the current mamake run. Prequisites that were already up to date, or prerequisites that do not contain a shell action, are not included. */*/Mamfile: - Use the automatic variables to eliminate repetitive values (the single-source-of-truth principle). Many rules are now identical except for their rule name and prerequisites, showing the need for another new mamake feature that would make it possible to further reduce redundancy -- to come soon. src/cmd/INIT/mamake.c: - For ${?} we need to keep track of whether a rule was updated by a shell action during this run. Add a RULE_updated flag for this. - Declare global pointers to the automatic variable nodes. - Amend duplicate() to make it easy to reallocate a string using realloc(), with an optimisation that avoids allocating memory for the empty string; this works by declaring a global constant 'empty' pointer to an empty string and comparing value pointers to that before freeing them. The realloc version is called reduplicate(). - Amend search() to return the pointer to the node (root), not the node name (root->name), if a value was given. Only one call in rule() used the root->name return value, so that's easy to fix. - main(): Create the global automatic variable nodes while initialising the global pointers to them, which is made possible by the previous change. Set their initial values to the unallocated empty string. Their ->value pointers are never NULL. - Add a tweak to substitute() to allow '?' as the first character of a variable name without interpreting it as an operator; ${?} is not possible without it. - In make(), when processing 'exec', expand variables immediately upon collecting each line of script and don't wait with expanding them until 'done' when executing the script. This avoids getting confusing values of ${<}, ${^} and ${?}. - make(): For 'make' and 'prev', save, set and restore the automatic variables as required by their expected function. - Saving and restoring pointers on the C stack is needed to make nested rules do the right thing; nesting corresponds with make() call recursion, so that's easy. - The initialisation of the nodes in main() makes it possible to address the global node pointers directly without any repeated search() calls. - The new reduplicate() function makes it convenient to free/reallocate values.
- Loading branch information
Showing
9 changed files
with
1,357 additions
and
1,250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.