Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build system: add mamake features, start refactoring Mamfiles
This adds three interrelated features to mamake and refactors the Mamfiles to take advantage of them. The new features are: 1. A new strict mode level 2 that activates some more backward incompatible tweaks for general sanity. See details below. 2. A new 'shim' command that works much like 'exec', except it defines common code prepended to all subsequent shell actions. 3. A new 'loop' block command that repeatedly processes the lines between it and 'done', with an iteration variable set to each of a series of whitespace-separated values. The Mamfiles are refactored to take advantage of these. That work is not done yet, they can be refactored further to make them easier to read and maintain. But they are now actually starting to look like they could have been designed by humans, although they remain very easy to parse by scripts (and I intend to keep them that way). src/cmd/INIT/mamake.c: - substitute(): - Add comments for legibility; some reformatting. - At strict >= 2, always keep ${foo:-bar}, ${foo:+bar}, ${foo:=bar}, ${foo=bar} unexpanded for passing on to shell scripts in 'exec'. They're irrelevant for MAM syntax and this allows Mamfiles to use common these shell language features. - At strict >= 2, disable a absurd hack that made ${mam_lib*} variables expand to only the first whitespace-separated word of the value after ${AR} was encountered. It was only used once, in libcmd/Mamfile (see below). - At strict >= 2, disable the insanity that is recursive expansion of variable references in variable values. All variables now expand to their literal values instead. - input(): - Exit on read error. - run(): - At strict => 2, prepend 'set -f' (a.k.a. 'set -o noglob') to all shell actions, disabling global pathname expansion for safer field splitting: any '?', '*' or '[' in variable values will no longer cause unexpected pathname expansion. - Prepend the shim to shell actions if one was set. - If a shim was set, apply the prepended code as well as the shell action itself to viewpathing; the shim must be subjected to viewpathing as it becomes part of the shell action. - attributes(): - At strict => 2, remove the deprectated 'archive', 'generated' and 'joint' attributes (note that RULE_generated continues to exist as an internal attribute assigend by 'exec'). - make(): - Add three arguments to prepare for recursive invocation by 'loop' in the context of the same rule. - Rename 'z' (modification time) to 'modtime' for legibility. - When recursively invoked by 'loop', share cmd (the 'exec -' buffer) with the caller and skip rule initialisation. - Fix a bug: do not call bindfile() if the rule is virtual. The bug caused a virtual target (e.g. 'all' or 'install') to be skipped if a file by that name exists. - case KEY('d','o','n','e'): - Simply break (enforcing no arguments) when in loop. - Make 'mismatched done statement' error message more useful by reporting which 'make' it was mismatched with. - At strict >= 2, prohibit supplying attributes here (deprecated in strict==1). - case KEY('e','x','e','c'): - If a shim is buffered, set state.shim and reset the buffer; any subsequent 'shim' command will start setting a new shim. - case KEY('l','o','o','p'): - Added. See the code and comments for details. - case KEY('s','e','t','v'): - At strict => 2, do not remove " from variable values set. - Ignore 'setv MAMAKE_STRICT' if it was previously set. - When handling 'setv MAMAKE_STRICT', treat the argument as a string value representing an integer and store its conversion (the strict level) in state.strict. - case KEY('s','h','i','m'): - Added. This adds line of code to the shim buffer. - When in loop, pass both cmd (via the parentcmd pointer) and the current rule's modification time back to the caller. **/Mamfile: - Major refactoring, taking advantage of the new features. src/lib/libcmd/Mamfile: - Fix 'exec - ${AR} x ${mam_libsum} sumlib.o' to avoid needing the absurd ${AR} hack. The first word of ${mam_libsum} can trivially be extracted by the shell script instead: exec - set -- ${mam_libsum} # set positional parameters exec - ${AR} x "$1" sumlib.o # use only the first one src/cmd/INIT/mamake.{rt,tst}: - Add some regression tests. src/cmd/INIT/utils/Mamfile_indent: - Add support for 'loop'...'done' indentation. - Move 'setv AR' so it follows the definitions of the variables it depends on. This was the only fix necessary after removing support for recursive expansion of variable values. src/cmd/ksh93/bltins/enum.c: - Use SH_DICT macro instead of ERROR_CATALOG like every other *.c file in src/cmd/ksh93; this allows enum.c to compile with the same compiler invocation (with -DSH_DICT="libshell").
- Loading branch information